]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.8.0-201302252106.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.0-201302252106.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..dba90c5 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 @@ -185,6 +204,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 @@ -194,6 +215,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160 +pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164 @@ -203,7 +225,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 @@ -213,8 +238,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 @@ -224,6 +252,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 @@ -235,13 +264,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 @@ -249,9 +282,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 6c72381..2fe9ae4 100644
227 --- a/Documentation/kernel-parameters.txt
228 +++ b/Documentation/kernel-parameters.txt
229 @@ -917,6 +917,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
231 Default: 1024
232
233 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234 + ignore grsecurity's /proc restrictions
235 +
236 +
237 hashdist= [KNL,NUMA] Large hashes allocated during boot
238 are distributed across NUMA nodes. Defaults on
239 for 64-bit NUMA, off otherwise.
240 @@ -2116,6 +2120,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
241 the specified number of seconds. This is to be used if
242 your oopses keep scrolling off the screen.
243
244 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
245 + virtualization environments that don't cope well with the
246 + expand down segment used by UDEREF on X86-32 or the frequent
247 + page table updates on X86-64.
248 +
249 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
250 +
251 pcbit= [HW,ISDN]
252
253 pcd. [PARIDE]
254 diff --git a/Makefile b/Makefile
255 index d69266c..e4f6593 100644
256 --- a/Makefile
257 +++ b/Makefile
258 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
259
260 HOSTCC = gcc
261 HOSTCXX = g++
262 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
263 -HOSTCXXFLAGS = -O2
264 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
265 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
266 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
267
268 # Decide whether to build built-in, modular, or both.
269 # Normally, just do built-in.
270 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
271 # Rules shared between *config targets and build targets
272
273 # Basic helpers built in scripts/
274 -PHONY += scripts_basic
275 -scripts_basic:
276 +PHONY += scripts_basic gcc-plugins
277 +scripts_basic: gcc-plugins
278 $(Q)$(MAKE) $(build)=scripts/basic
279 $(Q)rm -f .tmp_quiet_recordmcount
280
281 @@ -575,6 +576,64 @@ else
282 KBUILD_CFLAGS += -O2
283 endif
284
285 +ifndef DISABLE_PAX_PLUGINS
286 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
287 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
288 +else
289 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
290 +endif
291 +ifneq ($(PLUGINCC),)
292 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
293 +ifndef CONFIG_UML
294 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
295 +endif
296 +endif
297 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
298 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
299 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
300 +endif
301 +ifdef CONFIG_KALLOCSTAT_PLUGIN
302 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
303 +endif
304 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
305 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
306 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
307 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
308 +endif
309 +ifdef CONFIG_CHECKER_PLUGIN
310 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
311 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
312 +endif
313 +endif
314 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
315 +ifdef CONFIG_PAX_SIZE_OVERFLOW
316 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
317 +endif
318 +ifdef CONFIG_PAX_LATENT_ENTROPY
319 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
320 +endif
321 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
322 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
323 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
324 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
325 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
326 +ifeq ($(KBUILD_EXTMOD),)
327 +gcc-plugins:
328 + $(Q)$(MAKE) $(build)=tools/gcc
329 +else
330 +gcc-plugins: ;
331 +endif
332 +else
333 +gcc-plugins:
334 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
335 + $(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.))
336 +else
337 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
338 +endif
339 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
340 +endif
341 +endif
342 +
343 include $(srctree)/arch/$(SRCARCH)/Makefile
344
345 ifdef CONFIG_READABLE_ASM
346 @@ -731,7 +790,7 @@ export mod_sign_cmd
347
348
349 ifeq ($(KBUILD_EXTMOD),)
350 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
351 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
352
353 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
354 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
355 @@ -778,6 +837,8 @@ endif
356
357 # The actual objects are generated when descending,
358 # make sure no implicit rule kicks in
359 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
360 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
361 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
362
363 # Handle descending into subdirectories listed in $(vmlinux-dirs)
364 @@ -787,7 +848,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
365 # Error messages still appears in the original language
366
367 PHONY += $(vmlinux-dirs)
368 -$(vmlinux-dirs): prepare scripts
369 +$(vmlinux-dirs): gcc-plugins prepare scripts
370 $(Q)$(MAKE) $(build)=$@
371
372 # Store (new) KERNELRELASE string in include/config/kernel.release
373 @@ -831,6 +892,7 @@ prepare0: archprepare FORCE
374 $(Q)$(MAKE) $(build)=.
375
376 # All the preparing..
377 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
378 prepare: prepare0
379
380 # Generate some files
381 @@ -938,6 +1000,8 @@ all: modules
382 # using awk while concatenating to the final file.
383
384 PHONY += modules
385 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
386 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
387 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
388 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
389 @$(kecho) ' Building modules, stage 2.';
390 @@ -953,7 +1017,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
391
392 # Target to prepare building external modules
393 PHONY += modules_prepare
394 -modules_prepare: prepare scripts
395 +modules_prepare: gcc-plugins prepare scripts
396
397 # Target to install modules
398 PHONY += modules_install
399 @@ -1019,7 +1083,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
401 signing_key.priv signing_key.x509 x509.genkey \
402 extra_certificates signing_key.x509.keyid \
403 - signing_key.x509.signer
404 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
405
406 # clean - Delete most, but leave enough to build external modules
407 #
408 @@ -1059,6 +1123,7 @@ distclean: mrproper
409 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
410 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
411 -o -name '.*.rej' \
412 + -o -name '.*.rej' -o -name '*.so' \
413 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
414 -type f -print | xargs rm -f
415
416 @@ -1219,6 +1284,8 @@ PHONY += $(module-dirs) modules
417 $(module-dirs): crmodverdir $(objtree)/Module.symvers
418 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
419
420 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 modules: $(module-dirs)
423 @$(kecho) ' Building modules, stage 2.';
424 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
425 @@ -1355,17 +1422,21 @@ else
426 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
427 endif
428
429 -%.s: %.c prepare scripts FORCE
430 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
431 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
432 +%.s: %.c gcc-plugins prepare scripts FORCE
433 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
434 %.i: %.c prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 -%.o: %.c prepare scripts FORCE
437 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
438 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
439 +%.o: %.c gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 %.lst: %.c prepare scripts FORCE
442 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
443 -%.s: %.S prepare scripts FORCE
444 +%.s: %.S gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 -%.o: %.S prepare scripts FORCE
447 +%.o: %.S gcc-plugins prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449 %.symtypes: %.c prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451 @@ -1375,11 +1446,15 @@ endif
452 $(cmd_crmodverdir)
453 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
454 $(build)=$(build-dir)
455 -%/: prepare scripts FORCE
456 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458 +%/: gcc-plugins prepare scripts FORCE
459 $(cmd_crmodverdir)
460 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
461 $(build)=$(build-dir)
462 -%.ko: prepare scripts FORCE
463 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
464 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
465 +%.ko: gcc-plugins prepare scripts FORCE
466 $(cmd_crmodverdir)
467 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
468 $(build)=$(build-dir) $(@:.ko=.o)
469 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
470 index c2cbe4f..f7264b4 100644
471 --- a/arch/alpha/include/asm/atomic.h
472 +++ b/arch/alpha/include/asm/atomic.h
473 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
474 #define atomic_dec(v) atomic_sub(1,(v))
475 #define atomic64_dec(v) atomic64_sub(1,(v))
476
477 +#define atomic64_read_unchecked(v) atomic64_read(v)
478 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
479 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
480 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
481 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
482 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
483 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
484 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
485 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
486 +
487 #define smp_mb__before_atomic_dec() smp_mb()
488 #define smp_mb__after_atomic_dec() smp_mb()
489 #define smp_mb__before_atomic_inc() smp_mb()
490 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
491 index ad368a9..fbe0f25 100644
492 --- a/arch/alpha/include/asm/cache.h
493 +++ b/arch/alpha/include/asm/cache.h
494 @@ -4,19 +4,19 @@
495 #ifndef __ARCH_ALPHA_CACHE_H
496 #define __ARCH_ALPHA_CACHE_H
497
498 +#include <linux/const.h>
499
500 /* Bytes per L1 (data) cache line. */
501 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
502 -# define L1_CACHE_BYTES 64
503 # define L1_CACHE_SHIFT 6
504 #else
505 /* Both EV4 and EV5 are write-through, read-allocate,
506 direct-mapped, physical.
507 */
508 -# define L1_CACHE_BYTES 32
509 # define L1_CACHE_SHIFT 5
510 #endif
511
512 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
514
515 #endif
516 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
517 index 968d999..d36b2df 100644
518 --- a/arch/alpha/include/asm/elf.h
519 +++ b/arch/alpha/include/asm/elf.h
520 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
521
522 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
523
524 +#ifdef CONFIG_PAX_ASLR
525 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
526 +
527 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
528 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
529 +#endif
530 +
531 /* $0 is set by ld.so to a pointer to a function which might be
532 registered using atexit. This provides a mean for the dynamic
533 linker to call DT_FINI functions for shared libraries that have
534 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
535 index bc2a0da..8ad11ee 100644
536 --- a/arch/alpha/include/asm/pgalloc.h
537 +++ b/arch/alpha/include/asm/pgalloc.h
538 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 pgd_set(pgd, pmd);
540 }
541
542 +static inline void
543 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544 +{
545 + pgd_populate(mm, pgd, pmd);
546 +}
547 +
548 extern pgd_t *pgd_alloc(struct mm_struct *mm);
549
550 static inline void
551 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
552 index 81a4342..348b927 100644
553 --- a/arch/alpha/include/asm/pgtable.h
554 +++ b/arch/alpha/include/asm/pgtable.h
555 @@ -102,6 +102,17 @@ struct vm_area_struct;
556 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
557 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
558 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
559 +
560 +#ifdef CONFIG_PAX_PAGEEXEC
561 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
562 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
563 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
564 +#else
565 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
566 +# define PAGE_COPY_NOEXEC PAGE_COPY
567 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
568 +#endif
569 +
570 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
571
572 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
573 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
574 index 2fd00b7..cfd5069 100644
575 --- a/arch/alpha/kernel/module.c
576 +++ b/arch/alpha/kernel/module.c
577 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
578
579 /* The small sections were sorted to the end of the segment.
580 The following should definitely cover them. */
581 - gp = (u64)me->module_core + me->core_size - 0x8000;
582 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
583 got = sechdrs[me->arch.gotsecindex].sh_addr;
584
585 for (i = 0; i < n; i++) {
586 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
587 index 14db93e..47bed62 100644
588 --- a/arch/alpha/kernel/osf_sys.c
589 +++ b/arch/alpha/kernel/osf_sys.c
590 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
591 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
592
593 static unsigned long
594 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
595 - unsigned long limit)
596 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
597 + unsigned long limit, unsigned long flags)
598 {
599 struct vm_area_struct *vma = find_vma(current->mm, addr);
600 -
601 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
602 while (1) {
603 /* At this point: (!vma || addr < vma->vm_end). */
604 if (limit - len < addr)
605 return -ENOMEM;
606 - if (!vma || addr + len <= vma->vm_start)
607 + if (check_heap_stack_gap(vma, addr, len, offset))
608 return addr;
609 addr = vma->vm_end;
610 vma = vma->vm_next;
611 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
612 merely specific addresses, but regions of memory -- perhaps
613 this feature should be incorporated into all ports? */
614
615 +#ifdef CONFIG_PAX_RANDMMAP
616 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
617 +#endif
618 +
619 if (addr) {
620 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
621 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
622 if (addr != (unsigned long) -ENOMEM)
623 return addr;
624 }
625
626 /* Next, try allocating at TASK_UNMAPPED_BASE. */
627 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
628 - len, limit);
629 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
630 +
631 if (addr != (unsigned long) -ENOMEM)
632 return addr;
633
634 /* Finally, try allocating in low memory. */
635 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
636 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
637
638 return addr;
639 }
640 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641 index 0c4132d..88f0d53 100644
642 --- a/arch/alpha/mm/fault.c
643 +++ b/arch/alpha/mm/fault.c
644 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648 +#ifdef CONFIG_PAX_PAGEEXEC
649 +/*
650 + * PaX: decide what to do with offenders (regs->pc = fault address)
651 + *
652 + * returns 1 when task should be killed
653 + * 2 when patched PLT trampoline was detected
654 + * 3 when unpatched PLT trampoline was detected
655 + */
656 +static int pax_handle_fetch_fault(struct pt_regs *regs)
657 +{
658 +
659 +#ifdef CONFIG_PAX_EMUPLT
660 + int err;
661 +
662 + do { /* PaX: patched PLT emulation #1 */
663 + unsigned int ldah, ldq, jmp;
664 +
665 + err = get_user(ldah, (unsigned int *)regs->pc);
666 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668 +
669 + if (err)
670 + break;
671 +
672 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674 + jmp == 0x6BFB0000U)
675 + {
676 + unsigned long r27, addr;
677 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679 +
680 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681 + err = get_user(r27, (unsigned long *)addr);
682 + if (err)
683 + break;
684 +
685 + regs->r27 = r27;
686 + regs->pc = r27;
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: patched PLT emulation #2 */
692 + unsigned int ldah, lda, br;
693 +
694 + err = get_user(ldah, (unsigned int *)regs->pc);
695 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
696 + err |= get_user(br, (unsigned int *)(regs->pc+8));
697 +
698 + if (err)
699 + break;
700 +
701 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
703 + (br & 0xFFE00000U) == 0xC3E00000U)
704 + {
705 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708 +
709 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711 + return 2;
712 + }
713 + } while (0);
714 +
715 + do { /* PaX: unpatched PLT emulation */
716 + unsigned int br;
717 +
718 + err = get_user(br, (unsigned int *)regs->pc);
719 +
720 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721 + unsigned int br2, ldq, nop, jmp;
722 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723 +
724 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725 + err = get_user(br2, (unsigned int *)addr);
726 + err |= get_user(ldq, (unsigned int *)(addr+4));
727 + err |= get_user(nop, (unsigned int *)(addr+8));
728 + err |= get_user(jmp, (unsigned int *)(addr+12));
729 + err |= get_user(resolver, (unsigned long *)(addr+16));
730 +
731 + if (err)
732 + break;
733 +
734 + if (br2 == 0xC3600000U &&
735 + ldq == 0xA77B000CU &&
736 + nop == 0x47FF041FU &&
737 + jmp == 0x6B7B0000U)
738 + {
739 + regs->r28 = regs->pc+4;
740 + regs->r27 = addr+16;
741 + regs->pc = resolver;
742 + return 3;
743 + }
744 + }
745 + } while (0);
746 +#endif
747 +
748 + return 1;
749 +}
750 +
751 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752 +{
753 + unsigned long i;
754 +
755 + printk(KERN_ERR "PAX: bytes at PC: ");
756 + for (i = 0; i < 5; i++) {
757 + unsigned int c;
758 + if (get_user(c, (unsigned int *)pc+i))
759 + printk(KERN_CONT "???????? ");
760 + else
761 + printk(KERN_CONT "%08x ", c);
762 + }
763 + printk("\n");
764 +}
765 +#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769 @@ -133,8 +251,29 @@ retry:
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773 - if (!(vma->vm_flags & VM_EXEC))
774 + if (!(vma->vm_flags & VM_EXEC)) {
775 +
776 +#ifdef CONFIG_PAX_PAGEEXEC
777 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778 + goto bad_area;
779 +
780 + up_read(&mm->mmap_sem);
781 + switch (pax_handle_fetch_fault(regs)) {
782 +
783 +#ifdef CONFIG_PAX_EMUPLT
784 + case 2:
785 + case 3:
786 + return;
787 +#endif
788 +
789 + }
790 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791 + do_group_exit(SIGKILL);
792 +#else
793 goto bad_area;
794 +#endif
795 +
796 + }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
801 index 67874b8..0e40765 100644
802 --- a/arch/arm/Kconfig
803 +++ b/arch/arm/Kconfig
804 @@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
805
806 config UACCESS_WITH_MEMCPY
807 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
808 - depends on MMU
809 + depends on MMU && !PAX_MEMORY_UDEREF
810 default y if CPU_FEROCEON
811 help
812 Implement faster copy_to_user and clear_user methods for CPU
813 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
814 index c79f61f..9ac0642 100644
815 --- a/arch/arm/include/asm/atomic.h
816 +++ b/arch/arm/include/asm/atomic.h
817 @@ -17,17 +17,35 @@
818 #include <asm/barrier.h>
819 #include <asm/cmpxchg.h>
820
821 +#ifdef CONFIG_GENERIC_ATOMIC64
822 +#include <asm-generic/atomic64.h>
823 +#endif
824 +
825 #define ATOMIC_INIT(i) { (i) }
826
827 #ifdef __KERNEL__
828
829 +#define _ASM_EXTABLE(from, to) \
830 +" .pushsection __ex_table,\"a\"\n"\
831 +" .align 3\n" \
832 +" .long " #from ", " #to"\n" \
833 +" .popsection"
834 +
835 /*
836 * On ARM, ordinary assignment (str instruction) doesn't clear the local
837 * strex/ldrex monitor on some implementations. The reason we can use it for
838 * atomic_set() is the clrex or dummy strex done on every exception return.
839 */
840 #define atomic_read(v) (*(volatile int *)&(v)->counter)
841 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
842 +{
843 + return v->counter;
844 +}
845 #define atomic_set(v,i) (((v)->counter) = (i))
846 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
847 +{
848 + v->counter = i;
849 +}
850
851 #if __LINUX_ARM_ARCH__ >= 6
852
853 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
854 int result;
855
856 __asm__ __volatile__("@ atomic_add\n"
857 +"1: ldrex %1, [%3]\n"
858 +" adds %0, %1, %4\n"
859 +
860 +#ifdef CONFIG_PAX_REFCOUNT
861 +" bvc 3f\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +}
879 +
880 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
881 +{
882 + unsigned long tmp;
883 + int result;
884 +
885 + __asm__ __volatile__("@ atomic_add_unchecked\n"
886 "1: ldrex %0, [%3]\n"
887 " add %0, %0, %4\n"
888 " strex %1, %0, [%3]\n"
889 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
890 smp_mb();
891
892 __asm__ __volatile__("@ atomic_add_return\n"
893 +"1: ldrex %1, [%3]\n"
894 +" adds %0, %1, %4\n"
895 +
896 +#ifdef CONFIG_PAX_REFCOUNT
897 +" bvc 3f\n"
898 +" mov %0, %1\n"
899 +"2: bkpt 0xf103\n"
900 +"3:\n"
901 +#endif
902 +
903 +" strex %1, %0, [%3]\n"
904 +" teq %1, #0\n"
905 +" bne 1b"
906 +
907 +#ifdef CONFIG_PAX_REFCOUNT
908 +"\n4:\n"
909 + _ASM_EXTABLE(2b, 4b)
910 +#endif
911 +
912 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
913 + : "r" (&v->counter), "Ir" (i)
914 + : "cc");
915 +
916 + smp_mb();
917 +
918 + return result;
919 +}
920 +
921 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
922 +{
923 + unsigned long tmp;
924 + int result;
925 +
926 + smp_mb();
927 +
928 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
929 "1: ldrex %0, [%3]\n"
930 " add %0, %0, %4\n"
931 " strex %1, %0, [%3]\n"
932 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
933 int result;
934
935 __asm__ __volatile__("@ atomic_sub\n"
936 +"1: ldrex %1, [%3]\n"
937 +" subs %0, %1, %4\n"
938 +
939 +#ifdef CONFIG_PAX_REFCOUNT
940 +" bvc 3f\n"
941 +"2: bkpt 0xf103\n"
942 +"3:\n"
943 +#endif
944 +
945 +" strex %1, %0, [%3]\n"
946 +" teq %1, #0\n"
947 +" bne 1b"
948 +
949 +#ifdef CONFIG_PAX_REFCOUNT
950 +"\n4:\n"
951 + _ASM_EXTABLE(2b, 4b)
952 +#endif
953 +
954 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
955 + : "r" (&v->counter), "Ir" (i)
956 + : "cc");
957 +}
958 +
959 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
960 +{
961 + unsigned long tmp;
962 + int result;
963 +
964 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
965 "1: ldrex %0, [%3]\n"
966 " sub %0, %0, %4\n"
967 " strex %1, %0, [%3]\n"
968 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
969 smp_mb();
970
971 __asm__ __volatile__("@ atomic_sub_return\n"
972 -"1: ldrex %0, [%3]\n"
973 -" sub %0, %0, %4\n"
974 +"1: ldrex %1, [%3]\n"
975 +" subs %0, %1, %4\n"
976 +
977 +#ifdef CONFIG_PAX_REFCOUNT
978 +" bvc 3f\n"
979 +" mov %0, %1\n"
980 +"2: bkpt 0xf103\n"
981 +"3:\n"
982 +#endif
983 +
984 " strex %1, %0, [%3]\n"
985 " teq %1, #0\n"
986 " bne 1b"
987 +
988 +#ifdef CONFIG_PAX_REFCOUNT
989 +"\n4:\n"
990 + _ASM_EXTABLE(2b, 4b)
991 +#endif
992 +
993 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
994 : "r" (&v->counter), "Ir" (i)
995 : "cc");
996 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
997 return oldval;
998 }
999
1000 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1001 +{
1002 + unsigned long oldval, res;
1003 +
1004 + smp_mb();
1005 +
1006 + do {
1007 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1008 + "ldrex %1, [%3]\n"
1009 + "mov %0, #0\n"
1010 + "teq %1, %4\n"
1011 + "strexeq %0, %5, [%3]\n"
1012 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1013 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1014 + : "cc");
1015 + } while (res);
1016 +
1017 + smp_mb();
1018 +
1019 + return oldval;
1020 +}
1021 +
1022 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1023 {
1024 unsigned long tmp, tmp2;
1025 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1026
1027 return val;
1028 }
1029 +
1030 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1031 +{
1032 + return atomic_add_return(i, v);
1033 +}
1034 +
1035 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1036 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1037 +{
1038 + (void) atomic_add_return(i, v);
1039 +}
1040
1041 static inline int atomic_sub_return(int i, atomic_t *v)
1042 {
1043 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1044 return val;
1045 }
1046 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1047 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1048 +{
1049 + (void) atomic_sub_return(i, v);
1050 +}
1051
1052 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1053 {
1054 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1055 return ret;
1056 }
1057
1058 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1059 +{
1060 + return atomic_cmpxchg(v, old, new);
1061 +}
1062 +
1063 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1064 {
1065 unsigned long flags;
1066 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1067 #endif /* __LINUX_ARM_ARCH__ */
1068
1069 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1070 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1071 +{
1072 + return xchg(&v->counter, new);
1073 +}
1074
1075 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1076 {
1077 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1078 }
1079
1080 #define atomic_inc(v) atomic_add(1, v)
1081 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1082 +{
1083 + atomic_add_unchecked(1, v);
1084 +}
1085 #define atomic_dec(v) atomic_sub(1, v)
1086 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1087 +{
1088 + atomic_sub_unchecked(1, v);
1089 +}
1090
1091 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1092 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1093 +{
1094 + return atomic_add_return_unchecked(1, v) == 0;
1095 +}
1096 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1097 #define atomic_inc_return(v) (atomic_add_return(1, v))
1098 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1099 +{
1100 + return atomic_add_return_unchecked(1, v);
1101 +}
1102 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1103 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1104
1105 @@ -241,6 +428,14 @@ typedef struct {
1106 u64 __aligned(8) counter;
1107 } atomic64_t;
1108
1109 +#ifdef CONFIG_PAX_REFCOUNT
1110 +typedef struct {
1111 + u64 __aligned(8) counter;
1112 +} atomic64_unchecked_t;
1113 +#else
1114 +typedef atomic64_t atomic64_unchecked_t;
1115 +#endif
1116 +
1117 #define ATOMIC64_INIT(i) { (i) }
1118
1119 static inline u64 atomic64_read(const atomic64_t *v)
1120 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1121 return result;
1122 }
1123
1124 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1125 +{
1126 + u64 result;
1127 +
1128 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1129 +" ldrexd %0, %H0, [%1]"
1130 + : "=&r" (result)
1131 + : "r" (&v->counter), "Qo" (v->counter)
1132 + );
1133 +
1134 + return result;
1135 +}
1136 +
1137 static inline void atomic64_set(atomic64_t *v, u64 i)
1138 {
1139 u64 tmp;
1140 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1141 : "cc");
1142 }
1143
1144 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1145 +{
1146 + u64 tmp;
1147 +
1148 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1149 +"1: ldrexd %0, %H0, [%2]\n"
1150 +" strexd %0, %3, %H3, [%2]\n"
1151 +" teq %0, #0\n"
1152 +" bne 1b"
1153 + : "=&r" (tmp), "=Qo" (v->counter)
1154 + : "r" (&v->counter), "r" (i)
1155 + : "cc");
1156 +}
1157 +
1158 static inline void atomic64_add(u64 i, atomic64_t *v)
1159 {
1160 u64 result;
1161 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162 __asm__ __volatile__("@ atomic64_add\n"
1163 "1: ldrexd %0, %H0, [%3]\n"
1164 " adds %0, %0, %4\n"
1165 +" adcs %H0, %H0, %H4\n"
1166 +
1167 +#ifdef CONFIG_PAX_REFCOUNT
1168 +" bvc 3f\n"
1169 +"2: bkpt 0xf103\n"
1170 +"3:\n"
1171 +#endif
1172 +
1173 +" strexd %1, %0, %H0, [%3]\n"
1174 +" teq %1, #0\n"
1175 +" bne 1b"
1176 +
1177 +#ifdef CONFIG_PAX_REFCOUNT
1178 +"\n4:\n"
1179 + _ASM_EXTABLE(2b, 4b)
1180 +#endif
1181 +
1182 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1183 + : "r" (&v->counter), "r" (i)
1184 + : "cc");
1185 +}
1186 +
1187 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1188 +{
1189 + u64 result;
1190 + unsigned long tmp;
1191 +
1192 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1193 +"1: ldrexd %0, %H0, [%3]\n"
1194 +" adds %0, %0, %4\n"
1195 " adc %H0, %H0, %H4\n"
1196 " strexd %1, %0, %H0, [%3]\n"
1197 " teq %1, #0\n"
1198 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1199
1200 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1201 {
1202 - u64 result;
1203 - unsigned long tmp;
1204 + u64 result, tmp;
1205
1206 smp_mb();
1207
1208 __asm__ __volatile__("@ atomic64_add_return\n"
1209 +"1: ldrexd %1, %H1, [%3]\n"
1210 +" adds %0, %1, %4\n"
1211 +" adcs %H0, %H1, %H4\n"
1212 +
1213 +#ifdef CONFIG_PAX_REFCOUNT
1214 +" bvc 3f\n"
1215 +" mov %0, %1\n"
1216 +" mov %H0, %H1\n"
1217 +"2: bkpt 0xf103\n"
1218 +"3:\n"
1219 +#endif
1220 +
1221 +" strexd %1, %0, %H0, [%3]\n"
1222 +" teq %1, #0\n"
1223 +" bne 1b"
1224 +
1225 +#ifdef CONFIG_PAX_REFCOUNT
1226 +"\n4:\n"
1227 + _ASM_EXTABLE(2b, 4b)
1228 +#endif
1229 +
1230 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1231 + : "r" (&v->counter), "r" (i)
1232 + : "cc");
1233 +
1234 + smp_mb();
1235 +
1236 + return result;
1237 +}
1238 +
1239 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + smp_mb();
1245 +
1246 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1247 "1: ldrexd %0, %H0, [%3]\n"
1248 " adds %0, %0, %4\n"
1249 " adc %H0, %H0, %H4\n"
1250 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251 __asm__ __volatile__("@ atomic64_sub\n"
1252 "1: ldrexd %0, %H0, [%3]\n"
1253 " subs %0, %0, %4\n"
1254 +" sbcs %H0, %H0, %H4\n"
1255 +
1256 +#ifdef CONFIG_PAX_REFCOUNT
1257 +" bvc 3f\n"
1258 +"2: bkpt 0xf103\n"
1259 +"3:\n"
1260 +#endif
1261 +
1262 +" strexd %1, %0, %H0, [%3]\n"
1263 +" teq %1, #0\n"
1264 +" bne 1b"
1265 +
1266 +#ifdef CONFIG_PAX_REFCOUNT
1267 +"\n4:\n"
1268 + _ASM_EXTABLE(2b, 4b)
1269 +#endif
1270 +
1271 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1272 + : "r" (&v->counter), "r" (i)
1273 + : "cc");
1274 +}
1275 +
1276 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1277 +{
1278 + u64 result;
1279 + unsigned long tmp;
1280 +
1281 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1282 +"1: ldrexd %0, %H0, [%3]\n"
1283 +" subs %0, %0, %4\n"
1284 " sbc %H0, %H0, %H4\n"
1285 " strexd %1, %0, %H0, [%3]\n"
1286 " teq %1, #0\n"
1287 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1288
1289 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1290 {
1291 - u64 result;
1292 - unsigned long tmp;
1293 + u64 result, tmp;
1294
1295 smp_mb();
1296
1297 __asm__ __volatile__("@ atomic64_sub_return\n"
1298 -"1: ldrexd %0, %H0, [%3]\n"
1299 -" subs %0, %0, %4\n"
1300 -" sbc %H0, %H0, %H4\n"
1301 +"1: ldrexd %1, %H1, [%3]\n"
1302 +" subs %0, %1, %4\n"
1303 +" sbcs %H0, %H1, %H4\n"
1304 +
1305 +#ifdef CONFIG_PAX_REFCOUNT
1306 +" bvc 3f\n"
1307 +" mov %0, %1\n"
1308 +" mov %H0, %H1\n"
1309 +"2: bkpt 0xf103\n"
1310 +"3:\n"
1311 +#endif
1312 +
1313 " strexd %1, %0, %H0, [%3]\n"
1314 " teq %1, #0\n"
1315 " bne 1b"
1316 +
1317 +#ifdef CONFIG_PAX_REFCOUNT
1318 +"\n4:\n"
1319 + _ASM_EXTABLE(2b, 4b)
1320 +#endif
1321 +
1322 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1323 : "r" (&v->counter), "r" (i)
1324 : "cc");
1325 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1326 return oldval;
1327 }
1328
1329 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1330 +{
1331 + u64 oldval;
1332 + unsigned long res;
1333 +
1334 + smp_mb();
1335 +
1336 + do {
1337 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1338 + "ldrexd %1, %H1, [%3]\n"
1339 + "mov %0, #0\n"
1340 + "teq %1, %4\n"
1341 + "teqeq %H1, %H4\n"
1342 + "strexdeq %0, %5, %H5, [%3]"
1343 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1344 + : "r" (&ptr->counter), "r" (old), "r" (new)
1345 + : "cc");
1346 + } while (res);
1347 +
1348 + smp_mb();
1349 +
1350 + return oldval;
1351 +}
1352 +
1353 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1354 {
1355 u64 result;
1356 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1357
1358 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1359 {
1360 - u64 result;
1361 - unsigned long tmp;
1362 + u64 result, tmp;
1363
1364 smp_mb();
1365
1366 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1367 -"1: ldrexd %0, %H0, [%3]\n"
1368 -" subs %0, %0, #1\n"
1369 -" sbc %H0, %H0, #0\n"
1370 +"1: ldrexd %1, %H1, [%3]\n"
1371 +" subs %0, %1, #1\n"
1372 +" sbcs %H0, %H1, #0\n"
1373 +
1374 +#ifdef CONFIG_PAX_REFCOUNT
1375 +" bvc 3f\n"
1376 +" mov %0, %1\n"
1377 +" mov %H0, %H1\n"
1378 +"2: bkpt 0xf103\n"
1379 +"3:\n"
1380 +#endif
1381 +
1382 " teq %H0, #0\n"
1383 -" bmi 2f\n"
1384 +" bmi 4f\n"
1385 " strexd %1, %0, %H0, [%3]\n"
1386 " teq %1, #0\n"
1387 " bne 1b\n"
1388 -"2:"
1389 +"4:\n"
1390 +
1391 +#ifdef CONFIG_PAX_REFCOUNT
1392 + _ASM_EXTABLE(2b, 4b)
1393 +#endif
1394 +
1395 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1396 : "r" (&v->counter)
1397 : "cc");
1398 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1399 " teq %0, %5\n"
1400 " teqeq %H0, %H5\n"
1401 " moveq %1, #0\n"
1402 -" beq 2f\n"
1403 +" beq 4f\n"
1404 " adds %0, %0, %6\n"
1405 -" adc %H0, %H0, %H6\n"
1406 +" adcs %H0, %H0, %H6\n"
1407 +
1408 +#ifdef CONFIG_PAX_REFCOUNT
1409 +" bvc 3f\n"
1410 +"2: bkpt 0xf103\n"
1411 +"3:\n"
1412 +#endif
1413 +
1414 " strexd %2, %0, %H0, [%4]\n"
1415 " teq %2, #0\n"
1416 " bne 1b\n"
1417 -"2:"
1418 +"4:\n"
1419 +
1420 +#ifdef CONFIG_PAX_REFCOUNT
1421 + _ASM_EXTABLE(2b, 4b)
1422 +#endif
1423 +
1424 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1425 : "r" (&v->counter), "r" (u), "r" (a)
1426 : "cc");
1427 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1428
1429 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1430 #define atomic64_inc(v) atomic64_add(1LL, (v))
1431 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1432 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1433 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1434 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1435 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1436 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1437 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1438 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1439 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1440 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1441 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1442 index 75fe66b..ba3dee4 100644
1443 --- a/arch/arm/include/asm/cache.h
1444 +++ b/arch/arm/include/asm/cache.h
1445 @@ -4,8 +4,10 @@
1446 #ifndef __ASMARM_CACHE_H
1447 #define __ASMARM_CACHE_H
1448
1449 +#include <linux/const.h>
1450 +
1451 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1452 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1453 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1454
1455 /*
1456 * Memory returned by kmalloc() may be used for DMA, so we must make
1457 @@ -24,5 +26,6 @@
1458 #endif
1459
1460 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1461 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1462
1463 #endif
1464 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1465 index e1489c5..d418304 100644
1466 --- a/arch/arm/include/asm/cacheflush.h
1467 +++ b/arch/arm/include/asm/cacheflush.h
1468 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1469 void (*dma_unmap_area)(const void *, size_t, int);
1470
1471 void (*dma_flush_range)(const void *, const void *);
1472 -};
1473 +} __no_const;
1474
1475 /*
1476 * Select the calling method
1477 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1478 index 6dcc164..b14d917 100644
1479 --- a/arch/arm/include/asm/checksum.h
1480 +++ b/arch/arm/include/asm/checksum.h
1481 @@ -37,7 +37,19 @@ __wsum
1482 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1483
1484 __wsum
1485 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1486 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1487 +
1488 +static inline __wsum
1489 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1490 +{
1491 + __wsum ret;
1492 + pax_open_userland();
1493 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1494 + pax_close_userland();
1495 + return ret;
1496 +}
1497 +
1498 +
1499
1500 /*
1501 * Fold a partial checksum without adding pseudo headers
1502 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1503 index 7eb18c1..e38b6d2 100644
1504 --- a/arch/arm/include/asm/cmpxchg.h
1505 +++ b/arch/arm/include/asm/cmpxchg.h
1506 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1507
1508 #define xchg(ptr,x) \
1509 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1510 +#define xchg_unchecked(ptr,x) \
1511 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1512
1513 #include <asm-generic/cmpxchg-local.h>
1514
1515 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1516 index ab98fdd..6b19938 100644
1517 --- a/arch/arm/include/asm/delay.h
1518 +++ b/arch/arm/include/asm/delay.h
1519 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1520 void (*delay)(unsigned long);
1521 void (*const_udelay)(unsigned long);
1522 void (*udelay)(unsigned long);
1523 -} arm_delay_ops;
1524 +} *arm_delay_ops;
1525
1526 -#define __delay(n) arm_delay_ops.delay(n)
1527 +#define __delay(n) arm_delay_ops->delay(n)
1528
1529 /*
1530 * This function intentionally does not exist; if you see references to
1531 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1532 * first constant multiplications gets optimized away if the delay is
1533 * a constant)
1534 */
1535 -#define __udelay(n) arm_delay_ops.udelay(n)
1536 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1537 +#define __udelay(n) arm_delay_ops->udelay(n)
1538 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1539
1540 #define udelay(n) \
1541 (__builtin_constant_p(n) ? \
1542 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1543 index 6ddbe44..758b5f2 100644
1544 --- a/arch/arm/include/asm/domain.h
1545 +++ b/arch/arm/include/asm/domain.h
1546 @@ -48,18 +48,37 @@
1547 * Domain types
1548 */
1549 #define DOMAIN_NOACCESS 0
1550 -#define DOMAIN_CLIENT 1
1551 #ifdef CONFIG_CPU_USE_DOMAINS
1552 +#define DOMAIN_USERCLIENT 1
1553 +#define DOMAIN_KERNELCLIENT 1
1554 #define DOMAIN_MANAGER 3
1555 +#define DOMAIN_VECTORS DOMAIN_USER
1556 #else
1557 +
1558 +#ifdef CONFIG_PAX_KERNEXEC
1559 #define DOMAIN_MANAGER 1
1560 +#define DOMAIN_KERNEXEC 3
1561 +#else
1562 +#define DOMAIN_MANAGER 1
1563 +#endif
1564 +
1565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1566 +#define DOMAIN_USERCLIENT 0
1567 +#define DOMAIN_UDEREF 1
1568 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1569 +#else
1570 +#define DOMAIN_USERCLIENT 1
1571 +#define DOMAIN_VECTORS DOMAIN_USER
1572 +#endif
1573 +#define DOMAIN_KERNELCLIENT 1
1574 +
1575 #endif
1576
1577 #define domain_val(dom,type) ((type) << (2*(dom)))
1578
1579 #ifndef __ASSEMBLY__
1580
1581 -#ifdef CONFIG_CPU_USE_DOMAINS
1582 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1583 static inline void set_domain(unsigned val)
1584 {
1585 asm volatile(
1586 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1587 isb();
1588 }
1589
1590 -#define modify_domain(dom,type) \
1591 - do { \
1592 - struct thread_info *thread = current_thread_info(); \
1593 - unsigned int domain = thread->cpu_domain; \
1594 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1595 - thread->cpu_domain = domain | domain_val(dom, type); \
1596 - set_domain(thread->cpu_domain); \
1597 - } while (0)
1598 -
1599 +extern void modify_domain(unsigned int dom, unsigned int type);
1600 #else
1601 static inline void set_domain(unsigned val) { }
1602 static inline void modify_domain(unsigned dom, unsigned type) { }
1603 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1604 index 38050b1..9d90e8b 100644
1605 --- a/arch/arm/include/asm/elf.h
1606 +++ b/arch/arm/include/asm/elf.h
1607 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1608 the loader. We need to make sure that it is out of the way of the program
1609 that it will "exec", and that there is sufficient room for the brk. */
1610
1611 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1612 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1613 +
1614 +#ifdef CONFIG_PAX_ASLR
1615 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1616 +
1617 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1618 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1619 +#endif
1620
1621 /* When the program starts, a1 contains a pointer to a function to be
1622 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1623 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1624 extern void elf_set_personality(const struct elf32_hdr *);
1625 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1626
1627 -struct mm_struct;
1628 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1629 -#define arch_randomize_brk arch_randomize_brk
1630 -
1631 #endif
1632 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1633 index de53547..52b9a28 100644
1634 --- a/arch/arm/include/asm/fncpy.h
1635 +++ b/arch/arm/include/asm/fncpy.h
1636 @@ -81,7 +81,9 @@
1637 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1638 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1639 \
1640 + pax_open_kernel(); \
1641 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1642 + pax_close_kernel(); \
1643 flush_icache_range((unsigned long)(dest_buf), \
1644 (unsigned long)(dest_buf) + (size)); \
1645 \
1646 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1647 index e42cf59..7b94b8f 100644
1648 --- a/arch/arm/include/asm/futex.h
1649 +++ b/arch/arm/include/asm/futex.h
1650 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1651 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1652 return -EFAULT;
1653
1654 + pax_open_userland();
1655 +
1656 smp_mb();
1657 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1658 "1: ldrex %1, [%4]\n"
1659 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1660 : "cc", "memory");
1661 smp_mb();
1662
1663 + pax_close_userland();
1664 +
1665 *uval = val;
1666 return ret;
1667 }
1668 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1669 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1670 return -EFAULT;
1671
1672 + pax_open_userland();
1673 +
1674 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1675 "1: " TUSER(ldr) " %1, [%4]\n"
1676 " teq %1, %2\n"
1677 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1679 : "cc", "memory");
1680
1681 + pax_close_userland();
1682 +
1683 *uval = val;
1684 return ret;
1685 }
1686 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1687 return -EFAULT;
1688
1689 pagefault_disable(); /* implies preempt_disable() */
1690 + pax_open_userland();
1691
1692 switch (op) {
1693 case FUTEX_OP_SET:
1694 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1695 ret = -ENOSYS;
1696 }
1697
1698 + pax_close_userland();
1699 pagefault_enable(); /* subsumes preempt_enable() */
1700
1701 if (!ret) {
1702 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1703 index 83eb2f7..ed77159 100644
1704 --- a/arch/arm/include/asm/kmap_types.h
1705 +++ b/arch/arm/include/asm/kmap_types.h
1706 @@ -4,6 +4,6 @@
1707 /*
1708 * This is the "bare minimum". AIO seems to require this.
1709 */
1710 -#define KM_TYPE_NR 16
1711 +#define KM_TYPE_NR 17
1712
1713 #endif
1714 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1715 index 9e614a1..3302cca 100644
1716 --- a/arch/arm/include/asm/mach/dma.h
1717 +++ b/arch/arm/include/asm/mach/dma.h
1718 @@ -22,7 +22,7 @@ struct dma_ops {
1719 int (*residue)(unsigned int, dma_t *); /* optional */
1720 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1721 const char *type;
1722 -};
1723 +} __do_const;
1724
1725 struct dma_struct {
1726 void *addr; /* single DMA address */
1727 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1728 index 2fe141f..192dc01 100644
1729 --- a/arch/arm/include/asm/mach/map.h
1730 +++ b/arch/arm/include/asm/mach/map.h
1731 @@ -27,13 +27,16 @@ struct map_desc {
1732 #define MT_MINICLEAN 6
1733 #define MT_LOW_VECTORS 7
1734 #define MT_HIGH_VECTORS 8
1735 -#define MT_MEMORY 9
1736 +#define MT_MEMORY_RWX 9
1737 #define MT_ROM 10
1738 -#define MT_MEMORY_NONCACHED 11
1739 +#define MT_MEMORY_NONCACHED_RX 11
1740 #define MT_MEMORY_DTCM 12
1741 #define MT_MEMORY_ITCM 13
1742 #define MT_MEMORY_SO 14
1743 #define MT_MEMORY_DMA_READY 15
1744 +#define MT_MEMORY_RW 16
1745 +#define MT_MEMORY_RX 17
1746 +#define MT_MEMORY_NONCACHED_RW 18
1747
1748 #ifdef CONFIG_MMU
1749 extern void iotable_init(struct map_desc *, int);
1750 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1751 index 53426c6..c7baff3 100644
1752 --- a/arch/arm/include/asm/outercache.h
1753 +++ b/arch/arm/include/asm/outercache.h
1754 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1755 #endif
1756 void (*set_debug)(unsigned long);
1757 void (*resume)(void);
1758 -};
1759 +} __no_const;
1760
1761 #ifdef CONFIG_OUTER_CACHE
1762
1763 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1764 index 812a494..71fc0b6 100644
1765 --- a/arch/arm/include/asm/page.h
1766 +++ b/arch/arm/include/asm/page.h
1767 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1768 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1769 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1770 unsigned long vaddr, struct vm_area_struct *vma);
1771 -};
1772 +} __no_const;
1773
1774 #ifdef MULTI_USER
1775 extern struct cpu_user_fns cpu_user;
1776 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1777 index 943504f..c37a730 100644
1778 --- a/arch/arm/include/asm/pgalloc.h
1779 +++ b/arch/arm/include/asm/pgalloc.h
1780 @@ -17,6 +17,7 @@
1781 #include <asm/processor.h>
1782 #include <asm/cacheflush.h>
1783 #include <asm/tlbflush.h>
1784 +#include <asm/system_info.h>
1785
1786 #define check_pgt_cache() do { } while (0)
1787
1788 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1789 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1790 }
1791
1792 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1793 +{
1794 + pud_populate(mm, pud, pmd);
1795 +}
1796 +
1797 #else /* !CONFIG_ARM_LPAE */
1798
1799 /*
1800 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1801 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1802 #define pmd_free(mm, pmd) do { } while (0)
1803 #define pud_populate(mm,pmd,pte) BUG()
1804 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1805
1806 #endif /* CONFIG_ARM_LPAE */
1807
1808 @@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1809 __free_page(pte);
1810 }
1811
1812 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1813 +{
1814 +#ifdef CONFIG_ARM_LPAE
1815 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1816 +#else
1817 + if (addr & SECTION_SIZE)
1818 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1819 + else
1820 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1821 +#endif
1822 + flush_pmd_entry(pmdp);
1823 +}
1824 +
1825 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1826 pmdval_t prot)
1827 {
1828 @@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1829 static inline void
1830 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1831 {
1832 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1833 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1834 }
1835 #define pmd_pgtable(pmd) pmd_page(pmd)
1836
1837 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1838 index 5cfba15..f415e1a 100644
1839 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1840 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1841 @@ -20,12 +20,15 @@
1842 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1843 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1844 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1845 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1846 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1847 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1848 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1849 +
1850 /*
1851 * - section
1852 */
1853 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1854 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1855 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1856 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1857 @@ -37,6 +40,7 @@
1858 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1859 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1860 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1861 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1862
1863 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1864 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1865 @@ -66,6 +70,7 @@
1866 * - extended small page/tiny page
1867 */
1868 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1869 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1870 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1871 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1872 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1873 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1874 index f97ee02..07f1be5 100644
1875 --- a/arch/arm/include/asm/pgtable-2level.h
1876 +++ b/arch/arm/include/asm/pgtable-2level.h
1877 @@ -125,6 +125,7 @@
1878 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1879 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1880 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1881 +#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1882
1883 /*
1884 * These are the memory types, defined to be compatible with
1885 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1886 index d795282..a43ea90 100644
1887 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1888 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1889 @@ -32,15 +32,18 @@
1890 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1891 #define PMD_BIT4 (_AT(pmdval_t, 0))
1892 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1893 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1894
1895 /*
1896 * - section
1897 */
1898 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1899 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1900 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1901 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1902 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1903 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1904 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1905 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1906 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1907 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1908 @@ -66,6 +69,7 @@
1909 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1910 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1911 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1912 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1913 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1914
1915 /*
1916 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1917 index a3f3792..7b932a6 100644
1918 --- a/arch/arm/include/asm/pgtable-3level.h
1919 +++ b/arch/arm/include/asm/pgtable-3level.h
1920 @@ -74,6 +74,7 @@
1921 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1922 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1923 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1924 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1925 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1926 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1927 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1928 @@ -82,6 +83,7 @@
1929 /*
1930 * To be used in assembly code with the upper page attributes.
1931 */
1932 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1933 #define L_PTE_XN_HIGH (1 << (54 - 32))
1934 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1935
1936 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1937 index 9c82f988..514705a 100644
1938 --- a/arch/arm/include/asm/pgtable.h
1939 +++ b/arch/arm/include/asm/pgtable.h
1940 @@ -30,6 +30,9 @@
1941 #include <asm/pgtable-2level.h>
1942 #endif
1943
1944 +#define ktla_ktva(addr) (addr)
1945 +#define ktva_ktla(addr) (addr)
1946 +
1947 /*
1948 * Just any arbitrary offset to the start of the vmalloc VM area: the
1949 * current 8MB value just means that there will be a 8MB "hole" after the
1950 @@ -45,6 +48,9 @@
1951 #define LIBRARY_TEXT_START 0x0c000000
1952
1953 #ifndef __ASSEMBLY__
1954 +extern pteval_t __supported_pte_mask;
1955 +extern pmdval_t __supported_pmd_mask;
1956 +
1957 extern void __pte_error(const char *file, int line, pte_t);
1958 extern void __pmd_error(const char *file, int line, pmd_t);
1959 extern void __pgd_error(const char *file, int line, pgd_t);
1960 @@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1961 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1962 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1963
1964 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1965 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1966 +
1967 +#ifdef CONFIG_PAX_KERNEXEC
1968 +#include <asm/domain.h>
1969 +#include <linux/thread_info.h>
1970 +#include <linux/preempt.h>
1971 +#endif
1972 +
1973 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1974 +static inline int test_domain(int domain, int domaintype)
1975 +{
1976 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1977 +}
1978 +#endif
1979 +
1980 +#ifdef CONFIG_PAX_KERNEXEC
1981 +static inline unsigned long pax_open_kernel(void) {
1982 +#ifdef CONFIG_ARM_LPAE
1983 + /* TODO */
1984 +#else
1985 + preempt_disable();
1986 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1987 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
1988 +#endif
1989 + return 0;
1990 +}
1991 +
1992 +static inline unsigned long pax_close_kernel(void) {
1993 +#ifdef CONFIG_ARM_LPAE
1994 + /* TODO */
1995 +#else
1996 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
1997 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
1998 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
1999 + preempt_enable_no_resched();
2000 +#endif
2001 + return 0;
2002 +}
2003 +#else
2004 +static inline unsigned long pax_open_kernel(void) { return 0; }
2005 +static inline unsigned long pax_close_kernel(void) { return 0; }
2006 +#endif
2007 +
2008 /*
2009 * This is the lowest virtual address we can permit any user space
2010 * mapping to be mapped at. This is particularly important for
2011 @@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2012 /*
2013 * The pgprot_* and protection_map entries will be fixed up in runtime
2014 * to include the cachable and bufferable bits based on memory policy,
2015 - * as well as any architecture dependent bits like global/ASID and SMP
2016 - * shared mapping bits.
2017 + * as well as any architecture dependent bits like global/ASID, PXN,
2018 + * and SMP shared mapping bits.
2019 */
2020 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2021
2022 @@ -240,7 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2023
2024 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2025 {
2026 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE;
2027 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | __supported_pte_mask;
2028 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2029 return pte;
2030 }
2031 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2032 index f3628fb..a0672dd 100644
2033 --- a/arch/arm/include/asm/proc-fns.h
2034 +++ b/arch/arm/include/asm/proc-fns.h
2035 @@ -75,7 +75,7 @@ extern struct processor {
2036 unsigned int suspend_size;
2037 void (*do_suspend)(void *);
2038 void (*do_resume)(void *);
2039 -} processor;
2040 +} __do_const processor;
2041
2042 #ifndef MULTI_CPU
2043 extern void cpu_proc_init(void);
2044 diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2045 index 06e7d50..8a8e251 100644
2046 --- a/arch/arm/include/asm/processor.h
2047 +++ b/arch/arm/include/asm/processor.h
2048 @@ -65,9 +65,8 @@ struct thread_struct {
2049 regs->ARM_cpsr |= PSR_ENDSTATE; \
2050 regs->ARM_pc = pc & ~1; /* pc */ \
2051 regs->ARM_sp = sp; /* sp */ \
2052 - regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2053 - regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2054 - regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2055 + /* r2 (envp), r1 (argv), r0 (argc) */ \
2056 + (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2057 nommu_start_thread(regs); \
2058 })
2059
2060 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2061 index d3a22be..3a69ad5 100644
2062 --- a/arch/arm/include/asm/smp.h
2063 +++ b/arch/arm/include/asm/smp.h
2064 @@ -107,7 +107,7 @@ struct smp_operations {
2065 int (*cpu_disable)(unsigned int cpu);
2066 #endif
2067 #endif
2068 -};
2069 +} __no_const;
2070
2071 /*
2072 * set platform specific SMP operations
2073 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2074 index cddda1f..ff357f7 100644
2075 --- a/arch/arm/include/asm/thread_info.h
2076 +++ b/arch/arm/include/asm/thread_info.h
2077 @@ -77,9 +77,9 @@ struct thread_info {
2078 .flags = 0, \
2079 .preempt_count = INIT_PREEMPT_COUNT, \
2080 .addr_limit = KERNEL_DS, \
2081 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2082 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2083 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2084 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2085 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2086 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2087 .restart_block = { \
2088 .fn = do_no_restart_syscall, \
2089 }, \
2090 @@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2091 #define TIF_SYSCALL_AUDIT 9
2092 #define TIF_SYSCALL_TRACEPOINT 10
2093 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2094 +
2095 +/* within 8 bits of TIF_SYSCALL_TRACE
2096 + * to meet flexible second operand requirements
2097 + */
2098 +#define TIF_GRSEC_SETXID 12
2099 +
2100 #define TIF_USING_IWMMXT 17
2101 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2102 #define TIF_RESTORE_SIGMASK 20
2103 @@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2104 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2105 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2106 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2107 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2108
2109 /* Checks for any syscall work in entry-common.S */
2110 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2111 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2112 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2113
2114 /*
2115 * Change these and you break ASM code in entry-common.S
2116 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2117 index 7e1f760..752fcb7 100644
2118 --- a/arch/arm/include/asm/uaccess.h
2119 +++ b/arch/arm/include/asm/uaccess.h
2120 @@ -18,6 +18,7 @@
2121 #include <asm/domain.h>
2122 #include <asm/unified.h>
2123 #include <asm/compiler.h>
2124 +#include <asm/pgtable.h>
2125
2126 #define VERIFY_READ 0
2127 #define VERIFY_WRITE 1
2128 @@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2129 #define USER_DS TASK_SIZE
2130 #define get_fs() (current_thread_info()->addr_limit)
2131
2132 +static inline void pax_open_userland(void)
2133 +{
2134 +
2135 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2136 + if (get_fs() == USER_DS) {
2137 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2138 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2139 + }
2140 +#endif
2141 +
2142 +}
2143 +
2144 +static inline void pax_close_userland(void)
2145 +{
2146 +
2147 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2148 + if (get_fs() == USER_DS) {
2149 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2150 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2151 + }
2152 +#endif
2153 +
2154 +}
2155 +
2156 static inline void set_fs(mm_segment_t fs)
2157 {
2158 current_thread_info()->addr_limit = fs;
2159 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2160 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2161 }
2162
2163 #define segment_eq(a,b) ((a) == (b))
2164 @@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2165
2166 #define get_user(x,p) \
2167 ({ \
2168 + int __e; \
2169 might_fault(); \
2170 - __get_user_check(x,p); \
2171 + pax_open_userland(); \
2172 + __e = __get_user_check(x,p); \
2173 + pax_close_userland(); \
2174 + __e; \
2175 })
2176
2177 extern int __put_user_1(void *, unsigned int);
2178 @@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2179
2180 #define put_user(x,p) \
2181 ({ \
2182 + int __e; \
2183 might_fault(); \
2184 - __put_user_check(x,p); \
2185 + pax_open_userland(); \
2186 + __e = __put_user_check(x,p); \
2187 + pax_close_userland(); \
2188 + __e; \
2189 })
2190
2191 #else /* CONFIG_MMU */
2192 @@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2193 #define __get_user(x,ptr) \
2194 ({ \
2195 long __gu_err = 0; \
2196 + pax_open_userland(); \
2197 __get_user_err((x),(ptr),__gu_err); \
2198 + pax_close_userland(); \
2199 __gu_err; \
2200 })
2201
2202 #define __get_user_error(x,ptr,err) \
2203 ({ \
2204 + pax_open_userland(); \
2205 __get_user_err((x),(ptr),err); \
2206 + pax_close_userland(); \
2207 (void) 0; \
2208 })
2209
2210 @@ -312,13 +349,17 @@ do { \
2211 #define __put_user(x,ptr) \
2212 ({ \
2213 long __pu_err = 0; \
2214 + pax_open_userland(); \
2215 __put_user_err((x),(ptr),__pu_err); \
2216 + pax_close_userland(); \
2217 __pu_err; \
2218 })
2219
2220 #define __put_user_error(x,ptr,err) \
2221 ({ \
2222 + pax_open_userland(); \
2223 __put_user_err((x),(ptr),err); \
2224 + pax_close_userland(); \
2225 (void) 0; \
2226 })
2227
2228 @@ -418,11 +459,44 @@ do { \
2229
2230
2231 #ifdef CONFIG_MMU
2232 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2233 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2234 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2235 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2236 +
2237 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2238 +{
2239 + unsigned long ret;
2240 +
2241 + check_object_size(to, n, false);
2242 + pax_open_userland();
2243 + ret = ___copy_from_user(to, from, n);
2244 + pax_close_userland();
2245 + return ret;
2246 +}
2247 +
2248 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2249 +{
2250 + unsigned long ret;
2251 +
2252 + check_object_size(from, n, true);
2253 + pax_open_userland();
2254 + ret = ___copy_to_user(to, from, n);
2255 + pax_close_userland();
2256 + return ret;
2257 +}
2258 +
2259 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2260 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2261 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2262 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2263 +
2264 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2265 +{
2266 + unsigned long ret;
2267 + pax_open_userland();
2268 + ret = ___clear_user(addr, n);
2269 + pax_close_userland();
2270 + return ret;
2271 +}
2272 +
2273 #else
2274 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2275 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2276 @@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2277
2278 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2279 {
2280 + if ((long)n < 0)
2281 + return n;
2282 +
2283 if (access_ok(VERIFY_READ, from, n))
2284 n = __copy_from_user(to, from, n);
2285 else /* security hole - plug it */
2286 @@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2287
2288 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2289 {
2290 + if ((long)n < 0)
2291 + return n;
2292 +
2293 if (access_ok(VERIFY_WRITE, to, n))
2294 n = __copy_to_user(to, from, n);
2295 return n;
2296 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2297 index 96ee092..37f1844 100644
2298 --- a/arch/arm/include/uapi/asm/ptrace.h
2299 +++ b/arch/arm/include/uapi/asm/ptrace.h
2300 @@ -73,7 +73,7 @@
2301 * ARMv7 groups of PSR bits
2302 */
2303 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2304 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2305 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2306 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2307 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2308
2309 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2310 index 60d3b73..9168db0 100644
2311 --- a/arch/arm/kernel/armksyms.c
2312 +++ b/arch/arm/kernel/armksyms.c
2313 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
2314 #ifdef CONFIG_MMU
2315 EXPORT_SYMBOL(copy_page);
2316
2317 -EXPORT_SYMBOL(__copy_from_user);
2318 -EXPORT_SYMBOL(__copy_to_user);
2319 +EXPORT_SYMBOL(___copy_from_user);
2320 +EXPORT_SYMBOL(___copy_to_user);
2321 EXPORT_SYMBOL(__clear_user);
2322
2323 EXPORT_SYMBOL(__get_user_1);
2324 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2325 index 0f82098..3dbd3ee 100644
2326 --- a/arch/arm/kernel/entry-armv.S
2327 +++ b/arch/arm/kernel/entry-armv.S
2328 @@ -47,6 +47,87 @@
2329 9997:
2330 .endm
2331
2332 + .macro pax_enter_kernel
2333 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2334 + @ make aligned space for saved DACR
2335 + sub sp, sp, #8
2336 + @ save regs
2337 + stmdb sp!, {r1, r2}
2338 + @ read DACR from cpu_domain into r1
2339 + mov r2, sp
2340 + @ assume 8K pages, since we have to split the immediate in two
2341 + bic r2, r2, #(0x1fc0)
2342 + bic r2, r2, #(0x3f)
2343 + ldr r1, [r2, #TI_CPU_DOMAIN]
2344 + @ store old DACR on stack
2345 + str r1, [sp, #8]
2346 +#ifdef CONFIG_PAX_KERNEXEC
2347 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2348 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2349 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2350 +#endif
2351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2352 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2353 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2354 +#endif
2355 + @ write r1 to current_thread_info()->cpu_domain
2356 + str r1, [r2, #TI_CPU_DOMAIN]
2357 + @ write r1 to DACR
2358 + mcr p15, 0, r1, c3, c0, 0
2359 + @ instruction sync
2360 + instr_sync
2361 + @ restore regs
2362 + ldmia sp!, {r1, r2}
2363 +#endif
2364 + .endm
2365 +
2366 + .macro pax_open_userland
2367 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2368 + @ save regs
2369 + stmdb sp!, {r0, r1}
2370 + @ read DACR from cpu_domain into r1
2371 + mov r0, sp
2372 + @ assume 8K pages, since we have to split the immediate in two
2373 + bic r0, r0, #(0x1fc0)
2374 + bic r0, r0, #(0x3f)
2375 + ldr r1, [r0, #TI_CPU_DOMAIN]
2376 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2377 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2378 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2379 + @ write r1 to current_thread_info()->cpu_domain
2380 + str r1, [r0, #TI_CPU_DOMAIN]
2381 + @ write r1 to DACR
2382 + mcr p15, 0, r1, c3, c0, 0
2383 + @ instruction sync
2384 + instr_sync
2385 + @ restore regs
2386 + ldmia sp!, {r0, r1}
2387 +#endif
2388 + .endm
2389 +
2390 + .macro pax_close_userland
2391 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2392 + @ save regs
2393 + stmdb sp!, {r0, r1}
2394 + @ read DACR from cpu_domain into r1
2395 + mov r0, sp
2396 + @ assume 8K pages, since we have to split the immediate in two
2397 + bic r0, r0, #(0x1fc0)
2398 + bic r0, r0, #(0x3f)
2399 + ldr r1, [r0, #TI_CPU_DOMAIN]
2400 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2401 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2402 + @ write r1 to current_thread_info()->cpu_domain
2403 + str r1, [r0, #TI_CPU_DOMAIN]
2404 + @ write r1 to DACR
2405 + mcr p15, 0, r1, c3, c0, 0
2406 + @ instruction sync
2407 + instr_sync
2408 + @ restore regs
2409 + ldmia sp!, {r0, r1}
2410 +#endif
2411 + .endm
2412 +
2413 .macro pabt_helper
2414 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2415 #ifdef MULTI_PABORT
2416 @@ -89,11 +170,15 @@
2417 * Invalid mode handlers
2418 */
2419 .macro inv_entry, reason
2420 +
2421 + pax_enter_kernel
2422 +
2423 sub sp, sp, #S_FRAME_SIZE
2424 ARM( stmib sp, {r1 - lr} )
2425 THUMB( stmia sp, {r0 - r12} )
2426 THUMB( str sp, [sp, #S_SP] )
2427 THUMB( str lr, [sp, #S_LR] )
2428 +
2429 mov r1, #\reason
2430 .endm
2431
2432 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2433 .macro svc_entry, stack_hole=0
2434 UNWIND(.fnstart )
2435 UNWIND(.save {r0 - pc} )
2436 +
2437 + pax_enter_kernel
2438 +
2439 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2440 +
2441 #ifdef CONFIG_THUMB2_KERNEL
2442 SPFIX( str r0, [sp] ) @ temporarily saved
2443 SPFIX( mov r0, sp )
2444 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2445 ldmia r0, {r3 - r5}
2446 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2447 mov r6, #-1 @ "" "" "" ""
2448 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2449 + @ offset sp by 8 as done in pax_enter_kernel
2450 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2451 +#else
2452 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2453 +#endif
2454 SPFIX( addeq r2, r2, #4 )
2455 str r3, [sp, #-4]! @ save the "real" r0 copied
2456 @ from the exception stack
2457 @@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2458 .macro usr_entry
2459 UNWIND(.fnstart )
2460 UNWIND(.cantunwind ) @ don't unwind the user space
2461 +
2462 + pax_enter_kernel_user
2463 +
2464 sub sp, sp, #S_FRAME_SIZE
2465 ARM( stmib sp, {r1 - r12} )
2466 THUMB( stmia sp, {r0 - r12} )
2467 @@ -456,7 +553,9 @@ __und_usr:
2468 tst r3, #PSR_T_BIT @ Thumb mode?
2469 bne __und_usr_thumb
2470 sub r4, r2, #4 @ ARM instr at LR - 4
2471 + pax_open_userland
2472 1: ldrt r0, [r4]
2473 + pax_close_userland
2474 #ifdef CONFIG_CPU_ENDIAN_BE8
2475 rev r0, r0 @ little endian instruction
2476 #endif
2477 @@ -491,10 +590,14 @@ __und_usr_thumb:
2478 */
2479 .arch armv6t2
2480 #endif
2481 + pax_open_userland
2482 2: ldrht r5, [r4]
2483 + pax_close_userland
2484 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2485 blo __und_usr_fault_16 @ 16bit undefined instruction
2486 + pax_open_userland
2487 3: ldrht r0, [r2]
2488 + pax_close_userland
2489 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2490 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2491 orr r0, r0, r5, lsl #16
2492 @@ -733,7 +836,7 @@ ENTRY(__switch_to)
2493 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2494 THUMB( str sp, [ip], #4 )
2495 THUMB( str lr, [ip], #4 )
2496 -#ifdef CONFIG_CPU_USE_DOMAINS
2497 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2498 ldr r6, [r2, #TI_CPU_DOMAIN]
2499 #endif
2500 set_tls r3, r4, r5
2501 @@ -742,7 +845,7 @@ ENTRY(__switch_to)
2502 ldr r8, =__stack_chk_guard
2503 ldr r7, [r7, #TSK_STACK_CANARY]
2504 #endif
2505 -#ifdef CONFIG_CPU_USE_DOMAINS
2506 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2507 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2508 #endif
2509 mov r5, r0
2510 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2511 index a6c301e..908821b 100644
2512 --- a/arch/arm/kernel/entry-common.S
2513 +++ b/arch/arm/kernel/entry-common.S
2514 @@ -10,18 +10,46 @@
2515
2516 #include <asm/unistd.h>
2517 #include <asm/ftrace.h>
2518 +#include <asm/domain.h>
2519 #include <asm/unwind.h>
2520
2521 +#include "entry-header.S"
2522 +
2523 #ifdef CONFIG_NEED_RET_TO_USER
2524 #include <mach/entry-macro.S>
2525 #else
2526 .macro arch_ret_to_user, tmp1, tmp2
2527 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2528 + @ save regs
2529 + stmdb sp!, {r1, r2}
2530 + @ read DACR from cpu_domain into r1
2531 + mov r2, sp
2532 + @ assume 8K pages, since we have to split the immediate in two
2533 + bic r2, r2, #(0x1fc0)
2534 + bic r2, r2, #(0x3f)
2535 + ldr r1, [r2, #TI_CPU_DOMAIN]
2536 +#ifdef CONFIG_PAX_KERNEXEC
2537 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2538 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2539 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2540 +#endif
2541 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2542 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2543 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2544 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2545 +#endif
2546 + @ write r1 to current_thread_info()->cpu_domain
2547 + str r1, [r2, #TI_CPU_DOMAIN]
2548 + @ write r1 to DACR
2549 + mcr p15, 0, r1, c3, c0, 0
2550 + @ instruction sync
2551 + instr_sync
2552 + @ restore regs
2553 + ldmia sp!, {r1, r2}
2554 +#endif
2555 .endm
2556 #endif
2557
2558 -#include "entry-header.S"
2559 -
2560 -
2561 .align 5
2562 /*
2563 * This is the fast syscall return path. We do as little as
2564 @@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2565
2566 .align 5
2567 ENTRY(vector_swi)
2568 +
2569 sub sp, sp, #S_FRAME_SIZE
2570 stmia sp, {r0 - r12} @ Calling r0 - r12
2571 ARM( add r8, sp, #S_PC )
2572 @@ -388,6 +417,12 @@ ENTRY(vector_swi)
2573 ldr scno, [lr, #-4] @ get SWI instruction
2574 #endif
2575
2576 + /*
2577 + * do this here to avoid a performance hit of wrapping the code above
2578 + * that directly dereferences userland to parse the SWI instruction
2579 + */
2580 + pax_enter_kernel_user
2581 +
2582 #ifdef CONFIG_ALIGNMENT_TRAP
2583 ldr ip, __cr_alignment
2584 ldr ip, [ip]
2585 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2586 index 9a8531e..812e287 100644
2587 --- a/arch/arm/kernel/entry-header.S
2588 +++ b/arch/arm/kernel/entry-header.S
2589 @@ -73,9 +73,66 @@
2590 msr cpsr_c, \rtemp @ switch back to the SVC mode
2591 .endm
2592
2593 + .macro pax_enter_kernel_user
2594 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595 + @ save regs
2596 + stmdb sp!, {r0, r1}
2597 + @ read DACR from cpu_domain into r1
2598 + mov r0, sp
2599 + @ assume 8K pages, since we have to split the immediate in two
2600 + bic r0, r0, #(0x1fc0)
2601 + bic r0, r0, #(0x3f)
2602 + ldr r1, [r0, #TI_CPU_DOMAIN]
2603 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2604 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2605 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2606 +#endif
2607 +#ifdef CONFIG_PAX_KERNEXEC
2608 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2609 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2610 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2611 +#endif
2612 + @ write r1 to current_thread_info()->cpu_domain
2613 + str r1, [r0, #TI_CPU_DOMAIN]
2614 + @ write r1 to DACR
2615 + mcr p15, 0, r1, c3, c0, 0
2616 + @ instruction sync
2617 + instr_sync
2618 + @ restore regs
2619 + ldmia sp!, {r0, r1}
2620 +#endif
2621 + .endm
2622 +
2623 + .macro pax_exit_kernel
2624 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 + @ save regs
2626 + stmdb sp!, {r0, r1}
2627 + @ read old DACR from stack into r1
2628 + ldr r1, [sp, #(8 + S_SP)]
2629 + sub r1, r1, #8
2630 + ldr r1, [r1]
2631 +
2632 + @ write r1 to current_thread_info()->cpu_domain
2633 + mov r0, sp
2634 + @ assume 8K pages, since we have to split the immediate in two
2635 + bic r0, r0, #(0x1fc0)
2636 + bic r0, r0, #(0x3f)
2637 + str r1, [r0, #TI_CPU_DOMAIN]
2638 + @ write r1 to DACR
2639 + mcr p15, 0, r1, c3, c0, 0
2640 + @ instruction sync
2641 + instr_sync
2642 + @ restore regs
2643 + ldmia sp!, {r0, r1}
2644 +#endif
2645 + .endm
2646 +
2647 #ifndef CONFIG_THUMB2_KERNEL
2648 .macro svc_exit, rpsr
2649 msr spsr_cxsf, \rpsr
2650 +
2651 + pax_exit_kernel
2652 +
2653 #if defined(CONFIG_CPU_V6)
2654 ldr r0, [sp]
2655 strex r1, r2, [sp] @ clear the exclusive monitor
2656 @@ -121,6 +178,9 @@
2657 .endm
2658 #else /* CONFIG_THUMB2_KERNEL */
2659 .macro svc_exit, rpsr
2660 +
2661 + pax_exit_kernel
2662 +
2663 ldr lr, [sp, #S_SP] @ top of the stack
2664 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2665 clrex @ clear the exclusive monitor
2666 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2667 index 2adda11..7fbe958 100644
2668 --- a/arch/arm/kernel/fiq.c
2669 +++ b/arch/arm/kernel/fiq.c
2670 @@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2671 #if defined(CONFIG_CPU_USE_DOMAINS)
2672 memcpy((void *)0xffff001c, start, length);
2673 #else
2674 + pax_open_kernel();
2675 memcpy(vectors_page + 0x1c, start, length);
2676 + pax_close_kernel();
2677 #endif
2678 flush_icache_range(0xffff001c, 0xffff001c + length);
2679 if (!vectors_high())
2680 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2681 index 486a15a..2d6880e 100644
2682 --- a/arch/arm/kernel/head.S
2683 +++ b/arch/arm/kernel/head.S
2684 @@ -52,7 +52,9 @@
2685 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2686
2687 .macro pgtbl, rd, phys
2688 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2689 + mov \rd, #TEXT_OFFSET
2690 + sub \rd, #PG_DIR_SIZE
2691 + add \rd, \rd, \phys
2692 .endm
2693
2694 /*
2695 @@ -416,7 +418,7 @@ __enable_mmu:
2696 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2697 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2698 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2699 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2700 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2701 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2702 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2703 #endif
2704 diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2705 index 5ff2e77..556d030 100644
2706 --- a/arch/arm/kernel/hw_breakpoint.c
2707 +++ b/arch/arm/kernel/hw_breakpoint.c
2708 @@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2709 return NOTIFY_OK;
2710 }
2711
2712 -static struct notifier_block __cpuinitdata dbg_reset_nb = {
2713 +static struct notifier_block dbg_reset_nb = {
2714 .notifier_call = dbg_reset_notify,
2715 };
2716
2717 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2718 index 1e9be5d..03edbc2 100644
2719 --- a/arch/arm/kernel/module.c
2720 +++ b/arch/arm/kernel/module.c
2721 @@ -37,12 +37,37 @@
2722 #endif
2723
2724 #ifdef CONFIG_MMU
2725 -void *module_alloc(unsigned long size)
2726 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2727 {
2728 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2729 + return NULL;
2730 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2731 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2732 + GFP_KERNEL, prot, -1,
2733 __builtin_return_address(0));
2734 }
2735 +
2736 +void *module_alloc(unsigned long size)
2737 +{
2738 +
2739 +#ifdef CONFIG_PAX_KERNEXEC
2740 + return __module_alloc(size, PAGE_KERNEL);
2741 +#else
2742 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2743 +#endif
2744 +
2745 +}
2746 +
2747 +#ifdef CONFIG_PAX_KERNEXEC
2748 +void module_free_exec(struct module *mod, void *module_region)
2749 +{
2750 + module_free(mod, module_region);
2751 +}
2752 +
2753 +void *module_alloc_exec(unsigned long size)
2754 +{
2755 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2756 +}
2757 +#endif
2758 #endif
2759
2760 int
2761 diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2762 index 5f66206..dce492f 100644
2763 --- a/arch/arm/kernel/perf_event_cpu.c
2764 +++ b/arch/arm/kernel/perf_event_cpu.c
2765 @@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2766 return NOTIFY_OK;
2767 }
2768
2769 -static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2770 +static struct notifier_block cpu_pmu_hotplug_notifier = {
2771 .notifier_call = cpu_pmu_notify,
2772 };
2773
2774 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2775 index c6dec5f..f853532 100644
2776 --- a/arch/arm/kernel/process.c
2777 +++ b/arch/arm/kernel/process.c
2778 @@ -28,7 +28,6 @@
2779 #include <linux/tick.h>
2780 #include <linux/utsname.h>
2781 #include <linux/uaccess.h>
2782 -#include <linux/random.h>
2783 #include <linux/hw_breakpoint.h>
2784 #include <linux/cpuidle.h>
2785 #include <linux/leds.h>
2786 @@ -256,9 +255,10 @@ void machine_power_off(void)
2787 machine_shutdown();
2788 if (pm_power_off)
2789 pm_power_off();
2790 + BUG();
2791 }
2792
2793 -void machine_restart(char *cmd)
2794 +__noreturn void machine_restart(char *cmd)
2795 {
2796 machine_shutdown();
2797
2798 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2799 init_utsname()->release,
2800 (int)strcspn(init_utsname()->version, " "),
2801 init_utsname()->version);
2802 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2803 - print_symbol("LR is at %s\n", regs->ARM_lr);
2804 + printk("PC is at %pA\n", instruction_pointer(regs));
2805 + printk("LR is at %pA\n", regs->ARM_lr);
2806 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2807 "sp : %08lx ip : %08lx fp : %08lx\n",
2808 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2809 @@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2810 return 0;
2811 }
2812
2813 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2814 -{
2815 - unsigned long range_end = mm->brk + 0x02000000;
2816 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2817 -}
2818 -
2819 #ifdef CONFIG_MMU
2820 /*
2821 * The vectors page is always readable from user space for the
2822 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2823 index 03deeff..741ce88 100644
2824 --- a/arch/arm/kernel/ptrace.c
2825 +++ b/arch/arm/kernel/ptrace.c
2826 @@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2827 return current_thread_info()->syscall;
2828 }
2829
2830 +#ifdef CONFIG_GRKERNSEC_SETXID
2831 +extern void gr_delayed_cred_worker(void);
2832 +#endif
2833 +
2834 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2835 {
2836 current_thread_info()->syscall = scno;
2837
2838 +#ifdef CONFIG_GRKERNSEC_SETXID
2839 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2840 + gr_delayed_cred_worker();
2841 +#endif
2842 +
2843 /* Do the secure computing check first; failures should be fast. */
2844 if (secure_computing(scno) == -1)
2845 return -1;
2846 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2847 index 3f6cbb2..6d856f5 100644
2848 --- a/arch/arm/kernel/setup.c
2849 +++ b/arch/arm/kernel/setup.c
2850 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2851 unsigned int elf_hwcap __read_mostly;
2852 EXPORT_SYMBOL(elf_hwcap);
2853
2854 +pteval_t __supported_pte_mask __read_only;
2855 +pmdval_t __supported_pmd_mask __read_only;
2856
2857 #ifdef MULTI_CPU
2858 -struct processor processor __read_mostly;
2859 +struct processor processor;
2860 #endif
2861 #ifdef MULTI_TLB
2862 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2863 +struct cpu_tlb_fns cpu_tlb __read_only;
2864 #endif
2865 #ifdef MULTI_USER
2866 -struct cpu_user_fns cpu_user __read_mostly;
2867 +struct cpu_user_fns cpu_user __read_only;
2868 #endif
2869 #ifdef MULTI_CACHE
2870 -struct cpu_cache_fns cpu_cache __read_mostly;
2871 +struct cpu_cache_fns cpu_cache __read_only;
2872 #endif
2873 #ifdef CONFIG_OUTER_CACHE
2874 -struct outer_cache_fns outer_cache __read_mostly;
2875 +struct outer_cache_fns outer_cache __read_only;
2876 EXPORT_SYMBOL(outer_cache);
2877 #endif
2878
2879 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2880 asm("mrc p15, 0, %0, c0, c1, 4"
2881 : "=r" (mmfr0));
2882 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2883 - (mmfr0 & 0x000000f0) >= 0x00000030)
2884 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2885 cpu_arch = CPU_ARCH_ARMv7;
2886 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2887 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2888 + __supported_pte_mask |= L_PTE_PXN;
2889 + __supported_pmd_mask |= PMD_PXNTABLE;
2890 + }
2891 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2892 (mmfr0 & 0x000000f0) == 0x00000020)
2893 cpu_arch = CPU_ARCH_ARMv6;
2894 else
2895 @@ -462,7 +468,7 @@ static void __init setup_processor(void)
2896 __cpu_architecture = __get_cpu_architecture();
2897
2898 #ifdef MULTI_CPU
2899 - processor = *list->proc;
2900 + memcpy((void *)&processor, list->proc, sizeof processor);
2901 #endif
2902 #ifdef MULTI_TLB
2903 cpu_tlb = *list->tlb;
2904 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2905 index 84f4cbf..672f5b8 100644
2906 --- a/arch/arm/kernel/smp.c
2907 +++ b/arch/arm/kernel/smp.c
2908 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2909
2910 static DECLARE_COMPLETION(cpu_running);
2911
2912 -static struct smp_operations smp_ops;
2913 +static struct smp_operations smp_ops __read_only;
2914
2915 void __init smp_set_ops(struct smp_operations *ops)
2916 {
2917 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2918 index b0179b8..b7b16c7 100644
2919 --- a/arch/arm/kernel/traps.c
2920 +++ b/arch/arm/kernel/traps.c
2921 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2922 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2923 {
2924 #ifdef CONFIG_KALLSYMS
2925 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2926 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2927 #else
2928 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2929 #endif
2930 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2931 static int die_owner = -1;
2932 static unsigned int die_nest_count;
2933
2934 +extern void gr_handle_kernel_exploit(void);
2935 +
2936 static unsigned long oops_begin(void)
2937 {
2938 int cpu;
2939 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2940 panic("Fatal exception in interrupt");
2941 if (panic_on_oops)
2942 panic("Fatal exception");
2943 +
2944 + gr_handle_kernel_exploit();
2945 +
2946 if (signr)
2947 do_exit(signr);
2948 }
2949 @@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
2950 * The user helper at 0xffff0fe0 must be used instead.
2951 * (see entry-armv.S for details)
2952 */
2953 + pax_open_kernel();
2954 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
2955 + pax_close_kernel();
2956 }
2957 return 0;
2958
2959 @@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
2960 sigreturn_codes, sizeof(sigreturn_codes));
2961
2962 flush_icache_range(vectors, vectors + PAGE_SIZE);
2963 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
2964 +
2965 +#ifndef CONFIG_PAX_MEMORY_UDEREF
2966 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
2967 +#endif
2968 +
2969 }
2970 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2971 index 11c1785..c67d54c 100644
2972 --- a/arch/arm/kernel/vmlinux.lds.S
2973 +++ b/arch/arm/kernel/vmlinux.lds.S
2974 @@ -8,7 +8,11 @@
2975 #include <asm/thread_info.h>
2976 #include <asm/memory.h>
2977 #include <asm/page.h>
2978 -
2979 +
2980 +#ifdef CONFIG_PAX_KERNEXEC
2981 +#include <asm/pgtable.h>
2982 +#endif
2983 +
2984 #define PROC_INFO \
2985 . = ALIGN(4); \
2986 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2987 @@ -90,6 +94,11 @@ SECTIONS
2988 _text = .;
2989 HEAD_TEXT
2990 }
2991 +
2992 +#ifdef CONFIG_PAX_KERNEXEC
2993 + . = ALIGN(1<<SECTION_SHIFT);
2994 +#endif
2995 +
2996 .text : { /* Real text segment */
2997 _stext = .; /* Text and read-only data */
2998 __exception_text_start = .;
2999 @@ -144,6 +153,10 @@ SECTIONS
3000
3001 _etext = .; /* End of text and rodata section */
3002
3003 +#ifdef CONFIG_PAX_KERNEXEC
3004 + . = ALIGN(1<<SECTION_SHIFT);
3005 +#endif
3006 +
3007 #ifndef CONFIG_XIP_KERNEL
3008 . = ALIGN(PAGE_SIZE);
3009 __init_begin = .;
3010 @@ -203,6 +216,11 @@ SECTIONS
3011 . = PAGE_OFFSET + TEXT_OFFSET;
3012 #else
3013 __init_end = .;
3014 +
3015 +#ifdef CONFIG_PAX_KERNEXEC
3016 + . = ALIGN(1<<SECTION_SHIFT);
3017 +#endif
3018 +
3019 . = ALIGN(THREAD_SIZE);
3020 __data_loc = .;
3021 #endif
3022 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3023 index 14a0d98..7771a7d 100644
3024 --- a/arch/arm/lib/clear_user.S
3025 +++ b/arch/arm/lib/clear_user.S
3026 @@ -12,14 +12,14 @@
3027
3028 .text
3029
3030 -/* Prototype: int __clear_user(void *addr, size_t sz)
3031 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3032 * Purpose : clear some user memory
3033 * Params : addr - user memory address to clear
3034 * : sz - number of bytes to clear
3035 * Returns : number of bytes NOT cleared
3036 */
3037 ENTRY(__clear_user_std)
3038 -WEAK(__clear_user)
3039 +WEAK(___clear_user)
3040 stmfd sp!, {r1, lr}
3041 mov r2, #0
3042 cmp r1, #4
3043 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3044 USER( strnebt r2, [r0])
3045 mov r0, #0
3046 ldmfd sp!, {r1, pc}
3047 -ENDPROC(__clear_user)
3048 +ENDPROC(___clear_user)
3049 ENDPROC(__clear_user_std)
3050
3051 .pushsection .fixup,"ax"
3052 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3053 index 66a477a..bee61d3 100644
3054 --- a/arch/arm/lib/copy_from_user.S
3055 +++ b/arch/arm/lib/copy_from_user.S
3056 @@ -16,7 +16,7 @@
3057 /*
3058 * Prototype:
3059 *
3060 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3061 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3062 *
3063 * Purpose:
3064 *
3065 @@ -84,11 +84,11 @@
3066
3067 .text
3068
3069 -ENTRY(__copy_from_user)
3070 +ENTRY(___copy_from_user)
3071
3072 #include "copy_template.S"
3073
3074 -ENDPROC(__copy_from_user)
3075 +ENDPROC(___copy_from_user)
3076
3077 .pushsection .fixup,"ax"
3078 .align 0
3079 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3080 index 6ee2f67..d1cce76 100644
3081 --- a/arch/arm/lib/copy_page.S
3082 +++ b/arch/arm/lib/copy_page.S
3083 @@ -10,6 +10,7 @@
3084 * ASM optimised string functions
3085 */
3086 #include <linux/linkage.h>
3087 +#include <linux/const.h>
3088 #include <asm/assembler.h>
3089 #include <asm/asm-offsets.h>
3090 #include <asm/cache.h>
3091 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3092 index d066df6..df28194 100644
3093 --- a/arch/arm/lib/copy_to_user.S
3094 +++ b/arch/arm/lib/copy_to_user.S
3095 @@ -16,7 +16,7 @@
3096 /*
3097 * Prototype:
3098 *
3099 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3100 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3101 *
3102 * Purpose:
3103 *
3104 @@ -88,11 +88,11 @@
3105 .text
3106
3107 ENTRY(__copy_to_user_std)
3108 -WEAK(__copy_to_user)
3109 +WEAK(___copy_to_user)
3110
3111 #include "copy_template.S"
3112
3113 -ENDPROC(__copy_to_user)
3114 +ENDPROC(___copy_to_user)
3115 ENDPROC(__copy_to_user_std)
3116
3117 .pushsection .fixup,"ax"
3118 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3119 index 7d08b43..f7ca7ea 100644
3120 --- a/arch/arm/lib/csumpartialcopyuser.S
3121 +++ b/arch/arm/lib/csumpartialcopyuser.S
3122 @@ -57,8 +57,8 @@
3123 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3124 */
3125
3126 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3127 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3128 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3129 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3130
3131 #include "csumpartialcopygeneric.S"
3132
3133 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3134 index 0dc5385..45833ef 100644
3135 --- a/arch/arm/lib/delay.c
3136 +++ b/arch/arm/lib/delay.c
3137 @@ -28,12 +28,14 @@
3138 /*
3139 * Default to the loop-based delay implementation.
3140 */
3141 -struct arm_delay_ops arm_delay_ops = {
3142 +static struct arm_delay_ops arm_loop_delay_ops = {
3143 .delay = __loop_delay,
3144 .const_udelay = __loop_const_udelay,
3145 .udelay = __loop_udelay,
3146 };
3147
3148 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3149 +
3150 static const struct delay_timer *delay_timer;
3151 static bool delay_calibrated;
3152
3153 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
3154 __timer_const_udelay(usecs * UDELAY_MULT);
3155 }
3156
3157 +static struct arm_delay_ops arm_timer_delay_ops = {
3158 + .delay = __timer_delay,
3159 + .const_udelay = __timer_const_udelay,
3160 + .udelay = __timer_udelay,
3161 +};
3162 +
3163 void __init register_current_timer_delay(const struct delay_timer *timer)
3164 {
3165 if (!delay_calibrated) {
3166 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3167 delay_timer = timer;
3168 lpj_fine = timer->freq / HZ;
3169 loops_per_jiffy = lpj_fine;
3170 - arm_delay_ops.delay = __timer_delay;
3171 - arm_delay_ops.const_udelay = __timer_const_udelay;
3172 - arm_delay_ops.udelay = __timer_udelay;
3173 + arm_delay_ops = &arm_timer_delay_ops;
3174 delay_calibrated = true;
3175 } else {
3176 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3177 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3178 index 025f742..8432b08 100644
3179 --- a/arch/arm/lib/uaccess_with_memcpy.c
3180 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3181 @@ -104,7 +104,7 @@ out:
3182 }
3183
3184 unsigned long
3185 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3186 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3187 {
3188 /*
3189 * This test is stubbed out of the main function above to keep
3190 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3191 index bac21a5..b67ef8e 100644
3192 --- a/arch/arm/mach-kirkwood/common.c
3193 +++ b/arch/arm/mach-kirkwood/common.c
3194 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3195 clk_gate_ops.disable(hw);
3196 }
3197
3198 -static struct clk_ops clk_gate_fn_ops;
3199 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3200 +{
3201 + return clk_gate_ops.is_enabled(hw);
3202 +}
3203 +
3204 +static struct clk_ops clk_gate_fn_ops = {
3205 + .enable = clk_gate_fn_enable,
3206 + .disable = clk_gate_fn_disable,
3207 + .is_enabled = clk_gate_fn_is_enabled,
3208 +};
3209
3210 static struct clk __init *clk_register_gate_fn(struct device *dev,
3211 const char *name,
3212 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3213 gate_fn->fn_en = fn_en;
3214 gate_fn->fn_dis = fn_dis;
3215
3216 - /* ops is the gate ops, but with our enable/disable functions */
3217 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3218 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3219 - clk_gate_fn_ops = clk_gate_ops;
3220 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3221 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3222 - }
3223 -
3224 clk = clk_register(dev, &gate_fn->gate.hw);
3225
3226 if (IS_ERR(clk))
3227 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3228 index 0abb30f..54064da 100644
3229 --- a/arch/arm/mach-omap2/board-n8x0.c
3230 +++ b/arch/arm/mach-omap2/board-n8x0.c
3231 @@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3232 }
3233 #endif
3234
3235 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3236 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3237 .late_init = n8x0_menelaus_late_init,
3238 };
3239
3240 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3241 index 5d3b4f4..ddba3c0 100644
3242 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3243 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3244 @@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3245 return NOTIFY_OK;
3246 }
3247
3248 -static struct notifier_block __refdata irq_hotplug_notifier = {
3249 +static struct notifier_block irq_hotplug_notifier = {
3250 .notifier_call = irq_cpu_hotplug_notify,
3251 };
3252
3253 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3254 index 4653efb..8c60bf7 100644
3255 --- a/arch/arm/mach-omap2/omap_hwmod.c
3256 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3257 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3258 int (*init_clkdm)(struct omap_hwmod *oh);
3259 void (*update_context_lost)(struct omap_hwmod *oh);
3260 int (*get_context_lost)(struct omap_hwmod *oh);
3261 -};
3262 +} __no_const;
3263
3264 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3265 -static struct omap_hwmod_soc_ops soc_ops;
3266 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3267
3268 /* omap_hwmod_list contains all registered struct omap_hwmods */
3269 static LIST_HEAD(omap_hwmod_list);
3270 diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3271 index 6be4c4d..32ac32a 100644
3272 --- a/arch/arm/mach-ux500/include/mach/setup.h
3273 +++ b/arch/arm/mach-ux500/include/mach/setup.h
3274 @@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3275 .type = MT_DEVICE, \
3276 }
3277
3278 -#define __MEM_DEV_DESC(x, sz) { \
3279 - .virtual = IO_ADDRESS(x), \
3280 - .pfn = __phys_to_pfn(x), \
3281 - .length = sz, \
3282 - .type = MT_MEMORY, \
3283 -}
3284 -
3285 extern struct smp_operations ux500_smp_ops;
3286 extern void ux500_cpu_die(unsigned int cpu);
3287
3288 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3289 index 3fd629d..8b1aca9 100644
3290 --- a/arch/arm/mm/Kconfig
3291 +++ b/arch/arm/mm/Kconfig
3292 @@ -425,7 +425,7 @@ config CPU_32v5
3293
3294 config CPU_32v6
3295 bool
3296 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3297 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3298 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3299
3300 config CPU_32v6K
3301 @@ -577,6 +577,7 @@ config CPU_CP15_MPU
3302
3303 config CPU_USE_DOMAINS
3304 bool
3305 + depends on !ARM_LPAE && !PAX_KERNEXEC
3306 help
3307 This option enables or disables the use of domain switching
3308 via the set_fs() function.
3309 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3310 index 5dbf13f..6393f55 100644
3311 --- a/arch/arm/mm/fault.c
3312 +++ b/arch/arm/mm/fault.c
3313 @@ -25,6 +25,7 @@
3314 #include <asm/system_misc.h>
3315 #include <asm/system_info.h>
3316 #include <asm/tlbflush.h>
3317 +#include <asm/sections.h>
3318
3319 #include "fault.h"
3320
3321 @@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3322 if (fixup_exception(regs))
3323 return;
3324
3325 +#ifdef CONFIG_PAX_KERNEXEC
3326 + if ((fsr & FSR_WRITE) &&
3327 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3328 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3329 + {
3330 + if (current->signal->curr_ip)
3331 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3332 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3333 + else
3334 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3335 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3336 + }
3337 +#endif
3338 +
3339 /*
3340 * No handler, we'll have to terminate things with extreme prejudice.
3341 */
3342 @@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3343 }
3344 #endif
3345
3346 +#ifdef CONFIG_PAX_PAGEEXEC
3347 + if (fsr & FSR_LNX_PF) {
3348 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3349 + do_group_exit(SIGKILL);
3350 + }
3351 +#endif
3352 +
3353 tsk->thread.address = addr;
3354 tsk->thread.error_code = fsr;
3355 tsk->thread.trap_no = 14;
3356 @@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3357 }
3358 #endif /* CONFIG_MMU */
3359
3360 +#ifdef CONFIG_PAX_PAGEEXEC
3361 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3362 +{
3363 + long i;
3364 +
3365 + printk(KERN_ERR "PAX: bytes at PC: ");
3366 + for (i = 0; i < 20; i++) {
3367 + unsigned char c;
3368 + if (get_user(c, (__force unsigned char __user *)pc+i))
3369 + printk(KERN_CONT "?? ");
3370 + else
3371 + printk(KERN_CONT "%02x ", c);
3372 + }
3373 + printk("\n");
3374 +
3375 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3376 + for (i = -1; i < 20; i++) {
3377 + unsigned long c;
3378 + if (get_user(c, (__force unsigned long __user *)sp+i))
3379 + printk(KERN_CONT "???????? ");
3380 + else
3381 + printk(KERN_CONT "%08lx ", c);
3382 + }
3383 + printk("\n");
3384 +}
3385 +#endif
3386 +
3387 /*
3388 * First Level Translation Fault Handler
3389 *
3390 @@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3391 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3392 struct siginfo info;
3393
3394 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3395 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3396 + if (current->signal->curr_ip)
3397 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3398 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3399 + else
3400 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3401 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3402 + goto die;
3403 + }
3404 +#endif
3405 +
3406 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3407 return;
3408
3409 +die:
3410 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3411 inf->name, fsr, addr);
3412
3413 @@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3414 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3415 struct siginfo info;
3416
3417 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3418 + if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3419 + if (current->signal->curr_ip)
3420 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3421 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3422 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3423 + else
3424 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3425 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3426 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3427 + goto die;
3428 + }
3429 +#endif
3430 +
3431 +#ifdef CONFIG_PAX_REFCOUNT
3432 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3433 + unsigned int bkpt;
3434 +
3435 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3436 + current->thread.error_code = ifsr;
3437 + current->thread.trap_no = 0;
3438 + pax_report_refcount_overflow(regs);
3439 + fixup_exception(regs);
3440 + return;
3441 + }
3442 + }
3443 +#endif
3444 +
3445 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3446 return;
3447
3448 +die:
3449 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3450 inf->name, ifsr, addr);
3451
3452 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3453 index cf08bdf..772656c 100644
3454 --- a/arch/arm/mm/fault.h
3455 +++ b/arch/arm/mm/fault.h
3456 @@ -3,6 +3,7 @@
3457
3458 /*
3459 * Fault status register encodings. We steal bit 31 for our own purposes.
3460 + * Set when the FSR value is from an instruction fault.
3461 */
3462 #define FSR_LNX_PF (1 << 31)
3463 #define FSR_WRITE (1 << 11)
3464 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3465 }
3466 #endif
3467
3468 +/* valid for LPAE and !LPAE */
3469 +static inline int is_xn_fault(unsigned int fsr)
3470 +{
3471 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
3472 +}
3473 +
3474 +static inline int is_domain_fault(unsigned int fsr)
3475 +{
3476 + return ((fsr_fs(fsr) & 0xD) == 0x9);
3477 +}
3478 +
3479 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3480 unsigned long search_exception_table(unsigned long addr);
3481
3482 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3483 index ad722f1..763fdd3 100644
3484 --- a/arch/arm/mm/init.c
3485 +++ b/arch/arm/mm/init.c
3486 @@ -30,6 +30,8 @@
3487 #include <asm/setup.h>
3488 #include <asm/tlb.h>
3489 #include <asm/fixmap.h>
3490 +#include <asm/system_info.h>
3491 +#include <asm/cp15.h>
3492
3493 #include <asm/mach/arch.h>
3494 #include <asm/mach/map.h>
3495 @@ -736,7 +738,46 @@ void free_initmem(void)
3496 {
3497 #ifdef CONFIG_HAVE_TCM
3498 extern char __tcm_start, __tcm_end;
3499 +#endif
3500
3501 +#ifdef CONFIG_PAX_KERNEXEC
3502 + unsigned long addr;
3503 + pgd_t *pgd;
3504 + pud_t *pud;
3505 + pmd_t *pmd;
3506 + int cpu_arch = cpu_architecture();
3507 + unsigned int cr = get_cr();
3508 +
3509 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3510 + /* make pages tables, etc before .text NX */
3511 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3512 + pgd = pgd_offset_k(addr);
3513 + pud = pud_offset(pgd, addr);
3514 + pmd = pmd_offset(pud, addr);
3515 + __section_update(pmd, addr, PMD_SECT_XN);
3516 + }
3517 + /* make init NX */
3518 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3519 + pgd = pgd_offset_k(addr);
3520 + pud = pud_offset(pgd, addr);
3521 + pmd = pmd_offset(pud, addr);
3522 + __section_update(pmd, addr, PMD_SECT_XN);
3523 + }
3524 + /* make kernel code/rodata RX */
3525 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3526 + pgd = pgd_offset_k(addr);
3527 + pud = pud_offset(pgd, addr);
3528 + pmd = pmd_offset(pud, addr);
3529 +#ifdef CONFIG_ARM_LPAE
3530 + __section_update(pmd, addr, PMD_SECT_RDONLY);
3531 +#else
3532 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3533 +#endif
3534 + }
3535 + }
3536 +#endif
3537 +
3538 +#ifdef CONFIG_HAVE_TCM
3539 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3540 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3541 __phys_to_pfn(__pa(&__tcm_end)),
3542 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3543 index 88fd86c..7a224ce 100644
3544 --- a/arch/arm/mm/ioremap.c
3545 +++ b/arch/arm/mm/ioremap.c
3546 @@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3547 unsigned int mtype;
3548
3549 if (cached)
3550 - mtype = MT_MEMORY;
3551 + mtype = MT_MEMORY_RX;
3552 else
3553 - mtype = MT_MEMORY_NONCACHED;
3554 + mtype = MT_MEMORY_NONCACHED_RX;
3555
3556 return __arm_ioremap_caller(phys_addr, size, mtype,
3557 __builtin_return_address(0));
3558 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3559 index 10062ce..aa96dd7 100644
3560 --- a/arch/arm/mm/mmap.c
3561 +++ b/arch/arm/mm/mmap.c
3562 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3563 struct vm_area_struct *vma;
3564 int do_align = 0;
3565 int aliasing = cache_is_vipt_aliasing();
3566 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3567 struct vm_unmapped_area_info info;
3568
3569 /*
3570 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3571 if (len > TASK_SIZE)
3572 return -ENOMEM;
3573
3574 +#ifdef CONFIG_PAX_RANDMMAP
3575 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3576 +#endif
3577 +
3578 if (addr) {
3579 if (do_align)
3580 addr = COLOUR_ALIGN(addr, pgoff);
3581 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3582 addr = PAGE_ALIGN(addr);
3583
3584 vma = find_vma(mm, addr);
3585 - if (TASK_SIZE - len >= addr &&
3586 - (!vma || addr + len <= vma->vm_start))
3587 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3588 return addr;
3589 }
3590
3591 @@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3592 unsigned long addr = addr0;
3593 int do_align = 0;
3594 int aliasing = cache_is_vipt_aliasing();
3595 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3596 struct vm_unmapped_area_info info;
3597
3598 /*
3599 @@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3600 return addr;
3601 }
3602
3603 +#ifdef CONFIG_PAX_RANDMMAP
3604 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3605 +#endif
3606 +
3607 /* requesting a specific address */
3608 if (addr) {
3609 if (do_align)
3610 @@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3611 else
3612 addr = PAGE_ALIGN(addr);
3613 vma = find_vma(mm, addr);
3614 - if (TASK_SIZE - len >= addr &&
3615 - (!vma || addr + len <= vma->vm_start))
3616 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3617 return addr;
3618 }
3619
3620 @@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3621 VM_BUG_ON(addr != -ENOMEM);
3622 info.flags = 0;
3623 info.low_limit = mm->mmap_base;
3624 +
3625 +#ifdef CONFIG_PAX_RANDMMAP
3626 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3627 + info.low_limit += mm->delta_mmap;
3628 +#endif
3629 +
3630 info.high_limit = TASK_SIZE;
3631 addr = vm_unmapped_area(&info);
3632 }
3633 @@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3634 {
3635 unsigned long random_factor = 0UL;
3636
3637 +#ifdef CONFIG_PAX_RANDMMAP
3638 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3639 +#endif
3640 +
3641 /* 8 bits of randomness in 20 address space bits */
3642 if ((current->flags & PF_RANDOMIZE) &&
3643 !(current->personality & ADDR_NO_RANDOMIZE))
3644 @@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3645
3646 if (mmap_is_legacy()) {
3647 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3648 +
3649 +#ifdef CONFIG_PAX_RANDMMAP
3650 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3651 + mm->mmap_base += mm->delta_mmap;
3652 +#endif
3653 +
3654 mm->get_unmapped_area = arch_get_unmapped_area;
3655 mm->unmap_area = arch_unmap_area;
3656 } else {
3657 mm->mmap_base = mmap_base(random_factor);
3658 +
3659 +#ifdef CONFIG_PAX_RANDMMAP
3660 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3661 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3662 +#endif
3663 +
3664 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3665 mm->unmap_area = arch_unmap_area_topdown;
3666 }
3667 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3668 index ce328c7..f82bebb 100644
3669 --- a/arch/arm/mm/mmu.c
3670 +++ b/arch/arm/mm/mmu.c
3671 @@ -35,6 +35,23 @@
3672
3673 #include "mm.h"
3674
3675 +
3676 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3677 +void modify_domain(unsigned int dom, unsigned int type)
3678 +{
3679 + struct thread_info *thread = current_thread_info();
3680 + unsigned int domain = thread->cpu_domain;
3681 + /*
3682 + * DOMAIN_MANAGER might be defined to some other value,
3683 + * use the arch-defined constant
3684 + */
3685 + domain &= ~domain_val(dom, 3);
3686 + thread->cpu_domain = domain | domain_val(dom, type);
3687 + set_domain(thread->cpu_domain);
3688 +}
3689 +EXPORT_SYMBOL(modify_domain);
3690 +#endif
3691 +
3692 /*
3693 * empty_zero_page is a special page that is used for
3694 * zero-initialized data and COW.
3695 @@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3696 }
3697 #endif
3698
3699 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3700 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3701 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3702
3703 -static struct mem_type mem_types[] = {
3704 +#ifdef CONFIG_PAX_KERNEXEC
3705 +#define L_PTE_KERNEXEC L_PTE_RDONLY
3706 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3707 +#else
3708 +#define L_PTE_KERNEXEC L_PTE_DIRTY
3709 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3710 +#endif
3711 +
3712 +static struct mem_type mem_types[] __read_only = {
3713 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3714 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3715 L_PTE_SHARED,
3716 @@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3717 [MT_UNCACHED] = {
3718 .prot_pte = PROT_PTE_DEVICE,
3719 .prot_l1 = PMD_TYPE_TABLE,
3720 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3721 + .prot_sect = PROT_SECT_DEVICE,
3722 .domain = DOMAIN_IO,
3723 },
3724 [MT_CACHECLEAN] = {
3725 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3726 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3727 .domain = DOMAIN_KERNEL,
3728 },
3729 #ifndef CONFIG_ARM_LPAE
3730 [MT_MINICLEAN] = {
3731 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3732 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3733 .domain = DOMAIN_KERNEL,
3734 },
3735 #endif
3736 @@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3737 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3738 L_PTE_RDONLY,
3739 .prot_l1 = PMD_TYPE_TABLE,
3740 - .domain = DOMAIN_USER,
3741 + .domain = DOMAIN_VECTORS,
3742 },
3743 [MT_HIGH_VECTORS] = {
3744 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3745 L_PTE_USER | L_PTE_RDONLY,
3746 .prot_l1 = PMD_TYPE_TABLE,
3747 - .domain = DOMAIN_USER,
3748 + .domain = DOMAIN_VECTORS,
3749 },
3750 - [MT_MEMORY] = {
3751 + [MT_MEMORY_RWX] = {
3752 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3753 .prot_l1 = PMD_TYPE_TABLE,
3754 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3755 .domain = DOMAIN_KERNEL,
3756 },
3757 + [MT_MEMORY_RW] = {
3758 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3759 + .prot_l1 = PMD_TYPE_TABLE,
3760 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3761 + .domain = DOMAIN_KERNEL,
3762 + },
3763 + [MT_MEMORY_RX] = {
3764 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3765 + .prot_l1 = PMD_TYPE_TABLE,
3766 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3767 + .domain = DOMAIN_KERNEL,
3768 + },
3769 [MT_ROM] = {
3770 - .prot_sect = PMD_TYPE_SECT,
3771 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3772 .domain = DOMAIN_KERNEL,
3773 },
3774 - [MT_MEMORY_NONCACHED] = {
3775 + [MT_MEMORY_NONCACHED_RW] = {
3776 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3777 L_PTE_MT_BUFFERABLE,
3778 .prot_l1 = PMD_TYPE_TABLE,
3779 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3780 .domain = DOMAIN_KERNEL,
3781 },
3782 + [MT_MEMORY_NONCACHED_RX] = {
3783 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3784 + L_PTE_MT_BUFFERABLE,
3785 + .prot_l1 = PMD_TYPE_TABLE,
3786 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3787 + .domain = DOMAIN_KERNEL,
3788 + },
3789 [MT_MEMORY_DTCM] = {
3790 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3791 - L_PTE_XN,
3792 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3793 .prot_l1 = PMD_TYPE_TABLE,
3794 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3795 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3796 .domain = DOMAIN_KERNEL,
3797 },
3798 [MT_MEMORY_ITCM] = {
3799 @@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3800 },
3801 [MT_MEMORY_SO] = {
3802 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3803 - L_PTE_MT_UNCACHED | L_PTE_XN,
3804 + L_PTE_MT_UNCACHED,
3805 .prot_l1 = PMD_TYPE_TABLE,
3806 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3807 - PMD_SECT_UNCACHED | PMD_SECT_XN,
3808 + PMD_SECT_UNCACHED,
3809 .domain = DOMAIN_KERNEL,
3810 },
3811 [MT_MEMORY_DMA_READY] = {
3812 @@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3813 * to prevent speculative instruction fetches.
3814 */
3815 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3816 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3817 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
3818 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
3819 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
3820 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
3821 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
3822 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
3823 +
3824 + /* Mark other regions on ARMv6+ as execute-never */
3825 +
3826 +#ifdef CONFIG_PAX_KERNEXEC
3827 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
3828 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
3829 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
3830 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
3831 +#ifndef CONFIG_ARM_LPAE
3832 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
3833 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
3834 +#endif
3835 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
3836 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
3837 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
3838 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
3839 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
3840 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
3841 +#endif
3842 +
3843 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
3844 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
3845 }
3846 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3847 /*
3848 @@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
3849 * from SVC mode and no access from userspace.
3850 */
3851 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3852 +#ifdef CONFIG_PAX_KERNEXEC
3853 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3854 +#endif
3855 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3856 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3857 #endif
3858 @@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
3859 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
3860 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
3861 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
3862 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
3863 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
3864 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
3865 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
3866 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
3867 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
3868 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
3869 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
3870 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
3871 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
3872 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
3873 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
3874 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
3875 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
3876 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
3877 }
3878 }
3879
3880 @@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
3881 if (cpu_arch >= CPU_ARCH_ARMv6) {
3882 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3883 /* Non-cacheable Normal is XCB = 001 */
3884 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3885 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3886 + PMD_SECT_BUFFERED;
3887 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3888 PMD_SECT_BUFFERED;
3889 } else {
3890 /* For both ARMv6 and non-TEX-remapping ARMv7 */
3891 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3892 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3893 + PMD_SECT_TEX(1);
3894 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3895 PMD_SECT_TEX(1);
3896 }
3897 } else {
3898 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
3899 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
3900 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
3901 }
3902
3903 #ifdef CONFIG_ARM_LPAE
3904 @@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
3905 vecs_pgprot |= PTE_EXT_AF;
3906 #endif
3907
3908 + user_pgprot |= __supported_pte_mask;
3909 +
3910 for (i = 0; i < 16; i++) {
3911 pteval_t v = pgprot_val(protection_map[i]);
3912 protection_map[i] = __pgprot(v | user_pgprot);
3913 @@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
3914
3915 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
3916 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
3917 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
3918 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
3919 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
3920 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
3921 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
3922 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
3923 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
3924 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
3925 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
3926 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
3927 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
3928 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
3929 mem_types[MT_ROM].prot_sect |= cp->pmd;
3930
3931 switch (cp->pmd) {
3932 @@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
3933 * called function. This means you can't use any function or debugging
3934 * method which may touch any device, otherwise the kernel _will_ crash.
3935 */
3936 +
3937 +static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
3938 +
3939 static void __init devicemaps_init(struct machine_desc *mdesc)
3940 {
3941 struct map_desc map;
3942 unsigned long addr;
3943 - void *vectors;
3944
3945 - /*
3946 - * Allocate the vector page early.
3947 - */
3948 - vectors = early_alloc(PAGE_SIZE);
3949 -
3950 - early_trap_init(vectors);
3951 + early_trap_init(&vectors);
3952
3953 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
3954 pmd_clear(pmd_off_k(addr));
3955 @@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
3956 * location (0xffff0000). If we aren't using high-vectors, also
3957 * create a mapping at the low-vectors virtual address.
3958 */
3959 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
3960 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
3961 map.virtual = 0xffff0000;
3962 map.length = PAGE_SIZE;
3963 map.type = MT_HIGH_VECTORS;
3964 @@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
3965 map.pfn = __phys_to_pfn(start);
3966 map.virtual = __phys_to_virt(start);
3967 map.length = end - start;
3968 - map.type = MT_MEMORY;
3969
3970 +#ifdef CONFIG_PAX_KERNEXEC
3971 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
3972 + struct map_desc kernel;
3973 + struct map_desc initmap;
3974 +
3975 + /* when freeing initmem we will make this RW */
3976 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
3977 + initmap.virtual = (unsigned long)__init_begin;
3978 + initmap.length = _sdata - __init_begin;
3979 + initmap.type = MT_MEMORY_RWX;
3980 + create_mapping(&initmap);
3981 +
3982 + /* when freeing initmem we will make this RX */
3983 + kernel.pfn = __phys_to_pfn(__pa(_stext));
3984 + kernel.virtual = (unsigned long)_stext;
3985 + kernel.length = __init_begin - _stext;
3986 + kernel.type = MT_MEMORY_RWX;
3987 + create_mapping(&kernel);
3988 +
3989 + if (map.virtual < (unsigned long)_stext) {
3990 + map.length = (unsigned long)_stext - map.virtual;
3991 + map.type = MT_MEMORY_RWX;
3992 + create_mapping(&map);
3993 + }
3994 +
3995 + map.pfn = __phys_to_pfn(__pa(_sdata));
3996 + map.virtual = (unsigned long)_sdata;
3997 + map.length = end - __pa(_sdata);
3998 + }
3999 +#endif
4000 +
4001 + map.type = MT_MEMORY_RW;
4002 create_mapping(&map);
4003 }
4004 }
4005 diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4006 index 6d98c13..3cfb174 100644
4007 --- a/arch/arm/mm/proc-v7-2level.S
4008 +++ b/arch/arm/mm/proc-v7-2level.S
4009 @@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4010 tst r1, #L_PTE_XN
4011 orrne r3, r3, #PTE_EXT_XN
4012
4013 + tst r1, #L_PTE_PXN
4014 + orrne r3, r3, #PTE_EXT_PXN
4015 +
4016 tst r1, #L_PTE_YOUNG
4017 tstne r1, #L_PTE_VALID
4018 #ifndef CONFIG_CPU_USE_DOMAINS
4019 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4020 index a5bc92d..0bb4730 100644
4021 --- a/arch/arm/plat-omap/sram.c
4022 +++ b/arch/arm/plat-omap/sram.c
4023 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4024 * Looks like we need to preserve some bootloader code at the
4025 * beginning of SRAM for jumping to flash for reboot to work...
4026 */
4027 + pax_open_kernel();
4028 memset_io(omap_sram_base + omap_sram_skip, 0,
4029 omap_sram_size - omap_sram_skip);
4030 + pax_close_kernel();
4031 }
4032 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
4033 index b76c065..b6e766b 100644
4034 --- a/arch/arm/plat-orion/include/plat/addr-map.h
4035 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
4036 @@ -27,7 +27,7 @@ struct orion_addr_map_cfg {
4037 value in bridge_virt_base */
4038 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
4039 const int win);
4040 -};
4041 +} __no_const;
4042
4043 /*
4044 * Information needed to setup one address mapping.
4045 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4046 index f5144cd..71f6d1f 100644
4047 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4048 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4049 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4050 int (*started)(unsigned ch);
4051 int (*flush)(unsigned ch);
4052 int (*stop)(unsigned ch);
4053 -};
4054 +} __no_const;
4055
4056 extern void *samsung_dmadev_get_ops(void);
4057 extern void *s3c_dma_get_ops(void);
4058 diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4059 index 0c3ba9f..95722b3 100644
4060 --- a/arch/arm64/kernel/debug-monitors.c
4061 +++ b/arch/arm64/kernel/debug-monitors.c
4062 @@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4063 return NOTIFY_OK;
4064 }
4065
4066 -static struct notifier_block __cpuinitdata os_lock_nb = {
4067 +static struct notifier_block os_lock_nb = {
4068 .notifier_call = os_lock_notify,
4069 };
4070
4071 diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4072 index 5ab825c..96aaec8 100644
4073 --- a/arch/arm64/kernel/hw_breakpoint.c
4074 +++ b/arch/arm64/kernel/hw_breakpoint.c
4075 @@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4076 return NOTIFY_OK;
4077 }
4078
4079 -static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4080 +static struct notifier_block hw_breakpoint_reset_nb = {
4081 .notifier_call = hw_breakpoint_reset_notify,
4082 };
4083
4084 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4085 index c3a58a1..78fbf54 100644
4086 --- a/arch/avr32/include/asm/cache.h
4087 +++ b/arch/avr32/include/asm/cache.h
4088 @@ -1,8 +1,10 @@
4089 #ifndef __ASM_AVR32_CACHE_H
4090 #define __ASM_AVR32_CACHE_H
4091
4092 +#include <linux/const.h>
4093 +
4094 #define L1_CACHE_SHIFT 5
4095 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4096 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4097
4098 /*
4099 * Memory returned by kmalloc() may be used for DMA, so we must make
4100 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4101 index e2c3287..6c4f98c 100644
4102 --- a/arch/avr32/include/asm/elf.h
4103 +++ b/arch/avr32/include/asm/elf.h
4104 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4105 the loader. We need to make sure that it is out of the way of the program
4106 that it will "exec", and that there is sufficient room for the brk. */
4107
4108 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4109 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4110
4111 +#ifdef CONFIG_PAX_ASLR
4112 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4113 +
4114 +#define PAX_DELTA_MMAP_LEN 15
4115 +#define PAX_DELTA_STACK_LEN 15
4116 +#endif
4117
4118 /* This yields a mask that user programs can use to figure out what
4119 instruction set this CPU supports. This could be done in user space,
4120 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4121 index 479330b..53717a8 100644
4122 --- a/arch/avr32/include/asm/kmap_types.h
4123 +++ b/arch/avr32/include/asm/kmap_types.h
4124 @@ -2,9 +2,9 @@
4125 #define __ASM_AVR32_KMAP_TYPES_H
4126
4127 #ifdef CONFIG_DEBUG_HIGHMEM
4128 -# define KM_TYPE_NR 29
4129 +# define KM_TYPE_NR 30
4130 #else
4131 -# define KM_TYPE_NR 14
4132 +# define KM_TYPE_NR 15
4133 #endif
4134
4135 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4136 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4137 index b2f2d2d..d1c85cb 100644
4138 --- a/arch/avr32/mm/fault.c
4139 +++ b/arch/avr32/mm/fault.c
4140 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4141
4142 int exception_trace = 1;
4143
4144 +#ifdef CONFIG_PAX_PAGEEXEC
4145 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4146 +{
4147 + unsigned long i;
4148 +
4149 + printk(KERN_ERR "PAX: bytes at PC: ");
4150 + for (i = 0; i < 20; i++) {
4151 + unsigned char c;
4152 + if (get_user(c, (unsigned char *)pc+i))
4153 + printk(KERN_CONT "???????? ");
4154 + else
4155 + printk(KERN_CONT "%02x ", c);
4156 + }
4157 + printk("\n");
4158 +}
4159 +#endif
4160 +
4161 /*
4162 * This routine handles page faults. It determines the address and the
4163 * problem, and then passes it off to one of the appropriate routines.
4164 @@ -174,6 +191,16 @@ bad_area:
4165 up_read(&mm->mmap_sem);
4166
4167 if (user_mode(regs)) {
4168 +
4169 +#ifdef CONFIG_PAX_PAGEEXEC
4170 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4171 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4172 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4173 + do_group_exit(SIGKILL);
4174 + }
4175 + }
4176 +#endif
4177 +
4178 if (exception_trace && printk_ratelimit())
4179 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4180 "sp %08lx ecr %lu\n",
4181 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4182 index 568885a..f8008df 100644
4183 --- a/arch/blackfin/include/asm/cache.h
4184 +++ b/arch/blackfin/include/asm/cache.h
4185 @@ -7,6 +7,7 @@
4186 #ifndef __ARCH_BLACKFIN_CACHE_H
4187 #define __ARCH_BLACKFIN_CACHE_H
4188
4189 +#include <linux/const.h>
4190 #include <linux/linkage.h> /* for asmlinkage */
4191
4192 /*
4193 @@ -14,7 +15,7 @@
4194 * Blackfin loads 32 bytes for cache
4195 */
4196 #define L1_CACHE_SHIFT 5
4197 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4198 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4199 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4200
4201 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4202 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4203 index aea2718..3639a60 100644
4204 --- a/arch/cris/include/arch-v10/arch/cache.h
4205 +++ b/arch/cris/include/arch-v10/arch/cache.h
4206 @@ -1,8 +1,9 @@
4207 #ifndef _ASM_ARCH_CACHE_H
4208 #define _ASM_ARCH_CACHE_H
4209
4210 +#include <linux/const.h>
4211 /* Etrax 100LX have 32-byte cache-lines. */
4212 -#define L1_CACHE_BYTES 32
4213 #define L1_CACHE_SHIFT 5
4214 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4215
4216 #endif /* _ASM_ARCH_CACHE_H */
4217 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4218 index 7caf25d..ee65ac5 100644
4219 --- a/arch/cris/include/arch-v32/arch/cache.h
4220 +++ b/arch/cris/include/arch-v32/arch/cache.h
4221 @@ -1,11 +1,12 @@
4222 #ifndef _ASM_CRIS_ARCH_CACHE_H
4223 #define _ASM_CRIS_ARCH_CACHE_H
4224
4225 +#include <linux/const.h>
4226 #include <arch/hwregs/dma.h>
4227
4228 /* A cache-line is 32 bytes. */
4229 -#define L1_CACHE_BYTES 32
4230 #define L1_CACHE_SHIFT 5
4231 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4232
4233 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4234
4235 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4236 index b86329d..6709906 100644
4237 --- a/arch/frv/include/asm/atomic.h
4238 +++ b/arch/frv/include/asm/atomic.h
4239 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4240 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4241 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4242
4243 +#define atomic64_read_unchecked(v) atomic64_read(v)
4244 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4245 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4246 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4247 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4248 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4249 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4250 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4251 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4252 +
4253 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4254 {
4255 int c, old;
4256 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4257 index 2797163..c2a401d 100644
4258 --- a/arch/frv/include/asm/cache.h
4259 +++ b/arch/frv/include/asm/cache.h
4260 @@ -12,10 +12,11 @@
4261 #ifndef __ASM_CACHE_H
4262 #define __ASM_CACHE_H
4263
4264 +#include <linux/const.h>
4265
4266 /* bytes per L1 cache line */
4267 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4268 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4269 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4270
4271 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4272 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4273 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4274 index 43901f2..0d8b865 100644
4275 --- a/arch/frv/include/asm/kmap_types.h
4276 +++ b/arch/frv/include/asm/kmap_types.h
4277 @@ -2,6 +2,6 @@
4278 #ifndef _ASM_KMAP_TYPES_H
4279 #define _ASM_KMAP_TYPES_H
4280
4281 -#define KM_TYPE_NR 17
4282 +#define KM_TYPE_NR 18
4283
4284 #endif
4285 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4286 index 385fd30..3aaf4fe 100644
4287 --- a/arch/frv/mm/elf-fdpic.c
4288 +++ b/arch/frv/mm/elf-fdpic.c
4289 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4290 {
4291 struct vm_area_struct *vma;
4292 unsigned long limit;
4293 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4294
4295 if (len > TASK_SIZE)
4296 return -ENOMEM;
4297 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4298 if (addr) {
4299 addr = PAGE_ALIGN(addr);
4300 vma = find_vma(current->mm, addr);
4301 - if (TASK_SIZE - len >= addr &&
4302 - (!vma || addr + len <= vma->vm_start))
4303 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4304 goto success;
4305 }
4306
4307 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4308 for (; vma; vma = vma->vm_next) {
4309 if (addr > limit)
4310 break;
4311 - if (addr + len <= vma->vm_start)
4312 + if (check_heap_stack_gap(vma, addr, len, offset))
4313 goto success;
4314 addr = vma->vm_end;
4315 }
4316 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4317 for (; vma; vma = vma->vm_next) {
4318 if (addr > limit)
4319 break;
4320 - if (addr + len <= vma->vm_start)
4321 + if (check_heap_stack_gap(vma, addr, len, offset))
4322 goto success;
4323 addr = vma->vm_end;
4324 }
4325 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4326 index f4ca594..adc72fd6 100644
4327 --- a/arch/hexagon/include/asm/cache.h
4328 +++ b/arch/hexagon/include/asm/cache.h
4329 @@ -21,9 +21,11 @@
4330 #ifndef __ASM_CACHE_H
4331 #define __ASM_CACHE_H
4332
4333 +#include <linux/const.h>
4334 +
4335 /* Bytes per L1 cache line */
4336 -#define L1_CACHE_SHIFT (5)
4337 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4338 +#define L1_CACHE_SHIFT 5
4339 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4340
4341 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4342 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4343 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4344 index 6e6fe18..a6ae668 100644
4345 --- a/arch/ia64/include/asm/atomic.h
4346 +++ b/arch/ia64/include/asm/atomic.h
4347 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4348 #define atomic64_inc(v) atomic64_add(1, (v))
4349 #define atomic64_dec(v) atomic64_sub(1, (v))
4350
4351 +#define atomic64_read_unchecked(v) atomic64_read(v)
4352 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4353 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4354 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4355 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4356 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4357 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4358 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4359 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4360 +
4361 /* Atomic operations are already serializing */
4362 #define smp_mb__before_atomic_dec() barrier()
4363 #define smp_mb__after_atomic_dec() barrier()
4364 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4365 index 988254a..e1ee885 100644
4366 --- a/arch/ia64/include/asm/cache.h
4367 +++ b/arch/ia64/include/asm/cache.h
4368 @@ -1,6 +1,7 @@
4369 #ifndef _ASM_IA64_CACHE_H
4370 #define _ASM_IA64_CACHE_H
4371
4372 +#include <linux/const.h>
4373
4374 /*
4375 * Copyright (C) 1998-2000 Hewlett-Packard Co
4376 @@ -9,7 +10,7 @@
4377
4378 /* Bytes per L1 (data) cache line. */
4379 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4380 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4381 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4382
4383 #ifdef CONFIG_SMP
4384 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4385 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4386 index b5298eb..67c6e62 100644
4387 --- a/arch/ia64/include/asm/elf.h
4388 +++ b/arch/ia64/include/asm/elf.h
4389 @@ -42,6 +42,13 @@
4390 */
4391 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4392
4393 +#ifdef CONFIG_PAX_ASLR
4394 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4395 +
4396 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4397 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4398 +#endif
4399 +
4400 #define PT_IA_64_UNWIND 0x70000001
4401
4402 /* IA-64 relocations: */
4403 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4404 index 96a8d92..617a1cf 100644
4405 --- a/arch/ia64/include/asm/pgalloc.h
4406 +++ b/arch/ia64/include/asm/pgalloc.h
4407 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4408 pgd_val(*pgd_entry) = __pa(pud);
4409 }
4410
4411 +static inline void
4412 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4413 +{
4414 + pgd_populate(mm, pgd_entry, pud);
4415 +}
4416 +
4417 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4418 {
4419 return quicklist_alloc(0, GFP_KERNEL, NULL);
4420 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4421 pud_val(*pud_entry) = __pa(pmd);
4422 }
4423
4424 +static inline void
4425 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4426 +{
4427 + pud_populate(mm, pud_entry, pmd);
4428 +}
4429 +
4430 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4431 {
4432 return quicklist_alloc(0, GFP_KERNEL, NULL);
4433 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4434 index 815810c..d60bd4c 100644
4435 --- a/arch/ia64/include/asm/pgtable.h
4436 +++ b/arch/ia64/include/asm/pgtable.h
4437 @@ -12,7 +12,7 @@
4438 * David Mosberger-Tang <davidm@hpl.hp.com>
4439 */
4440
4441 -
4442 +#include <linux/const.h>
4443 #include <asm/mman.h>
4444 #include <asm/page.h>
4445 #include <asm/processor.h>
4446 @@ -142,6 +142,17 @@
4447 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4448 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4449 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4450 +
4451 +#ifdef CONFIG_PAX_PAGEEXEC
4452 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4453 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4454 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4455 +#else
4456 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4457 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4458 +# define PAGE_COPY_NOEXEC PAGE_COPY
4459 +#endif
4460 +
4461 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4462 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4463 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4464 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4465 index 54ff557..70c88b7 100644
4466 --- a/arch/ia64/include/asm/spinlock.h
4467 +++ b/arch/ia64/include/asm/spinlock.h
4468 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4469 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4470
4471 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4472 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4473 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4474 }
4475
4476 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4477 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4478 index 449c8c0..50cdf87 100644
4479 --- a/arch/ia64/include/asm/uaccess.h
4480 +++ b/arch/ia64/include/asm/uaccess.h
4481 @@ -42,6 +42,8 @@
4482 #include <asm/pgtable.h>
4483 #include <asm/io.h>
4484
4485 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4486 +
4487 /*
4488 * For historical reasons, the following macros are grossly misnamed:
4489 */
4490 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4491 static inline unsigned long
4492 __copy_to_user (void __user *to, const void *from, unsigned long count)
4493 {
4494 + if (count > INT_MAX)
4495 + return count;
4496 +
4497 + if (!__builtin_constant_p(count))
4498 + check_object_size(from, count, true);
4499 +
4500 return __copy_user(to, (__force void __user *) from, count);
4501 }
4502
4503 static inline unsigned long
4504 __copy_from_user (void *to, const void __user *from, unsigned long count)
4505 {
4506 + if (count > INT_MAX)
4507 + return count;
4508 +
4509 + if (!__builtin_constant_p(count))
4510 + check_object_size(to, count, false);
4511 +
4512 return __copy_user((__force void __user *) to, from, count);
4513 }
4514
4515 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4516 ({ \
4517 void __user *__cu_to = (to); \
4518 const void *__cu_from = (from); \
4519 - long __cu_len = (n); \
4520 + unsigned long __cu_len = (n); \
4521 \
4522 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
4523 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4524 + if (!__builtin_constant_p(n)) \
4525 + check_object_size(__cu_from, __cu_len, true); \
4526 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4527 + } \
4528 __cu_len; \
4529 })
4530
4531 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4532 ({ \
4533 void *__cu_to = (to); \
4534 const void __user *__cu_from = (from); \
4535 - long __cu_len = (n); \
4536 + unsigned long __cu_len = (n); \
4537 \
4538 __chk_user_ptr(__cu_from); \
4539 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
4540 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4541 + if (!__builtin_constant_p(n)) \
4542 + check_object_size(__cu_to, __cu_len, false); \
4543 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4544 + } \
4545 __cu_len; \
4546 })
4547
4548 diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4549 index 2d67317..07d8bfa 100644
4550 --- a/arch/ia64/kernel/err_inject.c
4551 +++ b/arch/ia64/kernel/err_inject.c
4552 @@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4553 return NOTIFY_OK;
4554 }
4555
4556 -static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4557 +static struct notifier_block err_inject_cpu_notifier =
4558 {
4559 .notifier_call = err_inject_cpu_callback,
4560 };
4561 diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4562 index 65bf9cd..794f06b 100644
4563 --- a/arch/ia64/kernel/mca.c
4564 +++ b/arch/ia64/kernel/mca.c
4565 @@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4566 return NOTIFY_OK;
4567 }
4568
4569 -static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4570 +static struct notifier_block mca_cpu_notifier = {
4571 .notifier_call = mca_cpu_callback
4572 };
4573
4574 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4575 index 24603be..948052d 100644
4576 --- a/arch/ia64/kernel/module.c
4577 +++ b/arch/ia64/kernel/module.c
4578 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4579 void
4580 module_free (struct module *mod, void *module_region)
4581 {
4582 - if (mod && mod->arch.init_unw_table &&
4583 - module_region == mod->module_init) {
4584 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4585 unw_remove_unwind_table(mod->arch.init_unw_table);
4586 mod->arch.init_unw_table = NULL;
4587 }
4588 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4589 }
4590
4591 static inline int
4592 +in_init_rx (const struct module *mod, uint64_t addr)
4593 +{
4594 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4595 +}
4596 +
4597 +static inline int
4598 +in_init_rw (const struct module *mod, uint64_t addr)
4599 +{
4600 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4601 +}
4602 +
4603 +static inline int
4604 in_init (const struct module *mod, uint64_t addr)
4605 {
4606 - return addr - (uint64_t) mod->module_init < mod->init_size;
4607 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4608 +}
4609 +
4610 +static inline int
4611 +in_core_rx (const struct module *mod, uint64_t addr)
4612 +{
4613 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4614 +}
4615 +
4616 +static inline int
4617 +in_core_rw (const struct module *mod, uint64_t addr)
4618 +{
4619 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4620 }
4621
4622 static inline int
4623 in_core (const struct module *mod, uint64_t addr)
4624 {
4625 - return addr - (uint64_t) mod->module_core < mod->core_size;
4626 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4627 }
4628
4629 static inline int
4630 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4631 break;
4632
4633 case RV_BDREL:
4634 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4635 + if (in_init_rx(mod, val))
4636 + val -= (uint64_t) mod->module_init_rx;
4637 + else if (in_init_rw(mod, val))
4638 + val -= (uint64_t) mod->module_init_rw;
4639 + else if (in_core_rx(mod, val))
4640 + val -= (uint64_t) mod->module_core_rx;
4641 + else if (in_core_rw(mod, val))
4642 + val -= (uint64_t) mod->module_core_rw;
4643 break;
4644
4645 case RV_LTV:
4646 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4647 * addresses have been selected...
4648 */
4649 uint64_t gp;
4650 - if (mod->core_size > MAX_LTOFF)
4651 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4652 /*
4653 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4654 * at the end of the module.
4655 */
4656 - gp = mod->core_size - MAX_LTOFF / 2;
4657 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4658 else
4659 - gp = mod->core_size / 2;
4660 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4661 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4662 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4663 mod->arch.gp = gp;
4664 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4665 }
4666 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4667 index 77597e5..6f28f3f 100644
4668 --- a/arch/ia64/kernel/palinfo.c
4669 +++ b/arch/ia64/kernel/palinfo.c
4670 @@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4671 return NOTIFY_OK;
4672 }
4673
4674 -static struct notifier_block __refdata palinfo_cpu_notifier =
4675 +static struct notifier_block palinfo_cpu_notifier =
4676 {
4677 .notifier_call = palinfo_cpu_callback,
4678 .priority = 0,
4679 diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4680 index 79802e5..1a89ec5 100644
4681 --- a/arch/ia64/kernel/salinfo.c
4682 +++ b/arch/ia64/kernel/salinfo.c
4683 @@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4684 return NOTIFY_OK;
4685 }
4686
4687 -static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4688 +static struct notifier_block salinfo_cpu_notifier =
4689 {
4690 .notifier_call = salinfo_cpu_callback,
4691 .priority = 0,
4692 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4693 index d9439ef..d0cac6b 100644
4694 --- a/arch/ia64/kernel/sys_ia64.c
4695 +++ b/arch/ia64/kernel/sys_ia64.c
4696 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4697 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4698 struct mm_struct *mm = current->mm;
4699 struct vm_area_struct *vma;
4700 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4701
4702 if (len > RGN_MAP_LIMIT)
4703 return -ENOMEM;
4704 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4705 if (REGION_NUMBER(addr) == RGN_HPAGE)
4706 addr = 0;
4707 #endif
4708 +
4709 +#ifdef CONFIG_PAX_RANDMMAP
4710 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4711 + addr = mm->free_area_cache;
4712 + else
4713 +#endif
4714 +
4715 if (!addr)
4716 addr = mm->free_area_cache;
4717
4718 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4719 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4720 /* At this point: (!vma || addr < vma->vm_end). */
4721 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4722 - if (start_addr != TASK_UNMAPPED_BASE) {
4723 + if (start_addr != mm->mmap_base) {
4724 /* Start a new search --- just in case we missed some holes. */
4725 - addr = TASK_UNMAPPED_BASE;
4726 + addr = mm->mmap_base;
4727 goto full_search;
4728 }
4729 return -ENOMEM;
4730 }
4731 - if (!vma || addr + len <= vma->vm_start) {
4732 + if (check_heap_stack_gap(vma, addr, len, offset)) {
4733 /* Remember the address where we stopped this search: */
4734 mm->free_area_cache = addr + len;
4735 return addr;
4736 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4737 index dc00b2c..cce53c2 100644
4738 --- a/arch/ia64/kernel/topology.c
4739 +++ b/arch/ia64/kernel/topology.c
4740 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4741 return NOTIFY_OK;
4742 }
4743
4744 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
4745 +static struct notifier_block cache_cpu_notifier =
4746 {
4747 .notifier_call = cache_cpu_callback
4748 };
4749 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4750 index 0ccb28f..8992469 100644
4751 --- a/arch/ia64/kernel/vmlinux.lds.S
4752 +++ b/arch/ia64/kernel/vmlinux.lds.S
4753 @@ -198,7 +198,7 @@ SECTIONS {
4754 /* Per-cpu data: */
4755 . = ALIGN(PERCPU_PAGE_SIZE);
4756 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4757 - __phys_per_cpu_start = __per_cpu_load;
4758 + __phys_per_cpu_start = per_cpu_load;
4759 /*
4760 * ensure percpu data fits
4761 * into percpu page size
4762 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4763 index 6cf0341..d352594 100644
4764 --- a/arch/ia64/mm/fault.c
4765 +++ b/arch/ia64/mm/fault.c
4766 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4767 return pte_present(pte);
4768 }
4769
4770 +#ifdef CONFIG_PAX_PAGEEXEC
4771 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4772 +{
4773 + unsigned long i;
4774 +
4775 + printk(KERN_ERR "PAX: bytes at PC: ");
4776 + for (i = 0; i < 8; i++) {
4777 + unsigned int c;
4778 + if (get_user(c, (unsigned int *)pc+i))
4779 + printk(KERN_CONT "???????? ");
4780 + else
4781 + printk(KERN_CONT "%08x ", c);
4782 + }
4783 + printk("\n");
4784 +}
4785 +#endif
4786 +
4787 # define VM_READ_BIT 0
4788 # define VM_WRITE_BIT 1
4789 # define VM_EXEC_BIT 2
4790 @@ -149,8 +166,21 @@ retry:
4791 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4792 goto bad_area;
4793
4794 - if ((vma->vm_flags & mask) != mask)
4795 + if ((vma->vm_flags & mask) != mask) {
4796 +
4797 +#ifdef CONFIG_PAX_PAGEEXEC
4798 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4799 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4800 + goto bad_area;
4801 +
4802 + up_read(&mm->mmap_sem);
4803 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4804 + do_group_exit(SIGKILL);
4805 + }
4806 +#endif
4807 +
4808 goto bad_area;
4809 + }
4810
4811 /*
4812 * If for any reason at all we couldn't handle the fault, make
4813 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4814 index 5ca674b..127c3cb 100644
4815 --- a/arch/ia64/mm/hugetlbpage.c
4816 +++ b/arch/ia64/mm/hugetlbpage.c
4817 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4818 unsigned long pgoff, unsigned long flags)
4819 {
4820 struct vm_area_struct *vmm;
4821 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4822
4823 if (len > RGN_MAP_LIMIT)
4824 return -ENOMEM;
4825 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4826 /* At this point: (!vmm || addr < vmm->vm_end). */
4827 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4828 return -ENOMEM;
4829 - if (!vmm || (addr + len) <= vmm->vm_start)
4830 + if (check_heap_stack_gap(vmm, addr, len, offset))
4831 return addr;
4832 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
4833 }
4834 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
4835 index b755ea9..b9a969e 100644
4836 --- a/arch/ia64/mm/init.c
4837 +++ b/arch/ia64/mm/init.c
4838 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
4839 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
4840 vma->vm_end = vma->vm_start + PAGE_SIZE;
4841 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
4842 +
4843 +#ifdef CONFIG_PAX_PAGEEXEC
4844 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
4845 + vma->vm_flags &= ~VM_EXEC;
4846 +
4847 +#ifdef CONFIG_PAX_MPROTECT
4848 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
4849 + vma->vm_flags &= ~VM_MAYEXEC;
4850 +#endif
4851 +
4852 + }
4853 +#endif
4854 +
4855 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4856 down_write(&current->mm->mmap_sem);
4857 if (insert_vm_struct(current->mm, vma)) {
4858 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
4859 index 40b3ee9..8c2c112 100644
4860 --- a/arch/m32r/include/asm/cache.h
4861 +++ b/arch/m32r/include/asm/cache.h
4862 @@ -1,8 +1,10 @@
4863 #ifndef _ASM_M32R_CACHE_H
4864 #define _ASM_M32R_CACHE_H
4865
4866 +#include <linux/const.h>
4867 +
4868 /* L1 cache line size */
4869 #define L1_CACHE_SHIFT 4
4870 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4871 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4872
4873 #endif /* _ASM_M32R_CACHE_H */
4874 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
4875 index 82abd15..d95ae5d 100644
4876 --- a/arch/m32r/lib/usercopy.c
4877 +++ b/arch/m32r/lib/usercopy.c
4878 @@ -14,6 +14,9 @@
4879 unsigned long
4880 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4881 {
4882 + if ((long)n < 0)
4883 + return n;
4884 +
4885 prefetch(from);
4886 if (access_ok(VERIFY_WRITE, to, n))
4887 __copy_user(to,from,n);
4888 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4889 unsigned long
4890 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
4891 {
4892 + if ((long)n < 0)
4893 + return n;
4894 +
4895 prefetchw(to);
4896 if (access_ok(VERIFY_READ, from, n))
4897 __copy_user_zeroing(to,from,n);
4898 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
4899 index 0395c51..5f26031 100644
4900 --- a/arch/m68k/include/asm/cache.h
4901 +++ b/arch/m68k/include/asm/cache.h
4902 @@ -4,9 +4,11 @@
4903 #ifndef __ARCH_M68K_CACHE_H
4904 #define __ARCH_M68K_CACHE_H
4905
4906 +#include <linux/const.h>
4907 +
4908 /* bytes per L1 cache line */
4909 #define L1_CACHE_SHIFT 4
4910 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
4911 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4912
4913 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4914
4915 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
4916 index 4efe96a..60e8699 100644
4917 --- a/arch/microblaze/include/asm/cache.h
4918 +++ b/arch/microblaze/include/asm/cache.h
4919 @@ -13,11 +13,12 @@
4920 #ifndef _ASM_MICROBLAZE_CACHE_H
4921 #define _ASM_MICROBLAZE_CACHE_H
4922
4923 +#include <linux/const.h>
4924 #include <asm/registers.h>
4925
4926 #define L1_CACHE_SHIFT 5
4927 /* word-granular cache in microblaze */
4928 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4929 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4930
4931 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4932
4933 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
4934 index 01cc6ba..bcb7a5d 100644
4935 --- a/arch/mips/include/asm/atomic.h
4936 +++ b/arch/mips/include/asm/atomic.h
4937 @@ -21,6 +21,10 @@
4938 #include <asm/cmpxchg.h>
4939 #include <asm/war.h>
4940
4941 +#ifdef CONFIG_GENERIC_ATOMIC64
4942 +#include <asm-generic/atomic64.h>
4943 +#endif
4944 +
4945 #define ATOMIC_INIT(i) { (i) }
4946
4947 /*
4948 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4949 */
4950 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
4951
4952 +#define atomic64_read_unchecked(v) atomic64_read(v)
4953 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4954 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4955 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4956 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4957 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4958 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4959 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4960 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4961 +
4962 #endif /* CONFIG_64BIT */
4963
4964 /*
4965 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
4966 index b4db69f..8f3b093 100644
4967 --- a/arch/mips/include/asm/cache.h
4968 +++ b/arch/mips/include/asm/cache.h
4969 @@ -9,10 +9,11 @@
4970 #ifndef _ASM_CACHE_H
4971 #define _ASM_CACHE_H
4972
4973 +#include <linux/const.h>
4974 #include <kmalloc.h>
4975
4976 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
4977 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4978 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4979
4980 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4981 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4982 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
4983 index 455c0ac..ad65fbe 100644
4984 --- a/arch/mips/include/asm/elf.h
4985 +++ b/arch/mips/include/asm/elf.h
4986 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
4987 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4988 #endif
4989
4990 +#ifdef CONFIG_PAX_ASLR
4991 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
4992 +
4993 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4994 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4995 +#endif
4996 +
4997 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4998 struct linux_binprm;
4999 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5000 int uses_interp);
5001
5002 -struct mm_struct;
5003 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5004 -#define arch_randomize_brk arch_randomize_brk
5005 -
5006 #endif /* _ASM_ELF_H */
5007 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5008 index c1f6afa..38cc6e9 100644
5009 --- a/arch/mips/include/asm/exec.h
5010 +++ b/arch/mips/include/asm/exec.h
5011 @@ -12,6 +12,6 @@
5012 #ifndef _ASM_EXEC_H
5013 #define _ASM_EXEC_H
5014
5015 -extern unsigned long arch_align_stack(unsigned long sp);
5016 +#define arch_align_stack(x) ((x) & ~0xfUL)
5017
5018 #endif /* _ASM_EXEC_H */
5019 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5020 index dbaec94..6a14935 100644
5021 --- a/arch/mips/include/asm/page.h
5022 +++ b/arch/mips/include/asm/page.h
5023 @@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5024 #ifdef CONFIG_CPU_MIPS32
5025 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5026 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5027 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5028 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5029 #else
5030 typedef struct { unsigned long long pte; } pte_t;
5031 #define pte_val(x) ((x).pte)
5032 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5033 index 881d18b..cea38bc 100644
5034 --- a/arch/mips/include/asm/pgalloc.h
5035 +++ b/arch/mips/include/asm/pgalloc.h
5036 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5037 {
5038 set_pud(pud, __pud((unsigned long)pmd));
5039 }
5040 +
5041 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5042 +{
5043 + pud_populate(mm, pud, pmd);
5044 +}
5045 #endif
5046
5047 /*
5048 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5049 index b2050b9..d71bb1b 100644
5050 --- a/arch/mips/include/asm/thread_info.h
5051 +++ b/arch/mips/include/asm/thread_info.h
5052 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5053 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5054 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5055 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5056 +/* li takes a 32bit immediate */
5057 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5058 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5059
5060 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5061 @@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5062 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5063 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5064 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5065 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5066 +
5067 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5068
5069 /* work to do in syscall_trace_leave() */
5070 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5071 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5072
5073 /* work to do on interrupt/exception return */
5074 #define _TIF_WORK_MASK \
5075 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5076 /* work to do on any return to u-space */
5077 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5078 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5079
5080 #endif /* __KERNEL__ */
5081
5082 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5083 index 9fdd8bc..4bd7f1a 100644
5084 --- a/arch/mips/kernel/binfmt_elfn32.c
5085 +++ b/arch/mips/kernel/binfmt_elfn32.c
5086 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5087 #undef ELF_ET_DYN_BASE
5088 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5089
5090 +#ifdef CONFIG_PAX_ASLR
5091 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5092 +
5093 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5094 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5095 +#endif
5096 +
5097 #include <asm/processor.h>
5098 #include <linux/module.h>
5099 #include <linux/elfcore.h>
5100 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5101 index ff44823..97f8906 100644
5102 --- a/arch/mips/kernel/binfmt_elfo32.c
5103 +++ b/arch/mips/kernel/binfmt_elfo32.c
5104 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5105 #undef ELF_ET_DYN_BASE
5106 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5107
5108 +#ifdef CONFIG_PAX_ASLR
5109 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5110 +
5111 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5112 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5113 +#endif
5114 +
5115 #include <asm/processor.h>
5116
5117 /*
5118 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5119 index a11c6f9..be5e164 100644
5120 --- a/arch/mips/kernel/process.c
5121 +++ b/arch/mips/kernel/process.c
5122 @@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5123 out:
5124 return pc;
5125 }
5126 -
5127 -/*
5128 - * Don't forget that the stack pointer must be aligned on a 8 bytes
5129 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5130 - */
5131 -unsigned long arch_align_stack(unsigned long sp)
5132 -{
5133 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5134 - sp -= get_random_int() & ~PAGE_MASK;
5135 -
5136 - return sp & ALMASK;
5137 -}
5138 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5139 index 4812c6d..2069554 100644
5140 --- a/arch/mips/kernel/ptrace.c
5141 +++ b/arch/mips/kernel/ptrace.c
5142 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
5143 return arch;
5144 }
5145
5146 +#ifdef CONFIG_GRKERNSEC_SETXID
5147 +extern void gr_delayed_cred_worker(void);
5148 +#endif
5149 +
5150 /*
5151 * Notification of system call entry/exit
5152 * - triggered by current->work.syscall_trace
5153 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5154 /* do the secure computing check first */
5155 secure_computing_strict(regs->regs[2]);
5156
5157 +#ifdef CONFIG_GRKERNSEC_SETXID
5158 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5159 + gr_delayed_cred_worker();
5160 +#endif
5161 +
5162 if (!(current->ptrace & PT_PTRACED))
5163 goto out;
5164
5165 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5166 index d20a4bc..7096ae5 100644
5167 --- a/arch/mips/kernel/scall32-o32.S
5168 +++ b/arch/mips/kernel/scall32-o32.S
5169 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5170
5171 stack_done:
5172 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5173 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5174 + li t1, _TIF_SYSCALL_WORK
5175 and t0, t1
5176 bnez t0, syscall_trace_entry # -> yes
5177
5178 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5179 index b64f642..0fe6eab 100644
5180 --- a/arch/mips/kernel/scall64-64.S
5181 +++ b/arch/mips/kernel/scall64-64.S
5182 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5183
5184 sd a3, PT_R26(sp) # save a3 for syscall restarting
5185
5186 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5187 + li t1, _TIF_SYSCALL_WORK
5188 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5189 and t0, t1, t0
5190 bnez t0, syscall_trace_entry
5191 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5192 index c29ac19..c592d05 100644
5193 --- a/arch/mips/kernel/scall64-n32.S
5194 +++ b/arch/mips/kernel/scall64-n32.S
5195 @@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5196
5197 sd a3, PT_R26(sp) # save a3 for syscall restarting
5198
5199 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5200 + li t1, _TIF_SYSCALL_WORK
5201 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5202 and t0, t1, t0
5203 bnez t0, n32_syscall_trace_entry
5204 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5205 index cf3e75e..72e93fe 100644
5206 --- a/arch/mips/kernel/scall64-o32.S
5207 +++ b/arch/mips/kernel/scall64-o32.S
5208 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5209 PTR 4b, bad_stack
5210 .previous
5211
5212 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5213 + li t1, _TIF_SYSCALL_WORK
5214 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5215 and t0, t1, t0
5216 bnez t0, trace_a_syscall
5217 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5218 index ddcec1e..c7f983e 100644
5219 --- a/arch/mips/mm/fault.c
5220 +++ b/arch/mips/mm/fault.c
5221 @@ -27,6 +27,23 @@
5222 #include <asm/highmem.h> /* For VMALLOC_END */
5223 #include <linux/kdebug.h>
5224
5225 +#ifdef CONFIG_PAX_PAGEEXEC
5226 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5227 +{
5228 + unsigned long i;
5229 +
5230 + printk(KERN_ERR "PAX: bytes at PC: ");
5231 + for (i = 0; i < 5; i++) {
5232 + unsigned int c;
5233 + if (get_user(c, (unsigned int *)pc+i))
5234 + printk(KERN_CONT "???????? ");
5235 + else
5236 + printk(KERN_CONT "%08x ", c);
5237 + }
5238 + printk("\n");
5239 +}
5240 +#endif
5241 +
5242 /*
5243 * This routine handles page faults. It determines the address,
5244 * and the problem, and then passes it off to one of the appropriate
5245 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5246 index 7e5fe27..479a219 100644
5247 --- a/arch/mips/mm/mmap.c
5248 +++ b/arch/mips/mm/mmap.c
5249 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5250 struct vm_area_struct *vma;
5251 unsigned long addr = addr0;
5252 int do_color_align;
5253 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5254 struct vm_unmapped_area_info info;
5255
5256 if (unlikely(len > TASK_SIZE))
5257 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5258 do_color_align = 1;
5259
5260 /* requesting a specific address */
5261 +
5262 +#ifdef CONFIG_PAX_RANDMMAP
5263 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5264 +#endif
5265 +
5266 if (addr) {
5267 if (do_color_align)
5268 addr = COLOUR_ALIGN(addr, pgoff);
5269 @@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5270 addr = PAGE_ALIGN(addr);
5271
5272 vma = find_vma(mm, addr);
5273 - if (TASK_SIZE - len >= addr &&
5274 - (!vma || addr + len <= vma->vm_start))
5275 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5276 return addr;
5277 }
5278
5279 @@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5280 {
5281 unsigned long random_factor = 0UL;
5282
5283 +#ifdef CONFIG_PAX_RANDMMAP
5284 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5285 +#endif
5286 +
5287 if (current->flags & PF_RANDOMIZE) {
5288 random_factor = get_random_int();
5289 random_factor = random_factor << PAGE_SHIFT;
5290 @@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5291
5292 if (mmap_is_legacy()) {
5293 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5294 +
5295 +#ifdef CONFIG_PAX_RANDMMAP
5296 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5297 + mm->mmap_base += mm->delta_mmap;
5298 +#endif
5299 +
5300 mm->get_unmapped_area = arch_get_unmapped_area;
5301 mm->unmap_area = arch_unmap_area;
5302 } else {
5303 mm->mmap_base = mmap_base(random_factor);
5304 +
5305 +#ifdef CONFIG_PAX_RANDMMAP
5306 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5307 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5308 +#endif
5309 +
5310 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5311 mm->unmap_area = arch_unmap_area_topdown;
5312 }
5313 }
5314
5315 -static inline unsigned long brk_rnd(void)
5316 -{
5317 - unsigned long rnd = get_random_int();
5318 -
5319 - rnd = rnd << PAGE_SHIFT;
5320 - /* 8MB for 32bit, 256MB for 64bit */
5321 - if (TASK_IS_32BIT_ADDR)
5322 - rnd = rnd & 0x7ffffful;
5323 - else
5324 - rnd = rnd & 0xffffffful;
5325 -
5326 - return rnd;
5327 -}
5328 -
5329 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5330 -{
5331 - unsigned long base = mm->brk;
5332 - unsigned long ret;
5333 -
5334 - ret = PAGE_ALIGN(base + brk_rnd());
5335 -
5336 - if (ret < mm->brk)
5337 - return mm->brk;
5338 -
5339 - return ret;
5340 -}
5341 -
5342 int __virt_addr_valid(const volatile void *kaddr)
5343 {
5344 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5345 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5346 index 967d144..db12197 100644
5347 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5348 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5349 @@ -11,12 +11,14 @@
5350 #ifndef _ASM_PROC_CACHE_H
5351 #define _ASM_PROC_CACHE_H
5352
5353 +#include <linux/const.h>
5354 +
5355 /* L1 cache */
5356
5357 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5358 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5359 -#define L1_CACHE_BYTES 16 /* bytes per entry */
5360 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5361 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5362 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5363
5364 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5365 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5366 index bcb5df2..84fabd2 100644
5367 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5368 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5369 @@ -16,13 +16,15 @@
5370 #ifndef _ASM_PROC_CACHE_H
5371 #define _ASM_PROC_CACHE_H
5372
5373 +#include <linux/const.h>
5374 +
5375 /*
5376 * L1 cache
5377 */
5378 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5379 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5380 -#define L1_CACHE_BYTES 32 /* bytes per entry */
5381 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5382 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5383 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5384
5385 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5386 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5387 index 4ce7a01..449202a 100644
5388 --- a/arch/openrisc/include/asm/cache.h
5389 +++ b/arch/openrisc/include/asm/cache.h
5390 @@ -19,11 +19,13 @@
5391 #ifndef __ASM_OPENRISC_CACHE_H
5392 #define __ASM_OPENRISC_CACHE_H
5393
5394 +#include <linux/const.h>
5395 +
5396 /* FIXME: How can we replace these with values from the CPU...
5397 * they shouldn't be hard-coded!
5398 */
5399
5400 -#define L1_CACHE_BYTES 16
5401 #define L1_CACHE_SHIFT 4
5402 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5403
5404 #endif /* __ASM_OPENRISC_CACHE_H */
5405 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5406 index af9cf30..2aae9b2 100644
5407 --- a/arch/parisc/include/asm/atomic.h
5408 +++ b/arch/parisc/include/asm/atomic.h
5409 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5410
5411 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5412
5413 +#define atomic64_read_unchecked(v) atomic64_read(v)
5414 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5415 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5416 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5417 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5418 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5419 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5420 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5421 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5422 +
5423 #endif /* !CONFIG_64BIT */
5424
5425
5426 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5427 index 47f11c7..3420df2 100644
5428 --- a/arch/parisc/include/asm/cache.h
5429 +++ b/arch/parisc/include/asm/cache.h
5430 @@ -5,6 +5,7 @@
5431 #ifndef __ARCH_PARISC_CACHE_H
5432 #define __ARCH_PARISC_CACHE_H
5433
5434 +#include <linux/const.h>
5435
5436 /*
5437 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5438 @@ -15,13 +16,13 @@
5439 * just ruin performance.
5440 */
5441 #ifdef CONFIG_PA20
5442 -#define L1_CACHE_BYTES 64
5443 #define L1_CACHE_SHIFT 6
5444 #else
5445 -#define L1_CACHE_BYTES 32
5446 #define L1_CACHE_SHIFT 5
5447 #endif
5448
5449 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5450 +
5451 #ifndef __ASSEMBLY__
5452
5453 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5454 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5455 index 19f6cb1..6c78cf2 100644
5456 --- a/arch/parisc/include/asm/elf.h
5457 +++ b/arch/parisc/include/asm/elf.h
5458 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5459
5460 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5461
5462 +#ifdef CONFIG_PAX_ASLR
5463 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5464 +
5465 +#define PAX_DELTA_MMAP_LEN 16
5466 +#define PAX_DELTA_STACK_LEN 16
5467 +#endif
5468 +
5469 /* This yields a mask that user programs can use to figure out what
5470 instruction set this CPU supports. This could be done in user space,
5471 but it's not easy, and we've already done it here. */
5472 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5473 index fc987a1..6e068ef 100644
5474 --- a/arch/parisc/include/asm/pgalloc.h
5475 +++ b/arch/parisc/include/asm/pgalloc.h
5476 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5477 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5478 }
5479
5480 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5481 +{
5482 + pgd_populate(mm, pgd, pmd);
5483 +}
5484 +
5485 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5486 {
5487 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5488 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5489 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5490 #define pmd_free(mm, x) do { } while (0)
5491 #define pgd_populate(mm, pmd, pte) BUG()
5492 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
5493
5494 #endif
5495
5496 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5497 index ee99f23..802b0a1 100644
5498 --- a/arch/parisc/include/asm/pgtable.h
5499 +++ b/arch/parisc/include/asm/pgtable.h
5500 @@ -212,6 +212,17 @@ struct vm_area_struct;
5501 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5502 #define PAGE_COPY PAGE_EXECREAD
5503 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5504 +
5505 +#ifdef CONFIG_PAX_PAGEEXEC
5506 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5507 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5508 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5509 +#else
5510 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5511 +# define PAGE_COPY_NOEXEC PAGE_COPY
5512 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5513 +#endif
5514 +
5515 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5516 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5517 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5518 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5519 index 4ba2c93..f5e3974 100644
5520 --- a/arch/parisc/include/asm/uaccess.h
5521 +++ b/arch/parisc/include/asm/uaccess.h
5522 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5523 const void __user *from,
5524 unsigned long n)
5525 {
5526 - int sz = __compiletime_object_size(to);
5527 + size_t sz = __compiletime_object_size(to);
5528 int ret = -EFAULT;
5529
5530 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5531 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5532 ret = __copy_from_user(to, from, n);
5533 else
5534 copy_from_user_overflow();
5535 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5536 index 2a625fb..9908930 100644
5537 --- a/arch/parisc/kernel/module.c
5538 +++ b/arch/parisc/kernel/module.c
5539 @@ -98,16 +98,38 @@
5540
5541 /* three functions to determine where in the module core
5542 * or init pieces the location is */
5543 +static inline int in_init_rx(struct module *me, void *loc)
5544 +{
5545 + return (loc >= me->module_init_rx &&
5546 + loc < (me->module_init_rx + me->init_size_rx));
5547 +}
5548 +
5549 +static inline int in_init_rw(struct module *me, void *loc)
5550 +{
5551 + return (loc >= me->module_init_rw &&
5552 + loc < (me->module_init_rw + me->init_size_rw));
5553 +}
5554 +
5555 static inline int in_init(struct module *me, void *loc)
5556 {
5557 - return (loc >= me->module_init &&
5558 - loc <= (me->module_init + me->init_size));
5559 + return in_init_rx(me, loc) || in_init_rw(me, loc);
5560 +}
5561 +
5562 +static inline int in_core_rx(struct module *me, void *loc)
5563 +{
5564 + return (loc >= me->module_core_rx &&
5565 + loc < (me->module_core_rx + me->core_size_rx));
5566 +}
5567 +
5568 +static inline int in_core_rw(struct module *me, void *loc)
5569 +{
5570 + return (loc >= me->module_core_rw &&
5571 + loc < (me->module_core_rw + me->core_size_rw));
5572 }
5573
5574 static inline int in_core(struct module *me, void *loc)
5575 {
5576 - return (loc >= me->module_core &&
5577 - loc <= (me->module_core + me->core_size));
5578 + return in_core_rx(me, loc) || in_core_rw(me, loc);
5579 }
5580
5581 static inline int in_local(struct module *me, void *loc)
5582 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5583 }
5584
5585 /* align things a bit */
5586 - me->core_size = ALIGN(me->core_size, 16);
5587 - me->arch.got_offset = me->core_size;
5588 - me->core_size += gots * sizeof(struct got_entry);
5589 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5590 + me->arch.got_offset = me->core_size_rw;
5591 + me->core_size_rw += gots * sizeof(struct got_entry);
5592
5593 - me->core_size = ALIGN(me->core_size, 16);
5594 - me->arch.fdesc_offset = me->core_size;
5595 - me->core_size += fdescs * sizeof(Elf_Fdesc);
5596 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5597 + me->arch.fdesc_offset = me->core_size_rw;
5598 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5599
5600 me->arch.got_max = gots;
5601 me->arch.fdesc_max = fdescs;
5602 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5603
5604 BUG_ON(value == 0);
5605
5606 - got = me->module_core + me->arch.got_offset;
5607 + got = me->module_core_rw + me->arch.got_offset;
5608 for (i = 0; got[i].addr; i++)
5609 if (got[i].addr == value)
5610 goto out;
5611 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5612 #ifdef CONFIG_64BIT
5613 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5614 {
5615 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5616 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5617
5618 if (!value) {
5619 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5620 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5621
5622 /* Create new one */
5623 fdesc->addr = value;
5624 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5625 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5626 return (Elf_Addr)fdesc;
5627 }
5628 #endif /* CONFIG_64BIT */
5629 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5630
5631 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5632 end = table + sechdrs[me->arch.unwind_section].sh_size;
5633 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5634 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5635
5636 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5637 me->arch.unwind_section, table, end, gp);
5638 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5639 index f76c108..92bad82 100644
5640 --- a/arch/parisc/kernel/sys_parisc.c
5641 +++ b/arch/parisc/kernel/sys_parisc.c
5642 @@ -33,9 +33,11 @@
5643 #include <linux/utsname.h>
5644 #include <linux/personality.h>
5645
5646 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5647 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5648 + unsigned long flags)
5649 {
5650 struct vm_area_struct *vma;
5651 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5652
5653 addr = PAGE_ALIGN(addr);
5654
5655 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5656 /* At this point: (!vma || addr < vma->vm_end). */
5657 if (TASK_SIZE - len < addr)
5658 return -ENOMEM;
5659 - if (!vma || addr + len <= vma->vm_start)
5660 + if (check_heap_stack_gap(vma, addr, len, offset))
5661 return addr;
5662 addr = vma->vm_end;
5663 }
5664 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5665 return offset & 0x3FF000;
5666 }
5667
5668 -static unsigned long get_shared_area(struct address_space *mapping,
5669 - unsigned long addr, unsigned long len, unsigned long pgoff)
5670 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5671 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5672 {
5673 struct vm_area_struct *vma;
5674 int offset = mapping ? get_offset(mapping) : 0;
5675 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5676
5677 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5678
5679 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5680 /* At this point: (!vma || addr < vma->vm_end). */
5681 if (TASK_SIZE - len < addr)
5682 return -ENOMEM;
5683 - if (!vma || addr + len <= vma->vm_start)
5684 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
5685 return addr;
5686 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5687 if (addr < vma->vm_end) /* handle wraparound */
5688 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5689 if (flags & MAP_FIXED)
5690 return addr;
5691 if (!addr)
5692 - addr = TASK_UNMAPPED_BASE;
5693 + addr = current->mm->mmap_base;
5694
5695 if (filp) {
5696 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5697 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5698 } else if(flags & MAP_SHARED) {
5699 - addr = get_shared_area(NULL, addr, len, pgoff);
5700 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5701 } else {
5702 - addr = get_unshared_area(addr, len);
5703 + addr = get_unshared_area(filp, addr, len, flags);
5704 }
5705 return addr;
5706 }
5707 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5708 index 45ba99f..8e22c33 100644
5709 --- a/arch/parisc/kernel/traps.c
5710 +++ b/arch/parisc/kernel/traps.c
5711 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5712
5713 down_read(&current->mm->mmap_sem);
5714 vma = find_vma(current->mm,regs->iaoq[0]);
5715 - if (vma && (regs->iaoq[0] >= vma->vm_start)
5716 - && (vma->vm_flags & VM_EXEC)) {
5717 -
5718 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5719 fault_address = regs->iaoq[0];
5720 fault_space = regs->iasq[0];
5721
5722 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5723 index 18162ce..94de376 100644
5724 --- a/arch/parisc/mm/fault.c
5725 +++ b/arch/parisc/mm/fault.c
5726 @@ -15,6 +15,7 @@
5727 #include <linux/sched.h>
5728 #include <linux/interrupt.h>
5729 #include <linux/module.h>
5730 +#include <linux/unistd.h>
5731
5732 #include <asm/uaccess.h>
5733 #include <asm/traps.h>
5734 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5735 static unsigned long
5736 parisc_acctyp(unsigned long code, unsigned int inst)
5737 {
5738 - if (code == 6 || code == 16)
5739 + if (code == 6 || code == 7 || code == 16)
5740 return VM_EXEC;
5741
5742 switch (inst & 0xf0000000) {
5743 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5744 }
5745 #endif
5746
5747 +#ifdef CONFIG_PAX_PAGEEXEC
5748 +/*
5749 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5750 + *
5751 + * returns 1 when task should be killed
5752 + * 2 when rt_sigreturn trampoline was detected
5753 + * 3 when unpatched PLT trampoline was detected
5754 + */
5755 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5756 +{
5757 +
5758 +#ifdef CONFIG_PAX_EMUPLT
5759 + int err;
5760 +
5761 + do { /* PaX: unpatched PLT emulation */
5762 + unsigned int bl, depwi;
5763 +
5764 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5765 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5766 +
5767 + if (err)
5768 + break;
5769 +
5770 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5771 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5772 +
5773 + err = get_user(ldw, (unsigned int *)addr);
5774 + err |= get_user(bv, (unsigned int *)(addr+4));
5775 + err |= get_user(ldw2, (unsigned int *)(addr+8));
5776 +
5777 + if (err)
5778 + break;
5779 +
5780 + if (ldw == 0x0E801096U &&
5781 + bv == 0xEAC0C000U &&
5782 + ldw2 == 0x0E881095U)
5783 + {
5784 + unsigned int resolver, map;
5785 +
5786 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5787 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5788 + if (err)
5789 + break;
5790 +
5791 + regs->gr[20] = instruction_pointer(regs)+8;
5792 + regs->gr[21] = map;
5793 + regs->gr[22] = resolver;
5794 + regs->iaoq[0] = resolver | 3UL;
5795 + regs->iaoq[1] = regs->iaoq[0] + 4;
5796 + return 3;
5797 + }
5798 + }
5799 + } while (0);
5800 +#endif
5801 +
5802 +#ifdef CONFIG_PAX_EMUTRAMP
5803 +
5804 +#ifndef CONFIG_PAX_EMUSIGRT
5805 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5806 + return 1;
5807 +#endif
5808 +
5809 + do { /* PaX: rt_sigreturn emulation */
5810 + unsigned int ldi1, ldi2, bel, nop;
5811 +
5812 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5813 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5814 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5815 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5816 +
5817 + if (err)
5818 + break;
5819 +
5820 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5821 + ldi2 == 0x3414015AU &&
5822 + bel == 0xE4008200U &&
5823 + nop == 0x08000240U)
5824 + {
5825 + regs->gr[25] = (ldi1 & 2) >> 1;
5826 + regs->gr[20] = __NR_rt_sigreturn;
5827 + regs->gr[31] = regs->iaoq[1] + 16;
5828 + regs->sr[0] = regs->iasq[1];
5829 + regs->iaoq[0] = 0x100UL;
5830 + regs->iaoq[1] = regs->iaoq[0] + 4;
5831 + regs->iasq[0] = regs->sr[2];
5832 + regs->iasq[1] = regs->sr[2];
5833 + return 2;
5834 + }
5835 + } while (0);
5836 +#endif
5837 +
5838 + return 1;
5839 +}
5840 +
5841 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5842 +{
5843 + unsigned long i;
5844 +
5845 + printk(KERN_ERR "PAX: bytes at PC: ");
5846 + for (i = 0; i < 5; i++) {
5847 + unsigned int c;
5848 + if (get_user(c, (unsigned int *)pc+i))
5849 + printk(KERN_CONT "???????? ");
5850 + else
5851 + printk(KERN_CONT "%08x ", c);
5852 + }
5853 + printk("\n");
5854 +}
5855 +#endif
5856 +
5857 int fixup_exception(struct pt_regs *regs)
5858 {
5859 const struct exception_table_entry *fix;
5860 @@ -192,8 +303,33 @@ good_area:
5861
5862 acc_type = parisc_acctyp(code,regs->iir);
5863
5864 - if ((vma->vm_flags & acc_type) != acc_type)
5865 + if ((vma->vm_flags & acc_type) != acc_type) {
5866 +
5867 +#ifdef CONFIG_PAX_PAGEEXEC
5868 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
5869 + (address & ~3UL) == instruction_pointer(regs))
5870 + {
5871 + up_read(&mm->mmap_sem);
5872 + switch (pax_handle_fetch_fault(regs)) {
5873 +
5874 +#ifdef CONFIG_PAX_EMUPLT
5875 + case 3:
5876 + return;
5877 +#endif
5878 +
5879 +#ifdef CONFIG_PAX_EMUTRAMP
5880 + case 2:
5881 + return;
5882 +#endif
5883 +
5884 + }
5885 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
5886 + do_group_exit(SIGKILL);
5887 + }
5888 +#endif
5889 +
5890 goto bad_area;
5891 + }
5892
5893 /*
5894 * If for any reason at all we couldn't handle the fault, make
5895 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
5896 index e3b1d41..8e81edf 100644
5897 --- a/arch/powerpc/include/asm/atomic.h
5898 +++ b/arch/powerpc/include/asm/atomic.h
5899 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
5900 return t1;
5901 }
5902
5903 +#define atomic64_read_unchecked(v) atomic64_read(v)
5904 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5905 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5906 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5907 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5908 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5909 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5910 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5911 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5912 +
5913 #endif /* __powerpc64__ */
5914
5915 #endif /* __KERNEL__ */
5916 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
5917 index 9e495c9..b6878e5 100644
5918 --- a/arch/powerpc/include/asm/cache.h
5919 +++ b/arch/powerpc/include/asm/cache.h
5920 @@ -3,6 +3,7 @@
5921
5922 #ifdef __KERNEL__
5923
5924 +#include <linux/const.h>
5925
5926 /* bytes per L1 cache line */
5927 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
5928 @@ -22,7 +23,7 @@
5929 #define L1_CACHE_SHIFT 7
5930 #endif
5931
5932 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5933 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5934
5935 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5936
5937 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
5938 index 6abf0a1..459d0f1 100644
5939 --- a/arch/powerpc/include/asm/elf.h
5940 +++ b/arch/powerpc/include/asm/elf.h
5941 @@ -28,8 +28,19 @@
5942 the loader. We need to make sure that it is out of the way of the program
5943 that it will "exec", and that there is sufficient room for the brk. */
5944
5945 -extern unsigned long randomize_et_dyn(unsigned long base);
5946 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
5947 +#define ELF_ET_DYN_BASE (0x20000000)
5948 +
5949 +#ifdef CONFIG_PAX_ASLR
5950 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
5951 +
5952 +#ifdef __powerpc64__
5953 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
5954 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
5955 +#else
5956 +#define PAX_DELTA_MMAP_LEN 15
5957 +#define PAX_DELTA_STACK_LEN 15
5958 +#endif
5959 +#endif
5960
5961 /*
5962 * Our registers are always unsigned longs, whether we're a 32 bit
5963 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5964 (0x7ff >> (PAGE_SHIFT - 12)) : \
5965 (0x3ffff >> (PAGE_SHIFT - 12)))
5966
5967 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5968 -#define arch_randomize_brk arch_randomize_brk
5969 -
5970 -
5971 #ifdef CONFIG_SPU_BASE
5972 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
5973 #define NT_SPU 1
5974 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
5975 index 8196e9c..d83a9f3 100644
5976 --- a/arch/powerpc/include/asm/exec.h
5977 +++ b/arch/powerpc/include/asm/exec.h
5978 @@ -4,6 +4,6 @@
5979 #ifndef _ASM_POWERPC_EXEC_H
5980 #define _ASM_POWERPC_EXEC_H
5981
5982 -extern unsigned long arch_align_stack(unsigned long sp);
5983 +#define arch_align_stack(x) ((x) & ~0xfUL)
5984
5985 #endif /* _ASM_POWERPC_EXEC_H */
5986 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
5987 index 5acabbd..7ea14fa 100644
5988 --- a/arch/powerpc/include/asm/kmap_types.h
5989 +++ b/arch/powerpc/include/asm/kmap_types.h
5990 @@ -10,7 +10,7 @@
5991 * 2 of the License, or (at your option) any later version.
5992 */
5993
5994 -#define KM_TYPE_NR 16
5995 +#define KM_TYPE_NR 17
5996
5997 #endif /* __KERNEL__ */
5998 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
5999 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6000 index 8565c25..2865190 100644
6001 --- a/arch/powerpc/include/asm/mman.h
6002 +++ b/arch/powerpc/include/asm/mman.h
6003 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6004 }
6005 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6006
6007 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6008 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6009 {
6010 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6011 }
6012 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6013 index f072e97..b436dee 100644
6014 --- a/arch/powerpc/include/asm/page.h
6015 +++ b/arch/powerpc/include/asm/page.h
6016 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6017 * and needs to be executable. This means the whole heap ends
6018 * up being executable.
6019 */
6020 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6021 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6022 +#define VM_DATA_DEFAULT_FLAGS32 \
6023 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6024 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6025
6026 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6027 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6028 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6029 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6030 #endif
6031
6032 +#define ktla_ktva(addr) (addr)
6033 +#define ktva_ktla(addr) (addr)
6034 +
6035 /*
6036 * Use the top bit of the higher-level page table entries to indicate whether
6037 * the entries we point to contain hugepages. This works because we know that
6038 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6039 index cd915d6..c10cee8 100644
6040 --- a/arch/powerpc/include/asm/page_64.h
6041 +++ b/arch/powerpc/include/asm/page_64.h
6042 @@ -154,15 +154,18 @@ do { \
6043 * stack by default, so in the absence of a PT_GNU_STACK program header
6044 * we turn execute permission off.
6045 */
6046 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6047 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6048 +#define VM_STACK_DEFAULT_FLAGS32 \
6049 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6050 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6051
6052 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6053 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6054
6055 +#ifndef CONFIG_PAX_PAGEEXEC
6056 #define VM_STACK_DEFAULT_FLAGS \
6057 (is_32bit_task() ? \
6058 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6059 +#endif
6060
6061 #include <asm-generic/getorder.h>
6062
6063 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6064 index 292725c..f87ae14 100644
6065 --- a/arch/powerpc/include/asm/pgalloc-64.h
6066 +++ b/arch/powerpc/include/asm/pgalloc-64.h
6067 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6068 #ifndef CONFIG_PPC_64K_PAGES
6069
6070 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6071 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6072
6073 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6074 {
6075 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6076 pud_set(pud, (unsigned long)pmd);
6077 }
6078
6079 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6080 +{
6081 + pud_populate(mm, pud, pmd);
6082 +}
6083 +
6084 #define pmd_populate(mm, pmd, pte_page) \
6085 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6086 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6087 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6088 #else /* CONFIG_PPC_64K_PAGES */
6089
6090 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6091 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6092
6093 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6094 pte_t *pte)
6095 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6096 index a9cbd3b..3b67efa 100644
6097 --- a/arch/powerpc/include/asm/pgtable.h
6098 +++ b/arch/powerpc/include/asm/pgtable.h
6099 @@ -2,6 +2,7 @@
6100 #define _ASM_POWERPC_PGTABLE_H
6101 #ifdef __KERNEL__
6102
6103 +#include <linux/const.h>
6104 #ifndef __ASSEMBLY__
6105 #include <asm/processor.h> /* For TASK_SIZE */
6106 #include <asm/mmu.h>
6107 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6108 index 4aad413..85d86bf 100644
6109 --- a/arch/powerpc/include/asm/pte-hash32.h
6110 +++ b/arch/powerpc/include/asm/pte-hash32.h
6111 @@ -21,6 +21,7 @@
6112 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6113 #define _PAGE_USER 0x004 /* usermode access allowed */
6114 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6115 +#define _PAGE_EXEC _PAGE_GUARDED
6116 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6117 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6118 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6119 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6120 index 3d5c9dc..62f8414 100644
6121 --- a/arch/powerpc/include/asm/reg.h
6122 +++ b/arch/powerpc/include/asm/reg.h
6123 @@ -215,6 +215,7 @@
6124 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6125 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6126 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6127 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6128 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6129 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6130 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6131 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6132 index 406b7b9..af63426 100644
6133 --- a/arch/powerpc/include/asm/thread_info.h
6134 +++ b/arch/powerpc/include/asm/thread_info.h
6135 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6136 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6137 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6138 #define TIF_SINGLESTEP 8 /* singlestepping active */
6139 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6140 #define TIF_SECCOMP 10 /* secure computing */
6141 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6142 #define TIF_NOERROR 12 /* Force successful syscall return */
6143 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6144 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6145 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6146 for stack store? */
6147 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6148 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6149 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6150
6151 /* as above, but as bit values */
6152 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6153 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6154 #define _TIF_UPROBE (1<<TIF_UPROBE)
6155 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6156 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6157 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6158 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6159 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6160 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6161 + _TIF_GRSEC_SETXID)
6162
6163 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6164 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6165 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6166 index 4db4959..335e00c 100644
6167 --- a/arch/powerpc/include/asm/uaccess.h
6168 +++ b/arch/powerpc/include/asm/uaccess.h
6169 @@ -13,6 +13,8 @@
6170 #define VERIFY_READ 0
6171 #define VERIFY_WRITE 1
6172
6173 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6174 +
6175 /*
6176 * The fs value determines whether argument validity checking should be
6177 * performed or not. If get_fs() == USER_DS, checking is performed, with
6178 @@ -318,52 +320,6 @@ do { \
6179 extern unsigned long __copy_tofrom_user(void __user *to,
6180 const void __user *from, unsigned long size);
6181
6182 -#ifndef __powerpc64__
6183 -
6184 -static inline unsigned long copy_from_user(void *to,
6185 - const void __user *from, unsigned long n)
6186 -{
6187 - unsigned long over;
6188 -
6189 - if (access_ok(VERIFY_READ, from, n))
6190 - return __copy_tofrom_user((__force void __user *)to, from, n);
6191 - if ((unsigned long)from < TASK_SIZE) {
6192 - over = (unsigned long)from + n - TASK_SIZE;
6193 - return __copy_tofrom_user((__force void __user *)to, from,
6194 - n - over) + over;
6195 - }
6196 - return n;
6197 -}
6198 -
6199 -static inline unsigned long copy_to_user(void __user *to,
6200 - const void *from, unsigned long n)
6201 -{
6202 - unsigned long over;
6203 -
6204 - if (access_ok(VERIFY_WRITE, to, n))
6205 - return __copy_tofrom_user(to, (__force void __user *)from, n);
6206 - if ((unsigned long)to < TASK_SIZE) {
6207 - over = (unsigned long)to + n - TASK_SIZE;
6208 - return __copy_tofrom_user(to, (__force void __user *)from,
6209 - n - over) + over;
6210 - }
6211 - return n;
6212 -}
6213 -
6214 -#else /* __powerpc64__ */
6215 -
6216 -#define __copy_in_user(to, from, size) \
6217 - __copy_tofrom_user((to), (from), (size))
6218 -
6219 -extern unsigned long copy_from_user(void *to, const void __user *from,
6220 - unsigned long n);
6221 -extern unsigned long copy_to_user(void __user *to, const void *from,
6222 - unsigned long n);
6223 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
6224 - unsigned long n);
6225 -
6226 -#endif /* __powerpc64__ */
6227 -
6228 static inline unsigned long __copy_from_user_inatomic(void *to,
6229 const void __user *from, unsigned long n)
6230 {
6231 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6232 if (ret == 0)
6233 return 0;
6234 }
6235 +
6236 + if (!__builtin_constant_p(n))
6237 + check_object_size(to, n, false);
6238 +
6239 return __copy_tofrom_user((__force void __user *)to, from, n);
6240 }
6241
6242 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6243 if (ret == 0)
6244 return 0;
6245 }
6246 +
6247 + if (!__builtin_constant_p(n))
6248 + check_object_size(from, n, true);
6249 +
6250 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6251 }
6252
6253 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6254 return __copy_to_user_inatomic(to, from, size);
6255 }
6256
6257 +#ifndef __powerpc64__
6258 +
6259 +static inline unsigned long __must_check copy_from_user(void *to,
6260 + const void __user *from, unsigned long n)
6261 +{
6262 + unsigned long over;
6263 +
6264 + if ((long)n < 0)
6265 + return n;
6266 +
6267 + if (access_ok(VERIFY_READ, from, n)) {
6268 + if (!__builtin_constant_p(n))
6269 + check_object_size(to, n, false);
6270 + return __copy_tofrom_user((__force void __user *)to, from, n);
6271 + }
6272 + if ((unsigned long)from < TASK_SIZE) {
6273 + over = (unsigned long)from + n - TASK_SIZE;
6274 + if (!__builtin_constant_p(n - over))
6275 + check_object_size(to, n - over, false);
6276 + return __copy_tofrom_user((__force void __user *)to, from,
6277 + n - over) + over;
6278 + }
6279 + return n;
6280 +}
6281 +
6282 +static inline unsigned long __must_check copy_to_user(void __user *to,
6283 + const void *from, unsigned long n)
6284 +{
6285 + unsigned long over;
6286 +
6287 + if ((long)n < 0)
6288 + return n;
6289 +
6290 + if (access_ok(VERIFY_WRITE, to, n)) {
6291 + if (!__builtin_constant_p(n))
6292 + check_object_size(from, n, true);
6293 + return __copy_tofrom_user(to, (__force void __user *)from, n);
6294 + }
6295 + if ((unsigned long)to < TASK_SIZE) {
6296 + over = (unsigned long)to + n - TASK_SIZE;
6297 + if (!__builtin_constant_p(n))
6298 + check_object_size(from, n - over, true);
6299 + return __copy_tofrom_user(to, (__force void __user *)from,
6300 + n - over) + over;
6301 + }
6302 + return n;
6303 +}
6304 +
6305 +#else /* __powerpc64__ */
6306 +
6307 +#define __copy_in_user(to, from, size) \
6308 + __copy_tofrom_user((to), (from), (size))
6309 +
6310 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6311 +{
6312 + if ((long)n < 0 || n > INT_MAX)
6313 + return n;
6314 +
6315 + if (!__builtin_constant_p(n))
6316 + check_object_size(to, n, false);
6317 +
6318 + if (likely(access_ok(VERIFY_READ, from, n)))
6319 + n = __copy_from_user(to, from, n);
6320 + else
6321 + memset(to, 0, n);
6322 + return n;
6323 +}
6324 +
6325 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6326 +{
6327 + if ((long)n < 0 || n > INT_MAX)
6328 + return n;
6329 +
6330 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
6331 + if (!__builtin_constant_p(n))
6332 + check_object_size(from, n, true);
6333 + n = __copy_to_user(to, from, n);
6334 + }
6335 + return n;
6336 +}
6337 +
6338 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
6339 + unsigned long n);
6340 +
6341 +#endif /* __powerpc64__ */
6342 +
6343 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6344
6345 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6346 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6347 index 4684e33..acc4d19e 100644
6348 --- a/arch/powerpc/kernel/exceptions-64e.S
6349 +++ b/arch/powerpc/kernel/exceptions-64e.S
6350 @@ -715,6 +715,7 @@ storage_fault_common:
6351 std r14,_DAR(r1)
6352 std r15,_DSISR(r1)
6353 addi r3,r1,STACK_FRAME_OVERHEAD
6354 + bl .save_nvgprs
6355 mr r4,r14
6356 mr r5,r15
6357 ld r14,PACA_EXGEN+EX_R14(r13)
6358 @@ -723,8 +724,7 @@ storage_fault_common:
6359 cmpdi r3,0
6360 bne- 1f
6361 b .ret_from_except_lite
6362 -1: bl .save_nvgprs
6363 - mr r5,r3
6364 +1: mr r5,r3
6365 addi r3,r1,STACK_FRAME_OVERHEAD
6366 ld r4,_DAR(r1)
6367 bl .bad_page_fault
6368 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6369 index 4665e82..080ea99 100644
6370 --- a/arch/powerpc/kernel/exceptions-64s.S
6371 +++ b/arch/powerpc/kernel/exceptions-64s.S
6372 @@ -1206,10 +1206,10 @@ handle_page_fault:
6373 11: ld r4,_DAR(r1)
6374 ld r5,_DSISR(r1)
6375 addi r3,r1,STACK_FRAME_OVERHEAD
6376 + bl .save_nvgprs
6377 bl .do_page_fault
6378 cmpdi r3,0
6379 beq+ 12f
6380 - bl .save_nvgprs
6381 mr r5,r3
6382 addi r3,r1,STACK_FRAME_OVERHEAD
6383 lwz r4,_DAR(r1)
6384 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6385 index 2e3200c..72095ce 100644
6386 --- a/arch/powerpc/kernel/module_32.c
6387 +++ b/arch/powerpc/kernel/module_32.c
6388 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6389 me->arch.core_plt_section = i;
6390 }
6391 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6392 - printk("Module doesn't contain .plt or .init.plt sections.\n");
6393 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6394 return -ENOEXEC;
6395 }
6396
6397 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6398
6399 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6400 /* Init, or core PLT? */
6401 - if (location >= mod->module_core
6402 - && location < mod->module_core + mod->core_size)
6403 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6404 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6405 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6406 - else
6407 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6408 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6409 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6410 + else {
6411 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6412 + return ~0UL;
6413 + }
6414
6415 /* Find this entry, or if that fails, the next avail. entry */
6416 while (entry->jump[0]) {
6417 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6418 index 8143067..21ae55b 100644
6419 --- a/arch/powerpc/kernel/process.c
6420 +++ b/arch/powerpc/kernel/process.c
6421 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6422 * Lookup NIP late so we have the best change of getting the
6423 * above info out without failing
6424 */
6425 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6426 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6427 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6428 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6429 #endif
6430 show_stack(current, (unsigned long *) regs->gpr[1]);
6431 if (!user_mode(regs))
6432 @@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6433 newsp = stack[0];
6434 ip = stack[STACK_FRAME_LR_SAVE];
6435 if (!firstframe || ip != lr) {
6436 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6437 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6438 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6439 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6440 - printk(" (%pS)",
6441 + printk(" (%pA)",
6442 (void *)current->ret_stack[curr_frame].ret);
6443 curr_frame--;
6444 }
6445 @@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6446 struct pt_regs *regs = (struct pt_regs *)
6447 (sp + STACK_FRAME_OVERHEAD);
6448 lr = regs->link;
6449 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
6450 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
6451 regs->trap, (void *)regs->nip, (void *)lr);
6452 firstframe = 1;
6453 }
6454 @@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6455 mtspr(SPRN_CTRLT, ctrl);
6456 }
6457 #endif /* CONFIG_PPC64 */
6458 -
6459 -unsigned long arch_align_stack(unsigned long sp)
6460 -{
6461 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6462 - sp -= get_random_int() & ~PAGE_MASK;
6463 - return sp & ~0xf;
6464 -}
6465 -
6466 -static inline unsigned long brk_rnd(void)
6467 -{
6468 - unsigned long rnd = 0;
6469 -
6470 - /* 8MB for 32bit, 1GB for 64bit */
6471 - if (is_32bit_task())
6472 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6473 - else
6474 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6475 -
6476 - return rnd << PAGE_SHIFT;
6477 -}
6478 -
6479 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6480 -{
6481 - unsigned long base = mm->brk;
6482 - unsigned long ret;
6483 -
6484 -#ifdef CONFIG_PPC_STD_MMU_64
6485 - /*
6486 - * If we are using 1TB segments and we are allowed to randomise
6487 - * the heap, we can put it above 1TB so it is backed by a 1TB
6488 - * segment. Otherwise the heap will be in the bottom 1TB
6489 - * which always uses 256MB segments and this may result in a
6490 - * performance penalty.
6491 - */
6492 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6493 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6494 -#endif
6495 -
6496 - ret = PAGE_ALIGN(base + brk_rnd());
6497 -
6498 - if (ret < mm->brk)
6499 - return mm->brk;
6500 -
6501 - return ret;
6502 -}
6503 -
6504 -unsigned long randomize_et_dyn(unsigned long base)
6505 -{
6506 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6507 -
6508 - if (ret < base)
6509 - return base;
6510 -
6511 - return ret;
6512 -}
6513 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6514 index c497000..8fde506 100644
6515 --- a/arch/powerpc/kernel/ptrace.c
6516 +++ b/arch/powerpc/kernel/ptrace.c
6517 @@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6518 return ret;
6519 }
6520
6521 +#ifdef CONFIG_GRKERNSEC_SETXID
6522 +extern void gr_delayed_cred_worker(void);
6523 +#endif
6524 +
6525 /*
6526 * We must return the syscall number to actually look up in the table.
6527 * This can be -1L to skip running any syscall at all.
6528 @@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6529
6530 secure_computing_strict(regs->gpr[0]);
6531
6532 +#ifdef CONFIG_GRKERNSEC_SETXID
6533 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6534 + gr_delayed_cred_worker();
6535 +#endif
6536 +
6537 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6538 tracehook_report_syscall_entry(regs))
6539 /*
6540 @@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6541 {
6542 int step;
6543
6544 +#ifdef CONFIG_GRKERNSEC_SETXID
6545 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6546 + gr_delayed_cred_worker();
6547 +#endif
6548 +
6549 audit_syscall_exit(regs);
6550
6551 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6552 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6553 index 804e323..79181c1 100644
6554 --- a/arch/powerpc/kernel/signal_32.c
6555 +++ b/arch/powerpc/kernel/signal_32.c
6556 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6557 /* Save user registers on the stack */
6558 frame = &rt_sf->uc.uc_mcontext;
6559 addr = frame;
6560 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6561 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6562 if (save_user_regs(regs, frame, 0, 1))
6563 goto badframe;
6564 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6565 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6566 index 1ca045d..139c3f7 100644
6567 --- a/arch/powerpc/kernel/signal_64.c
6568 +++ b/arch/powerpc/kernel/signal_64.c
6569 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6570 current->thread.fpscr.val = 0;
6571
6572 /* Set up to return from userspace. */
6573 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6574 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6575 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6576 } else {
6577 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6578 diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6579 index 3ce1f86..c30e629 100644
6580 --- a/arch/powerpc/kernel/sysfs.c
6581 +++ b/arch/powerpc/kernel/sysfs.c
6582 @@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6583 return NOTIFY_OK;
6584 }
6585
6586 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6587 +static struct notifier_block sysfs_cpu_nb = {
6588 .notifier_call = sysfs_cpu_notify,
6589 };
6590
6591 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6592 index 3251840..3f7c77a 100644
6593 --- a/arch/powerpc/kernel/traps.c
6594 +++ b/arch/powerpc/kernel/traps.c
6595 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6596 return flags;
6597 }
6598
6599 +extern void gr_handle_kernel_exploit(void);
6600 +
6601 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6602 int signr)
6603 {
6604 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6605 panic("Fatal exception in interrupt");
6606 if (panic_on_oops)
6607 panic("Fatal exception");
6608 +
6609 + gr_handle_kernel_exploit();
6610 +
6611 do_exit(signr);
6612 }
6613
6614 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6615 index 1b2076f..835e4be 100644
6616 --- a/arch/powerpc/kernel/vdso.c
6617 +++ b/arch/powerpc/kernel/vdso.c
6618 @@ -34,6 +34,7 @@
6619 #include <asm/firmware.h>
6620 #include <asm/vdso.h>
6621 #include <asm/vdso_datapage.h>
6622 +#include <asm/mman.h>
6623
6624 #include "setup.h"
6625
6626 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6627 vdso_base = VDSO32_MBASE;
6628 #endif
6629
6630 - current->mm->context.vdso_base = 0;
6631 + current->mm->context.vdso_base = ~0UL;
6632
6633 /* vDSO has a problem and was disabled, just don't "enable" it for the
6634 * process
6635 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6636 vdso_base = get_unmapped_area(NULL, vdso_base,
6637 (vdso_pages << PAGE_SHIFT) +
6638 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6639 - 0, 0);
6640 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
6641 if (IS_ERR_VALUE(vdso_base)) {
6642 rc = vdso_base;
6643 goto fail_mmapsem;
6644 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6645 index 5eea6f3..5d10396 100644
6646 --- a/arch/powerpc/lib/usercopy_64.c
6647 +++ b/arch/powerpc/lib/usercopy_64.c
6648 @@ -9,22 +9,6 @@
6649 #include <linux/module.h>
6650 #include <asm/uaccess.h>
6651
6652 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6653 -{
6654 - if (likely(access_ok(VERIFY_READ, from, n)))
6655 - n = __copy_from_user(to, from, n);
6656 - else
6657 - memset(to, 0, n);
6658 - return n;
6659 -}
6660 -
6661 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6662 -{
6663 - if (likely(access_ok(VERIFY_WRITE, to, n)))
6664 - n = __copy_to_user(to, from, n);
6665 - return n;
6666 -}
6667 -
6668 unsigned long copy_in_user(void __user *to, const void __user *from,
6669 unsigned long n)
6670 {
6671 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6672 return n;
6673 }
6674
6675 -EXPORT_SYMBOL(copy_from_user);
6676 -EXPORT_SYMBOL(copy_to_user);
6677 EXPORT_SYMBOL(copy_in_user);
6678
6679 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6680 index 3a8489a..6a63b3b 100644
6681 --- a/arch/powerpc/mm/fault.c
6682 +++ b/arch/powerpc/mm/fault.c
6683 @@ -32,6 +32,10 @@
6684 #include <linux/perf_event.h>
6685 #include <linux/magic.h>
6686 #include <linux/ratelimit.h>
6687 +#include <linux/slab.h>
6688 +#include <linux/pagemap.h>
6689 +#include <linux/compiler.h>
6690 +#include <linux/unistd.h>
6691
6692 #include <asm/firmware.h>
6693 #include <asm/page.h>
6694 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6695 }
6696 #endif
6697
6698 +#ifdef CONFIG_PAX_PAGEEXEC
6699 +/*
6700 + * PaX: decide what to do with offenders (regs->nip = fault address)
6701 + *
6702 + * returns 1 when task should be killed
6703 + */
6704 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6705 +{
6706 + return 1;
6707 +}
6708 +
6709 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6710 +{
6711 + unsigned long i;
6712 +
6713 + printk(KERN_ERR "PAX: bytes at PC: ");
6714 + for (i = 0; i < 5; i++) {
6715 + unsigned int c;
6716 + if (get_user(c, (unsigned int __user *)pc+i))
6717 + printk(KERN_CONT "???????? ");
6718 + else
6719 + printk(KERN_CONT "%08x ", c);
6720 + }
6721 + printk("\n");
6722 +}
6723 +#endif
6724 +
6725 /*
6726 * Check whether the instruction at regs->nip is a store using
6727 * an update addressing form which will update r1.
6728 @@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6729 * indicate errors in DSISR but can validly be set in SRR1.
6730 */
6731 if (trap == 0x400)
6732 - error_code &= 0x48200000;
6733 + error_code &= 0x58200000;
6734 else
6735 is_write = error_code & DSISR_ISSTORE;
6736 #else
6737 @@ -364,7 +395,7 @@ good_area:
6738 * "undefined". Of those that can be set, this is the only
6739 * one which seems bad.
6740 */
6741 - if (error_code & 0x10000000)
6742 + if (error_code & DSISR_GUARDED)
6743 /* Guarded storage error. */
6744 goto bad_area;
6745 #endif /* CONFIG_8xx */
6746 @@ -379,7 +410,7 @@ good_area:
6747 * processors use the same I/D cache coherency mechanism
6748 * as embedded.
6749 */
6750 - if (error_code & DSISR_PROTFAULT)
6751 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6752 goto bad_area;
6753 #endif /* CONFIG_PPC_STD_MMU */
6754
6755 @@ -462,6 +493,23 @@ bad_area:
6756 bad_area_nosemaphore:
6757 /* User mode accesses cause a SIGSEGV */
6758 if (user_mode(regs)) {
6759 +
6760 +#ifdef CONFIG_PAX_PAGEEXEC
6761 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6762 +#ifdef CONFIG_PPC_STD_MMU
6763 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6764 +#else
6765 + if (is_exec && regs->nip == address) {
6766 +#endif
6767 + switch (pax_handle_fetch_fault(regs)) {
6768 + }
6769 +
6770 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6771 + do_group_exit(SIGKILL);
6772 + }
6773 + }
6774 +#endif
6775 +
6776 _exception(SIGSEGV, regs, code, address);
6777 return 0;
6778 }
6779 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6780 index 67a42ed..cd463e0 100644
6781 --- a/arch/powerpc/mm/mmap_64.c
6782 +++ b/arch/powerpc/mm/mmap_64.c
6783 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6784 {
6785 unsigned long rnd = 0;
6786
6787 +#ifdef CONFIG_PAX_RANDMMAP
6788 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6789 +#endif
6790 +
6791 if (current->flags & PF_RANDOMIZE) {
6792 /* 8MB for 32bit, 1GB for 64bit */
6793 if (is_32bit_task())
6794 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6795 */
6796 if (mmap_is_legacy()) {
6797 mm->mmap_base = TASK_UNMAPPED_BASE;
6798 +
6799 +#ifdef CONFIG_PAX_RANDMMAP
6800 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6801 + mm->mmap_base += mm->delta_mmap;
6802 +#endif
6803 +
6804 mm->get_unmapped_area = arch_get_unmapped_area;
6805 mm->unmap_area = arch_unmap_area;
6806 } else {
6807 mm->mmap_base = mmap_base();
6808 +
6809 +#ifdef CONFIG_PAX_RANDMMAP
6810 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6811 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6812 +#endif
6813 +
6814 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6815 mm->unmap_area = arch_unmap_area_topdown;
6816 }
6817 diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6818 index e779642..e5bb889 100644
6819 --- a/arch/powerpc/mm/mmu_context_nohash.c
6820 +++ b/arch/powerpc/mm/mmu_context_nohash.c
6821 @@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6822 return NOTIFY_OK;
6823 }
6824
6825 -static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6826 +static struct notifier_block mmu_context_cpu_nb = {
6827 .notifier_call = mmu_context_cpu_notify,
6828 };
6829
6830 diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
6831 index bba87ca..c346a33 100644
6832 --- a/arch/powerpc/mm/numa.c
6833 +++ b/arch/powerpc/mm/numa.c
6834 @@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
6835 return ret;
6836 }
6837
6838 -static struct notifier_block __cpuinitdata ppc64_numa_nb = {
6839 +static struct notifier_block ppc64_numa_nb = {
6840 .notifier_call = cpu_numa_callback,
6841 .priority = 1 /* Must run before sched domains notifier. */
6842 };
6843 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
6844 index cf9dada..241529f 100644
6845 --- a/arch/powerpc/mm/slice.c
6846 +++ b/arch/powerpc/mm/slice.c
6847 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
6848 if ((mm->task_size - len) < addr)
6849 return 0;
6850 vma = find_vma(mm, addr);
6851 - return (!vma || (addr + len) <= vma->vm_start);
6852 + return check_heap_stack_gap(vma, addr, len, 0);
6853 }
6854
6855 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
6856 @@ -272,7 +272,7 @@ full_search:
6857 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
6858 continue;
6859 }
6860 - if (!vma || addr + len <= vma->vm_start) {
6861 + if (check_heap_stack_gap(vma, addr, len, 0)) {
6862 /*
6863 * Remember the place where we stopped the search:
6864 */
6865 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6866 }
6867 }
6868
6869 - addr = mm->mmap_base;
6870 - while (addr > len) {
6871 + if (mm->mmap_base < len)
6872 + addr = -ENOMEM;
6873 + else
6874 + addr = mm->mmap_base - len;
6875 +
6876 + while (!IS_ERR_VALUE(addr)) {
6877 /* Go down by chunk size */
6878 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
6879 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
6880
6881 /* Check for hit with different page size */
6882 mask = slice_range_to_mask(addr, len);
6883 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6884 * return with success:
6885 */
6886 vma = find_vma(mm, addr);
6887 - if (!vma || (addr + len) <= vma->vm_start) {
6888 + if (check_heap_stack_gap(vma, addr, len, 0)) {
6889 /* remember the address as a hint for next time */
6890 if (use_cache)
6891 mm->free_area_cache = addr;
6892 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6893 mm->cached_hole_size = vma->vm_start - addr;
6894
6895 /* try just below the current vma->vm_start */
6896 - addr = vma->vm_start;
6897 + addr = skip_heap_stack_gap(vma, len, 0);
6898 }
6899
6900 /*
6901 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
6902 if (fixed && addr > (mm->task_size - len))
6903 return -EINVAL;
6904
6905 +#ifdef CONFIG_PAX_RANDMMAP
6906 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
6907 + addr = 0;
6908 +#endif
6909 +
6910 /* If hint, make sure it matches our alignment restrictions */
6911 if (!fixed && addr) {
6912 addr = _ALIGN_UP(addr, 1ul << pshift);
6913 diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
6914 index bdb738a..49c9f95 100644
6915 --- a/arch/powerpc/platforms/powermac/smp.c
6916 +++ b/arch/powerpc/platforms/powermac/smp.c
6917 @@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
6918 return NOTIFY_OK;
6919 }
6920
6921 -static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
6922 +static struct notifier_block smp_core99_cpu_nb = {
6923 .notifier_call = smp_core99_cpu_notify,
6924 };
6925 #endif /* CONFIG_HOTPLUG_CPU */
6926 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
6927 index c797832..ce575c8 100644
6928 --- a/arch/s390/include/asm/atomic.h
6929 +++ b/arch/s390/include/asm/atomic.h
6930 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
6931 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
6932 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6933
6934 +#define atomic64_read_unchecked(v) atomic64_read(v)
6935 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6936 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6937 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6938 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6939 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6940 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6941 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6942 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6943 +
6944 #define smp_mb__before_atomic_dec() smp_mb()
6945 #define smp_mb__after_atomic_dec() smp_mb()
6946 #define smp_mb__before_atomic_inc() smp_mb()
6947 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
6948 index 4d7ccac..d03d0ad 100644
6949 --- a/arch/s390/include/asm/cache.h
6950 +++ b/arch/s390/include/asm/cache.h
6951 @@ -9,8 +9,10 @@
6952 #ifndef __ARCH_S390_CACHE_H
6953 #define __ARCH_S390_CACHE_H
6954
6955 -#define L1_CACHE_BYTES 256
6956 +#include <linux/const.h>
6957 +
6958 #define L1_CACHE_SHIFT 8
6959 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6960 #define NET_SKB_PAD 32
6961
6962 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6963 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
6964 index 178ff96..8c93bd1 100644
6965 --- a/arch/s390/include/asm/elf.h
6966 +++ b/arch/s390/include/asm/elf.h
6967 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
6968 the loader. We need to make sure that it is out of the way of the program
6969 that it will "exec", and that there is sufficient room for the brk. */
6970
6971 -extern unsigned long randomize_et_dyn(unsigned long base);
6972 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
6973 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
6974 +
6975 +#ifdef CONFIG_PAX_ASLR
6976 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
6977 +
6978 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6979 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6980 +#endif
6981
6982 /* This yields a mask that user programs can use to figure out what
6983 instruction set this CPU supports. */
6984 @@ -210,9 +216,6 @@ struct linux_binprm;
6985 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6986 int arch_setup_additional_pages(struct linux_binprm *, int);
6987
6988 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6989 -#define arch_randomize_brk arch_randomize_brk
6990 -
6991 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
6992
6993 #endif
6994 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
6995 index c4a93d6..4d2a9b4 100644
6996 --- a/arch/s390/include/asm/exec.h
6997 +++ b/arch/s390/include/asm/exec.h
6998 @@ -7,6 +7,6 @@
6999 #ifndef __ASM_EXEC_H
7000 #define __ASM_EXEC_H
7001
7002 -extern unsigned long arch_align_stack(unsigned long sp);
7003 +#define arch_align_stack(x) ((x) & ~0xfUL)
7004
7005 #endif /* __ASM_EXEC_H */
7006 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7007 index 34268df..ea97318 100644
7008 --- a/arch/s390/include/asm/uaccess.h
7009 +++ b/arch/s390/include/asm/uaccess.h
7010 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
7011 copy_to_user(void __user *to, const void *from, unsigned long n)
7012 {
7013 might_fault();
7014 +
7015 + if ((long)n < 0)
7016 + return n;
7017 +
7018 if (access_ok(VERIFY_WRITE, to, n))
7019 n = __copy_to_user(to, from, n);
7020 return n;
7021 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7022 static inline unsigned long __must_check
7023 __copy_from_user(void *to, const void __user *from, unsigned long n)
7024 {
7025 + if ((long)n < 0)
7026 + return n;
7027 +
7028 if (__builtin_constant_p(n) && (n <= 256))
7029 return uaccess.copy_from_user_small(n, from, to);
7030 else
7031 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7032 static inline unsigned long __must_check
7033 copy_from_user(void *to, const void __user *from, unsigned long n)
7034 {
7035 - unsigned int sz = __compiletime_object_size(to);
7036 + size_t sz = __compiletime_object_size(to);
7037
7038 might_fault();
7039 - if (unlikely(sz != -1 && sz < n)) {
7040 +
7041 + if ((long)n < 0)
7042 + return n;
7043 +
7044 + if (unlikely(sz != (size_t)-1 && sz < n)) {
7045 copy_from_user_overflow();
7046 return n;
7047 }
7048 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7049 index 4610dea..cf0af21 100644
7050 --- a/arch/s390/kernel/module.c
7051 +++ b/arch/s390/kernel/module.c
7052 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7053
7054 /* Increase core size by size of got & plt and set start
7055 offsets for got and plt. */
7056 - me->core_size = ALIGN(me->core_size, 4);
7057 - me->arch.got_offset = me->core_size;
7058 - me->core_size += me->arch.got_size;
7059 - me->arch.plt_offset = me->core_size;
7060 - me->core_size += me->arch.plt_size;
7061 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
7062 + me->arch.got_offset = me->core_size_rw;
7063 + me->core_size_rw += me->arch.got_size;
7064 + me->arch.plt_offset = me->core_size_rx;
7065 + me->core_size_rx += me->arch.plt_size;
7066 return 0;
7067 }
7068
7069 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7070 if (info->got_initialized == 0) {
7071 Elf_Addr *gotent;
7072
7073 - gotent = me->module_core + me->arch.got_offset +
7074 + gotent = me->module_core_rw + me->arch.got_offset +
7075 info->got_offset;
7076 *gotent = val;
7077 info->got_initialized = 1;
7078 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7079 else if (r_type == R_390_GOTENT ||
7080 r_type == R_390_GOTPLTENT)
7081 *(unsigned int *) loc =
7082 - (val + (Elf_Addr) me->module_core - loc) >> 1;
7083 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7084 else if (r_type == R_390_GOT64 ||
7085 r_type == R_390_GOTPLT64)
7086 *(unsigned long *) loc = val;
7087 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7088 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7089 if (info->plt_initialized == 0) {
7090 unsigned int *ip;
7091 - ip = me->module_core + me->arch.plt_offset +
7092 + ip = me->module_core_rx + me->arch.plt_offset +
7093 info->plt_offset;
7094 #ifndef CONFIG_64BIT
7095 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7096 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7097 val - loc + 0xffffUL < 0x1ffffeUL) ||
7098 (r_type == R_390_PLT32DBL &&
7099 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7100 - val = (Elf_Addr) me->module_core +
7101 + val = (Elf_Addr) me->module_core_rx +
7102 me->arch.plt_offset +
7103 info->plt_offset;
7104 val += rela->r_addend - loc;
7105 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7106 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7107 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7108 val = val + rela->r_addend -
7109 - ((Elf_Addr) me->module_core + me->arch.got_offset);
7110 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7111 if (r_type == R_390_GOTOFF16)
7112 *(unsigned short *) loc = val;
7113 else if (r_type == R_390_GOTOFF32)
7114 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7115 break;
7116 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7117 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7118 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
7119 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7120 rela->r_addend - loc;
7121 if (r_type == R_390_GOTPC)
7122 *(unsigned int *) loc = val;
7123 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7124 index 536d645..4a5bd9e 100644
7125 --- a/arch/s390/kernel/process.c
7126 +++ b/arch/s390/kernel/process.c
7127 @@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7128 }
7129 return 0;
7130 }
7131 -
7132 -unsigned long arch_align_stack(unsigned long sp)
7133 -{
7134 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7135 - sp -= get_random_int() & ~PAGE_MASK;
7136 - return sp & ~0xf;
7137 -}
7138 -
7139 -static inline unsigned long brk_rnd(void)
7140 -{
7141 - /* 8MB for 32bit, 1GB for 64bit */
7142 - if (is_32bit_task())
7143 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7144 - else
7145 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7146 -}
7147 -
7148 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7149 -{
7150 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7151 -
7152 - if (ret < mm->brk)
7153 - return mm->brk;
7154 - return ret;
7155 -}
7156 -
7157 -unsigned long randomize_et_dyn(unsigned long base)
7158 -{
7159 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7160 -
7161 - if (!(current->flags & PF_RANDOMIZE))
7162 - return base;
7163 - if (ret < base)
7164 - return base;
7165 - return ret;
7166 -}
7167 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7168 index c59a5ef..3fae59c 100644
7169 --- a/arch/s390/mm/mmap.c
7170 +++ b/arch/s390/mm/mmap.c
7171 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7172 */
7173 if (mmap_is_legacy()) {
7174 mm->mmap_base = TASK_UNMAPPED_BASE;
7175 +
7176 +#ifdef CONFIG_PAX_RANDMMAP
7177 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7178 + mm->mmap_base += mm->delta_mmap;
7179 +#endif
7180 +
7181 mm->get_unmapped_area = arch_get_unmapped_area;
7182 mm->unmap_area = arch_unmap_area;
7183 } else {
7184 mm->mmap_base = mmap_base();
7185 +
7186 +#ifdef CONFIG_PAX_RANDMMAP
7187 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7188 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7189 +#endif
7190 +
7191 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7192 mm->unmap_area = arch_unmap_area_topdown;
7193 }
7194 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7195 */
7196 if (mmap_is_legacy()) {
7197 mm->mmap_base = TASK_UNMAPPED_BASE;
7198 +
7199 +#ifdef CONFIG_PAX_RANDMMAP
7200 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7201 + mm->mmap_base += mm->delta_mmap;
7202 +#endif
7203 +
7204 mm->get_unmapped_area = s390_get_unmapped_area;
7205 mm->unmap_area = arch_unmap_area;
7206 } else {
7207 mm->mmap_base = mmap_base();
7208 +
7209 +#ifdef CONFIG_PAX_RANDMMAP
7210 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7211 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7212 +#endif
7213 +
7214 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7215 mm->unmap_area = arch_unmap_area_topdown;
7216 }
7217 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7218 index ae3d59f..f65f075 100644
7219 --- a/arch/score/include/asm/cache.h
7220 +++ b/arch/score/include/asm/cache.h
7221 @@ -1,7 +1,9 @@
7222 #ifndef _ASM_SCORE_CACHE_H
7223 #define _ASM_SCORE_CACHE_H
7224
7225 +#include <linux/const.h>
7226 +
7227 #define L1_CACHE_SHIFT 4
7228 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7229 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7230
7231 #endif /* _ASM_SCORE_CACHE_H */
7232 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7233 index f9f3cd5..58ff438 100644
7234 --- a/arch/score/include/asm/exec.h
7235 +++ b/arch/score/include/asm/exec.h
7236 @@ -1,6 +1,6 @@
7237 #ifndef _ASM_SCORE_EXEC_H
7238 #define _ASM_SCORE_EXEC_H
7239
7240 -extern unsigned long arch_align_stack(unsigned long sp);
7241 +#define arch_align_stack(x) (x)
7242
7243 #endif /* _ASM_SCORE_EXEC_H */
7244 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7245 index 7956846..5f37677 100644
7246 --- a/arch/score/kernel/process.c
7247 +++ b/arch/score/kernel/process.c
7248 @@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7249
7250 return task_pt_regs(task)->cp0_epc;
7251 }
7252 -
7253 -unsigned long arch_align_stack(unsigned long sp)
7254 -{
7255 - return sp;
7256 -}
7257 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7258 index ef9e555..331bd29 100644
7259 --- a/arch/sh/include/asm/cache.h
7260 +++ b/arch/sh/include/asm/cache.h
7261 @@ -9,10 +9,11 @@
7262 #define __ASM_SH_CACHE_H
7263 #ifdef __KERNEL__
7264
7265 +#include <linux/const.h>
7266 #include <linux/init.h>
7267 #include <cpu/cache.h>
7268
7269 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7270 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7271
7272 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7273
7274 diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7275 index 03f2b55..b027032 100644
7276 --- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7277 +++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7278 @@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7279 return NOTIFY_OK;
7280 }
7281
7282 -static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7283 +static struct notifier_block shx3_cpu_notifier = {
7284 .notifier_call = shx3_cpu_callback,
7285 };
7286
7287 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7288 index 6777177..cb5e44f 100644
7289 --- a/arch/sh/mm/mmap.c
7290 +++ b/arch/sh/mm/mmap.c
7291 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7292 struct mm_struct *mm = current->mm;
7293 struct vm_area_struct *vma;
7294 int do_colour_align;
7295 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7296 struct vm_unmapped_area_info info;
7297
7298 if (flags & MAP_FIXED) {
7299 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7300 if (filp || (flags & MAP_SHARED))
7301 do_colour_align = 1;
7302
7303 +#ifdef CONFIG_PAX_RANDMMAP
7304 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7305 +#endif
7306 +
7307 if (addr) {
7308 if (do_colour_align)
7309 addr = COLOUR_ALIGN(addr, pgoff);
7310 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7311 addr = PAGE_ALIGN(addr);
7312
7313 vma = find_vma(mm, addr);
7314 - if (TASK_SIZE - len >= addr &&
7315 - (!vma || addr + len <= vma->vm_start))
7316 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7317 return addr;
7318 }
7319
7320 info.flags = 0;
7321 info.length = len;
7322 - info.low_limit = TASK_UNMAPPED_BASE;
7323 + info.low_limit = mm->mmap_base;
7324 info.high_limit = TASK_SIZE;
7325 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7326 info.align_offset = pgoff << PAGE_SHIFT;
7327 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7328 struct mm_struct *mm = current->mm;
7329 unsigned long addr = addr0;
7330 int do_colour_align;
7331 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7332 struct vm_unmapped_area_info info;
7333
7334 if (flags & MAP_FIXED) {
7335 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7336 if (filp || (flags & MAP_SHARED))
7337 do_colour_align = 1;
7338
7339 +#ifdef CONFIG_PAX_RANDMMAP
7340 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7341 +#endif
7342 +
7343 /* requesting a specific address */
7344 if (addr) {
7345 if (do_colour_align)
7346 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7347 addr = PAGE_ALIGN(addr);
7348
7349 vma = find_vma(mm, addr);
7350 - if (TASK_SIZE - len >= addr &&
7351 - (!vma || addr + len <= vma->vm_start))
7352 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7353 return addr;
7354 }
7355
7356 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7357 VM_BUG_ON(addr != -ENOMEM);
7358 info.flags = 0;
7359 info.low_limit = TASK_UNMAPPED_BASE;
7360 +
7361 +#ifdef CONFIG_PAX_RANDMMAP
7362 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7363 + info.low_limit += mm->delta_mmap;
7364 +#endif
7365 +
7366 info.high_limit = TASK_SIZE;
7367 addr = vm_unmapped_area(&info);
7368 }
7369 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7370 index be56a24..443328f 100644
7371 --- a/arch/sparc/include/asm/atomic_64.h
7372 +++ b/arch/sparc/include/asm/atomic_64.h
7373 @@ -14,18 +14,40 @@
7374 #define ATOMIC64_INIT(i) { (i) }
7375
7376 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7377 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7378 +{
7379 + return v->counter;
7380 +}
7381 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7382 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7383 +{
7384 + return v->counter;
7385 +}
7386
7387 #define atomic_set(v, i) (((v)->counter) = i)
7388 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7389 +{
7390 + v->counter = i;
7391 +}
7392 #define atomic64_set(v, i) (((v)->counter) = i)
7393 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7394 +{
7395 + v->counter = i;
7396 +}
7397
7398 extern void atomic_add(int, atomic_t *);
7399 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7400 extern void atomic64_add(long, atomic64_t *);
7401 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7402 extern void atomic_sub(int, atomic_t *);
7403 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7404 extern void atomic64_sub(long, atomic64_t *);
7405 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7406
7407 extern int atomic_add_ret(int, atomic_t *);
7408 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7409 extern long atomic64_add_ret(long, atomic64_t *);
7410 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7411 extern int atomic_sub_ret(int, atomic_t *);
7412 extern long atomic64_sub_ret(long, atomic64_t *);
7413
7414 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7415 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7416
7417 #define atomic_inc_return(v) atomic_add_ret(1, v)
7418 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7419 +{
7420 + return atomic_add_ret_unchecked(1, v);
7421 +}
7422 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7423 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7424 +{
7425 + return atomic64_add_ret_unchecked(1, v);
7426 +}
7427
7428 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7429 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7430
7431 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7432 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7433 +{
7434 + return atomic_add_ret_unchecked(i, v);
7435 +}
7436 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7437 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7438 +{
7439 + return atomic64_add_ret_unchecked(i, v);
7440 +}
7441
7442 /*
7443 * atomic_inc_and_test - increment and test
7444 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7445 * other cases.
7446 */
7447 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7448 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7449 +{
7450 + return atomic_inc_return_unchecked(v) == 0;
7451 +}
7452 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7453
7454 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7455 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7456 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7457
7458 #define atomic_inc(v) atomic_add(1, v)
7459 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7460 +{
7461 + atomic_add_unchecked(1, v);
7462 +}
7463 #define atomic64_inc(v) atomic64_add(1, v)
7464 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7465 +{
7466 + atomic64_add_unchecked(1, v);
7467 +}
7468
7469 #define atomic_dec(v) atomic_sub(1, v)
7470 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7471 +{
7472 + atomic_sub_unchecked(1, v);
7473 +}
7474 #define atomic64_dec(v) atomic64_sub(1, v)
7475 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7476 +{
7477 + atomic64_sub_unchecked(1, v);
7478 +}
7479
7480 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7481 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7482
7483 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7484 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7485 +{
7486 + return cmpxchg(&v->counter, old, new);
7487 +}
7488 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7489 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7490 +{
7491 + return xchg(&v->counter, new);
7492 +}
7493
7494 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7495 {
7496 - int c, old;
7497 + int c, old, new;
7498 c = atomic_read(v);
7499 for (;;) {
7500 - if (unlikely(c == (u)))
7501 + if (unlikely(c == u))
7502 break;
7503 - old = atomic_cmpxchg((v), c, c + (a));
7504 +
7505 + asm volatile("addcc %2, %0, %0\n"
7506 +
7507 +#ifdef CONFIG_PAX_REFCOUNT
7508 + "tvs %%icc, 6\n"
7509 +#endif
7510 +
7511 + : "=r" (new)
7512 + : "0" (c), "ir" (a)
7513 + : "cc");
7514 +
7515 + old = atomic_cmpxchg(v, c, new);
7516 if (likely(old == c))
7517 break;
7518 c = old;
7519 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7520 #define atomic64_cmpxchg(v, o, n) \
7521 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7522 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7523 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7524 +{
7525 + return xchg(&v->counter, new);
7526 +}
7527
7528 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7529 {
7530 - long c, old;
7531 + long c, old, new;
7532 c = atomic64_read(v);
7533 for (;;) {
7534 - if (unlikely(c == (u)))
7535 + if (unlikely(c == u))
7536 break;
7537 - old = atomic64_cmpxchg((v), c, c + (a));
7538 +
7539 + asm volatile("addcc %2, %0, %0\n"
7540 +
7541 +#ifdef CONFIG_PAX_REFCOUNT
7542 + "tvs %%xcc, 6\n"
7543 +#endif
7544 +
7545 + : "=r" (new)
7546 + : "0" (c), "ir" (a)
7547 + : "cc");
7548 +
7549 + old = atomic64_cmpxchg(v, c, new);
7550 if (likely(old == c))
7551 break;
7552 c = old;
7553 }
7554 - return c != (u);
7555 + return c != u;
7556 }
7557
7558 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7559 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7560 index 5bb6991..5c2132e 100644
7561 --- a/arch/sparc/include/asm/cache.h
7562 +++ b/arch/sparc/include/asm/cache.h
7563 @@ -7,10 +7,12 @@
7564 #ifndef _SPARC_CACHE_H
7565 #define _SPARC_CACHE_H
7566
7567 +#include <linux/const.h>
7568 +
7569 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7570
7571 #define L1_CACHE_SHIFT 5
7572 -#define L1_CACHE_BYTES 32
7573 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7574
7575 #ifdef CONFIG_SPARC32
7576 #define SMP_CACHE_BYTES_SHIFT 5
7577 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7578 index ac74a2c..a9e58af 100644
7579 --- a/arch/sparc/include/asm/elf_32.h
7580 +++ b/arch/sparc/include/asm/elf_32.h
7581 @@ -114,6 +114,13 @@ typedef struct {
7582
7583 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7584
7585 +#ifdef CONFIG_PAX_ASLR
7586 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7587 +
7588 +#define PAX_DELTA_MMAP_LEN 16
7589 +#define PAX_DELTA_STACK_LEN 16
7590 +#endif
7591 +
7592 /* This yields a mask that user programs can use to figure out what
7593 instruction set this cpu supports. This can NOT be done in userspace
7594 on Sparc. */
7595 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7596 index 370ca1e..d4f4a98 100644
7597 --- a/arch/sparc/include/asm/elf_64.h
7598 +++ b/arch/sparc/include/asm/elf_64.h
7599 @@ -189,6 +189,13 @@ typedef struct {
7600 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7601 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7602
7603 +#ifdef CONFIG_PAX_ASLR
7604 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7605 +
7606 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7607 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7608 +#endif
7609 +
7610 extern unsigned long sparc64_elf_hwcap;
7611 #define ELF_HWCAP sparc64_elf_hwcap
7612
7613 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7614 index 9b1c36d..209298b 100644
7615 --- a/arch/sparc/include/asm/pgalloc_32.h
7616 +++ b/arch/sparc/include/asm/pgalloc_32.h
7617 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7618 }
7619
7620 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7621 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7622
7623 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7624 unsigned long address)
7625 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7626 index bcfe063..b333142 100644
7627 --- a/arch/sparc/include/asm/pgalloc_64.h
7628 +++ b/arch/sparc/include/asm/pgalloc_64.h
7629 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7630 }
7631
7632 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7633 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7634
7635 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7636 {
7637 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7638 index 6fc1348..390c50a 100644
7639 --- a/arch/sparc/include/asm/pgtable_32.h
7640 +++ b/arch/sparc/include/asm/pgtable_32.h
7641 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7642 #define PAGE_SHARED SRMMU_PAGE_SHARED
7643 #define PAGE_COPY SRMMU_PAGE_COPY
7644 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7645 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7646 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7647 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7648 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7649
7650 /* Top-level page directory - dummy used by init-mm.
7651 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7652
7653 /* xwr */
7654 #define __P000 PAGE_NONE
7655 -#define __P001 PAGE_READONLY
7656 -#define __P010 PAGE_COPY
7657 -#define __P011 PAGE_COPY
7658 +#define __P001 PAGE_READONLY_NOEXEC
7659 +#define __P010 PAGE_COPY_NOEXEC
7660 +#define __P011 PAGE_COPY_NOEXEC
7661 #define __P100 PAGE_READONLY
7662 #define __P101 PAGE_READONLY
7663 #define __P110 PAGE_COPY
7664 #define __P111 PAGE_COPY
7665
7666 #define __S000 PAGE_NONE
7667 -#define __S001 PAGE_READONLY
7668 -#define __S010 PAGE_SHARED
7669 -#define __S011 PAGE_SHARED
7670 +#define __S001 PAGE_READONLY_NOEXEC
7671 +#define __S010 PAGE_SHARED_NOEXEC
7672 +#define __S011 PAGE_SHARED_NOEXEC
7673 #define __S100 PAGE_READONLY
7674 #define __S101 PAGE_READONLY
7675 #define __S110 PAGE_SHARED
7676 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7677 index 79da178..c2eede8 100644
7678 --- a/arch/sparc/include/asm/pgtsrmmu.h
7679 +++ b/arch/sparc/include/asm/pgtsrmmu.h
7680 @@ -115,6 +115,11 @@
7681 SRMMU_EXEC | SRMMU_REF)
7682 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7683 SRMMU_EXEC | SRMMU_REF)
7684 +
7685 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7686 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7687 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7688 +
7689 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7690 SRMMU_DIRTY | SRMMU_REF)
7691
7692 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7693 index 9689176..63c18ea 100644
7694 --- a/arch/sparc/include/asm/spinlock_64.h
7695 +++ b/arch/sparc/include/asm/spinlock_64.h
7696 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7697
7698 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7699
7700 -static void inline arch_read_lock(arch_rwlock_t *lock)
7701 +static inline void arch_read_lock(arch_rwlock_t *lock)
7702 {
7703 unsigned long tmp1, tmp2;
7704
7705 __asm__ __volatile__ (
7706 "1: ldsw [%2], %0\n"
7707 " brlz,pn %0, 2f\n"
7708 -"4: add %0, 1, %1\n"
7709 +"4: addcc %0, 1, %1\n"
7710 +
7711 +#ifdef CONFIG_PAX_REFCOUNT
7712 +" tvs %%icc, 6\n"
7713 +#endif
7714 +
7715 " cas [%2], %0, %1\n"
7716 " cmp %0, %1\n"
7717 " bne,pn %%icc, 1b\n"
7718 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7719 " .previous"
7720 : "=&r" (tmp1), "=&r" (tmp2)
7721 : "r" (lock)
7722 - : "memory");
7723 + : "memory", "cc");
7724 }
7725
7726 -static int inline arch_read_trylock(arch_rwlock_t *lock)
7727 +static inline int arch_read_trylock(arch_rwlock_t *lock)
7728 {
7729 int tmp1, tmp2;
7730
7731 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7732 "1: ldsw [%2], %0\n"
7733 " brlz,a,pn %0, 2f\n"
7734 " mov 0, %0\n"
7735 -" add %0, 1, %1\n"
7736 +" addcc %0, 1, %1\n"
7737 +
7738 +#ifdef CONFIG_PAX_REFCOUNT
7739 +" tvs %%icc, 6\n"
7740 +#endif
7741 +
7742 " cas [%2], %0, %1\n"
7743 " cmp %0, %1\n"
7744 " bne,pn %%icc, 1b\n"
7745 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7746 return tmp1;
7747 }
7748
7749 -static void inline arch_read_unlock(arch_rwlock_t *lock)
7750 +static inline void arch_read_unlock(arch_rwlock_t *lock)
7751 {
7752 unsigned long tmp1, tmp2;
7753
7754 __asm__ __volatile__(
7755 "1: lduw [%2], %0\n"
7756 -" sub %0, 1, %1\n"
7757 +" subcc %0, 1, %1\n"
7758 +
7759 +#ifdef CONFIG_PAX_REFCOUNT
7760 +" tvs %%icc, 6\n"
7761 +#endif
7762 +
7763 " cas [%2], %0, %1\n"
7764 " cmp %0, %1\n"
7765 " bne,pn %%xcc, 1b\n"
7766 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7767 : "memory");
7768 }
7769
7770 -static void inline arch_write_lock(arch_rwlock_t *lock)
7771 +static inline void arch_write_lock(arch_rwlock_t *lock)
7772 {
7773 unsigned long mask, tmp1, tmp2;
7774
7775 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7776 : "memory");
7777 }
7778
7779 -static void inline arch_write_unlock(arch_rwlock_t *lock)
7780 +static inline void arch_write_unlock(arch_rwlock_t *lock)
7781 {
7782 __asm__ __volatile__(
7783 " stw %%g0, [%0]"
7784 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7785 : "memory");
7786 }
7787
7788 -static int inline arch_write_trylock(arch_rwlock_t *lock)
7789 +static inline int arch_write_trylock(arch_rwlock_t *lock)
7790 {
7791 unsigned long mask, tmp1, tmp2, result;
7792
7793 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7794 index 25849ae..924c54b 100644
7795 --- a/arch/sparc/include/asm/thread_info_32.h
7796 +++ b/arch/sparc/include/asm/thread_info_32.h
7797 @@ -49,6 +49,8 @@ struct thread_info {
7798 unsigned long w_saved;
7799
7800 struct restart_block restart_block;
7801 +
7802 + unsigned long lowest_stack;
7803 };
7804
7805 /*
7806 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7807 index 269bd92..e46a9b8 100644
7808 --- a/arch/sparc/include/asm/thread_info_64.h
7809 +++ b/arch/sparc/include/asm/thread_info_64.h
7810 @@ -63,6 +63,8 @@ struct thread_info {
7811 struct pt_regs *kern_una_regs;
7812 unsigned int kern_una_insn;
7813
7814 + unsigned long lowest_stack;
7815 +
7816 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7817 };
7818
7819 @@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7820 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7821 /* flag bit 6 is available */
7822 #define TIF_32BIT 7 /* 32-bit binary */
7823 -/* flag bit 8 is available */
7824 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7825 #define TIF_SECCOMP 9 /* secure computing */
7826 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7827 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7828 +
7829 /* NOTE: Thread flags >= 12 should be ones we have no interest
7830 * in using in assembly, else we can't use the mask as
7831 * an immediate value in instructions such as andcc.
7832 @@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
7833 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
7834 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7835 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
7836 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7837
7838 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
7839 _TIF_DO_NOTIFY_RESUME_MASK | \
7840 _TIF_NEED_RESCHED)
7841 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
7842
7843 +#define _TIF_WORK_SYSCALL \
7844 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
7845 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7846 +
7847 +
7848 /*
7849 * Thread-synchronous status.
7850 *
7851 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
7852 index 0167d26..9acd8ed 100644
7853 --- a/arch/sparc/include/asm/uaccess.h
7854 +++ b/arch/sparc/include/asm/uaccess.h
7855 @@ -1,5 +1,13 @@
7856 #ifndef ___ASM_SPARC_UACCESS_H
7857 #define ___ASM_SPARC_UACCESS_H
7858 +
7859 +#ifdef __KERNEL__
7860 +#ifndef __ASSEMBLY__
7861 +#include <linux/types.h>
7862 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
7863 +#endif
7864 +#endif
7865 +
7866 #if defined(__sparc__) && defined(__arch64__)
7867 #include <asm/uaccess_64.h>
7868 #else
7869 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
7870 index 53a28dd..50c38c3 100644
7871 --- a/arch/sparc/include/asm/uaccess_32.h
7872 +++ b/arch/sparc/include/asm/uaccess_32.h
7873 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
7874
7875 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7876 {
7877 - if (n && __access_ok((unsigned long) to, n))
7878 + if ((long)n < 0)
7879 + return n;
7880 +
7881 + if (n && __access_ok((unsigned long) to, n)) {
7882 + if (!__builtin_constant_p(n))
7883 + check_object_size(from, n, true);
7884 return __copy_user(to, (__force void __user *) from, n);
7885 - else
7886 + } else
7887 return n;
7888 }
7889
7890 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
7891 {
7892 + if ((long)n < 0)
7893 + return n;
7894 +
7895 + if (!__builtin_constant_p(n))
7896 + check_object_size(from, n, true);
7897 +
7898 return __copy_user(to, (__force void __user *) from, n);
7899 }
7900
7901 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7902 {
7903 - if (n && __access_ok((unsigned long) from, n))
7904 + if ((long)n < 0)
7905 + return n;
7906 +
7907 + if (n && __access_ok((unsigned long) from, n)) {
7908 + if (!__builtin_constant_p(n))
7909 + check_object_size(to, n, false);
7910 return __copy_user((__force void __user *) to, from, n);
7911 - else
7912 + } else
7913 return n;
7914 }
7915
7916 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
7917 {
7918 + if ((long)n < 0)
7919 + return n;
7920 +
7921 return __copy_user((__force void __user *) to, from, n);
7922 }
7923
7924 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
7925 index e562d3c..191f176 100644
7926 --- a/arch/sparc/include/asm/uaccess_64.h
7927 +++ b/arch/sparc/include/asm/uaccess_64.h
7928 @@ -10,6 +10,7 @@
7929 #include <linux/compiler.h>
7930 #include <linux/string.h>
7931 #include <linux/thread_info.h>
7932 +#include <linux/kernel.h>
7933 #include <asm/asi.h>
7934 #include <asm/spitfire.h>
7935 #include <asm-generic/uaccess-unaligned.h>
7936 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
7937 static inline unsigned long __must_check
7938 copy_from_user(void *to, const void __user *from, unsigned long size)
7939 {
7940 - unsigned long ret = ___copy_from_user(to, from, size);
7941 + unsigned long ret;
7942
7943 + if ((long)size < 0 || size > INT_MAX)
7944 + return size;
7945 +
7946 + if (!__builtin_constant_p(size))
7947 + check_object_size(to, size, false);
7948 +
7949 + ret = ___copy_from_user(to, from, size);
7950 if (unlikely(ret))
7951 ret = copy_from_user_fixup(to, from, size);
7952
7953 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
7954 static inline unsigned long __must_check
7955 copy_to_user(void __user *to, const void *from, unsigned long size)
7956 {
7957 - unsigned long ret = ___copy_to_user(to, from, size);
7958 + unsigned long ret;
7959
7960 + if ((long)size < 0 || size > INT_MAX)
7961 + return size;
7962 +
7963 + if (!__builtin_constant_p(size))
7964 + check_object_size(from, size, true);
7965 +
7966 + ret = ___copy_to_user(to, from, size);
7967 if (unlikely(ret))
7968 ret = copy_to_user_fixup(to, from, size);
7969 return ret;
7970 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
7971 index 6cf591b..b49e65a 100644
7972 --- a/arch/sparc/kernel/Makefile
7973 +++ b/arch/sparc/kernel/Makefile
7974 @@ -3,7 +3,7 @@
7975 #
7976
7977 asflags-y := -ansi
7978 -ccflags-y := -Werror
7979 +#ccflags-y := -Werror
7980
7981 extra-y := head_$(BITS).o
7982
7983 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
7984 index be8e862..5b50b12 100644
7985 --- a/arch/sparc/kernel/process_32.c
7986 +++ b/arch/sparc/kernel/process_32.c
7987 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
7988
7989 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
7990 r->psr, r->pc, r->npc, r->y, print_tainted());
7991 - printk("PC: <%pS>\n", (void *) r->pc);
7992 + printk("PC: <%pA>\n", (void *) r->pc);
7993 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7994 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
7995 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
7996 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7997 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
7998 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
7999 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8000 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8001
8002 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8003 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8004 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8005 rw = (struct reg_window32 *) fp;
8006 pc = rw->ins[7];
8007 printk("[%08lx : ", pc);
8008 - printk("%pS ] ", (void *) pc);
8009 + printk("%pA ] ", (void *) pc);
8010 fp = rw->ins[6];
8011 } while (++count < 16);
8012 printk("\n");
8013 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8014 index cdb80b2..5ca141d 100644
8015 --- a/arch/sparc/kernel/process_64.c
8016 +++ b/arch/sparc/kernel/process_64.c
8017 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8018 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8019 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8020 if (regs->tstate & TSTATE_PRIV)
8021 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8022 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8023 }
8024
8025 void show_regs(struct pt_regs *regs)
8026 {
8027 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8028 regs->tpc, regs->tnpc, regs->y, print_tainted());
8029 - printk("TPC: <%pS>\n", (void *) regs->tpc);
8030 + printk("TPC: <%pA>\n", (void *) regs->tpc);
8031 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8032 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8033 regs->u_regs[3]);
8034 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8035 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8036 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8037 regs->u_regs[15]);
8038 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8039 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8040 show_regwindow(regs);
8041 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8042 }
8043 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8044 ((tp && tp->task) ? tp->task->pid : -1));
8045
8046 if (gp->tstate & TSTATE_PRIV) {
8047 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8048 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8049 (void *) gp->tpc,
8050 (void *) gp->o7,
8051 (void *) gp->i7,
8052 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8053 index 7ff45e4..a58f271 100644
8054 --- a/arch/sparc/kernel/ptrace_64.c
8055 +++ b/arch/sparc/kernel/ptrace_64.c
8056 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8057 return ret;
8058 }
8059
8060 +#ifdef CONFIG_GRKERNSEC_SETXID
8061 +extern void gr_delayed_cred_worker(void);
8062 +#endif
8063 +
8064 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8065 {
8066 int ret = 0;
8067 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8068 /* do the secure computing check first */
8069 secure_computing_strict(regs->u_regs[UREG_G1]);
8070
8071 +#ifdef CONFIG_GRKERNSEC_SETXID
8072 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8073 + gr_delayed_cred_worker();
8074 +#endif
8075 +
8076 if (test_thread_flag(TIF_SYSCALL_TRACE))
8077 ret = tracehook_report_syscall_entry(regs);
8078
8079 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8080
8081 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8082 {
8083 +#ifdef CONFIG_GRKERNSEC_SETXID
8084 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8085 + gr_delayed_cred_worker();
8086 +#endif
8087 +
8088 audit_syscall_exit(regs);
8089
8090 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8091 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8092 index 2da0bdc..79128d2 100644
8093 --- a/arch/sparc/kernel/sys_sparc_32.c
8094 +++ b/arch/sparc/kernel/sys_sparc_32.c
8095 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8096 if (len > TASK_SIZE - PAGE_SIZE)
8097 return -ENOMEM;
8098 if (!addr)
8099 - addr = TASK_UNMAPPED_BASE;
8100 + addr = current->mm->mmap_base;
8101
8102 info.flags = 0;
8103 info.length = len;
8104 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8105 index 708bc29..f0129cb 100644
8106 --- a/arch/sparc/kernel/sys_sparc_64.c
8107 +++ b/arch/sparc/kernel/sys_sparc_64.c
8108 @@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8109 struct vm_area_struct * vma;
8110 unsigned long task_size = TASK_SIZE;
8111 int do_color_align;
8112 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8113 struct vm_unmapped_area_info info;
8114
8115 if (flags & MAP_FIXED) {
8116 /* We do not accept a shared mapping if it would violate
8117 * cache aliasing constraints.
8118 */
8119 - if ((flags & MAP_SHARED) &&
8120 + if ((filp || (flags & MAP_SHARED)) &&
8121 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8122 return -EINVAL;
8123 return addr;
8124 @@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8125 if (filp || (flags & MAP_SHARED))
8126 do_color_align = 1;
8127
8128 +#ifdef CONFIG_PAX_RANDMMAP
8129 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8130 +#endif
8131 +
8132 if (addr) {
8133 if (do_color_align)
8134 addr = COLOR_ALIGN(addr, pgoff);
8135 @@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8136 addr = PAGE_ALIGN(addr);
8137
8138 vma = find_vma(mm, addr);
8139 - if (task_size - len >= addr &&
8140 - (!vma || addr + len <= vma->vm_start))
8141 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8142 return addr;
8143 }
8144
8145 info.flags = 0;
8146 info.length = len;
8147 - info.low_limit = TASK_UNMAPPED_BASE;
8148 + info.low_limit = mm->mmap_base;
8149 info.high_limit = min(task_size, VA_EXCLUDE_START);
8150 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8151 info.align_offset = pgoff << PAGE_SHIFT;
8152 @@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8153 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8154 VM_BUG_ON(addr != -ENOMEM);
8155 info.low_limit = VA_EXCLUDE_END;
8156 +
8157 +#ifdef CONFIG_PAX_RANDMMAP
8158 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8159 + info.low_limit += mm->delta_mmap;
8160 +#endif
8161 +
8162 info.high_limit = task_size;
8163 addr = vm_unmapped_area(&info);
8164 }
8165 @@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8166 unsigned long task_size = STACK_TOP32;
8167 unsigned long addr = addr0;
8168 int do_color_align;
8169 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8170 struct vm_unmapped_area_info info;
8171
8172 /* This should only ever run for 32-bit processes. */
8173 @@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8174 /* We do not accept a shared mapping if it would violate
8175 * cache aliasing constraints.
8176 */
8177 - if ((flags & MAP_SHARED) &&
8178 + if ((filp || (flags & MAP_SHARED)) &&
8179 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8180 return -EINVAL;
8181 return addr;
8182 @@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8183 if (filp || (flags & MAP_SHARED))
8184 do_color_align = 1;
8185
8186 +#ifdef CONFIG_PAX_RANDMMAP
8187 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8188 +#endif
8189 +
8190 /* requesting a specific address */
8191 if (addr) {
8192 if (do_color_align)
8193 @@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8194 addr = PAGE_ALIGN(addr);
8195
8196 vma = find_vma(mm, addr);
8197 - if (task_size - len >= addr &&
8198 - (!vma || addr + len <= vma->vm_start))
8199 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8200 return addr;
8201 }
8202
8203 @@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8204 VM_BUG_ON(addr != -ENOMEM);
8205 info.flags = 0;
8206 info.low_limit = TASK_UNMAPPED_BASE;
8207 +
8208 +#ifdef CONFIG_PAX_RANDMMAP
8209 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8210 + info.low_limit += mm->delta_mmap;
8211 +#endif
8212 +
8213 info.high_limit = STACK_TOP32;
8214 addr = vm_unmapped_area(&info);
8215 }
8216 @@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8217 {
8218 unsigned long rnd = 0UL;
8219
8220 +#ifdef CONFIG_PAX_RANDMMAP
8221 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8222 +#endif
8223 +
8224 if (current->flags & PF_RANDOMIZE) {
8225 unsigned long val = get_random_int();
8226 if (test_thread_flag(TIF_32BIT))
8227 @@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8228 gap == RLIM_INFINITY ||
8229 sysctl_legacy_va_layout) {
8230 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8231 +
8232 +#ifdef CONFIG_PAX_RANDMMAP
8233 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8234 + mm->mmap_base += mm->delta_mmap;
8235 +#endif
8236 +
8237 mm->get_unmapped_area = arch_get_unmapped_area;
8238 mm->unmap_area = arch_unmap_area;
8239 } else {
8240 @@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8241 gap = (task_size / 6 * 5);
8242
8243 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8244 +
8245 +#ifdef CONFIG_PAX_RANDMMAP
8246 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8247 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8248 +#endif
8249 +
8250 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8251 mm->unmap_area = arch_unmap_area_topdown;
8252 }
8253 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8254 index e0fed77..604a7e5 100644
8255 --- a/arch/sparc/kernel/syscalls.S
8256 +++ b/arch/sparc/kernel/syscalls.S
8257 @@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8258 #endif
8259 .align 32
8260 1: ldx [%g6 + TI_FLAGS], %l5
8261 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8262 + andcc %l5, _TIF_WORK_SYSCALL, %g0
8263 be,pt %icc, rtrap
8264 nop
8265 call syscall_trace_leave
8266 @@ -190,7 +190,7 @@ linux_sparc_syscall32:
8267
8268 srl %i5, 0, %o5 ! IEU1
8269 srl %i2, 0, %o2 ! IEU0 Group
8270 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8271 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8272 bne,pn %icc, linux_syscall_trace32 ! CTI
8273 mov %i0, %l5 ! IEU1
8274 call %l7 ! CTI Group brk forced
8275 @@ -213,7 +213,7 @@ linux_sparc_syscall:
8276
8277 mov %i3, %o3 ! IEU1
8278 mov %i4, %o4 ! IEU0 Group
8279 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8280 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8281 bne,pn %icc, linux_syscall_trace ! CTI Group
8282 mov %i0, %l5 ! IEU0
8283 2: call %l7 ! CTI Group brk forced
8284 @@ -229,7 +229,7 @@ ret_sys_call:
8285
8286 cmp %o0, -ERESTART_RESTARTBLOCK
8287 bgeu,pn %xcc, 1f
8288 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8289 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8290 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8291
8292 2:
8293 diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8294 index 654e8aa..45f431b 100644
8295 --- a/arch/sparc/kernel/sysfs.c
8296 +++ b/arch/sparc/kernel/sysfs.c
8297 @@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8298 return NOTIFY_OK;
8299 }
8300
8301 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8302 +static struct notifier_block sysfs_cpu_nb = {
8303 .notifier_call = sysfs_cpu_notify,
8304 };
8305
8306 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8307 index a5785ea..405c5f7 100644
8308 --- a/arch/sparc/kernel/traps_32.c
8309 +++ b/arch/sparc/kernel/traps_32.c
8310 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8311 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8312 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8313
8314 +extern void gr_handle_kernel_exploit(void);
8315 +
8316 void die_if_kernel(char *str, struct pt_regs *regs)
8317 {
8318 static int die_counter;
8319 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8320 count++ < 30 &&
8321 (((unsigned long) rw) >= PAGE_OFFSET) &&
8322 !(((unsigned long) rw) & 0x7)) {
8323 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
8324 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
8325 (void *) rw->ins[7]);
8326 rw = (struct reg_window32 *)rw->ins[6];
8327 }
8328 }
8329 printk("Instruction DUMP:");
8330 instruction_dump ((unsigned long *) regs->pc);
8331 - if(regs->psr & PSR_PS)
8332 + if(regs->psr & PSR_PS) {
8333 + gr_handle_kernel_exploit();
8334 do_exit(SIGKILL);
8335 + }
8336 do_exit(SIGSEGV);
8337 }
8338
8339 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8340 index e7ecf15..6520e65 100644
8341 --- a/arch/sparc/kernel/traps_64.c
8342 +++ b/arch/sparc/kernel/traps_64.c
8343 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8344 i + 1,
8345 p->trapstack[i].tstate, p->trapstack[i].tpc,
8346 p->trapstack[i].tnpc, p->trapstack[i].tt);
8347 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8348 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8349 }
8350 }
8351
8352 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8353
8354 lvl -= 0x100;
8355 if (regs->tstate & TSTATE_PRIV) {
8356 +
8357 +#ifdef CONFIG_PAX_REFCOUNT
8358 + if (lvl == 6)
8359 + pax_report_refcount_overflow(regs);
8360 +#endif
8361 +
8362 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8363 die_if_kernel(buffer, regs);
8364 }
8365 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8366 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8367 {
8368 char buffer[32];
8369 -
8370 +
8371 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8372 0, lvl, SIGTRAP) == NOTIFY_STOP)
8373 return;
8374
8375 +#ifdef CONFIG_PAX_REFCOUNT
8376 + if (lvl == 6)
8377 + pax_report_refcount_overflow(regs);
8378 +#endif
8379 +
8380 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8381
8382 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8383 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8384 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8385 printk("%s" "ERROR(%d): ",
8386 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8387 - printk("TPC<%pS>\n", (void *) regs->tpc);
8388 + printk("TPC<%pA>\n", (void *) regs->tpc);
8389 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8390 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8391 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8392 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8393 smp_processor_id(),
8394 (type & 0x1) ? 'I' : 'D',
8395 regs->tpc);
8396 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8397 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8398 panic("Irrecoverable Cheetah+ parity error.");
8399 }
8400
8401 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8402 smp_processor_id(),
8403 (type & 0x1) ? 'I' : 'D',
8404 regs->tpc);
8405 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8406 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8407 }
8408
8409 struct sun4v_error_entry {
8410 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8411
8412 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8413 regs->tpc, tl);
8414 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8415 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8416 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8417 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8418 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8419 (void *) regs->u_regs[UREG_I7]);
8420 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8421 "pte[%lx] error[%lx]\n",
8422 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8423
8424 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8425 regs->tpc, tl);
8426 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8427 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8428 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8429 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8430 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8431 (void *) regs->u_regs[UREG_I7]);
8432 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8433 "pte[%lx] error[%lx]\n",
8434 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8435 fp = (unsigned long)sf->fp + STACK_BIAS;
8436 }
8437
8438 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8439 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8440 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8441 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8442 int index = tsk->curr_ret_stack;
8443 if (tsk->ret_stack && index >= graph) {
8444 pc = tsk->ret_stack[index - graph].ret;
8445 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8446 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8447 graph++;
8448 }
8449 }
8450 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8451 return (struct reg_window *) (fp + STACK_BIAS);
8452 }
8453
8454 +extern void gr_handle_kernel_exploit(void);
8455 +
8456 void die_if_kernel(char *str, struct pt_regs *regs)
8457 {
8458 static int die_counter;
8459 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8460 while (rw &&
8461 count++ < 30 &&
8462 kstack_valid(tp, (unsigned long) rw)) {
8463 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
8464 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
8465 (void *) rw->ins[7]);
8466
8467 rw = kernel_stack_up(rw);
8468 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8469 }
8470 user_instruction_dump ((unsigned int __user *) regs->tpc);
8471 }
8472 - if (regs->tstate & TSTATE_PRIV)
8473 + if (regs->tstate & TSTATE_PRIV) {
8474 + gr_handle_kernel_exploit();
8475 do_exit(SIGKILL);
8476 + }
8477 do_exit(SIGSEGV);
8478 }
8479 EXPORT_SYMBOL(die_if_kernel);
8480 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8481 index 8201c25e..072a2a7 100644
8482 --- a/arch/sparc/kernel/unaligned_64.c
8483 +++ b/arch/sparc/kernel/unaligned_64.c
8484 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8485 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8486
8487 if (__ratelimit(&ratelimit)) {
8488 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
8489 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
8490 regs->tpc, (void *) regs->tpc);
8491 }
8492 }
8493 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8494 index 8410065f2..4fd4ca22 100644
8495 --- a/arch/sparc/lib/Makefile
8496 +++ b/arch/sparc/lib/Makefile
8497 @@ -2,7 +2,7 @@
8498 #
8499
8500 asflags-y := -ansi -DST_DIV0=0x02
8501 -ccflags-y := -Werror
8502 +#ccflags-y := -Werror
8503
8504 lib-$(CONFIG_SPARC32) += ashrdi3.o
8505 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8506 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8507 index 85c233d..68500e0 100644
8508 --- a/arch/sparc/lib/atomic_64.S
8509 +++ b/arch/sparc/lib/atomic_64.S
8510 @@ -17,7 +17,12 @@
8511 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8512 BACKOFF_SETUP(%o2)
8513 1: lduw [%o1], %g1
8514 - add %g1, %o0, %g7
8515 + addcc %g1, %o0, %g7
8516 +
8517 +#ifdef CONFIG_PAX_REFCOUNT
8518 + tvs %icc, 6
8519 +#endif
8520 +
8521 cas [%o1], %g1, %g7
8522 cmp %g1, %g7
8523 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8524 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8525 2: BACKOFF_SPIN(%o2, %o3, 1b)
8526 ENDPROC(atomic_add)
8527
8528 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8529 + BACKOFF_SETUP(%o2)
8530 +1: lduw [%o1], %g1
8531 + add %g1, %o0, %g7
8532 + cas [%o1], %g1, %g7
8533 + cmp %g1, %g7
8534 + bne,pn %icc, 2f
8535 + nop
8536 + retl
8537 + nop
8538 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8539 +ENDPROC(atomic_add_unchecked)
8540 +
8541 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8542 BACKOFF_SETUP(%o2)
8543 1: lduw [%o1], %g1
8544 - sub %g1, %o0, %g7
8545 + subcc %g1, %o0, %g7
8546 +
8547 +#ifdef CONFIG_PAX_REFCOUNT
8548 + tvs %icc, 6
8549 +#endif
8550 +
8551 cas [%o1], %g1, %g7
8552 cmp %g1, %g7
8553 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8554 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8555 2: BACKOFF_SPIN(%o2, %o3, 1b)
8556 ENDPROC(atomic_sub)
8557
8558 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8559 + BACKOFF_SETUP(%o2)
8560 +1: lduw [%o1], %g1
8561 + sub %g1, %o0, %g7
8562 + cas [%o1], %g1, %g7
8563 + cmp %g1, %g7
8564 + bne,pn %icc, 2f
8565 + nop
8566 + retl
8567 + nop
8568 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8569 +ENDPROC(atomic_sub_unchecked)
8570 +
8571 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8572 BACKOFF_SETUP(%o2)
8573 1: lduw [%o1], %g1
8574 - add %g1, %o0, %g7
8575 + addcc %g1, %o0, %g7
8576 +
8577 +#ifdef CONFIG_PAX_REFCOUNT
8578 + tvs %icc, 6
8579 +#endif
8580 +
8581 cas [%o1], %g1, %g7
8582 cmp %g1, %g7
8583 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8584 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8585 2: BACKOFF_SPIN(%o2, %o3, 1b)
8586 ENDPROC(atomic_add_ret)
8587
8588 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8589 + BACKOFF_SETUP(%o2)
8590 +1: lduw [%o1], %g1
8591 + addcc %g1, %o0, %g7
8592 + cas [%o1], %g1, %g7
8593 + cmp %g1, %g7
8594 + bne,pn %icc, 2f
8595 + add %g7, %o0, %g7
8596 + sra %g7, 0, %o0
8597 + retl
8598 + nop
8599 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8600 +ENDPROC(atomic_add_ret_unchecked)
8601 +
8602 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8603 BACKOFF_SETUP(%o2)
8604 1: lduw [%o1], %g1
8605 - sub %g1, %o0, %g7
8606 + subcc %g1, %o0, %g7
8607 +
8608 +#ifdef CONFIG_PAX_REFCOUNT
8609 + tvs %icc, 6
8610 +#endif
8611 +
8612 cas [%o1], %g1, %g7
8613 cmp %g1, %g7
8614 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8615 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8616 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8617 BACKOFF_SETUP(%o2)
8618 1: ldx [%o1], %g1
8619 - add %g1, %o0, %g7
8620 + addcc %g1, %o0, %g7
8621 +
8622 +#ifdef CONFIG_PAX_REFCOUNT
8623 + tvs %xcc, 6
8624 +#endif
8625 +
8626 casx [%o1], %g1, %g7
8627 cmp %g1, %g7
8628 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8629 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8630 2: BACKOFF_SPIN(%o2, %o3, 1b)
8631 ENDPROC(atomic64_add)
8632
8633 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8634 + BACKOFF_SETUP(%o2)
8635 +1: ldx [%o1], %g1
8636 + addcc %g1, %o0, %g7
8637 + casx [%o1], %g1, %g7
8638 + cmp %g1, %g7
8639 + bne,pn %xcc, 2f
8640 + nop
8641 + retl
8642 + nop
8643 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8644 +ENDPROC(atomic64_add_unchecked)
8645 +
8646 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8647 BACKOFF_SETUP(%o2)
8648 1: ldx [%o1], %g1
8649 - sub %g1, %o0, %g7
8650 + subcc %g1, %o0, %g7
8651 +
8652 +#ifdef CONFIG_PAX_REFCOUNT
8653 + tvs %xcc, 6
8654 +#endif
8655 +
8656 casx [%o1], %g1, %g7
8657 cmp %g1, %g7
8658 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8659 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8660 2: BACKOFF_SPIN(%o2, %o3, 1b)
8661 ENDPROC(atomic64_sub)
8662
8663 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8664 + BACKOFF_SETUP(%o2)
8665 +1: ldx [%o1], %g1
8666 + subcc %g1, %o0, %g7
8667 + casx [%o1], %g1, %g7
8668 + cmp %g1, %g7
8669 + bne,pn %xcc, 2f
8670 + nop
8671 + retl
8672 + nop
8673 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8674 +ENDPROC(atomic64_sub_unchecked)
8675 +
8676 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8677 BACKOFF_SETUP(%o2)
8678 1: ldx [%o1], %g1
8679 - add %g1, %o0, %g7
8680 + addcc %g1, %o0, %g7
8681 +
8682 +#ifdef CONFIG_PAX_REFCOUNT
8683 + tvs %xcc, 6
8684 +#endif
8685 +
8686 casx [%o1], %g1, %g7
8687 cmp %g1, %g7
8688 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8689 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8690 2: BACKOFF_SPIN(%o2, %o3, 1b)
8691 ENDPROC(atomic64_add_ret)
8692
8693 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8694 + BACKOFF_SETUP(%o2)
8695 +1: ldx [%o1], %g1
8696 + addcc %g1, %o0, %g7
8697 + casx [%o1], %g1, %g7
8698 + cmp %g1, %g7
8699 + bne,pn %xcc, 2f
8700 + add %g7, %o0, %g7
8701 + mov %g7, %o0
8702 + retl
8703 + nop
8704 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8705 +ENDPROC(atomic64_add_ret_unchecked)
8706 +
8707 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8708 BACKOFF_SETUP(%o2)
8709 1: ldx [%o1], %g1
8710 - sub %g1, %o0, %g7
8711 + subcc %g1, %o0, %g7
8712 +
8713 +#ifdef CONFIG_PAX_REFCOUNT
8714 + tvs %xcc, 6
8715 +#endif
8716 +
8717 casx [%o1], %g1, %g7
8718 cmp %g1, %g7
8719 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8720 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8721 index 0c4e35e..745d3e4 100644
8722 --- a/arch/sparc/lib/ksyms.c
8723 +++ b/arch/sparc/lib/ksyms.c
8724 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8725
8726 /* Atomic counter implementation. */
8727 EXPORT_SYMBOL(atomic_add);
8728 +EXPORT_SYMBOL(atomic_add_unchecked);
8729 EXPORT_SYMBOL(atomic_add_ret);
8730 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
8731 EXPORT_SYMBOL(atomic_sub);
8732 +EXPORT_SYMBOL(atomic_sub_unchecked);
8733 EXPORT_SYMBOL(atomic_sub_ret);
8734 EXPORT_SYMBOL(atomic64_add);
8735 +EXPORT_SYMBOL(atomic64_add_unchecked);
8736 EXPORT_SYMBOL(atomic64_add_ret);
8737 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8738 EXPORT_SYMBOL(atomic64_sub);
8739 +EXPORT_SYMBOL(atomic64_sub_unchecked);
8740 EXPORT_SYMBOL(atomic64_sub_ret);
8741 EXPORT_SYMBOL(atomic64_dec_if_positive);
8742
8743 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8744 index 30c3ecc..736f015 100644
8745 --- a/arch/sparc/mm/Makefile
8746 +++ b/arch/sparc/mm/Makefile
8747 @@ -2,7 +2,7 @@
8748 #
8749
8750 asflags-y := -ansi
8751 -ccflags-y := -Werror
8752 +#ccflags-y := -Werror
8753
8754 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8755 obj-y += fault_$(BITS).o
8756 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8757 index e98bfda..ea8d221 100644
8758 --- a/arch/sparc/mm/fault_32.c
8759 +++ b/arch/sparc/mm/fault_32.c
8760 @@ -21,6 +21,9 @@
8761 #include <linux/perf_event.h>
8762 #include <linux/interrupt.h>
8763 #include <linux/kdebug.h>
8764 +#include <linux/slab.h>
8765 +#include <linux/pagemap.h>
8766 +#include <linux/compiler.h>
8767
8768 #include <asm/page.h>
8769 #include <asm/pgtable.h>
8770 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8771 return safe_compute_effective_address(regs, insn);
8772 }
8773
8774 +#ifdef CONFIG_PAX_PAGEEXEC
8775 +#ifdef CONFIG_PAX_DLRESOLVE
8776 +static void pax_emuplt_close(struct vm_area_struct *vma)
8777 +{
8778 + vma->vm_mm->call_dl_resolve = 0UL;
8779 +}
8780 +
8781 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8782 +{
8783 + unsigned int *kaddr;
8784 +
8785 + vmf->page = alloc_page(GFP_HIGHUSER);
8786 + if (!vmf->page)
8787 + return VM_FAULT_OOM;
8788 +
8789 + kaddr = kmap(vmf->page);
8790 + memset(kaddr, 0, PAGE_SIZE);
8791 + kaddr[0] = 0x9DE3BFA8U; /* save */
8792 + flush_dcache_page(vmf->page);
8793 + kunmap(vmf->page);
8794 + return VM_FAULT_MAJOR;
8795 +}
8796 +
8797 +static const struct vm_operations_struct pax_vm_ops = {
8798 + .close = pax_emuplt_close,
8799 + .fault = pax_emuplt_fault
8800 +};
8801 +
8802 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8803 +{
8804 + int ret;
8805 +
8806 + INIT_LIST_HEAD(&vma->anon_vma_chain);
8807 + vma->vm_mm = current->mm;
8808 + vma->vm_start = addr;
8809 + vma->vm_end = addr + PAGE_SIZE;
8810 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8811 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8812 + vma->vm_ops = &pax_vm_ops;
8813 +
8814 + ret = insert_vm_struct(current->mm, vma);
8815 + if (ret)
8816 + return ret;
8817 +
8818 + ++current->mm->total_vm;
8819 + return 0;
8820 +}
8821 +#endif
8822 +
8823 +/*
8824 + * PaX: decide what to do with offenders (regs->pc = fault address)
8825 + *
8826 + * returns 1 when task should be killed
8827 + * 2 when patched PLT trampoline was detected
8828 + * 3 when unpatched PLT trampoline was detected
8829 + */
8830 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8831 +{
8832 +
8833 +#ifdef CONFIG_PAX_EMUPLT
8834 + int err;
8835 +
8836 + do { /* PaX: patched PLT emulation #1 */
8837 + unsigned int sethi1, sethi2, jmpl;
8838 +
8839 + err = get_user(sethi1, (unsigned int *)regs->pc);
8840 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
8841 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
8842 +
8843 + if (err)
8844 + break;
8845 +
8846 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8847 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
8848 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
8849 + {
8850 + unsigned int addr;
8851 +
8852 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8853 + addr = regs->u_regs[UREG_G1];
8854 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8855 + regs->pc = addr;
8856 + regs->npc = addr+4;
8857 + return 2;
8858 + }
8859 + } while (0);
8860 +
8861 + do { /* PaX: patched PLT emulation #2 */
8862 + unsigned int ba;
8863 +
8864 + err = get_user(ba, (unsigned int *)regs->pc);
8865 +
8866 + if (err)
8867 + break;
8868 +
8869 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8870 + unsigned int addr;
8871 +
8872 + if ((ba & 0xFFC00000U) == 0x30800000U)
8873 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8874 + else
8875 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8876 + regs->pc = addr;
8877 + regs->npc = addr+4;
8878 + return 2;
8879 + }
8880 + } while (0);
8881 +
8882 + do { /* PaX: patched PLT emulation #3 */
8883 + unsigned int sethi, bajmpl, nop;
8884 +
8885 + err = get_user(sethi, (unsigned int *)regs->pc);
8886 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
8887 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
8888 +
8889 + if (err)
8890 + break;
8891 +
8892 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8893 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8894 + nop == 0x01000000U)
8895 + {
8896 + unsigned int addr;
8897 +
8898 + addr = (sethi & 0x003FFFFFU) << 10;
8899 + regs->u_regs[UREG_G1] = addr;
8900 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8901 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8902 + else
8903 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8904 + regs->pc = addr;
8905 + regs->npc = addr+4;
8906 + return 2;
8907 + }
8908 + } while (0);
8909 +
8910 + do { /* PaX: unpatched PLT emulation step 1 */
8911 + unsigned int sethi, ba, nop;
8912 +
8913 + err = get_user(sethi, (unsigned int *)regs->pc);
8914 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
8915 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
8916 +
8917 + if (err)
8918 + break;
8919 +
8920 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8921 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8922 + nop == 0x01000000U)
8923 + {
8924 + unsigned int addr, save, call;
8925 +
8926 + if ((ba & 0xFFC00000U) == 0x30800000U)
8927 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8928 + else
8929 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8930 +
8931 + err = get_user(save, (unsigned int *)addr);
8932 + err |= get_user(call, (unsigned int *)(addr+4));
8933 + err |= get_user(nop, (unsigned int *)(addr+8));
8934 + if (err)
8935 + break;
8936 +
8937 +#ifdef CONFIG_PAX_DLRESOLVE
8938 + if (save == 0x9DE3BFA8U &&
8939 + (call & 0xC0000000U) == 0x40000000U &&
8940 + nop == 0x01000000U)
8941 + {
8942 + struct vm_area_struct *vma;
8943 + unsigned long call_dl_resolve;
8944 +
8945 + down_read(&current->mm->mmap_sem);
8946 + call_dl_resolve = current->mm->call_dl_resolve;
8947 + up_read(&current->mm->mmap_sem);
8948 + if (likely(call_dl_resolve))
8949 + goto emulate;
8950 +
8951 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8952 +
8953 + down_write(&current->mm->mmap_sem);
8954 + if (current->mm->call_dl_resolve) {
8955 + call_dl_resolve = current->mm->call_dl_resolve;
8956 + up_write(&current->mm->mmap_sem);
8957 + if (vma)
8958 + kmem_cache_free(vm_area_cachep, vma);
8959 + goto emulate;
8960 + }
8961 +
8962 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8963 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8964 + up_write(&current->mm->mmap_sem);
8965 + if (vma)
8966 + kmem_cache_free(vm_area_cachep, vma);
8967 + return 1;
8968 + }
8969 +
8970 + if (pax_insert_vma(vma, call_dl_resolve)) {
8971 + up_write(&current->mm->mmap_sem);
8972 + kmem_cache_free(vm_area_cachep, vma);
8973 + return 1;
8974 + }
8975 +
8976 + current->mm->call_dl_resolve = call_dl_resolve;
8977 + up_write(&current->mm->mmap_sem);
8978 +
8979 +emulate:
8980 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8981 + regs->pc = call_dl_resolve;
8982 + regs->npc = addr+4;
8983 + return 3;
8984 + }
8985 +#endif
8986 +
8987 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8988 + if ((save & 0xFFC00000U) == 0x05000000U &&
8989 + (call & 0xFFFFE000U) == 0x85C0A000U &&
8990 + nop == 0x01000000U)
8991 + {
8992 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8993 + regs->u_regs[UREG_G2] = addr + 4;
8994 + addr = (save & 0x003FFFFFU) << 10;
8995 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8996 + regs->pc = addr;
8997 + regs->npc = addr+4;
8998 + return 3;
8999 + }
9000 + }
9001 + } while (0);
9002 +
9003 + do { /* PaX: unpatched PLT emulation step 2 */
9004 + unsigned int save, call, nop;
9005 +
9006 + err = get_user(save, (unsigned int *)(regs->pc-4));
9007 + err |= get_user(call, (unsigned int *)regs->pc);
9008 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
9009 + if (err)
9010 + break;
9011 +
9012 + if (save == 0x9DE3BFA8U &&
9013 + (call & 0xC0000000U) == 0x40000000U &&
9014 + nop == 0x01000000U)
9015 + {
9016 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9017 +
9018 + regs->u_regs[UREG_RETPC] = regs->pc;
9019 + regs->pc = dl_resolve;
9020 + regs->npc = dl_resolve+4;
9021 + return 3;
9022 + }
9023 + } while (0);
9024 +#endif
9025 +
9026 + return 1;
9027 +}
9028 +
9029 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9030 +{
9031 + unsigned long i;
9032 +
9033 + printk(KERN_ERR "PAX: bytes at PC: ");
9034 + for (i = 0; i < 8; i++) {
9035 + unsigned int c;
9036 + if (get_user(c, (unsigned int *)pc+i))
9037 + printk(KERN_CONT "???????? ");
9038 + else
9039 + printk(KERN_CONT "%08x ", c);
9040 + }
9041 + printk("\n");
9042 +}
9043 +#endif
9044 +
9045 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9046 int text_fault)
9047 {
9048 @@ -230,6 +504,24 @@ good_area:
9049 if (!(vma->vm_flags & VM_WRITE))
9050 goto bad_area;
9051 } else {
9052 +
9053 +#ifdef CONFIG_PAX_PAGEEXEC
9054 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9055 + up_read(&mm->mmap_sem);
9056 + switch (pax_handle_fetch_fault(regs)) {
9057 +
9058 +#ifdef CONFIG_PAX_EMUPLT
9059 + case 2:
9060 + case 3:
9061 + return;
9062 +#endif
9063 +
9064 + }
9065 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9066 + do_group_exit(SIGKILL);
9067 + }
9068 +#endif
9069 +
9070 /* Allow reads even for write-only mappings */
9071 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9072 goto bad_area;
9073 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9074 index 097aee7..5ca6697 100644
9075 --- a/arch/sparc/mm/fault_64.c
9076 +++ b/arch/sparc/mm/fault_64.c
9077 @@ -21,6 +21,9 @@
9078 #include <linux/kprobes.h>
9079 #include <linux/kdebug.h>
9080 #include <linux/percpu.h>
9081 +#include <linux/slab.h>
9082 +#include <linux/pagemap.h>
9083 +#include <linux/compiler.h>
9084
9085 #include <asm/page.h>
9086 #include <asm/pgtable.h>
9087 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9088 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9089 regs->tpc);
9090 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9091 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9092 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9093 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9094 dump_stack();
9095 unhandled_fault(regs->tpc, current, regs);
9096 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9097 show_regs(regs);
9098 }
9099
9100 +#ifdef CONFIG_PAX_PAGEEXEC
9101 +#ifdef CONFIG_PAX_DLRESOLVE
9102 +static void pax_emuplt_close(struct vm_area_struct *vma)
9103 +{
9104 + vma->vm_mm->call_dl_resolve = 0UL;
9105 +}
9106 +
9107 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9108 +{
9109 + unsigned int *kaddr;
9110 +
9111 + vmf->page = alloc_page(GFP_HIGHUSER);
9112 + if (!vmf->page)
9113 + return VM_FAULT_OOM;
9114 +
9115 + kaddr = kmap(vmf->page);
9116 + memset(kaddr, 0, PAGE_SIZE);
9117 + kaddr[0] = 0x9DE3BFA8U; /* save */
9118 + flush_dcache_page(vmf->page);
9119 + kunmap(vmf->page);
9120 + return VM_FAULT_MAJOR;
9121 +}
9122 +
9123 +static const struct vm_operations_struct pax_vm_ops = {
9124 + .close = pax_emuplt_close,
9125 + .fault = pax_emuplt_fault
9126 +};
9127 +
9128 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9129 +{
9130 + int ret;
9131 +
9132 + INIT_LIST_HEAD(&vma->anon_vma_chain);
9133 + vma->vm_mm = current->mm;
9134 + vma->vm_start = addr;
9135 + vma->vm_end = addr + PAGE_SIZE;
9136 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9137 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9138 + vma->vm_ops = &pax_vm_ops;
9139 +
9140 + ret = insert_vm_struct(current->mm, vma);
9141 + if (ret)
9142 + return ret;
9143 +
9144 + ++current->mm->total_vm;
9145 + return 0;
9146 +}
9147 +#endif
9148 +
9149 +/*
9150 + * PaX: decide what to do with offenders (regs->tpc = fault address)
9151 + *
9152 + * returns 1 when task should be killed
9153 + * 2 when patched PLT trampoline was detected
9154 + * 3 when unpatched PLT trampoline was detected
9155 + */
9156 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9157 +{
9158 +
9159 +#ifdef CONFIG_PAX_EMUPLT
9160 + int err;
9161 +
9162 + do { /* PaX: patched PLT emulation #1 */
9163 + unsigned int sethi1, sethi2, jmpl;
9164 +
9165 + err = get_user(sethi1, (unsigned int *)regs->tpc);
9166 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9167 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9168 +
9169 + if (err)
9170 + break;
9171 +
9172 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9173 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
9174 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
9175 + {
9176 + unsigned long addr;
9177 +
9178 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9179 + addr = regs->u_regs[UREG_G1];
9180 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9181 +
9182 + if (test_thread_flag(TIF_32BIT))
9183 + addr &= 0xFFFFFFFFUL;
9184 +
9185 + regs->tpc = addr;
9186 + regs->tnpc = addr+4;
9187 + return 2;
9188 + }
9189 + } while (0);
9190 +
9191 + do { /* PaX: patched PLT emulation #2 */
9192 + unsigned int ba;
9193 +
9194 + err = get_user(ba, (unsigned int *)regs->tpc);
9195 +
9196 + if (err)
9197 + break;
9198 +
9199 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9200 + unsigned long addr;
9201 +
9202 + if ((ba & 0xFFC00000U) == 0x30800000U)
9203 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9204 + else
9205 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9206 +
9207 + if (test_thread_flag(TIF_32BIT))
9208 + addr &= 0xFFFFFFFFUL;
9209 +
9210 + regs->tpc = addr;
9211 + regs->tnpc = addr+4;
9212 + return 2;
9213 + }
9214 + } while (0);
9215 +
9216 + do { /* PaX: patched PLT emulation #3 */
9217 + unsigned int sethi, bajmpl, nop;
9218 +
9219 + err = get_user(sethi, (unsigned int *)regs->tpc);
9220 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9221 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9222 +
9223 + if (err)
9224 + break;
9225 +
9226 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9227 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9228 + nop == 0x01000000U)
9229 + {
9230 + unsigned long addr;
9231 +
9232 + addr = (sethi & 0x003FFFFFU) << 10;
9233 + regs->u_regs[UREG_G1] = addr;
9234 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9235 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9236 + else
9237 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9238 +
9239 + if (test_thread_flag(TIF_32BIT))
9240 + addr &= 0xFFFFFFFFUL;
9241 +
9242 + regs->tpc = addr;
9243 + regs->tnpc = addr+4;
9244 + return 2;
9245 + }
9246 + } while (0);
9247 +
9248 + do { /* PaX: patched PLT emulation #4 */
9249 + unsigned int sethi, mov1, call, mov2;
9250 +
9251 + err = get_user(sethi, (unsigned int *)regs->tpc);
9252 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9253 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
9254 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9255 +
9256 + if (err)
9257 + break;
9258 +
9259 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9260 + mov1 == 0x8210000FU &&
9261 + (call & 0xC0000000U) == 0x40000000U &&
9262 + mov2 == 0x9E100001U)
9263 + {
9264 + unsigned long addr;
9265 +
9266 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9267 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9268 +
9269 + if (test_thread_flag(TIF_32BIT))
9270 + addr &= 0xFFFFFFFFUL;
9271 +
9272 + regs->tpc = addr;
9273 + regs->tnpc = addr+4;
9274 + return 2;
9275 + }
9276 + } while (0);
9277 +
9278 + do { /* PaX: patched PLT emulation #5 */
9279 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9280 +
9281 + err = get_user(sethi, (unsigned int *)regs->tpc);
9282 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9283 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9284 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9285 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9286 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9287 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9288 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9289 +
9290 + if (err)
9291 + break;
9292 +
9293 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9294 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9295 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9296 + (or1 & 0xFFFFE000U) == 0x82106000U &&
9297 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9298 + sllx == 0x83287020U &&
9299 + jmpl == 0x81C04005U &&
9300 + nop == 0x01000000U)
9301 + {
9302 + unsigned long addr;
9303 +
9304 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9305 + regs->u_regs[UREG_G1] <<= 32;
9306 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9307 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9308 + regs->tpc = addr;
9309 + regs->tnpc = addr+4;
9310 + return 2;
9311 + }
9312 + } while (0);
9313 +
9314 + do { /* PaX: patched PLT emulation #6 */
9315 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9316 +
9317 + err = get_user(sethi, (unsigned int *)regs->tpc);
9318 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9319 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9320 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9321 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
9322 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9323 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9324 +
9325 + if (err)
9326 + break;
9327 +
9328 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9329 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9330 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9331 + sllx == 0x83287020U &&
9332 + (or & 0xFFFFE000U) == 0x8A116000U &&
9333 + jmpl == 0x81C04005U &&
9334 + nop == 0x01000000U)
9335 + {
9336 + unsigned long addr;
9337 +
9338 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9339 + regs->u_regs[UREG_G1] <<= 32;
9340 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9341 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9342 + regs->tpc = addr;
9343 + regs->tnpc = addr+4;
9344 + return 2;
9345 + }
9346 + } while (0);
9347 +
9348 + do { /* PaX: unpatched PLT emulation step 1 */
9349 + unsigned int sethi, ba, nop;
9350 +
9351 + err = get_user(sethi, (unsigned int *)regs->tpc);
9352 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9353 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9354 +
9355 + if (err)
9356 + break;
9357 +
9358 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9359 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9360 + nop == 0x01000000U)
9361 + {
9362 + unsigned long addr;
9363 + unsigned int save, call;
9364 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9365 +
9366 + if ((ba & 0xFFC00000U) == 0x30800000U)
9367 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9368 + else
9369 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9370 +
9371 + if (test_thread_flag(TIF_32BIT))
9372 + addr &= 0xFFFFFFFFUL;
9373 +
9374 + err = get_user(save, (unsigned int *)addr);
9375 + err |= get_user(call, (unsigned int *)(addr+4));
9376 + err |= get_user(nop, (unsigned int *)(addr+8));
9377 + if (err)
9378 + break;
9379 +
9380 +#ifdef CONFIG_PAX_DLRESOLVE
9381 + if (save == 0x9DE3BFA8U &&
9382 + (call & 0xC0000000U) == 0x40000000U &&
9383 + nop == 0x01000000U)
9384 + {
9385 + struct vm_area_struct *vma;
9386 + unsigned long call_dl_resolve;
9387 +
9388 + down_read(&current->mm->mmap_sem);
9389 + call_dl_resolve = current->mm->call_dl_resolve;
9390 + up_read(&current->mm->mmap_sem);
9391 + if (likely(call_dl_resolve))
9392 + goto emulate;
9393 +
9394 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9395 +
9396 + down_write(&current->mm->mmap_sem);
9397 + if (current->mm->call_dl_resolve) {
9398 + call_dl_resolve = current->mm->call_dl_resolve;
9399 + up_write(&current->mm->mmap_sem);
9400 + if (vma)
9401 + kmem_cache_free(vm_area_cachep, vma);
9402 + goto emulate;
9403 + }
9404 +
9405 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9406 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9407 + up_write(&current->mm->mmap_sem);
9408 + if (vma)
9409 + kmem_cache_free(vm_area_cachep, vma);
9410 + return 1;
9411 + }
9412 +
9413 + if (pax_insert_vma(vma, call_dl_resolve)) {
9414 + up_write(&current->mm->mmap_sem);
9415 + kmem_cache_free(vm_area_cachep, vma);
9416 + return 1;
9417 + }
9418 +
9419 + current->mm->call_dl_resolve = call_dl_resolve;
9420 + up_write(&current->mm->mmap_sem);
9421 +
9422 +emulate:
9423 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9424 + regs->tpc = call_dl_resolve;
9425 + regs->tnpc = addr+4;
9426 + return 3;
9427 + }
9428 +#endif
9429 +
9430 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9431 + if ((save & 0xFFC00000U) == 0x05000000U &&
9432 + (call & 0xFFFFE000U) == 0x85C0A000U &&
9433 + nop == 0x01000000U)
9434 + {
9435 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9436 + regs->u_regs[UREG_G2] = addr + 4;
9437 + addr = (save & 0x003FFFFFU) << 10;
9438 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9439 +
9440 + if (test_thread_flag(TIF_32BIT))
9441 + addr &= 0xFFFFFFFFUL;
9442 +
9443 + regs->tpc = addr;
9444 + regs->tnpc = addr+4;
9445 + return 3;
9446 + }
9447 +
9448 + /* PaX: 64-bit PLT stub */
9449 + err = get_user(sethi1, (unsigned int *)addr);
9450 + err |= get_user(sethi2, (unsigned int *)(addr+4));
9451 + err |= get_user(or1, (unsigned int *)(addr+8));
9452 + err |= get_user(or2, (unsigned int *)(addr+12));
9453 + err |= get_user(sllx, (unsigned int *)(addr+16));
9454 + err |= get_user(add, (unsigned int *)(addr+20));
9455 + err |= get_user(jmpl, (unsigned int *)(addr+24));
9456 + err |= get_user(nop, (unsigned int *)(addr+28));
9457 + if (err)
9458 + break;
9459 +
9460 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9461 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9462 + (or1 & 0xFFFFE000U) == 0x88112000U &&
9463 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9464 + sllx == 0x89293020U &&
9465 + add == 0x8A010005U &&
9466 + jmpl == 0x89C14000U &&
9467 + nop == 0x01000000U)
9468 + {
9469 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9470 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9471 + regs->u_regs[UREG_G4] <<= 32;
9472 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9473 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9474 + regs->u_regs[UREG_G4] = addr + 24;
9475 + addr = regs->u_regs[UREG_G5];
9476 + regs->tpc = addr;
9477 + regs->tnpc = addr+4;
9478 + return 3;
9479 + }
9480 + }
9481 + } while (0);
9482 +
9483 +#ifdef CONFIG_PAX_DLRESOLVE
9484 + do { /* PaX: unpatched PLT emulation step 2 */
9485 + unsigned int save, call, nop;
9486 +
9487 + err = get_user(save, (unsigned int *)(regs->tpc-4));
9488 + err |= get_user(call, (unsigned int *)regs->tpc);
9489 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9490 + if (err)
9491 + break;
9492 +
9493 + if (save == 0x9DE3BFA8U &&
9494 + (call & 0xC0000000U) == 0x40000000U &&
9495 + nop == 0x01000000U)
9496 + {
9497 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9498 +
9499 + if (test_thread_flag(TIF_32BIT))
9500 + dl_resolve &= 0xFFFFFFFFUL;
9501 +
9502 + regs->u_regs[UREG_RETPC] = regs->tpc;
9503 + regs->tpc = dl_resolve;
9504 + regs->tnpc = dl_resolve+4;
9505 + return 3;
9506 + }
9507 + } while (0);
9508 +#endif
9509 +
9510 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9511 + unsigned int sethi, ba, nop;
9512 +
9513 + err = get_user(sethi, (unsigned int *)regs->tpc);
9514 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9515 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9516 +
9517 + if (err)
9518 + break;
9519 +
9520 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9521 + (ba & 0xFFF00000U) == 0x30600000U &&
9522 + nop == 0x01000000U)
9523 + {
9524 + unsigned long addr;
9525 +
9526 + addr = (sethi & 0x003FFFFFU) << 10;
9527 + regs->u_regs[UREG_G1] = addr;
9528 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9529 +
9530 + if (test_thread_flag(TIF_32BIT))
9531 + addr &= 0xFFFFFFFFUL;
9532 +
9533 + regs->tpc = addr;
9534 + regs->tnpc = addr+4;
9535 + return 2;
9536 + }
9537 + } while (0);
9538 +
9539 +#endif
9540 +
9541 + return 1;
9542 +}
9543 +
9544 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9545 +{
9546 + unsigned long i;
9547 +
9548 + printk(KERN_ERR "PAX: bytes at PC: ");
9549 + for (i = 0; i < 8; i++) {
9550 + unsigned int c;
9551 + if (get_user(c, (unsigned int *)pc+i))
9552 + printk(KERN_CONT "???????? ");
9553 + else
9554 + printk(KERN_CONT "%08x ", c);
9555 + }
9556 + printk("\n");
9557 +}
9558 +#endif
9559 +
9560 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9561 {
9562 struct mm_struct *mm = current->mm;
9563 @@ -341,6 +804,29 @@ retry:
9564 if (!vma)
9565 goto bad_area;
9566
9567 +#ifdef CONFIG_PAX_PAGEEXEC
9568 + /* PaX: detect ITLB misses on non-exec pages */
9569 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9570 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9571 + {
9572 + if (address != regs->tpc)
9573 + goto good_area;
9574 +
9575 + up_read(&mm->mmap_sem);
9576 + switch (pax_handle_fetch_fault(regs)) {
9577 +
9578 +#ifdef CONFIG_PAX_EMUPLT
9579 + case 2:
9580 + case 3:
9581 + return;
9582 +#endif
9583 +
9584 + }
9585 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9586 + do_group_exit(SIGKILL);
9587 + }
9588 +#endif
9589 +
9590 /* Pure DTLB misses do not tell us whether the fault causing
9591 * load/store/atomic was a write or not, it only says that there
9592 * was no match. So in such a case we (carefully) read the
9593 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9594 index d2b5944..bd813f2 100644
9595 --- a/arch/sparc/mm/hugetlbpage.c
9596 +++ b/arch/sparc/mm/hugetlbpage.c
9597 @@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9598
9599 info.flags = 0;
9600 info.length = len;
9601 - info.low_limit = TASK_UNMAPPED_BASE;
9602 + info.low_limit = mm->mmap_base;
9603 info.high_limit = min(task_size, VA_EXCLUDE_START);
9604 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9605 info.align_offset = 0;
9606 @@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9607 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9608 VM_BUG_ON(addr != -ENOMEM);
9609 info.low_limit = VA_EXCLUDE_END;
9610 +
9611 +#ifdef CONFIG_PAX_RANDMMAP
9612 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9613 + info.low_limit += mm->delta_mmap;
9614 +#endif
9615 +
9616 info.high_limit = task_size;
9617 addr = vm_unmapped_area(&info);
9618 }
9619 @@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9620 VM_BUG_ON(addr != -ENOMEM);
9621 info.flags = 0;
9622 info.low_limit = TASK_UNMAPPED_BASE;
9623 +
9624 +#ifdef CONFIG_PAX_RANDMMAP
9625 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9626 + info.low_limit += mm->delta_mmap;
9627 +#endif
9628 +
9629 info.high_limit = STACK_TOP32;
9630 addr = vm_unmapped_area(&info);
9631 }
9632 @@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9633 struct mm_struct *mm = current->mm;
9634 struct vm_area_struct *vma;
9635 unsigned long task_size = TASK_SIZE;
9636 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9637
9638 if (test_thread_flag(TIF_32BIT))
9639 task_size = STACK_TOP32;
9640 @@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9641 return addr;
9642 }
9643
9644 +#ifdef CONFIG_PAX_RANDMMAP
9645 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9646 +#endif
9647 +
9648 if (addr) {
9649 addr = ALIGN(addr, HPAGE_SIZE);
9650 vma = find_vma(mm, addr);
9651 - if (task_size - len >= addr &&
9652 - (!vma || addr + len <= vma->vm_start))
9653 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9654 return addr;
9655 }
9656 if (mm->get_unmapped_area == arch_get_unmapped_area)
9657 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9658 index f4500c6..889656c 100644
9659 --- a/arch/tile/include/asm/atomic_64.h
9660 +++ b/arch/tile/include/asm/atomic_64.h
9661 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9662
9663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9664
9665 +#define atomic64_read_unchecked(v) atomic64_read(v)
9666 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9667 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9668 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9669 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9670 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9671 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9672 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9673 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9674 +
9675 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9676 #define smp_mb__before_atomic_dec() smp_mb()
9677 #define smp_mb__after_atomic_dec() smp_mb()
9678 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9679 index a9a5299..0fce79e 100644
9680 --- a/arch/tile/include/asm/cache.h
9681 +++ b/arch/tile/include/asm/cache.h
9682 @@ -15,11 +15,12 @@
9683 #ifndef _ASM_TILE_CACHE_H
9684 #define _ASM_TILE_CACHE_H
9685
9686 +#include <linux/const.h>
9687 #include <arch/chip.h>
9688
9689 /* bytes per L1 data cache line */
9690 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9691 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9692 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9693
9694 /* bytes per L2 cache line */
9695 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9696 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9697 index 9ab078a..d6635c2 100644
9698 --- a/arch/tile/include/asm/uaccess.h
9699 +++ b/arch/tile/include/asm/uaccess.h
9700 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9701 const void __user *from,
9702 unsigned long n)
9703 {
9704 - int sz = __compiletime_object_size(to);
9705 + size_t sz = __compiletime_object_size(to);
9706
9707 - if (likely(sz == -1 || sz >= n))
9708 + if (likely(sz == (size_t)-1 || sz >= n))
9709 n = _copy_from_user(to, from, n);
9710 else
9711 copy_from_user_overflow();
9712 diff --git a/arch/um/Makefile b/arch/um/Makefile
9713 index 133f7de..1d6f2f1 100644
9714 --- a/arch/um/Makefile
9715 +++ b/arch/um/Makefile
9716 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9717 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9718 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9719
9720 +ifdef CONSTIFY_PLUGIN
9721 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9722 +endif
9723 +
9724 #This will adjust *FLAGS accordingly to the platform.
9725 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9726
9727 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9728 index 19e1bdd..3665b77 100644
9729 --- a/arch/um/include/asm/cache.h
9730 +++ b/arch/um/include/asm/cache.h
9731 @@ -1,6 +1,7 @@
9732 #ifndef __UM_CACHE_H
9733 #define __UM_CACHE_H
9734
9735 +#include <linux/const.h>
9736
9737 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9738 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9739 @@ -12,6 +13,6 @@
9740 # define L1_CACHE_SHIFT 5
9741 #endif
9742
9743 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9744 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9745
9746 #endif
9747 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9748 index 2e0a6b1..a64d0f5 100644
9749 --- a/arch/um/include/asm/kmap_types.h
9750 +++ b/arch/um/include/asm/kmap_types.h
9751 @@ -8,6 +8,6 @@
9752
9753 /* No more #include "asm/arch/kmap_types.h" ! */
9754
9755 -#define KM_TYPE_NR 14
9756 +#define KM_TYPE_NR 15
9757
9758 #endif
9759 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9760 index 5ff53d9..5850cdf 100644
9761 --- a/arch/um/include/asm/page.h
9762 +++ b/arch/um/include/asm/page.h
9763 @@ -14,6 +14,9 @@
9764 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9765 #define PAGE_MASK (~(PAGE_SIZE-1))
9766
9767 +#define ktla_ktva(addr) (addr)
9768 +#define ktva_ktla(addr) (addr)
9769 +
9770 #ifndef __ASSEMBLY__
9771
9772 struct page;
9773 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9774 index 0032f92..cd151e0 100644
9775 --- a/arch/um/include/asm/pgtable-3level.h
9776 +++ b/arch/um/include/asm/pgtable-3level.h
9777 @@ -58,6 +58,7 @@
9778 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9779 #define pud_populate(mm, pud, pmd) \
9780 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9781 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9782
9783 #ifdef CONFIG_64BIT
9784 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9785 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9786 index b462b13..e7a19aa 100644
9787 --- a/arch/um/kernel/process.c
9788 +++ b/arch/um/kernel/process.c
9789 @@ -386,22 +386,6 @@ int singlestepping(void * t)
9790 return 2;
9791 }
9792
9793 -/*
9794 - * Only x86 and x86_64 have an arch_align_stack().
9795 - * All other arches have "#define arch_align_stack(x) (x)"
9796 - * in their asm/system.h
9797 - * As this is included in UML from asm-um/system-generic.h,
9798 - * we can use it to behave as the subarch does.
9799 - */
9800 -#ifndef arch_align_stack
9801 -unsigned long arch_align_stack(unsigned long sp)
9802 -{
9803 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9804 - sp -= get_random_int() % 8192;
9805 - return sp & ~0xf;
9806 -}
9807 -#endif
9808 -
9809 unsigned long get_wchan(struct task_struct *p)
9810 {
9811 unsigned long stack_page, sp, ip;
9812 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9813 index ad8f795..2c7eec6 100644
9814 --- a/arch/unicore32/include/asm/cache.h
9815 +++ b/arch/unicore32/include/asm/cache.h
9816 @@ -12,8 +12,10 @@
9817 #ifndef __UNICORE_CACHE_H__
9818 #define __UNICORE_CACHE_H__
9819
9820 -#define L1_CACHE_SHIFT (5)
9821 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9822 +#include <linux/const.h>
9823 +
9824 +#define L1_CACHE_SHIFT 5
9825 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9826
9827 /*
9828 * Memory returned by kmalloc() may be used for DMA, so we must make
9829 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9830 index 225543b..f12405b 100644
9831 --- a/arch/x86/Kconfig
9832 +++ b/arch/x86/Kconfig
9833 @@ -238,7 +238,7 @@ config X86_HT
9834
9835 config X86_32_LAZY_GS
9836 def_bool y
9837 - depends on X86_32 && !CC_STACKPROTECTOR
9838 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
9839
9840 config ARCH_HWEIGHT_CFLAGS
9841 string
9842 @@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
9843
9844 config X86_MSR
9845 tristate "/dev/cpu/*/msr - Model-specific register support"
9846 + depends on !GRKERNSEC_KMEM
9847 ---help---
9848 This device gives privileged processes access to the x86
9849 Model-Specific Registers (MSRs). It is a character device with
9850 @@ -1054,7 +1055,7 @@ choice
9851
9852 config NOHIGHMEM
9853 bool "off"
9854 - depends on !X86_NUMAQ
9855 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9856 ---help---
9857 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
9858 However, the address space of 32-bit x86 processors is only 4
9859 @@ -1091,7 +1092,7 @@ config NOHIGHMEM
9860
9861 config HIGHMEM4G
9862 bool "4GB"
9863 - depends on !X86_NUMAQ
9864 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9865 ---help---
9866 Select this if you have a 32-bit processor and between 1 and 4
9867 gigabytes of physical RAM.
9868 @@ -1145,7 +1146,7 @@ config PAGE_OFFSET
9869 hex
9870 default 0xB0000000 if VMSPLIT_3G_OPT
9871 default 0x80000000 if VMSPLIT_2G
9872 - default 0x78000000 if VMSPLIT_2G_OPT
9873 + default 0x70000000 if VMSPLIT_2G_OPT
9874 default 0x40000000 if VMSPLIT_1G
9875 default 0xC0000000
9876 depends on X86_32
9877 @@ -1546,6 +1547,7 @@ config SECCOMP
9878
9879 config CC_STACKPROTECTOR
9880 bool "Enable -fstack-protector buffer overflow detection"
9881 + depends on X86_64 || !PAX_MEMORY_UDEREF
9882 ---help---
9883 This option turns on the -fstack-protector GCC feature. This
9884 feature puts, at the beginning of functions, a canary value on
9885 @@ -1603,6 +1605,7 @@ config KEXEC_JUMP
9886 config PHYSICAL_START
9887 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
9888 default "0x1000000"
9889 + range 0x400000 0x40000000
9890 ---help---
9891 This gives the physical address where the kernel is loaded.
9892
9893 @@ -1666,6 +1669,7 @@ config X86_NEED_RELOCS
9894 config PHYSICAL_ALIGN
9895 hex "Alignment value to which kernel should be aligned" if X86_32
9896 default "0x1000000"
9897 + range 0x400000 0x1000000 if PAX_KERNEXEC
9898 range 0x2000 0x1000000
9899 ---help---
9900 This value puts the alignment restrictions on physical address
9901 @@ -1741,9 +1745,10 @@ config DEBUG_HOTPLUG_CPU0
9902 If unsure, say N.
9903
9904 config COMPAT_VDSO
9905 - def_bool y
9906 + def_bool n
9907 prompt "Compat VDSO support"
9908 depends on X86_32 || IA32_EMULATION
9909 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
9910 ---help---
9911 Map the 32-bit VDSO to the predictable old-style address too.
9912
9913 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
9914 index c026cca..14657ae 100644
9915 --- a/arch/x86/Kconfig.cpu
9916 +++ b/arch/x86/Kconfig.cpu
9917 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
9918
9919 config X86_F00F_BUG
9920 def_bool y
9921 - depends on M586MMX || M586TSC || M586 || M486
9922 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
9923
9924 config X86_INVD_BUG
9925 def_bool y
9926 @@ -327,7 +327,7 @@ config X86_INVD_BUG
9927
9928 config X86_ALIGNMENT_16
9929 def_bool y
9930 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9931 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9932
9933 config X86_INTEL_USERCOPY
9934 def_bool y
9935 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
9936 # generates cmov.
9937 config X86_CMOV
9938 def_bool y
9939 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9940 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9941
9942 config X86_MINIMUM_CPU_FAMILY
9943 int
9944 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
9945 index b322f12..652d0d9 100644
9946 --- a/arch/x86/Kconfig.debug
9947 +++ b/arch/x86/Kconfig.debug
9948 @@ -84,7 +84,7 @@ config X86_PTDUMP
9949 config DEBUG_RODATA
9950 bool "Write protect kernel read-only data structures"
9951 default y
9952 - depends on DEBUG_KERNEL
9953 + depends on DEBUG_KERNEL && BROKEN
9954 ---help---
9955 Mark the kernel read-only data as write-protected in the pagetables,
9956 in order to catch accidental (and incorrect) writes to such const
9957 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
9958
9959 config DEBUG_SET_MODULE_RONX
9960 bool "Set loadable kernel module data as NX and text as RO"
9961 - depends on MODULES
9962 + depends on MODULES && BROKEN
9963 ---help---
9964 This option helps catch unintended modifications to loadable
9965 kernel module's text and read-only data. It also prevents execution
9966 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
9967
9968 config DEBUG_STRICT_USER_COPY_CHECKS
9969 bool "Strict copy size checks"
9970 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
9971 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
9972 ---help---
9973 Enabling this option turns a certain set of sanity checks for user
9974 copy operations into compile time failures.
9975 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
9976 index e71fc42..7829607 100644
9977 --- a/arch/x86/Makefile
9978 +++ b/arch/x86/Makefile
9979 @@ -50,6 +50,7 @@ else
9980 UTS_MACHINE := x86_64
9981 CHECKFLAGS += -D__x86_64__ -m64
9982
9983 + biarch := $(call cc-option,-m64)
9984 KBUILD_AFLAGS += -m64
9985 KBUILD_CFLAGS += -m64
9986
9987 @@ -230,3 +231,12 @@ define archhelp
9988 echo ' FDARGS="..." arguments for the booted kernel'
9989 echo ' FDINITRD=file initrd for the booted kernel'
9990 endef
9991 +
9992 +define OLD_LD
9993 +
9994 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
9995 +*** Please upgrade your binutils to 2.18 or newer
9996 +endef
9997 +
9998 +archprepare:
9999 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10000 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10001 index 379814b..add62ce 100644
10002 --- a/arch/x86/boot/Makefile
10003 +++ b/arch/x86/boot/Makefile
10004 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10005 $(call cc-option, -fno-stack-protector) \
10006 $(call cc-option, -mpreferred-stack-boundary=2)
10007 KBUILD_CFLAGS += $(call cc-option, -m32)
10008 +ifdef CONSTIFY_PLUGIN
10009 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10010 +endif
10011 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10012 GCOV_PROFILE := n
10013
10014 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10015 index 878e4b9..20537ab 100644
10016 --- a/arch/x86/boot/bitops.h
10017 +++ b/arch/x86/boot/bitops.h
10018 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10019 u8 v;
10020 const u32 *p = (const u32 *)addr;
10021
10022 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10023 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10024 return v;
10025 }
10026
10027 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10028
10029 static inline void set_bit(int nr, void *addr)
10030 {
10031 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10032 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10033 }
10034
10035 #endif /* BOOT_BITOPS_H */
10036 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10037 index 18997e5..83d9c67 100644
10038 --- a/arch/x86/boot/boot.h
10039 +++ b/arch/x86/boot/boot.h
10040 @@ -85,7 +85,7 @@ static inline void io_delay(void)
10041 static inline u16 ds(void)
10042 {
10043 u16 seg;
10044 - asm("movw %%ds,%0" : "=rm" (seg));
10045 + asm volatile("movw %%ds,%0" : "=rm" (seg));
10046 return seg;
10047 }
10048
10049 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10050 static inline int memcmp(const void *s1, const void *s2, size_t len)
10051 {
10052 u8 diff;
10053 - asm("repe; cmpsb; setnz %0"
10054 + asm volatile("repe; cmpsb; setnz %0"
10055 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10056 return diff;
10057 }
10058 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10059 index 8a84501..b2d165f 100644
10060 --- a/arch/x86/boot/compressed/Makefile
10061 +++ b/arch/x86/boot/compressed/Makefile
10062 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10063 KBUILD_CFLAGS += $(cflags-y)
10064 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10065 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10066 +ifdef CONSTIFY_PLUGIN
10067 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10068 +endif
10069
10070 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10071 GCOV_PROFILE := n
10072 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10073 index f8fa411..c570c53 100644
10074 --- a/arch/x86/boot/compressed/eboot.c
10075 +++ b/arch/x86/boot/compressed/eboot.c
10076 @@ -145,7 +145,6 @@ again:
10077 *addr = max_addr;
10078 }
10079
10080 -free_pool:
10081 efi_call_phys1(sys_table->boottime->free_pool, map);
10082
10083 fail:
10084 @@ -209,7 +208,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10085 if (i == map_size / desc_size)
10086 status = EFI_NOT_FOUND;
10087
10088 -free_pool:
10089 efi_call_phys1(sys_table->boottime->free_pool, map);
10090 fail:
10091 return status;
10092 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10093 index 1e3184f..0d11e2e 100644
10094 --- a/arch/x86/boot/compressed/head_32.S
10095 +++ b/arch/x86/boot/compressed/head_32.S
10096 @@ -118,7 +118,7 @@ preferred_addr:
10097 notl %eax
10098 andl %eax, %ebx
10099 #else
10100 - movl $LOAD_PHYSICAL_ADDR, %ebx
10101 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10102 #endif
10103
10104 /* Target address to relocate to for decompression */
10105 @@ -204,7 +204,7 @@ relocated:
10106 * and where it was actually loaded.
10107 */
10108 movl %ebp, %ebx
10109 - subl $LOAD_PHYSICAL_ADDR, %ebx
10110 + subl $____LOAD_PHYSICAL_ADDR, %ebx
10111 jz 2f /* Nothing to be done if loaded at compiled addr. */
10112 /*
10113 * Process relocations.
10114 @@ -212,8 +212,7 @@ relocated:
10115
10116 1: subl $4, %edi
10117 movl (%edi), %ecx
10118 - testl %ecx, %ecx
10119 - jz 2f
10120 + jecxz 2f
10121 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10122 jmp 1b
10123 2:
10124 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10125 index f5d1aaa..cce11dc 100644
10126 --- a/arch/x86/boot/compressed/head_64.S
10127 +++ b/arch/x86/boot/compressed/head_64.S
10128 @@ -91,7 +91,7 @@ ENTRY(startup_32)
10129 notl %eax
10130 andl %eax, %ebx
10131 #else
10132 - movl $LOAD_PHYSICAL_ADDR, %ebx
10133 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10134 #endif
10135
10136 /* Target address to relocate to for decompression */
10137 @@ -273,7 +273,7 @@ preferred_addr:
10138 notq %rax
10139 andq %rax, %rbp
10140 #else
10141 - movq $LOAD_PHYSICAL_ADDR, %rbp
10142 + movq $____LOAD_PHYSICAL_ADDR, %rbp
10143 #endif
10144
10145 /* Target address to relocate to for decompression */
10146 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10147 index 88f7ff6..ed695dd 100644
10148 --- a/arch/x86/boot/compressed/misc.c
10149 +++ b/arch/x86/boot/compressed/misc.c
10150 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
10151 case PT_LOAD:
10152 #ifdef CONFIG_RELOCATABLE
10153 dest = output;
10154 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10155 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10156 #else
10157 dest = (void *)(phdr->p_paddr);
10158 #endif
10159 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10160 error("Destination address too large");
10161 #endif
10162 #ifndef CONFIG_RELOCATABLE
10163 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10164 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10165 error("Wrong destination address");
10166 #endif
10167
10168 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10169 index 4d3ff03..e4972ff 100644
10170 --- a/arch/x86/boot/cpucheck.c
10171 +++ b/arch/x86/boot/cpucheck.c
10172 @@ -74,7 +74,7 @@ static int has_fpu(void)
10173 u16 fcw = -1, fsw = -1;
10174 u32 cr0;
10175
10176 - asm("movl %%cr0,%0" : "=r" (cr0));
10177 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
10178 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10179 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10180 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10181 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10182 {
10183 u32 f0, f1;
10184
10185 - asm("pushfl ; "
10186 + asm volatile("pushfl ; "
10187 "pushfl ; "
10188 "popl %0 ; "
10189 "movl %0,%1 ; "
10190 @@ -115,7 +115,7 @@ static void get_flags(void)
10191 set_bit(X86_FEATURE_FPU, cpu.flags);
10192
10193 if (has_eflag(X86_EFLAGS_ID)) {
10194 - asm("cpuid"
10195 + asm volatile("cpuid"
10196 : "=a" (max_intel_level),
10197 "=b" (cpu_vendor[0]),
10198 "=d" (cpu_vendor[1]),
10199 @@ -124,7 +124,7 @@ static void get_flags(void)
10200
10201 if (max_intel_level >= 0x00000001 &&
10202 max_intel_level <= 0x0000ffff) {
10203 - asm("cpuid"
10204 + asm volatile("cpuid"
10205 : "=a" (tfms),
10206 "=c" (cpu.flags[4]),
10207 "=d" (cpu.flags[0])
10208 @@ -136,7 +136,7 @@ static void get_flags(void)
10209 cpu.model += ((tfms >> 16) & 0xf) << 4;
10210 }
10211
10212 - asm("cpuid"
10213 + asm volatile("cpuid"
10214 : "=a" (max_amd_level)
10215 : "a" (0x80000000)
10216 : "ebx", "ecx", "edx");
10217 @@ -144,7 +144,7 @@ static void get_flags(void)
10218 if (max_amd_level >= 0x80000001 &&
10219 max_amd_level <= 0x8000ffff) {
10220 u32 eax = 0x80000001;
10221 - asm("cpuid"
10222 + asm volatile("cpuid"
10223 : "+a" (eax),
10224 "=c" (cpu.flags[6]),
10225 "=d" (cpu.flags[1])
10226 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10227 u32 ecx = MSR_K7_HWCR;
10228 u32 eax, edx;
10229
10230 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10231 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10232 eax &= ~(1 << 15);
10233 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10234 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10235
10236 get_flags(); /* Make sure it really did something */
10237 err = check_flags();
10238 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10239 u32 ecx = MSR_VIA_FCR;
10240 u32 eax, edx;
10241
10242 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10243 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10244 eax |= (1<<1)|(1<<7);
10245 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10246 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10247
10248 set_bit(X86_FEATURE_CX8, cpu.flags);
10249 err = check_flags();
10250 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10251 u32 eax, edx;
10252 u32 level = 1;
10253
10254 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10255 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10256 - asm("cpuid"
10257 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10258 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10259 + asm volatile("cpuid"
10260 : "+a" (level), "=d" (cpu.flags[0])
10261 : : "ecx", "ebx");
10262 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10263 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10264
10265 err = check_flags();
10266 }
10267 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10268 index 944ce59..87ee37a 100644
10269 --- a/arch/x86/boot/header.S
10270 +++ b/arch/x86/boot/header.S
10271 @@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10272 # single linked list of
10273 # struct setup_data
10274
10275 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10276 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10277
10278 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10279 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10280 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10281 +#else
10282 #define VO_INIT_SIZE (VO__end - VO__text)
10283 +#endif
10284 #if ZO_INIT_SIZE > VO_INIT_SIZE
10285 #define INIT_SIZE ZO_INIT_SIZE
10286 #else
10287 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10288 index db75d07..8e6d0af 100644
10289 --- a/arch/x86/boot/memory.c
10290 +++ b/arch/x86/boot/memory.c
10291 @@ -19,7 +19,7 @@
10292
10293 static int detect_memory_e820(void)
10294 {
10295 - int count = 0;
10296 + unsigned int count = 0;
10297 struct biosregs ireg, oreg;
10298 struct e820entry *desc = boot_params.e820_map;
10299 static struct e820entry buf; /* static so it is zeroed */
10300 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10301 index 11e8c6e..fdbb1ed 100644
10302 --- a/arch/x86/boot/video-vesa.c
10303 +++ b/arch/x86/boot/video-vesa.c
10304 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10305
10306 boot_params.screen_info.vesapm_seg = oreg.es;
10307 boot_params.screen_info.vesapm_off = oreg.di;
10308 + boot_params.screen_info.vesapm_size = oreg.cx;
10309 }
10310
10311 /*
10312 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10313 index 43eda28..5ab5fdb 100644
10314 --- a/arch/x86/boot/video.c
10315 +++ b/arch/x86/boot/video.c
10316 @@ -96,7 +96,7 @@ static void store_mode_params(void)
10317 static unsigned int get_entry(void)
10318 {
10319 char entry_buf[4];
10320 - int i, len = 0;
10321 + unsigned int i, len = 0;
10322 int key;
10323 unsigned int v;
10324
10325 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10326 index 5b577d5..3c1fed4 100644
10327 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
10328 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10329 @@ -8,6 +8,8 @@
10330 * including this sentence is retained in full.
10331 */
10332
10333 +#include <asm/alternative-asm.h>
10334 +
10335 .extern crypto_ft_tab
10336 .extern crypto_it_tab
10337 .extern crypto_fl_tab
10338 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10339 je B192; \
10340 leaq 32(r9),r9;
10341
10342 +#define ret pax_force_retaddr 0, 1; ret
10343 +
10344 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10345 movq r1,r2; \
10346 movq r3,r4; \
10347 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10348 index 3470624..201259d 100644
10349 --- a/arch/x86/crypto/aesni-intel_asm.S
10350 +++ b/arch/x86/crypto/aesni-intel_asm.S
10351 @@ -31,6 +31,7 @@
10352
10353 #include <linux/linkage.h>
10354 #include <asm/inst.h>
10355 +#include <asm/alternative-asm.h>
10356
10357 #ifdef __x86_64__
10358 .data
10359 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10360 pop %r14
10361 pop %r13
10362 pop %r12
10363 + pax_force_retaddr 0, 1
10364 ret
10365 +ENDPROC(aesni_gcm_dec)
10366
10367
10368 /*****************************************************************************
10369 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10370 pop %r14
10371 pop %r13
10372 pop %r12
10373 + pax_force_retaddr 0, 1
10374 ret
10375 +ENDPROC(aesni_gcm_enc)
10376
10377 #endif
10378
10379 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
10380 pxor %xmm1, %xmm0
10381 movaps %xmm0, (TKEYP)
10382 add $0x10, TKEYP
10383 + pax_force_retaddr_bts
10384 ret
10385
10386 .align 4
10387 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
10388 shufps $0b01001110, %xmm2, %xmm1
10389 movaps %xmm1, 0x10(TKEYP)
10390 add $0x20, TKEYP
10391 + pax_force_retaddr_bts
10392 ret
10393
10394 .align 4
10395 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
10396
10397 movaps %xmm0, (TKEYP)
10398 add $0x10, TKEYP
10399 + pax_force_retaddr_bts
10400 ret
10401
10402 .align 4
10403 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
10404 pxor %xmm1, %xmm2
10405 movaps %xmm2, (TKEYP)
10406 add $0x10, TKEYP
10407 + pax_force_retaddr_bts
10408 ret
10409
10410 /*
10411 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10412 #ifndef __x86_64__
10413 popl KEYP
10414 #endif
10415 + pax_force_retaddr 0, 1
10416 ret
10417 +ENDPROC(aesni_set_key)
10418
10419 /*
10420 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10421 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10422 popl KLEN
10423 popl KEYP
10424 #endif
10425 + pax_force_retaddr 0, 1
10426 ret
10427 +ENDPROC(aesni_enc)
10428
10429 /*
10430 * _aesni_enc1: internal ABI
10431 @@ -1959,6 +1972,7 @@ _aesni_enc1:
10432 AESENC KEY STATE
10433 movaps 0x70(TKEYP), KEY
10434 AESENCLAST KEY STATE
10435 + pax_force_retaddr_bts
10436 ret
10437
10438 /*
10439 @@ -2067,6 +2081,7 @@ _aesni_enc4:
10440 AESENCLAST KEY STATE2
10441 AESENCLAST KEY STATE3
10442 AESENCLAST KEY STATE4
10443 + pax_force_retaddr_bts
10444 ret
10445
10446 /*
10447 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10448 popl KLEN
10449 popl KEYP
10450 #endif
10451 + pax_force_retaddr 0, 1
10452 ret
10453 +ENDPROC(aesni_dec)
10454
10455 /*
10456 * _aesni_dec1: internal ABI
10457 @@ -2146,6 +2163,7 @@ _aesni_dec1:
10458 AESDEC KEY STATE
10459 movaps 0x70(TKEYP), KEY
10460 AESDECLAST KEY STATE
10461 + pax_force_retaddr_bts
10462 ret
10463
10464 /*
10465 @@ -2254,6 +2272,7 @@ _aesni_dec4:
10466 AESDECLAST KEY STATE2
10467 AESDECLAST KEY STATE3
10468 AESDECLAST KEY STATE4
10469 + pax_force_retaddr_bts
10470 ret
10471
10472 /*
10473 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10474 popl KEYP
10475 popl LEN
10476 #endif
10477 + pax_force_retaddr 0, 1
10478 ret
10479 +ENDPROC(aesni_ecb_enc)
10480
10481 /*
10482 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10483 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10484 popl KEYP
10485 popl LEN
10486 #endif
10487 + pax_force_retaddr 0, 1
10488 ret
10489 +ENDPROC(aesni_ecb_dec)
10490
10491 /*
10492 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10493 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10494 popl LEN
10495 popl IVP
10496 #endif
10497 + pax_force_retaddr 0, 1
10498 ret
10499 +ENDPROC(aesni_cbc_enc)
10500
10501 /*
10502 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10503 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10504 popl LEN
10505 popl IVP
10506 #endif
10507 + pax_force_retaddr 0, 1
10508 ret
10509 +ENDPROC(aesni_cbc_dec)
10510
10511 #ifdef __x86_64__
10512 .align 16
10513 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
10514 mov $1, TCTR_LOW
10515 MOVQ_R64_XMM TCTR_LOW INC
10516 MOVQ_R64_XMM CTR TCTR_LOW
10517 + pax_force_retaddr_bts
10518 ret
10519
10520 /*
10521 @@ -2554,6 +2582,7 @@ _aesni_inc:
10522 .Linc_low:
10523 movaps CTR, IV
10524 PSHUFB_XMM BSWAP_MASK IV
10525 + pax_force_retaddr_bts
10526 ret
10527
10528 /*
10529 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10530 .Lctr_enc_ret:
10531 movups IV, (IVP)
10532 .Lctr_enc_just_ret:
10533 + pax_force_retaddr 0, 1
10534 ret
10535 +ENDPROC(aesni_ctr_enc)
10536 #endif
10537 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10538 index 391d245..67f35c2 100644
10539 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10540 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10541 @@ -20,6 +20,8 @@
10542 *
10543 */
10544
10545 +#include <asm/alternative-asm.h>
10546 +
10547 .file "blowfish-x86_64-asm.S"
10548 .text
10549
10550 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
10551 jnz __enc_xor;
10552
10553 write_block();
10554 + pax_force_retaddr 0, 1
10555 ret;
10556 __enc_xor:
10557 xor_block();
10558 + pax_force_retaddr 0, 1
10559 ret;
10560
10561 .align 8
10562 @@ -188,6 +192,7 @@ blowfish_dec_blk:
10563
10564 movq %r11, %rbp;
10565
10566 + pax_force_retaddr 0, 1
10567 ret;
10568
10569 /**********************************************************************
10570 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10571
10572 popq %rbx;
10573 popq %rbp;
10574 + pax_force_retaddr 0, 1
10575 ret;
10576
10577 __enc_xor4:
10578 @@ -349,6 +355,7 @@ __enc_xor4:
10579
10580 popq %rbx;
10581 popq %rbp;
10582 + pax_force_retaddr 0, 1
10583 ret;
10584
10585 .align 8
10586 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10587 popq %rbx;
10588 popq %rbp;
10589
10590 + pax_force_retaddr 0, 1
10591 ret;
10592
10593 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10594 index 0b33743..7a56206 100644
10595 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10596 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10597 @@ -20,6 +20,8 @@
10598 *
10599 */
10600
10601 +#include <asm/alternative-asm.h>
10602 +
10603 .file "camellia-x86_64-asm_64.S"
10604 .text
10605
10606 @@ -229,12 +231,14 @@ __enc_done:
10607 enc_outunpack(mov, RT1);
10608
10609 movq RRBP, %rbp;
10610 + pax_force_retaddr 0, 1
10611 ret;
10612
10613 __enc_xor:
10614 enc_outunpack(xor, RT1);
10615
10616 movq RRBP, %rbp;
10617 + pax_force_retaddr 0, 1
10618 ret;
10619
10620 .global camellia_dec_blk;
10621 @@ -275,6 +279,7 @@ __dec_rounds16:
10622 dec_outunpack();
10623
10624 movq RRBP, %rbp;
10625 + pax_force_retaddr 0, 1
10626 ret;
10627
10628 /**********************************************************************
10629 @@ -468,6 +473,7 @@ __enc2_done:
10630
10631 movq RRBP, %rbp;
10632 popq %rbx;
10633 + pax_force_retaddr 0, 1
10634 ret;
10635
10636 __enc2_xor:
10637 @@ -475,6 +481,7 @@ __enc2_xor:
10638
10639 movq RRBP, %rbp;
10640 popq %rbx;
10641 + pax_force_retaddr 0, 1
10642 ret;
10643
10644 .global camellia_dec_blk_2way;
10645 @@ -517,4 +524,5 @@ __dec2_rounds16:
10646
10647 movq RRBP, %rbp;
10648 movq RXOR, %rbx;
10649 + pax_force_retaddr 0, 1
10650 ret;
10651 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10652 index 15b00ac..2071784 100644
10653 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10654 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10655 @@ -23,6 +23,8 @@
10656 *
10657 */
10658
10659 +#include <asm/alternative-asm.h>
10660 +
10661 .file "cast5-avx-x86_64-asm_64.S"
10662
10663 .extern cast_s1
10664 @@ -281,6 +283,7 @@ __skip_enc:
10665 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10666 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10667
10668 + pax_force_retaddr 0, 1
10669 ret;
10670
10671 .align 16
10672 @@ -353,6 +356,7 @@ __dec_tail:
10673 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10674 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10675
10676 + pax_force_retaddr 0, 1
10677 ret;
10678
10679 __skip_dec:
10680 @@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10681 vmovdqu RR4, (6*4*4)(%r11);
10682 vmovdqu RL4, (7*4*4)(%r11);
10683
10684 + pax_force_retaddr
10685 ret;
10686
10687 .align 16
10688 @@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10689 vmovdqu RR4, (6*4*4)(%r11);
10690 vmovdqu RL4, (7*4*4)(%r11);
10691
10692 + pax_force_retaddr
10693 ret;
10694
10695 .align 16
10696 @@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10697
10698 popq %r12;
10699
10700 + pax_force_retaddr
10701 ret;
10702
10703 .align 16
10704 @@ -555,4 +562,5 @@ cast5_ctr_16way:
10705
10706 popq %r12;
10707
10708 + pax_force_retaddr
10709 ret;
10710 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10711 index 2569d0d..637c289 100644
10712 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10713 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10714 @@ -23,6 +23,8 @@
10715 *
10716 */
10717
10718 +#include <asm/alternative-asm.h>
10719 +
10720 #include "glue_helper-asm-avx.S"
10721
10722 .file "cast6-avx-x86_64-asm_64.S"
10723 @@ -294,6 +296,7 @@ __cast6_enc_blk8:
10724 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10725 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10726
10727 + pax_force_retaddr 0, 1
10728 ret;
10729
10730 .align 8
10731 @@ -340,6 +343,7 @@ __cast6_dec_blk8:
10732 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10733 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10734
10735 + pax_force_retaddr 0, 1
10736 ret;
10737
10738 .align 8
10739 @@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10740
10741 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10742
10743 + pax_force_retaddr
10744 ret;
10745
10746 .align 8
10747 @@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10748
10749 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10750
10751 + pax_force_retaddr
10752 ret;
10753
10754 .align 8
10755 @@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10756
10757 popq %r12;
10758
10759 + pax_force_retaddr
10760 ret;
10761
10762 .align 8
10763 @@ -436,4 +443,5 @@ cast6_ctr_8way:
10764
10765 popq %r12;
10766
10767 + pax_force_retaddr
10768 ret;
10769 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10770 index 6214a9b..1f4fc9a 100644
10771 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10772 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10773 @@ -1,3 +1,5 @@
10774 +#include <asm/alternative-asm.h>
10775 +
10776 # enter ECRYPT_encrypt_bytes
10777 .text
10778 .p2align 5
10779 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10780 add %r11,%rsp
10781 mov %rdi,%rax
10782 mov %rsi,%rdx
10783 + pax_force_retaddr 0, 1
10784 ret
10785 # bytesatleast65:
10786 ._bytesatleast65:
10787 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
10788 add %r11,%rsp
10789 mov %rdi,%rax
10790 mov %rsi,%rdx
10791 + pax_force_retaddr
10792 ret
10793 # enter ECRYPT_ivsetup
10794 .text
10795 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10796 add %r11,%rsp
10797 mov %rdi,%rax
10798 mov %rsi,%rdx
10799 + pax_force_retaddr
10800 ret
10801 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10802 index 02b0e9f..cf4cf5c 100644
10803 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10804 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10805 @@ -24,6 +24,8 @@
10806 *
10807 */
10808
10809 +#include <asm/alternative-asm.h>
10810 +
10811 #include "glue_helper-asm-avx.S"
10812
10813 .file "serpent-avx-x86_64-asm_64.S"
10814 @@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10815 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10816 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10817
10818 + pax_force_retaddr
10819 ret;
10820
10821 .align 8
10822 @@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10823 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10824 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10825
10826 + pax_force_retaddr
10827 ret;
10828
10829 .align 8
10830 @@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
10831
10832 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10833
10834 + pax_force_retaddr
10835 ret;
10836
10837 .align 8
10838 @@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
10839
10840 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10841
10842 + pax_force_retaddr
10843 ret;
10844
10845 .align 8
10846 @@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
10847
10848 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10849
10850 + pax_force_retaddr
10851 ret;
10852
10853 .align 8
10854 @@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
10855
10856 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10857
10858 + pax_force_retaddr
10859 ret;
10860 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10861 index 3ee1ff0..cbc568b 100644
10862 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10863 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10864 @@ -24,6 +24,8 @@
10865 *
10866 */
10867
10868 +#include <asm/alternative-asm.h>
10869 +
10870 .file "serpent-sse2-x86_64-asm_64.S"
10871 .text
10872
10873 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
10874 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10875 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10876
10877 + pax_force_retaddr
10878 ret;
10879
10880 __enc_xor8:
10881 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10882 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10883
10884 + pax_force_retaddr
10885 ret;
10886
10887 .align 8
10888 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
10889 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10890 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10891
10892 + pax_force_retaddr
10893 ret;
10894 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
10895 index 49d6987..df66bd4 100644
10896 --- a/arch/x86/crypto/sha1_ssse3_asm.S
10897 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
10898 @@ -28,6 +28,8 @@
10899 * (at your option) any later version.
10900 */
10901
10902 +#include <asm/alternative-asm.h>
10903 +
10904 #define CTX %rdi // arg1
10905 #define BUF %rsi // arg2
10906 #define CNT %rdx // arg3
10907 @@ -104,6 +106,7 @@
10908 pop %r12
10909 pop %rbp
10910 pop %rbx
10911 + pax_force_retaddr 0, 1
10912 ret
10913
10914 .size \name, .-\name
10915 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10916 index ebac16b..8092eb9 100644
10917 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10918 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10919 @@ -23,6 +23,8 @@
10920 *
10921 */
10922
10923 +#include <asm/alternative-asm.h>
10924 +
10925 #include "glue_helper-asm-avx.S"
10926
10927 .file "twofish-avx-x86_64-asm_64.S"
10928 @@ -283,6 +285,7 @@ __twofish_enc_blk8:
10929 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
10930 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
10931
10932 + pax_force_retaddr 0, 1
10933 ret;
10934
10935 .align 8
10936 @@ -324,6 +327,7 @@ __twofish_dec_blk8:
10937 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
10938 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
10939
10940 + pax_force_retaddr 0, 1
10941 ret;
10942
10943 .align 8
10944 @@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
10945
10946 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
10947
10948 + pax_force_retaddr 0, 1
10949 ret;
10950
10951 .align 8
10952 @@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
10953
10954 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10955
10956 + pax_force_retaddr 0, 1
10957 ret;
10958
10959 .align 8
10960 @@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
10961
10962 popq %r12;
10963
10964 + pax_force_retaddr 0, 1
10965 ret;
10966
10967 .align 8
10968 @@ -420,4 +427,5 @@ twofish_ctr_8way:
10969
10970 popq %r12;
10971
10972 + pax_force_retaddr 0, 1
10973 ret;
10974 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10975 index 5b012a2..36d5364 100644
10976 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10977 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10978 @@ -20,6 +20,8 @@
10979 *
10980 */
10981
10982 +#include <asm/alternative-asm.h>
10983 +
10984 .file "twofish-x86_64-asm-3way.S"
10985 .text
10986
10987 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
10988 popq %r13;
10989 popq %r14;
10990 popq %r15;
10991 + pax_force_retaddr 0, 1
10992 ret;
10993
10994 __enc_xor3:
10995 @@ -271,6 +274,7 @@ __enc_xor3:
10996 popq %r13;
10997 popq %r14;
10998 popq %r15;
10999 + pax_force_retaddr 0, 1
11000 ret;
11001
11002 .global twofish_dec_blk_3way
11003 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11004 popq %r13;
11005 popq %r14;
11006 popq %r15;
11007 + pax_force_retaddr 0, 1
11008 ret;
11009
11010 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11011 index 7bcf3fc..f53832f 100644
11012 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11013 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11014 @@ -21,6 +21,7 @@
11015 .text
11016
11017 #include <asm/asm-offsets.h>
11018 +#include <asm/alternative-asm.h>
11019
11020 #define a_offset 0
11021 #define b_offset 4
11022 @@ -268,6 +269,7 @@ twofish_enc_blk:
11023
11024 popq R1
11025 movq $1,%rax
11026 + pax_force_retaddr 0, 1
11027 ret
11028
11029 twofish_dec_blk:
11030 @@ -319,4 +321,5 @@ twofish_dec_blk:
11031
11032 popq R1
11033 movq $1,%rax
11034 + pax_force_retaddr 0, 1
11035 ret
11036 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11037 index a703af1..f5b9c36 100644
11038 --- a/arch/x86/ia32/ia32_aout.c
11039 +++ b/arch/x86/ia32/ia32_aout.c
11040 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11041 unsigned long dump_start, dump_size;
11042 struct user32 dump;
11043
11044 + memset(&dump, 0, sizeof(dump));
11045 +
11046 fs = get_fs();
11047 set_fs(KERNEL_DS);
11048 has_dumped = 1;
11049 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11050 index a1daf4a..f8c4537 100644
11051 --- a/arch/x86/ia32/ia32_signal.c
11052 +++ b/arch/x86/ia32/ia32_signal.c
11053 @@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11054 sp -= frame_size;
11055 /* Align the stack pointer according to the i386 ABI,
11056 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11057 - sp = ((sp + 4) & -16ul) - 4;
11058 + sp = ((sp - 12) & -16ul) - 4;
11059 return (void __user *) sp;
11060 }
11061
11062 @@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11063 * These are actually not used anymore, but left because some
11064 * gdb versions depend on them as a marker.
11065 */
11066 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11067 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11068 } put_user_catch(err);
11069
11070 if (err)
11071 @@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11072 0xb8,
11073 __NR_ia32_rt_sigreturn,
11074 0x80cd,
11075 - 0,
11076 + 0
11077 };
11078
11079 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11080 @@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11081
11082 if (ka->sa.sa_flags & SA_RESTORER)
11083 restorer = ka->sa.sa_restorer;
11084 + else if (current->mm->context.vdso)
11085 + /* Return stub is in 32bit vsyscall page */
11086 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11087 else
11088 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11089 - rt_sigreturn);
11090 + restorer = &frame->retcode;
11091 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11092
11093 /*
11094 * Not actually used anymore, but left because some gdb
11095 * versions need it.
11096 */
11097 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11098 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11099 } put_user_catch(err);
11100
11101 err |= copy_siginfo_to_user32(&frame->info, info);
11102 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11103 index 142c4ce..19b683f 100644
11104 --- a/arch/x86/ia32/ia32entry.S
11105 +++ b/arch/x86/ia32/ia32entry.S
11106 @@ -15,8 +15,10 @@
11107 #include <asm/irqflags.h>
11108 #include <asm/asm.h>
11109 #include <asm/smap.h>
11110 +#include <asm/pgtable.h>
11111 #include <linux/linkage.h>
11112 #include <linux/err.h>
11113 +#include <asm/alternative-asm.h>
11114
11115 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11116 #include <linux/elf-em.h>
11117 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11118 ENDPROC(native_irq_enable_sysexit)
11119 #endif
11120
11121 + .macro pax_enter_kernel_user
11122 + pax_set_fptr_mask
11123 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11124 + call pax_enter_kernel_user
11125 +#endif
11126 + .endm
11127 +
11128 + .macro pax_exit_kernel_user
11129 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11130 + call pax_exit_kernel_user
11131 +#endif
11132 +#ifdef CONFIG_PAX_RANDKSTACK
11133 + pushq %rax
11134 + pushq %r11
11135 + call pax_randomize_kstack
11136 + popq %r11
11137 + popq %rax
11138 +#endif
11139 + .endm
11140 +
11141 +.macro pax_erase_kstack
11142 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11143 + call pax_erase_kstack
11144 +#endif
11145 +.endm
11146 +
11147 /*
11148 * 32bit SYSENTER instruction entry.
11149 *
11150 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11151 CFI_REGISTER rsp,rbp
11152 SWAPGS_UNSAFE_STACK
11153 movq PER_CPU_VAR(kernel_stack), %rsp
11154 - addq $(KERNEL_STACK_OFFSET),%rsp
11155 - /*
11156 - * No need to follow this irqs on/off section: the syscall
11157 - * disabled irqs, here we enable it straight after entry:
11158 - */
11159 - ENABLE_INTERRUPTS(CLBR_NONE)
11160 movl %ebp,%ebp /* zero extension */
11161 pushq_cfi $__USER32_DS
11162 /*CFI_REL_OFFSET ss,0*/
11163 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11164 CFI_REL_OFFSET rsp,0
11165 pushfq_cfi
11166 /*CFI_REL_OFFSET rflags,0*/
11167 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11168 - CFI_REGISTER rip,r10
11169 + orl $X86_EFLAGS_IF,(%rsp)
11170 + GET_THREAD_INFO(%r11)
11171 + movl TI_sysenter_return(%r11), %r11d
11172 + CFI_REGISTER rip,r11
11173 pushq_cfi $__USER32_CS
11174 /*CFI_REL_OFFSET cs,0*/
11175 movl %eax, %eax
11176 - pushq_cfi %r10
11177 + pushq_cfi %r11
11178 CFI_REL_OFFSET rip,0
11179 pushq_cfi %rax
11180 cld
11181 SAVE_ARGS 0,1,0
11182 + pax_enter_kernel_user
11183 +
11184 +#ifdef CONFIG_PAX_RANDKSTACK
11185 + pax_erase_kstack
11186 +#endif
11187 +
11188 + /*
11189 + * No need to follow this irqs on/off section: the syscall
11190 + * disabled irqs, here we enable it straight after entry:
11191 + */
11192 + ENABLE_INTERRUPTS(CLBR_NONE)
11193 /* no need to do an access_ok check here because rbp has been
11194 32bit zero extended */
11195 +
11196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11197 + mov $PAX_USER_SHADOW_BASE,%r11
11198 + add %r11,%rbp
11199 +#endif
11200 +
11201 ASM_STAC
11202 1: movl (%rbp),%ebp
11203 _ASM_EXTABLE(1b,ia32_badarg)
11204 ASM_CLAC
11205 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11206 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11207 + GET_THREAD_INFO(%r11)
11208 + orl $TS_COMPAT,TI_status(%r11)
11209 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11210 CFI_REMEMBER_STATE
11211 jnz sysenter_tracesys
11212 cmpq $(IA32_NR_syscalls-1),%rax
11213 @@ -162,12 +204,15 @@ sysenter_do_call:
11214 sysenter_dispatch:
11215 call *ia32_sys_call_table(,%rax,8)
11216 movq %rax,RAX-ARGOFFSET(%rsp)
11217 + GET_THREAD_INFO(%r11)
11218 DISABLE_INTERRUPTS(CLBR_NONE)
11219 TRACE_IRQS_OFF
11220 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11221 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11222 jnz sysexit_audit
11223 sysexit_from_sys_call:
11224 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11225 + pax_exit_kernel_user
11226 + pax_erase_kstack
11227 + andl $~TS_COMPAT,TI_status(%r11)
11228 /* clear IF, that popfq doesn't enable interrupts early */
11229 andl $~0x200,EFLAGS-R11(%rsp)
11230 movl RIP-R11(%rsp),%edx /* User %eip */
11231 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
11232 movl %eax,%esi /* 2nd arg: syscall number */
11233 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11234 call __audit_syscall_entry
11235 +
11236 + pax_erase_kstack
11237 +
11238 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11239 cmpq $(IA32_NR_syscalls-1),%rax
11240 ja ia32_badsys
11241 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
11242 .endm
11243
11244 .macro auditsys_exit exit
11245 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11246 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11247 jnz ia32_ret_from_sys_call
11248 TRACE_IRQS_ON
11249 ENABLE_INTERRUPTS(CLBR_NONE)
11250 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
11251 1: setbe %al /* 1 if error, 0 if not */
11252 movzbl %al,%edi /* zero-extend that into %edi */
11253 call __audit_syscall_exit
11254 + GET_THREAD_INFO(%r11)
11255 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11256 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11257 DISABLE_INTERRUPTS(CLBR_NONE)
11258 TRACE_IRQS_OFF
11259 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11260 + testl %edi,TI_flags(%r11)
11261 jz \exit
11262 CLEAR_RREGS -ARGOFFSET
11263 jmp int_with_check
11264 @@ -237,7 +286,7 @@ sysexit_audit:
11265
11266 sysenter_tracesys:
11267 #ifdef CONFIG_AUDITSYSCALL
11268 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11269 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11270 jz sysenter_auditsys
11271 #endif
11272 SAVE_REST
11273 @@ -249,6 +298,9 @@ sysenter_tracesys:
11274 RESTORE_REST
11275 cmpq $(IA32_NR_syscalls-1),%rax
11276 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11277 +
11278 + pax_erase_kstack
11279 +
11280 jmp sysenter_do_call
11281 CFI_ENDPROC
11282 ENDPROC(ia32_sysenter_target)
11283 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11284 ENTRY(ia32_cstar_target)
11285 CFI_STARTPROC32 simple
11286 CFI_SIGNAL_FRAME
11287 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11288 + CFI_DEF_CFA rsp,0
11289 CFI_REGISTER rip,rcx
11290 /*CFI_REGISTER rflags,r11*/
11291 SWAPGS_UNSAFE_STACK
11292 movl %esp,%r8d
11293 CFI_REGISTER rsp,r8
11294 movq PER_CPU_VAR(kernel_stack),%rsp
11295 + SAVE_ARGS 8*6,0,0
11296 + pax_enter_kernel_user
11297 +
11298 +#ifdef CONFIG_PAX_RANDKSTACK
11299 + pax_erase_kstack
11300 +#endif
11301 +
11302 /*
11303 * No need to follow this irqs on/off section: the syscall
11304 * disabled irqs and here we enable it straight after entry:
11305 */
11306 ENABLE_INTERRUPTS(CLBR_NONE)
11307 - SAVE_ARGS 8,0,0
11308 movl %eax,%eax /* zero extension */
11309 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11310 movq %rcx,RIP-ARGOFFSET(%rsp)
11311 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11312 /* no need to do an access_ok check here because r8 has been
11313 32bit zero extended */
11314 /* hardware stack frame is complete now */
11315 +
11316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11317 + mov $PAX_USER_SHADOW_BASE,%r11
11318 + add %r11,%r8
11319 +#endif
11320 +
11321 ASM_STAC
11322 1: movl (%r8),%r9d
11323 _ASM_EXTABLE(1b,ia32_badarg)
11324 ASM_CLAC
11325 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11326 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11327 + GET_THREAD_INFO(%r11)
11328 + orl $TS_COMPAT,TI_status(%r11)
11329 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11330 CFI_REMEMBER_STATE
11331 jnz cstar_tracesys
11332 cmpq $IA32_NR_syscalls-1,%rax
11333 @@ -319,12 +384,15 @@ cstar_do_call:
11334 cstar_dispatch:
11335 call *ia32_sys_call_table(,%rax,8)
11336 movq %rax,RAX-ARGOFFSET(%rsp)
11337 + GET_THREAD_INFO(%r11)
11338 DISABLE_INTERRUPTS(CLBR_NONE)
11339 TRACE_IRQS_OFF
11340 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11341 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11342 jnz sysretl_audit
11343 sysretl_from_sys_call:
11344 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11345 + pax_exit_kernel_user
11346 + pax_erase_kstack
11347 + andl $~TS_COMPAT,TI_status(%r11)
11348 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11349 movl RIP-ARGOFFSET(%rsp),%ecx
11350 CFI_REGISTER rip,rcx
11351 @@ -352,7 +420,7 @@ sysretl_audit:
11352
11353 cstar_tracesys:
11354 #ifdef CONFIG_AUDITSYSCALL
11355 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11356 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11357 jz cstar_auditsys
11358 #endif
11359 xchgl %r9d,%ebp
11360 @@ -366,6 +434,9 @@ cstar_tracesys:
11361 xchgl %ebp,%r9d
11362 cmpq $(IA32_NR_syscalls-1),%rax
11363 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11364 +
11365 + pax_erase_kstack
11366 +
11367 jmp cstar_do_call
11368 END(ia32_cstar_target)
11369
11370 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11371 CFI_REL_OFFSET rip,RIP-RIP
11372 PARAVIRT_ADJUST_EXCEPTION_FRAME
11373 SWAPGS
11374 - /*
11375 - * No need to follow this irqs on/off section: the syscall
11376 - * disabled irqs and here we enable it straight after entry:
11377 - */
11378 - ENABLE_INTERRUPTS(CLBR_NONE)
11379 movl %eax,%eax
11380 pushq_cfi %rax
11381 cld
11382 /* note the registers are not zero extended to the sf.
11383 this could be a problem. */
11384 SAVE_ARGS 0,1,0
11385 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11386 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11387 + pax_enter_kernel_user
11388 +
11389 +#ifdef CONFIG_PAX_RANDKSTACK
11390 + pax_erase_kstack
11391 +#endif
11392 +
11393 + /*
11394 + * No need to follow this irqs on/off section: the syscall
11395 + * disabled irqs and here we enable it straight after entry:
11396 + */
11397 + ENABLE_INTERRUPTS(CLBR_NONE)
11398 + GET_THREAD_INFO(%r11)
11399 + orl $TS_COMPAT,TI_status(%r11)
11400 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11401 jnz ia32_tracesys
11402 cmpq $(IA32_NR_syscalls-1),%rax
11403 ja ia32_badsys
11404 @@ -442,6 +520,9 @@ ia32_tracesys:
11405 RESTORE_REST
11406 cmpq $(IA32_NR_syscalls-1),%rax
11407 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11408 +
11409 + pax_erase_kstack
11410 +
11411 jmp ia32_do_call
11412 END(ia32_syscall)
11413
11414 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11415 index d0b689b..34be51d 100644
11416 --- a/arch/x86/ia32/sys_ia32.c
11417 +++ b/arch/x86/ia32/sys_ia32.c
11418 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11419 */
11420 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11421 {
11422 - typeof(ubuf->st_uid) uid = 0;
11423 - typeof(ubuf->st_gid) gid = 0;
11424 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
11425 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
11426 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11427 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11428 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11429 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11430 mm_segment_t old_fs = get_fs();
11431
11432 set_fs(KERNEL_DS);
11433 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11434 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11435 set_fs(old_fs);
11436 if (put_compat_timespec(&t, interval))
11437 return -EFAULT;
11438 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11439 mm_segment_t old_fs = get_fs();
11440
11441 set_fs(KERNEL_DS);
11442 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11443 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11444 set_fs(old_fs);
11445 if (!ret) {
11446 switch (_NSIG_WORDS) {
11447 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11448 if (copy_siginfo_from_user32(&info, uinfo))
11449 return -EFAULT;
11450 set_fs(KERNEL_DS);
11451 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11452 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11453 set_fs(old_fs);
11454 return ret;
11455 }
11456 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11457 return -EFAULT;
11458
11459 set_fs(KERNEL_DS);
11460 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11461 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11462 count);
11463 set_fs(old_fs);
11464
11465 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11466 index 372231c..a5aa1a1 100644
11467 --- a/arch/x86/include/asm/alternative-asm.h
11468 +++ b/arch/x86/include/asm/alternative-asm.h
11469 @@ -18,6 +18,45 @@
11470 .endm
11471 #endif
11472
11473 +#ifdef KERNEXEC_PLUGIN
11474 + .macro pax_force_retaddr_bts rip=0
11475 + btsq $63,\rip(%rsp)
11476 + .endm
11477 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11478 + .macro pax_force_retaddr rip=0, reload=0
11479 + btsq $63,\rip(%rsp)
11480 + .endm
11481 + .macro pax_force_fptr ptr
11482 + btsq $63,\ptr
11483 + .endm
11484 + .macro pax_set_fptr_mask
11485 + .endm
11486 +#endif
11487 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11488 + .macro pax_force_retaddr rip=0, reload=0
11489 + .if \reload
11490 + pax_set_fptr_mask
11491 + .endif
11492 + orq %r10,\rip(%rsp)
11493 + .endm
11494 + .macro pax_force_fptr ptr
11495 + orq %r10,\ptr
11496 + .endm
11497 + .macro pax_set_fptr_mask
11498 + movabs $0x8000000000000000,%r10
11499 + .endm
11500 +#endif
11501 +#else
11502 + .macro pax_force_retaddr rip=0, reload=0
11503 + .endm
11504 + .macro pax_force_fptr ptr
11505 + .endm
11506 + .macro pax_force_retaddr_bts rip=0
11507 + .endm
11508 + .macro pax_set_fptr_mask
11509 + .endm
11510 +#endif
11511 +
11512 .macro altinstruction_entry orig alt feature orig_len alt_len
11513 .long \orig - .
11514 .long \alt - .
11515 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11516 index 58ed6d9..f1cbe58 100644
11517 --- a/arch/x86/include/asm/alternative.h
11518 +++ b/arch/x86/include/asm/alternative.h
11519 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11520 ".pushsection .discard,\"aw\",@progbits\n" \
11521 DISCARD_ENTRY(1) \
11522 ".popsection\n" \
11523 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11524 + ".pushsection .altinstr_replacement, \"a\"\n" \
11525 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11526 ".popsection"
11527
11528 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11529 DISCARD_ENTRY(1) \
11530 DISCARD_ENTRY(2) \
11531 ".popsection\n" \
11532 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11533 + ".pushsection .altinstr_replacement, \"a\"\n" \
11534 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11535 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11536 ".popsection"
11537 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11538 index 3388034..050f0b9 100644
11539 --- a/arch/x86/include/asm/apic.h
11540 +++ b/arch/x86/include/asm/apic.h
11541 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11542
11543 #ifdef CONFIG_X86_LOCAL_APIC
11544
11545 -extern unsigned int apic_verbosity;
11546 +extern int apic_verbosity;
11547 extern int local_apic_timer_c2_ok;
11548
11549 extern int disable_apic;
11550 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11551 index 20370c6..a2eb9b0 100644
11552 --- a/arch/x86/include/asm/apm.h
11553 +++ b/arch/x86/include/asm/apm.h
11554 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11555 __asm__ __volatile__(APM_DO_ZERO_SEGS
11556 "pushl %%edi\n\t"
11557 "pushl %%ebp\n\t"
11558 - "lcall *%%cs:apm_bios_entry\n\t"
11559 + "lcall *%%ss:apm_bios_entry\n\t"
11560 "setc %%al\n\t"
11561 "popl %%ebp\n\t"
11562 "popl %%edi\n\t"
11563 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11564 __asm__ __volatile__(APM_DO_ZERO_SEGS
11565 "pushl %%edi\n\t"
11566 "pushl %%ebp\n\t"
11567 - "lcall *%%cs:apm_bios_entry\n\t"
11568 + "lcall *%%ss:apm_bios_entry\n\t"
11569 "setc %%bl\n\t"
11570 "popl %%ebp\n\t"
11571 "popl %%edi\n\t"
11572 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11573 index 722aa3b..3a0bb27 100644
11574 --- a/arch/x86/include/asm/atomic.h
11575 +++ b/arch/x86/include/asm/atomic.h
11576 @@ -22,7 +22,18 @@
11577 */
11578 static inline int atomic_read(const atomic_t *v)
11579 {
11580 - return (*(volatile int *)&(v)->counter);
11581 + return (*(volatile const int *)&(v)->counter);
11582 +}
11583 +
11584 +/**
11585 + * atomic_read_unchecked - read atomic variable
11586 + * @v: pointer of type atomic_unchecked_t
11587 + *
11588 + * Atomically reads the value of @v.
11589 + */
11590 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11591 +{
11592 + return (*(volatile const int *)&(v)->counter);
11593 }
11594
11595 /**
11596 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11597 }
11598
11599 /**
11600 + * atomic_set_unchecked - set atomic variable
11601 + * @v: pointer of type atomic_unchecked_t
11602 + * @i: required value
11603 + *
11604 + * Atomically sets the value of @v to @i.
11605 + */
11606 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11607 +{
11608 + v->counter = i;
11609 +}
11610 +
11611 +/**
11612 * atomic_add - add integer to atomic variable
11613 * @i: integer value to add
11614 * @v: pointer of type atomic_t
11615 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11616 */
11617 static inline void atomic_add(int i, atomic_t *v)
11618 {
11619 - asm volatile(LOCK_PREFIX "addl %1,%0"
11620 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11621 +
11622 +#ifdef CONFIG_PAX_REFCOUNT
11623 + "jno 0f\n"
11624 + LOCK_PREFIX "subl %1,%0\n"
11625 + "int $4\n0:\n"
11626 + _ASM_EXTABLE(0b, 0b)
11627 +#endif
11628 +
11629 + : "+m" (v->counter)
11630 + : "ir" (i));
11631 +}
11632 +
11633 +/**
11634 + * atomic_add_unchecked - add integer to atomic variable
11635 + * @i: integer value to add
11636 + * @v: pointer of type atomic_unchecked_t
11637 + *
11638 + * Atomically adds @i to @v.
11639 + */
11640 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11641 +{
11642 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11643 : "+m" (v->counter)
11644 : "ir" (i));
11645 }
11646 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11647 */
11648 static inline void atomic_sub(int i, atomic_t *v)
11649 {
11650 - asm volatile(LOCK_PREFIX "subl %1,%0"
11651 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11652 +
11653 +#ifdef CONFIG_PAX_REFCOUNT
11654 + "jno 0f\n"
11655 + LOCK_PREFIX "addl %1,%0\n"
11656 + "int $4\n0:\n"
11657 + _ASM_EXTABLE(0b, 0b)
11658 +#endif
11659 +
11660 + : "+m" (v->counter)
11661 + : "ir" (i));
11662 +}
11663 +
11664 +/**
11665 + * atomic_sub_unchecked - subtract integer from atomic variable
11666 + * @i: integer value to subtract
11667 + * @v: pointer of type atomic_unchecked_t
11668 + *
11669 + * Atomically subtracts @i from @v.
11670 + */
11671 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11672 +{
11673 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11674 : "+m" (v->counter)
11675 : "ir" (i));
11676 }
11677 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11678 {
11679 unsigned char c;
11680
11681 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11682 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
11683 +
11684 +#ifdef CONFIG_PAX_REFCOUNT
11685 + "jno 0f\n"
11686 + LOCK_PREFIX "addl %2,%0\n"
11687 + "int $4\n0:\n"
11688 + _ASM_EXTABLE(0b, 0b)
11689 +#endif
11690 +
11691 + "sete %1\n"
11692 : "+m" (v->counter), "=qm" (c)
11693 : "ir" (i) : "memory");
11694 return c;
11695 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11696 */
11697 static inline void atomic_inc(atomic_t *v)
11698 {
11699 - asm volatile(LOCK_PREFIX "incl %0"
11700 + asm volatile(LOCK_PREFIX "incl %0\n"
11701 +
11702 +#ifdef CONFIG_PAX_REFCOUNT
11703 + "jno 0f\n"
11704 + LOCK_PREFIX "decl %0\n"
11705 + "int $4\n0:\n"
11706 + _ASM_EXTABLE(0b, 0b)
11707 +#endif
11708 +
11709 + : "+m" (v->counter));
11710 +}
11711 +
11712 +/**
11713 + * atomic_inc_unchecked - increment atomic variable
11714 + * @v: pointer of type atomic_unchecked_t
11715 + *
11716 + * Atomically increments @v by 1.
11717 + */
11718 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11719 +{
11720 + asm volatile(LOCK_PREFIX "incl %0\n"
11721 : "+m" (v->counter));
11722 }
11723
11724 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11725 */
11726 static inline void atomic_dec(atomic_t *v)
11727 {
11728 - asm volatile(LOCK_PREFIX "decl %0"
11729 + asm volatile(LOCK_PREFIX "decl %0\n"
11730 +
11731 +#ifdef CONFIG_PAX_REFCOUNT
11732 + "jno 0f\n"
11733 + LOCK_PREFIX "incl %0\n"
11734 + "int $4\n0:\n"
11735 + _ASM_EXTABLE(0b, 0b)
11736 +#endif
11737 +
11738 + : "+m" (v->counter));
11739 +}
11740 +
11741 +/**
11742 + * atomic_dec_unchecked - decrement atomic variable
11743 + * @v: pointer of type atomic_unchecked_t
11744 + *
11745 + * Atomically decrements @v by 1.
11746 + */
11747 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11748 +{
11749 + asm volatile(LOCK_PREFIX "decl %0\n"
11750 : "+m" (v->counter));
11751 }
11752
11753 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11754 {
11755 unsigned char c;
11756
11757 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
11758 + asm volatile(LOCK_PREFIX "decl %0\n"
11759 +
11760 +#ifdef CONFIG_PAX_REFCOUNT
11761 + "jno 0f\n"
11762 + LOCK_PREFIX "incl %0\n"
11763 + "int $4\n0:\n"
11764 + _ASM_EXTABLE(0b, 0b)
11765 +#endif
11766 +
11767 + "sete %1\n"
11768 : "+m" (v->counter), "=qm" (c)
11769 : : "memory");
11770 return c != 0;
11771 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11772 {
11773 unsigned char c;
11774
11775 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
11776 + asm volatile(LOCK_PREFIX "incl %0\n"
11777 +
11778 +#ifdef CONFIG_PAX_REFCOUNT
11779 + "jno 0f\n"
11780 + LOCK_PREFIX "decl %0\n"
11781 + "int $4\n0:\n"
11782 + _ASM_EXTABLE(0b, 0b)
11783 +#endif
11784 +
11785 + "sete %1\n"
11786 + : "+m" (v->counter), "=qm" (c)
11787 + : : "memory");
11788 + return c != 0;
11789 +}
11790 +
11791 +/**
11792 + * atomic_inc_and_test_unchecked - increment and test
11793 + * @v: pointer of type atomic_unchecked_t
11794 + *
11795 + * Atomically increments @v by 1
11796 + * and returns true if the result is zero, or false for all
11797 + * other cases.
11798 + */
11799 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11800 +{
11801 + unsigned char c;
11802 +
11803 + asm volatile(LOCK_PREFIX "incl %0\n"
11804 + "sete %1\n"
11805 : "+m" (v->counter), "=qm" (c)
11806 : : "memory");
11807 return c != 0;
11808 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11809 {
11810 unsigned char c;
11811
11812 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11813 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
11814 +
11815 +#ifdef CONFIG_PAX_REFCOUNT
11816 + "jno 0f\n"
11817 + LOCK_PREFIX "subl %2,%0\n"
11818 + "int $4\n0:\n"
11819 + _ASM_EXTABLE(0b, 0b)
11820 +#endif
11821 +
11822 + "sets %1\n"
11823 : "+m" (v->counter), "=qm" (c)
11824 : "ir" (i) : "memory");
11825 return c;
11826 @@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11827 */
11828 static inline int atomic_add_return(int i, atomic_t *v)
11829 {
11830 + return i + xadd_check_overflow(&v->counter, i);
11831 +}
11832 +
11833 +/**
11834 + * atomic_add_return_unchecked - add integer and return
11835 + * @i: integer value to add
11836 + * @v: pointer of type atomic_unchecked_t
11837 + *
11838 + * Atomically adds @i to @v and returns @i + @v
11839 + */
11840 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
11841 +{
11842 return i + xadd(&v->counter, i);
11843 }
11844
11845 @@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
11846 }
11847
11848 #define atomic_inc_return(v) (atomic_add_return(1, v))
11849 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
11850 +{
11851 + return atomic_add_return_unchecked(1, v);
11852 +}
11853 #define atomic_dec_return(v) (atomic_sub_return(1, v))
11854
11855 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11856 @@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11857 return cmpxchg(&v->counter, old, new);
11858 }
11859
11860 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
11861 +{
11862 + return cmpxchg(&v->counter, old, new);
11863 +}
11864 +
11865 static inline int atomic_xchg(atomic_t *v, int new)
11866 {
11867 return xchg(&v->counter, new);
11868 }
11869
11870 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
11871 +{
11872 + return xchg(&v->counter, new);
11873 +}
11874 +
11875 /**
11876 * __atomic_add_unless - add unless the number is already a given value
11877 * @v: pointer of type atomic_t
11878 @@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
11879 */
11880 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11881 {
11882 - int c, old;
11883 + int c, old, new;
11884 c = atomic_read(v);
11885 for (;;) {
11886 - if (unlikely(c == (u)))
11887 + if (unlikely(c == u))
11888 break;
11889 - old = atomic_cmpxchg((v), c, c + (a));
11890 +
11891 + asm volatile("addl %2,%0\n"
11892 +
11893 +#ifdef CONFIG_PAX_REFCOUNT
11894 + "jno 0f\n"
11895 + "subl %2,%0\n"
11896 + "int $4\n0:\n"
11897 + _ASM_EXTABLE(0b, 0b)
11898 +#endif
11899 +
11900 + : "=r" (new)
11901 + : "0" (c), "ir" (a));
11902 +
11903 + old = atomic_cmpxchg(v, c, new);
11904 if (likely(old == c))
11905 break;
11906 c = old;
11907 @@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11908 }
11909
11910 /**
11911 + * atomic_inc_not_zero_hint - increment if not null
11912 + * @v: pointer of type atomic_t
11913 + * @hint: probable value of the atomic before the increment
11914 + *
11915 + * This version of atomic_inc_not_zero() gives a hint of probable
11916 + * value of the atomic. This helps processor to not read the memory
11917 + * before doing the atomic read/modify/write cycle, lowering
11918 + * number of bus transactions on some arches.
11919 + *
11920 + * Returns: 0 if increment was not done, 1 otherwise.
11921 + */
11922 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
11923 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
11924 +{
11925 + int val, c = hint, new;
11926 +
11927 + /* sanity test, should be removed by compiler if hint is a constant */
11928 + if (!hint)
11929 + return __atomic_add_unless(v, 1, 0);
11930 +
11931 + do {
11932 + asm volatile("incl %0\n"
11933 +
11934 +#ifdef CONFIG_PAX_REFCOUNT
11935 + "jno 0f\n"
11936 + "decl %0\n"
11937 + "int $4\n0:\n"
11938 + _ASM_EXTABLE(0b, 0b)
11939 +#endif
11940 +
11941 + : "=r" (new)
11942 + : "0" (c));
11943 +
11944 + val = atomic_cmpxchg(v, c, new);
11945 + if (val == c)
11946 + return 1;
11947 + c = val;
11948 + } while (c);
11949 +
11950 + return 0;
11951 +}
11952 +
11953 +/**
11954 * atomic_inc_short - increment of a short integer
11955 * @v: pointer to type int
11956 *
11957 @@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
11958 #endif
11959
11960 /* These are x86-specific, used by some header files */
11961 -#define atomic_clear_mask(mask, addr) \
11962 - asm volatile(LOCK_PREFIX "andl %0,%1" \
11963 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
11964 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
11965 +{
11966 + asm volatile(LOCK_PREFIX "andl %1,%0"
11967 + : "+m" (v->counter)
11968 + : "r" (~(mask))
11969 + : "memory");
11970 +}
11971
11972 -#define atomic_set_mask(mask, addr) \
11973 - asm volatile(LOCK_PREFIX "orl %0,%1" \
11974 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
11975 - : "memory")
11976 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11977 +{
11978 + asm volatile(LOCK_PREFIX "andl %1,%0"
11979 + : "+m" (v->counter)
11980 + : "r" (~(mask))
11981 + : "memory");
11982 +}
11983 +
11984 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
11985 +{
11986 + asm volatile(LOCK_PREFIX "orl %1,%0"
11987 + : "+m" (v->counter)
11988 + : "r" (mask)
11989 + : "memory");
11990 +}
11991 +
11992 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11993 +{
11994 + asm volatile(LOCK_PREFIX "orl %1,%0"
11995 + : "+m" (v->counter)
11996 + : "r" (mask)
11997 + : "memory");
11998 +}
11999
12000 /* Atomic operations are already serializing on x86 */
12001 #define smp_mb__before_atomic_dec() barrier()
12002 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12003 index b154de7..aadebd8 100644
12004 --- a/arch/x86/include/asm/atomic64_32.h
12005 +++ b/arch/x86/include/asm/atomic64_32.h
12006 @@ -12,6 +12,14 @@ typedef struct {
12007 u64 __aligned(8) counter;
12008 } atomic64_t;
12009
12010 +#ifdef CONFIG_PAX_REFCOUNT
12011 +typedef struct {
12012 + u64 __aligned(8) counter;
12013 +} atomic64_unchecked_t;
12014 +#else
12015 +typedef atomic64_t atomic64_unchecked_t;
12016 +#endif
12017 +
12018 #define ATOMIC64_INIT(val) { (val) }
12019
12020 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12021 @@ -37,21 +45,31 @@ typedef struct {
12022 ATOMIC64_DECL_ONE(sym##_386)
12023
12024 ATOMIC64_DECL_ONE(add_386);
12025 +ATOMIC64_DECL_ONE(add_unchecked_386);
12026 ATOMIC64_DECL_ONE(sub_386);
12027 +ATOMIC64_DECL_ONE(sub_unchecked_386);
12028 ATOMIC64_DECL_ONE(inc_386);
12029 +ATOMIC64_DECL_ONE(inc_unchecked_386);
12030 ATOMIC64_DECL_ONE(dec_386);
12031 +ATOMIC64_DECL_ONE(dec_unchecked_386);
12032 #endif
12033
12034 #define alternative_atomic64(f, out, in...) \
12035 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12036
12037 ATOMIC64_DECL(read);
12038 +ATOMIC64_DECL(read_unchecked);
12039 ATOMIC64_DECL(set);
12040 +ATOMIC64_DECL(set_unchecked);
12041 ATOMIC64_DECL(xchg);
12042 ATOMIC64_DECL(add_return);
12043 +ATOMIC64_DECL(add_return_unchecked);
12044 ATOMIC64_DECL(sub_return);
12045 +ATOMIC64_DECL(sub_return_unchecked);
12046 ATOMIC64_DECL(inc_return);
12047 +ATOMIC64_DECL(inc_return_unchecked);
12048 ATOMIC64_DECL(dec_return);
12049 +ATOMIC64_DECL(dec_return_unchecked);
12050 ATOMIC64_DECL(dec_if_positive);
12051 ATOMIC64_DECL(inc_not_zero);
12052 ATOMIC64_DECL(add_unless);
12053 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12054 }
12055
12056 /**
12057 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12058 + * @p: pointer to type atomic64_unchecked_t
12059 + * @o: expected value
12060 + * @n: new value
12061 + *
12062 + * Atomically sets @v to @n if it was equal to @o and returns
12063 + * the old value.
12064 + */
12065 +
12066 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12067 +{
12068 + return cmpxchg64(&v->counter, o, n);
12069 +}
12070 +
12071 +/**
12072 * atomic64_xchg - xchg atomic64 variable
12073 * @v: pointer to type atomic64_t
12074 * @n: value to assign
12075 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12076 }
12077
12078 /**
12079 + * atomic64_set_unchecked - set atomic64 variable
12080 + * @v: pointer to type atomic64_unchecked_t
12081 + * @n: value to assign
12082 + *
12083 + * Atomically sets the value of @v to @n.
12084 + */
12085 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12086 +{
12087 + unsigned high = (unsigned)(i >> 32);
12088 + unsigned low = (unsigned)i;
12089 + alternative_atomic64(set, /* no output */,
12090 + "S" (v), "b" (low), "c" (high)
12091 + : "eax", "edx", "memory");
12092 +}
12093 +
12094 +/**
12095 * atomic64_read - read atomic64 variable
12096 * @v: pointer to type atomic64_t
12097 *
12098 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12099 }
12100
12101 /**
12102 + * atomic64_read_unchecked - read atomic64 variable
12103 + * @v: pointer to type atomic64_unchecked_t
12104 + *
12105 + * Atomically reads the value of @v and returns it.
12106 + */
12107 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12108 +{
12109 + long long r;
12110 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12111 + return r;
12112 + }
12113 +
12114 +/**
12115 * atomic64_add_return - add and return
12116 * @i: integer value to add
12117 * @v: pointer to type atomic64_t
12118 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12119 return i;
12120 }
12121
12122 +/**
12123 + * atomic64_add_return_unchecked - add and return
12124 + * @i: integer value to add
12125 + * @v: pointer to type atomic64_unchecked_t
12126 + *
12127 + * Atomically adds @i to @v and returns @i + *@v
12128 + */
12129 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12130 +{
12131 + alternative_atomic64(add_return_unchecked,
12132 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12133 + ASM_NO_INPUT_CLOBBER("memory"));
12134 + return i;
12135 +}
12136 +
12137 /*
12138 * Other variants with different arithmetic operators:
12139 */
12140 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12141 return a;
12142 }
12143
12144 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12145 +{
12146 + long long a;
12147 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
12148 + "S" (v) : "memory", "ecx");
12149 + return a;
12150 +}
12151 +
12152 static inline long long atomic64_dec_return(atomic64_t *v)
12153 {
12154 long long a;
12155 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12156 }
12157
12158 /**
12159 + * atomic64_add_unchecked - add integer to atomic64 variable
12160 + * @i: integer value to add
12161 + * @v: pointer to type atomic64_unchecked_t
12162 + *
12163 + * Atomically adds @i to @v.
12164 + */
12165 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12166 +{
12167 + __alternative_atomic64(add_unchecked, add_return_unchecked,
12168 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12169 + ASM_NO_INPUT_CLOBBER("memory"));
12170 + return i;
12171 +}
12172 +
12173 +/**
12174 * atomic64_sub - subtract the atomic64 variable
12175 * @i: integer value to subtract
12176 * @v: pointer to type atomic64_t
12177 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12178 index 0e1cbfc..5623683 100644
12179 --- a/arch/x86/include/asm/atomic64_64.h
12180 +++ b/arch/x86/include/asm/atomic64_64.h
12181 @@ -18,7 +18,19 @@
12182 */
12183 static inline long atomic64_read(const atomic64_t *v)
12184 {
12185 - return (*(volatile long *)&(v)->counter);
12186 + return (*(volatile const long *)&(v)->counter);
12187 +}
12188 +
12189 +/**
12190 + * atomic64_read_unchecked - read atomic64 variable
12191 + * @v: pointer of type atomic64_unchecked_t
12192 + *
12193 + * Atomically reads the value of @v.
12194 + * Doesn't imply a read memory barrier.
12195 + */
12196 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12197 +{
12198 + return (*(volatile const long *)&(v)->counter);
12199 }
12200
12201 /**
12202 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12203 }
12204
12205 /**
12206 + * atomic64_set_unchecked - set atomic64 variable
12207 + * @v: pointer to type atomic64_unchecked_t
12208 + * @i: required value
12209 + *
12210 + * Atomically sets the value of @v to @i.
12211 + */
12212 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12213 +{
12214 + v->counter = i;
12215 +}
12216 +
12217 +/**
12218 * atomic64_add - add integer to atomic64 variable
12219 * @i: integer value to add
12220 * @v: pointer to type atomic64_t
12221 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12222 */
12223 static inline void atomic64_add(long i, atomic64_t *v)
12224 {
12225 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
12226 +
12227 +#ifdef CONFIG_PAX_REFCOUNT
12228 + "jno 0f\n"
12229 + LOCK_PREFIX "subq %1,%0\n"
12230 + "int $4\n0:\n"
12231 + _ASM_EXTABLE(0b, 0b)
12232 +#endif
12233 +
12234 + : "=m" (v->counter)
12235 + : "er" (i), "m" (v->counter));
12236 +}
12237 +
12238 +/**
12239 + * atomic64_add_unchecked - add integer to atomic64 variable
12240 + * @i: integer value to add
12241 + * @v: pointer to type atomic64_unchecked_t
12242 + *
12243 + * Atomically adds @i to @v.
12244 + */
12245 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12246 +{
12247 asm volatile(LOCK_PREFIX "addq %1,%0"
12248 : "=m" (v->counter)
12249 : "er" (i), "m" (v->counter));
12250 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12251 */
12252 static inline void atomic64_sub(long i, atomic64_t *v)
12253 {
12254 - asm volatile(LOCK_PREFIX "subq %1,%0"
12255 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12256 +
12257 +#ifdef CONFIG_PAX_REFCOUNT
12258 + "jno 0f\n"
12259 + LOCK_PREFIX "addq %1,%0\n"
12260 + "int $4\n0:\n"
12261 + _ASM_EXTABLE(0b, 0b)
12262 +#endif
12263 +
12264 + : "=m" (v->counter)
12265 + : "er" (i), "m" (v->counter));
12266 +}
12267 +
12268 +/**
12269 + * atomic64_sub_unchecked - subtract the atomic64 variable
12270 + * @i: integer value to subtract
12271 + * @v: pointer to type atomic64_unchecked_t
12272 + *
12273 + * Atomically subtracts @i from @v.
12274 + */
12275 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12276 +{
12277 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12278 : "=m" (v->counter)
12279 : "er" (i), "m" (v->counter));
12280 }
12281 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12282 {
12283 unsigned char c;
12284
12285 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12286 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
12287 +
12288 +#ifdef CONFIG_PAX_REFCOUNT
12289 + "jno 0f\n"
12290 + LOCK_PREFIX "addq %2,%0\n"
12291 + "int $4\n0:\n"
12292 + _ASM_EXTABLE(0b, 0b)
12293 +#endif
12294 +
12295 + "sete %1\n"
12296 : "=m" (v->counter), "=qm" (c)
12297 : "er" (i), "m" (v->counter) : "memory");
12298 return c;
12299 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12300 */
12301 static inline void atomic64_inc(atomic64_t *v)
12302 {
12303 + asm volatile(LOCK_PREFIX "incq %0\n"
12304 +
12305 +#ifdef CONFIG_PAX_REFCOUNT
12306 + "jno 0f\n"
12307 + LOCK_PREFIX "decq %0\n"
12308 + "int $4\n0:\n"
12309 + _ASM_EXTABLE(0b, 0b)
12310 +#endif
12311 +
12312 + : "=m" (v->counter)
12313 + : "m" (v->counter));
12314 +}
12315 +
12316 +/**
12317 + * atomic64_inc_unchecked - increment atomic64 variable
12318 + * @v: pointer to type atomic64_unchecked_t
12319 + *
12320 + * Atomically increments @v by 1.
12321 + */
12322 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12323 +{
12324 asm volatile(LOCK_PREFIX "incq %0"
12325 : "=m" (v->counter)
12326 : "m" (v->counter));
12327 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12328 */
12329 static inline void atomic64_dec(atomic64_t *v)
12330 {
12331 - asm volatile(LOCK_PREFIX "decq %0"
12332 + asm volatile(LOCK_PREFIX "decq %0\n"
12333 +
12334 +#ifdef CONFIG_PAX_REFCOUNT
12335 + "jno 0f\n"
12336 + LOCK_PREFIX "incq %0\n"
12337 + "int $4\n0:\n"
12338 + _ASM_EXTABLE(0b, 0b)
12339 +#endif
12340 +
12341 + : "=m" (v->counter)
12342 + : "m" (v->counter));
12343 +}
12344 +
12345 +/**
12346 + * atomic64_dec_unchecked - decrement atomic64 variable
12347 + * @v: pointer to type atomic64_t
12348 + *
12349 + * Atomically decrements @v by 1.
12350 + */
12351 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12352 +{
12353 + asm volatile(LOCK_PREFIX "decq %0\n"
12354 : "=m" (v->counter)
12355 : "m" (v->counter));
12356 }
12357 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12358 {
12359 unsigned char c;
12360
12361 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
12362 + asm volatile(LOCK_PREFIX "decq %0\n"
12363 +
12364 +#ifdef CONFIG_PAX_REFCOUNT
12365 + "jno 0f\n"
12366 + LOCK_PREFIX "incq %0\n"
12367 + "int $4\n0:\n"
12368 + _ASM_EXTABLE(0b, 0b)
12369 +#endif
12370 +
12371 + "sete %1\n"
12372 : "=m" (v->counter), "=qm" (c)
12373 : "m" (v->counter) : "memory");
12374 return c != 0;
12375 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12376 {
12377 unsigned char c;
12378
12379 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
12380 + asm volatile(LOCK_PREFIX "incq %0\n"
12381 +
12382 +#ifdef CONFIG_PAX_REFCOUNT
12383 + "jno 0f\n"
12384 + LOCK_PREFIX "decq %0\n"
12385 + "int $4\n0:\n"
12386 + _ASM_EXTABLE(0b, 0b)
12387 +#endif
12388 +
12389 + "sete %1\n"
12390 : "=m" (v->counter), "=qm" (c)
12391 : "m" (v->counter) : "memory");
12392 return c != 0;
12393 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12394 {
12395 unsigned char c;
12396
12397 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12398 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
12399 +
12400 +#ifdef CONFIG_PAX_REFCOUNT
12401 + "jno 0f\n"
12402 + LOCK_PREFIX "subq %2,%0\n"
12403 + "int $4\n0:\n"
12404 + _ASM_EXTABLE(0b, 0b)
12405 +#endif
12406 +
12407 + "sets %1\n"
12408 : "=m" (v->counter), "=qm" (c)
12409 : "er" (i), "m" (v->counter) : "memory");
12410 return c;
12411 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12412 */
12413 static inline long atomic64_add_return(long i, atomic64_t *v)
12414 {
12415 + return i + xadd_check_overflow(&v->counter, i);
12416 +}
12417 +
12418 +/**
12419 + * atomic64_add_return_unchecked - add and return
12420 + * @i: integer value to add
12421 + * @v: pointer to type atomic64_unchecked_t
12422 + *
12423 + * Atomically adds @i to @v and returns @i + @v
12424 + */
12425 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12426 +{
12427 return i + xadd(&v->counter, i);
12428 }
12429
12430 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12431 }
12432
12433 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12434 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12435 +{
12436 + return atomic64_add_return_unchecked(1, v);
12437 +}
12438 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12439
12440 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12441 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12442 return cmpxchg(&v->counter, old, new);
12443 }
12444
12445 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12446 +{
12447 + return cmpxchg(&v->counter, old, new);
12448 +}
12449 +
12450 static inline long atomic64_xchg(atomic64_t *v, long new)
12451 {
12452 return xchg(&v->counter, new);
12453 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12454 */
12455 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12456 {
12457 - long c, old;
12458 + long c, old, new;
12459 c = atomic64_read(v);
12460 for (;;) {
12461 - if (unlikely(c == (u)))
12462 + if (unlikely(c == u))
12463 break;
12464 - old = atomic64_cmpxchg((v), c, c + (a));
12465 +
12466 + asm volatile("add %2,%0\n"
12467 +
12468 +#ifdef CONFIG_PAX_REFCOUNT
12469 + "jno 0f\n"
12470 + "sub %2,%0\n"
12471 + "int $4\n0:\n"
12472 + _ASM_EXTABLE(0b, 0b)
12473 +#endif
12474 +
12475 + : "=r" (new)
12476 + : "0" (c), "ir" (a));
12477 +
12478 + old = atomic64_cmpxchg(v, c, new);
12479 if (likely(old == c))
12480 break;
12481 c = old;
12482 }
12483 - return c != (u);
12484 + return c != u;
12485 }
12486
12487 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12488 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12489 index 6dfd019..0c6699f 100644
12490 --- a/arch/x86/include/asm/bitops.h
12491 +++ b/arch/x86/include/asm/bitops.h
12492 @@ -40,7 +40,7 @@
12493 * a mask operation on a byte.
12494 */
12495 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12496 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12497 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12498 #define CONST_MASK(nr) (1 << ((nr) & 7))
12499
12500 /**
12501 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12502 index 4fa687a..60f2d39 100644
12503 --- a/arch/x86/include/asm/boot.h
12504 +++ b/arch/x86/include/asm/boot.h
12505 @@ -6,10 +6,15 @@
12506 #include <uapi/asm/boot.h>
12507
12508 /* Physical address where kernel should be loaded. */
12509 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12510 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12511 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12512 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12513
12514 +#ifndef __ASSEMBLY__
12515 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
12516 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12517 +#endif
12518 +
12519 /* Minimum kernel alignment, as a power of two */
12520 #ifdef CONFIG_X86_64
12521 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12522 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12523 index 48f99f1..d78ebf9 100644
12524 --- a/arch/x86/include/asm/cache.h
12525 +++ b/arch/x86/include/asm/cache.h
12526 @@ -5,12 +5,13 @@
12527
12528 /* L1 cache line size */
12529 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12530 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12531 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12532
12533 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12534 +#define __read_only __attribute__((__section__(".data..read_only")))
12535
12536 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12537 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12538 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12539
12540 #ifdef CONFIG_X86_VSMP
12541 #ifdef CONFIG_SMP
12542 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12543 index 9863ee3..4a1f8e1 100644
12544 --- a/arch/x86/include/asm/cacheflush.h
12545 +++ b/arch/x86/include/asm/cacheflush.h
12546 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12547 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12548
12549 if (pg_flags == _PGMT_DEFAULT)
12550 - return -1;
12551 + return ~0UL;
12552 else if (pg_flags == _PGMT_WC)
12553 return _PAGE_CACHE_WC;
12554 else if (pg_flags == _PGMT_UC_MINUS)
12555 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12556 index 46fc474..b02b0f9 100644
12557 --- a/arch/x86/include/asm/checksum_32.h
12558 +++ b/arch/x86/include/asm/checksum_32.h
12559 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12560 int len, __wsum sum,
12561 int *src_err_ptr, int *dst_err_ptr);
12562
12563 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12564 + int len, __wsum sum,
12565 + int *src_err_ptr, int *dst_err_ptr);
12566 +
12567 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12568 + int len, __wsum sum,
12569 + int *src_err_ptr, int *dst_err_ptr);
12570 +
12571 /*
12572 * Note: when you get a NULL pointer exception here this means someone
12573 * passed in an incorrect kernel address to one of these functions.
12574 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12575 int *err_ptr)
12576 {
12577 might_sleep();
12578 - return csum_partial_copy_generic((__force void *)src, dst,
12579 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
12580 len, sum, err_ptr, NULL);
12581 }
12582
12583 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12584 {
12585 might_sleep();
12586 if (access_ok(VERIFY_WRITE, dst, len))
12587 - return csum_partial_copy_generic(src, (__force void *)dst,
12588 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12589 len, sum, NULL, err_ptr);
12590
12591 if (len)
12592 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12593 index 8d871ea..c1a0dc9 100644
12594 --- a/arch/x86/include/asm/cmpxchg.h
12595 +++ b/arch/x86/include/asm/cmpxchg.h
12596 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12597 __compiletime_error("Bad argument size for cmpxchg");
12598 extern void __xadd_wrong_size(void)
12599 __compiletime_error("Bad argument size for xadd");
12600 +extern void __xadd_check_overflow_wrong_size(void)
12601 + __compiletime_error("Bad argument size for xadd_check_overflow");
12602 extern void __add_wrong_size(void)
12603 __compiletime_error("Bad argument size for add");
12604 +extern void __add_check_overflow_wrong_size(void)
12605 + __compiletime_error("Bad argument size for add_check_overflow");
12606
12607 /*
12608 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12609 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12610 __ret; \
12611 })
12612
12613 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12614 + ({ \
12615 + __typeof__ (*(ptr)) __ret = (arg); \
12616 + switch (sizeof(*(ptr))) { \
12617 + case __X86_CASE_L: \
12618 + asm volatile (lock #op "l %0, %1\n" \
12619 + "jno 0f\n" \
12620 + "mov %0,%1\n" \
12621 + "int $4\n0:\n" \
12622 + _ASM_EXTABLE(0b, 0b) \
12623 + : "+r" (__ret), "+m" (*(ptr)) \
12624 + : : "memory", "cc"); \
12625 + break; \
12626 + case __X86_CASE_Q: \
12627 + asm volatile (lock #op "q %q0, %1\n" \
12628 + "jno 0f\n" \
12629 + "mov %0,%1\n" \
12630 + "int $4\n0:\n" \
12631 + _ASM_EXTABLE(0b, 0b) \
12632 + : "+r" (__ret), "+m" (*(ptr)) \
12633 + : : "memory", "cc"); \
12634 + break; \
12635 + default: \
12636 + __ ## op ## _check_overflow_wrong_size(); \
12637 + } \
12638 + __ret; \
12639 + })
12640 +
12641 /*
12642 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12643 * Since this is generally used to protect other memory information, we
12644 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12645 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12646 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12647
12648 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12649 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12650 +
12651 #define __add(ptr, inc, lock) \
12652 ({ \
12653 __typeof__ (*(ptr)) __ret = (inc); \
12654 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12655 index 2d9075e..b75a844 100644
12656 --- a/arch/x86/include/asm/cpufeature.h
12657 +++ b/arch/x86/include/asm/cpufeature.h
12658 @@ -206,7 +206,7 @@
12659 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12660 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12661 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12662 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12663 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12664 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12665 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12666 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12667 @@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12668 ".section .discard,\"aw\",@progbits\n"
12669 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12670 ".previous\n"
12671 - ".section .altinstr_replacement,\"ax\"\n"
12672 + ".section .altinstr_replacement,\"a\"\n"
12673 "3: movb $1,%0\n"
12674 "4:\n"
12675 ".previous\n"
12676 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12677 index 8bf1c06..f723dfd 100644
12678 --- a/arch/x86/include/asm/desc.h
12679 +++ b/arch/x86/include/asm/desc.h
12680 @@ -4,6 +4,7 @@
12681 #include <asm/desc_defs.h>
12682 #include <asm/ldt.h>
12683 #include <asm/mmu.h>
12684 +#include <asm/pgtable.h>
12685
12686 #include <linux/smp.h>
12687 #include <linux/percpu.h>
12688 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12689
12690 desc->type = (info->read_exec_only ^ 1) << 1;
12691 desc->type |= info->contents << 2;
12692 + desc->type |= info->seg_not_present ^ 1;
12693
12694 desc->s = 1;
12695 desc->dpl = 0x3;
12696 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12697 }
12698
12699 extern struct desc_ptr idt_descr;
12700 -extern gate_desc idt_table[];
12701 extern struct desc_ptr nmi_idt_descr;
12702 -extern gate_desc nmi_idt_table[];
12703 -
12704 -struct gdt_page {
12705 - struct desc_struct gdt[GDT_ENTRIES];
12706 -} __attribute__((aligned(PAGE_SIZE)));
12707 -
12708 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12709 +extern gate_desc idt_table[256];
12710 +extern gate_desc nmi_idt_table[256];
12711
12712 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12713 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12714 {
12715 - return per_cpu(gdt_page, cpu).gdt;
12716 + return cpu_gdt_table[cpu];
12717 }
12718
12719 #ifdef CONFIG_X86_64
12720 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12721 unsigned long base, unsigned dpl, unsigned flags,
12722 unsigned short seg)
12723 {
12724 - gate->a = (seg << 16) | (base & 0xffff);
12725 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12726 + gate->gate.offset_low = base;
12727 + gate->gate.seg = seg;
12728 + gate->gate.reserved = 0;
12729 + gate->gate.type = type;
12730 + gate->gate.s = 0;
12731 + gate->gate.dpl = dpl;
12732 + gate->gate.p = 1;
12733 + gate->gate.offset_high = base >> 16;
12734 }
12735
12736 #endif
12737 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12738
12739 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12740 {
12741 + pax_open_kernel();
12742 memcpy(&idt[entry], gate, sizeof(*gate));
12743 + pax_close_kernel();
12744 }
12745
12746 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12747 {
12748 + pax_open_kernel();
12749 memcpy(&ldt[entry], desc, 8);
12750 + pax_close_kernel();
12751 }
12752
12753 static inline void
12754 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12755 default: size = sizeof(*gdt); break;
12756 }
12757
12758 + pax_open_kernel();
12759 memcpy(&gdt[entry], desc, size);
12760 + pax_close_kernel();
12761 }
12762
12763 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12764 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12765
12766 static inline void native_load_tr_desc(void)
12767 {
12768 + pax_open_kernel();
12769 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12770 + pax_close_kernel();
12771 }
12772
12773 static inline void native_load_gdt(const struct desc_ptr *dtr)
12774 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12775 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12776 unsigned int i;
12777
12778 + pax_open_kernel();
12779 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12780 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12781 + pax_close_kernel();
12782 }
12783
12784 #define _LDT_empty(info) \
12785 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12786 }
12787
12788 #ifdef CONFIG_X86_64
12789 -static inline void set_nmi_gate(int gate, void *addr)
12790 +static inline void set_nmi_gate(int gate, const void *addr)
12791 {
12792 gate_desc s;
12793
12794 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12795 }
12796 #endif
12797
12798 -static inline void _set_gate(int gate, unsigned type, void *addr,
12799 +static inline void _set_gate(int gate, unsigned type, const void *addr,
12800 unsigned dpl, unsigned ist, unsigned seg)
12801 {
12802 gate_desc s;
12803 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12804 * Pentium F0 0F bugfix can have resulted in the mapped
12805 * IDT being write-protected.
12806 */
12807 -static inline void set_intr_gate(unsigned int n, void *addr)
12808 +static inline void set_intr_gate(unsigned int n, const void *addr)
12809 {
12810 BUG_ON((unsigned)n > 0xFF);
12811 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12812 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12813 /*
12814 * This routine sets up an interrupt gate at directory privilege level 3.
12815 */
12816 -static inline void set_system_intr_gate(unsigned int n, void *addr)
12817 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
12818 {
12819 BUG_ON((unsigned)n > 0xFF);
12820 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12821 }
12822
12823 -static inline void set_system_trap_gate(unsigned int n, void *addr)
12824 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
12825 {
12826 BUG_ON((unsigned)n > 0xFF);
12827 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12828 }
12829
12830 -static inline void set_trap_gate(unsigned int n, void *addr)
12831 +static inline void set_trap_gate(unsigned int n, const void *addr)
12832 {
12833 BUG_ON((unsigned)n > 0xFF);
12834 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
12835 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
12836 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
12837 {
12838 BUG_ON((unsigned)n > 0xFF);
12839 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
12840 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
12841 }
12842
12843 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
12844 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
12845 {
12846 BUG_ON((unsigned)n > 0xFF);
12847 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
12848 }
12849
12850 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
12851 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
12852 {
12853 BUG_ON((unsigned)n > 0xFF);
12854 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
12855 }
12856
12857 +#ifdef CONFIG_X86_32
12858 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
12859 +{
12860 + struct desc_struct d;
12861 +
12862 + if (likely(limit))
12863 + limit = (limit - 1UL) >> PAGE_SHIFT;
12864 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
12865 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
12866 +}
12867 +#endif
12868 +
12869 #endif /* _ASM_X86_DESC_H */
12870 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
12871 index 278441f..b95a174 100644
12872 --- a/arch/x86/include/asm/desc_defs.h
12873 +++ b/arch/x86/include/asm/desc_defs.h
12874 @@ -31,6 +31,12 @@ struct desc_struct {
12875 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
12876 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
12877 };
12878 + struct {
12879 + u16 offset_low;
12880 + u16 seg;
12881 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
12882 + unsigned offset_high: 16;
12883 + } gate;
12884 };
12885 } __attribute__((packed));
12886
12887 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
12888 index 9c999c1..3860cb8 100644
12889 --- a/arch/x86/include/asm/elf.h
12890 +++ b/arch/x86/include/asm/elf.h
12891 @@ -243,7 +243,25 @@ extern int force_personality32;
12892 the loader. We need to make sure that it is out of the way of the program
12893 that it will "exec", and that there is sufficient room for the brk. */
12894
12895 +#ifdef CONFIG_PAX_SEGMEXEC
12896 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
12897 +#else
12898 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
12899 +#endif
12900 +
12901 +#ifdef CONFIG_PAX_ASLR
12902 +#ifdef CONFIG_X86_32
12903 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
12904 +
12905 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12906 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12907 +#else
12908 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
12909 +
12910 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12911 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12912 +#endif
12913 +#endif
12914
12915 /* This yields a mask that user programs can use to figure out what
12916 instruction set this CPU supports. This could be done in user space,
12917 @@ -296,16 +314,12 @@ do { \
12918
12919 #define ARCH_DLINFO \
12920 do { \
12921 - if (vdso_enabled) \
12922 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12923 - (unsigned long)current->mm->context.vdso); \
12924 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12925 } while (0)
12926
12927 #define ARCH_DLINFO_X32 \
12928 do { \
12929 - if (vdso_enabled) \
12930 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12931 - (unsigned long)current->mm->context.vdso); \
12932 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12933 } while (0)
12934
12935 #define AT_SYSINFO 32
12936 @@ -320,7 +334,7 @@ else \
12937
12938 #endif /* !CONFIG_X86_32 */
12939
12940 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
12941 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
12942
12943 #define VDSO_ENTRY \
12944 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
12945 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
12946 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
12947 #define compat_arch_setup_additional_pages syscall32_setup_pages
12948
12949 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
12950 -#define arch_randomize_brk arch_randomize_brk
12951 -
12952 /*
12953 * True on X86_32 or when emulating IA32 on X86_64
12954 */
12955 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
12956 index 75ce3f4..882e801 100644
12957 --- a/arch/x86/include/asm/emergency-restart.h
12958 +++ b/arch/x86/include/asm/emergency-restart.h
12959 @@ -13,6 +13,6 @@ enum reboot_type {
12960
12961 extern enum reboot_type reboot_type;
12962
12963 -extern void machine_emergency_restart(void);
12964 +extern void machine_emergency_restart(void) __noreturn;
12965
12966 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
12967 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
12968 index 41ab26e..a88c9e6 100644
12969 --- a/arch/x86/include/asm/fpu-internal.h
12970 +++ b/arch/x86/include/asm/fpu-internal.h
12971 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
12972 ({ \
12973 int err; \
12974 asm volatile(ASM_STAC "\n" \
12975 - "1:" #insn "\n\t" \
12976 + "1:" \
12977 + __copyuser_seg \
12978 + #insn "\n\t" \
12979 "2: " ASM_CLAC "\n" \
12980 ".section .fixup,\"ax\"\n" \
12981 "3: movl $-1,%[err]\n" \
12982 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
12983 "emms\n\t" /* clear stack tags */
12984 "fildl %P[addr]", /* set F?P to defined value */
12985 X86_FEATURE_FXSAVE_LEAK,
12986 - [addr] "m" (tsk->thread.fpu.has_fpu));
12987 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
12988
12989 return fpu_restore_checking(&tsk->thread.fpu);
12990 }
12991 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
12992 index be27ba1..8f13ff9 100644
12993 --- a/arch/x86/include/asm/futex.h
12994 +++ b/arch/x86/include/asm/futex.h
12995 @@ -12,6 +12,7 @@
12996 #include <asm/smap.h>
12997
12998 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
12999 + typecheck(u32 __user *, uaddr); \
13000 asm volatile("\t" ASM_STAC "\n" \
13001 "1:\t" insn "\n" \
13002 "2:\t" ASM_CLAC "\n" \
13003 @@ -20,15 +21,16 @@
13004 "\tjmp\t2b\n" \
13005 "\t.previous\n" \
13006 _ASM_EXTABLE(1b, 3b) \
13007 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13008 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13009 : "i" (-EFAULT), "0" (oparg), "1" (0))
13010
13011 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13012 + typecheck(u32 __user *, uaddr); \
13013 asm volatile("\t" ASM_STAC "\n" \
13014 "1:\tmovl %2, %0\n" \
13015 "\tmovl\t%0, %3\n" \
13016 "\t" insn "\n" \
13017 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13018 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13019 "\tjnz\t1b\n" \
13020 "3:\t" ASM_CLAC "\n" \
13021 "\t.section .fixup,\"ax\"\n" \
13022 @@ -38,7 +40,7 @@
13023 _ASM_EXTABLE(1b, 4b) \
13024 _ASM_EXTABLE(2b, 4b) \
13025 : "=&a" (oldval), "=&r" (ret), \
13026 - "+m" (*uaddr), "=&r" (tem) \
13027 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13028 : "r" (oparg), "i" (-EFAULT), "1" (0))
13029
13030 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13031 @@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13032
13033 switch (op) {
13034 case FUTEX_OP_SET:
13035 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13036 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13037 break;
13038 case FUTEX_OP_ADD:
13039 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13040 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13041 uaddr, oparg);
13042 break;
13043 case FUTEX_OP_OR:
13044 @@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13045 return -EFAULT;
13046
13047 asm volatile("\t" ASM_STAC "\n"
13048 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13049 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13050 "2:\t" ASM_CLAC "\n"
13051 "\t.section .fixup, \"ax\"\n"
13052 "3:\tmov %3, %0\n"
13053 "\tjmp 2b\n"
13054 "\t.previous\n"
13055 _ASM_EXTABLE(1b, 3b)
13056 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13057 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13058 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13059 : "memory"
13060 );
13061 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13062 index eb92a6e..b98b2f4 100644
13063 --- a/arch/x86/include/asm/hw_irq.h
13064 +++ b/arch/x86/include/asm/hw_irq.h
13065 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13066 extern void enable_IO_APIC(void);
13067
13068 /* Statistics */
13069 -extern atomic_t irq_err_count;
13070 -extern atomic_t irq_mis_count;
13071 +extern atomic_unchecked_t irq_err_count;
13072 +extern atomic_unchecked_t irq_mis_count;
13073
13074 /* EISA */
13075 extern void eisa_set_level_irq(unsigned int irq);
13076 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13077 index d8e8eef..15b1179 100644
13078 --- a/arch/x86/include/asm/io.h
13079 +++ b/arch/x86/include/asm/io.h
13080 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13081 return ioremap_nocache(offset, size);
13082 }
13083
13084 -extern void iounmap(volatile void __iomem *addr);
13085 +extern void iounmap(const volatile void __iomem *addr);
13086
13087 extern void set_iounmap_nonlazy(void);
13088
13089 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13090
13091 #include <linux/vmalloc.h>
13092
13093 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13094 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13095 +{
13096 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13097 +}
13098 +
13099 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13100 +{
13101 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13102 +}
13103 +
13104 /*
13105 * Convert a virtual cached pointer to an uncached pointer
13106 */
13107 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13108 index bba3cf8..06bc8da 100644
13109 --- a/arch/x86/include/asm/irqflags.h
13110 +++ b/arch/x86/include/asm/irqflags.h
13111 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13112 sti; \
13113 sysexit
13114
13115 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
13116 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13117 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
13118 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13119 +
13120 #else
13121 #define INTERRUPT_RETURN iret
13122 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13123 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13124 index d3ddd17..c9fb0cc 100644
13125 --- a/arch/x86/include/asm/kprobes.h
13126 +++ b/arch/x86/include/asm/kprobes.h
13127 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13128 #define RELATIVEJUMP_SIZE 5
13129 #define RELATIVECALL_OPCODE 0xe8
13130 #define RELATIVE_ADDR_SIZE 4
13131 -#define MAX_STACK_SIZE 64
13132 -#define MIN_STACK_SIZE(ADDR) \
13133 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13134 - THREAD_SIZE - (unsigned long)(ADDR))) \
13135 - ? (MAX_STACK_SIZE) \
13136 - : (((unsigned long)current_thread_info()) + \
13137 - THREAD_SIZE - (unsigned long)(ADDR)))
13138 +#define MAX_STACK_SIZE 64UL
13139 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13140
13141 #define flush_insn_slot(p) do { } while (0)
13142
13143 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13144 index 2d89e39..baee879 100644
13145 --- a/arch/x86/include/asm/local.h
13146 +++ b/arch/x86/include/asm/local.h
13147 @@ -10,33 +10,97 @@ typedef struct {
13148 atomic_long_t a;
13149 } local_t;
13150
13151 +typedef struct {
13152 + atomic_long_unchecked_t a;
13153 +} local_unchecked_t;
13154 +
13155 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13156
13157 #define local_read(l) atomic_long_read(&(l)->a)
13158 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13159 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13160 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13161
13162 static inline void local_inc(local_t *l)
13163 {
13164 - asm volatile(_ASM_INC "%0"
13165 + asm volatile(_ASM_INC "%0\n"
13166 +
13167 +#ifdef CONFIG_PAX_REFCOUNT
13168 + "jno 0f\n"
13169 + _ASM_DEC "%0\n"
13170 + "int $4\n0:\n"
13171 + _ASM_EXTABLE(0b, 0b)
13172 +#endif
13173 +
13174 + : "+m" (l->a.counter));
13175 +}
13176 +
13177 +static inline void local_inc_unchecked(local_unchecked_t *l)
13178 +{
13179 + asm volatile(_ASM_INC "%0\n"
13180 : "+m" (l->a.counter));
13181 }
13182
13183 static inline void local_dec(local_t *l)
13184 {
13185 - asm volatile(_ASM_DEC "%0"
13186 + asm volatile(_ASM_DEC "%0\n"
13187 +
13188 +#ifdef CONFIG_PAX_REFCOUNT
13189 + "jno 0f\n"
13190 + _ASM_INC "%0\n"
13191 + "int $4\n0:\n"
13192 + _ASM_EXTABLE(0b, 0b)
13193 +#endif
13194 +
13195 + : "+m" (l->a.counter));
13196 +}
13197 +
13198 +static inline void local_dec_unchecked(local_unchecked_t *l)
13199 +{
13200 + asm volatile(_ASM_DEC "%0\n"
13201 : "+m" (l->a.counter));
13202 }
13203
13204 static inline void local_add(long i, local_t *l)
13205 {
13206 - asm volatile(_ASM_ADD "%1,%0"
13207 + asm volatile(_ASM_ADD "%1,%0\n"
13208 +
13209 +#ifdef CONFIG_PAX_REFCOUNT
13210 + "jno 0f\n"
13211 + _ASM_SUB "%1,%0\n"
13212 + "int $4\n0:\n"
13213 + _ASM_EXTABLE(0b, 0b)
13214 +#endif
13215 +
13216 + : "+m" (l->a.counter)
13217 + : "ir" (i));
13218 +}
13219 +
13220 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
13221 +{
13222 + asm volatile(_ASM_ADD "%1,%0\n"
13223 : "+m" (l->a.counter)
13224 : "ir" (i));
13225 }
13226
13227 static inline void local_sub(long i, local_t *l)
13228 {
13229 - asm volatile(_ASM_SUB "%1,%0"
13230 + asm volatile(_ASM_SUB "%1,%0\n"
13231 +
13232 +#ifdef CONFIG_PAX_REFCOUNT
13233 + "jno 0f\n"
13234 + _ASM_ADD "%1,%0\n"
13235 + "int $4\n0:\n"
13236 + _ASM_EXTABLE(0b, 0b)
13237 +#endif
13238 +
13239 + : "+m" (l->a.counter)
13240 + : "ir" (i));
13241 +}
13242 +
13243 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13244 +{
13245 + asm volatile(_ASM_SUB "%1,%0\n"
13246 : "+m" (l->a.counter)
13247 : "ir" (i));
13248 }
13249 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13250 {
13251 unsigned char c;
13252
13253 - asm volatile(_ASM_SUB "%2,%0; sete %1"
13254 + asm volatile(_ASM_SUB "%2,%0\n"
13255 +
13256 +#ifdef CONFIG_PAX_REFCOUNT
13257 + "jno 0f\n"
13258 + _ASM_ADD "%2,%0\n"
13259 + "int $4\n0:\n"
13260 + _ASM_EXTABLE(0b, 0b)
13261 +#endif
13262 +
13263 + "sete %1\n"
13264 : "+m" (l->a.counter), "=qm" (c)
13265 : "ir" (i) : "memory");
13266 return c;
13267 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13268 {
13269 unsigned char c;
13270
13271 - asm volatile(_ASM_DEC "%0; sete %1"
13272 + asm volatile(_ASM_DEC "%0\n"
13273 +
13274 +#ifdef CONFIG_PAX_REFCOUNT
13275 + "jno 0f\n"
13276 + _ASM_INC "%0\n"
13277 + "int $4\n0:\n"
13278 + _ASM_EXTABLE(0b, 0b)
13279 +#endif
13280 +
13281 + "sete %1\n"
13282 : "+m" (l->a.counter), "=qm" (c)
13283 : : "memory");
13284 return c != 0;
13285 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13286 {
13287 unsigned char c;
13288
13289 - asm volatile(_ASM_INC "%0; sete %1"
13290 + asm volatile(_ASM_INC "%0\n"
13291 +
13292 +#ifdef CONFIG_PAX_REFCOUNT
13293 + "jno 0f\n"
13294 + _ASM_DEC "%0\n"
13295 + "int $4\n0:\n"
13296 + _ASM_EXTABLE(0b, 0b)
13297 +#endif
13298 +
13299 + "sete %1\n"
13300 : "+m" (l->a.counter), "=qm" (c)
13301 : : "memory");
13302 return c != 0;
13303 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13304 {
13305 unsigned char c;
13306
13307 - asm volatile(_ASM_ADD "%2,%0; sets %1"
13308 + asm volatile(_ASM_ADD "%2,%0\n"
13309 +
13310 +#ifdef CONFIG_PAX_REFCOUNT
13311 + "jno 0f\n"
13312 + _ASM_SUB "%2,%0\n"
13313 + "int $4\n0:\n"
13314 + _ASM_EXTABLE(0b, 0b)
13315 +#endif
13316 +
13317 + "sets %1\n"
13318 : "+m" (l->a.counter), "=qm" (c)
13319 : "ir" (i) : "memory");
13320 return c;
13321 @@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13322 static inline long local_add_return(long i, local_t *l)
13323 {
13324 long __i = i;
13325 + asm volatile(_ASM_XADD "%0, %1\n"
13326 +
13327 +#ifdef CONFIG_PAX_REFCOUNT
13328 + "jno 0f\n"
13329 + _ASM_MOV "%0,%1\n"
13330 + "int $4\n0:\n"
13331 + _ASM_EXTABLE(0b, 0b)
13332 +#endif
13333 +
13334 + : "+r" (i), "+m" (l->a.counter)
13335 + : : "memory");
13336 + return i + __i;
13337 +}
13338 +
13339 +/**
13340 + * local_add_return_unchecked - add and return
13341 + * @i: integer value to add
13342 + * @l: pointer to type local_unchecked_t
13343 + *
13344 + * Atomically adds @i to @l and returns @i + @l
13345 + */
13346 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13347 +{
13348 + long __i = i;
13349 asm volatile(_ASM_XADD "%0, %1;"
13350 : "+r" (i), "+m" (l->a.counter)
13351 : : "memory");
13352 @@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13353
13354 #define local_cmpxchg(l, o, n) \
13355 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13356 +#define local_cmpxchg_unchecked(l, o, n) \
13357 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
13358 /* Always has a lock prefix */
13359 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13360
13361 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13362 new file mode 100644
13363 index 0000000..2bfd3ba
13364 --- /dev/null
13365 +++ b/arch/x86/include/asm/mman.h
13366 @@ -0,0 +1,15 @@
13367 +#ifndef _X86_MMAN_H
13368 +#define _X86_MMAN_H
13369 +
13370 +#include <uapi/asm/mman.h>
13371 +
13372 +#ifdef __KERNEL__
13373 +#ifndef __ASSEMBLY__
13374 +#ifdef CONFIG_X86_32
13375 +#define arch_mmap_check i386_mmap_check
13376 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13377 +#endif
13378 +#endif
13379 +#endif
13380 +
13381 +#endif /* X86_MMAN_H */
13382 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13383 index 5f55e69..e20bfb1 100644
13384 --- a/arch/x86/include/asm/mmu.h
13385 +++ b/arch/x86/include/asm/mmu.h
13386 @@ -9,7 +9,7 @@
13387 * we put the segment information here.
13388 */
13389 typedef struct {
13390 - void *ldt;
13391 + struct desc_struct *ldt;
13392 int size;
13393
13394 #ifdef CONFIG_X86_64
13395 @@ -18,7 +18,19 @@ typedef struct {
13396 #endif
13397
13398 struct mutex lock;
13399 - void *vdso;
13400 + unsigned long vdso;
13401 +
13402 +#ifdef CONFIG_X86_32
13403 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13404 + unsigned long user_cs_base;
13405 + unsigned long user_cs_limit;
13406 +
13407 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13408 + cpumask_t cpu_user_cs_mask;
13409 +#endif
13410 +
13411 +#endif
13412 +#endif
13413 } mm_context_t;
13414
13415 #ifdef CONFIG_SMP
13416 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13417 index cdbf367..adb37ac 100644
13418 --- a/arch/x86/include/asm/mmu_context.h
13419 +++ b/arch/x86/include/asm/mmu_context.h
13420 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13421
13422 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13423 {
13424 +
13425 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13426 + unsigned int i;
13427 + pgd_t *pgd;
13428 +
13429 + pax_open_kernel();
13430 + pgd = get_cpu_pgd(smp_processor_id());
13431 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13432 + set_pgd_batched(pgd+i, native_make_pgd(0));
13433 + pax_close_kernel();
13434 +#endif
13435 +
13436 #ifdef CONFIG_SMP
13437 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13438 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13439 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13440 struct task_struct *tsk)
13441 {
13442 unsigned cpu = smp_processor_id();
13443 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13444 + int tlbstate = TLBSTATE_OK;
13445 +#endif
13446
13447 if (likely(prev != next)) {
13448 #ifdef CONFIG_SMP
13449 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13450 + tlbstate = this_cpu_read(cpu_tlbstate.state);
13451 +#endif
13452 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13453 this_cpu_write(cpu_tlbstate.active_mm, next);
13454 #endif
13455 cpumask_set_cpu(cpu, mm_cpumask(next));
13456
13457 /* Re-load page tables */
13458 +#ifdef CONFIG_PAX_PER_CPU_PGD
13459 + pax_open_kernel();
13460 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13461 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13462 + pax_close_kernel();
13463 + load_cr3(get_cpu_pgd(cpu));
13464 +#else
13465 load_cr3(next->pgd);
13466 +#endif
13467
13468 /* stop flush ipis for the previous mm */
13469 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13470 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13471 */
13472 if (unlikely(prev->context.ldt != next->context.ldt))
13473 load_LDT_nolock(&next->context);
13474 - }
13475 +
13476 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13477 + if (!(__supported_pte_mask & _PAGE_NX)) {
13478 + smp_mb__before_clear_bit();
13479 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13480 + smp_mb__after_clear_bit();
13481 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13482 + }
13483 +#endif
13484 +
13485 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13486 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13487 + prev->context.user_cs_limit != next->context.user_cs_limit))
13488 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13489 #ifdef CONFIG_SMP
13490 + else if (unlikely(tlbstate != TLBSTATE_OK))
13491 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13492 +#endif
13493 +#endif
13494 +
13495 + }
13496 else {
13497 +
13498 +#ifdef CONFIG_PAX_PER_CPU_PGD
13499 + pax_open_kernel();
13500 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13501 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13502 + pax_close_kernel();
13503 + load_cr3(get_cpu_pgd(cpu));
13504 +#endif
13505 +
13506 +#ifdef CONFIG_SMP
13507 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13508 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13509
13510 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13511 * tlb flush IPI delivery. We must reload CR3
13512 * to make sure to use no freed page tables.
13513 */
13514 +
13515 +#ifndef CONFIG_PAX_PER_CPU_PGD
13516 load_cr3(next->pgd);
13517 +#endif
13518 +
13519 load_LDT_nolock(&next->context);
13520 +
13521 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13522 + if (!(__supported_pte_mask & _PAGE_NX))
13523 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13524 +#endif
13525 +
13526 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13527 +#ifdef CONFIG_PAX_PAGEEXEC
13528 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13529 +#endif
13530 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13531 +#endif
13532 +
13533 }
13534 +#endif
13535 }
13536 -#endif
13537 }
13538
13539 #define activate_mm(prev, next) \
13540 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13541 index e3b7819..b257c64 100644
13542 --- a/arch/x86/include/asm/module.h
13543 +++ b/arch/x86/include/asm/module.h
13544 @@ -5,6 +5,7 @@
13545
13546 #ifdef CONFIG_X86_64
13547 /* X86_64 does not define MODULE_PROC_FAMILY */
13548 +#define MODULE_PROC_FAMILY ""
13549 #elif defined CONFIG_M486
13550 #define MODULE_PROC_FAMILY "486 "
13551 #elif defined CONFIG_M586
13552 @@ -57,8 +58,20 @@
13553 #error unknown processor family
13554 #endif
13555
13556 -#ifdef CONFIG_X86_32
13557 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13558 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13559 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13560 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13561 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13562 +#else
13563 +#define MODULE_PAX_KERNEXEC ""
13564 #endif
13565
13566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13567 +#define MODULE_PAX_UDEREF "UDEREF "
13568 +#else
13569 +#define MODULE_PAX_UDEREF ""
13570 +#endif
13571 +
13572 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13573 +
13574 #endif /* _ASM_X86_MODULE_H */
13575 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13576 index 320f7bb..e89f8f8 100644
13577 --- a/arch/x86/include/asm/page_64_types.h
13578 +++ b/arch/x86/include/asm/page_64_types.h
13579 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13580
13581 /* duplicated to the one in bootmem.h */
13582 extern unsigned long max_pfn;
13583 -extern unsigned long phys_base;
13584 +extern const unsigned long phys_base;
13585
13586 extern unsigned long __phys_addr(unsigned long);
13587 #define __phys_reloc_hide(x) (x)
13588 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13589 index 5edd174..9cf5821 100644
13590 --- a/arch/x86/include/asm/paravirt.h
13591 +++ b/arch/x86/include/asm/paravirt.h
13592 @@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13593 val);
13594 }
13595
13596 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13597 +{
13598 + pgdval_t val = native_pgd_val(pgd);
13599 +
13600 + if (sizeof(pgdval_t) > sizeof(long))
13601 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13602 + val, (u64)val >> 32);
13603 + else
13604 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13605 + val);
13606 +}
13607 +
13608 static inline void pgd_clear(pgd_t *pgdp)
13609 {
13610 set_pgd(pgdp, __pgd(0));
13611 @@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13612 pv_mmu_ops.set_fixmap(idx, phys, flags);
13613 }
13614
13615 +#ifdef CONFIG_PAX_KERNEXEC
13616 +static inline unsigned long pax_open_kernel(void)
13617 +{
13618 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13619 +}
13620 +
13621 +static inline unsigned long pax_close_kernel(void)
13622 +{
13623 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13624 +}
13625 +#else
13626 +static inline unsigned long pax_open_kernel(void) { return 0; }
13627 +static inline unsigned long pax_close_kernel(void) { return 0; }
13628 +#endif
13629 +
13630 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13631
13632 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13633 @@ -927,7 +954,7 @@ extern void default_banner(void);
13634
13635 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13636 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13637 -#define PARA_INDIRECT(addr) *%cs:addr
13638 +#define PARA_INDIRECT(addr) *%ss:addr
13639 #endif
13640
13641 #define INTERRUPT_RETURN \
13642 @@ -1002,6 +1029,21 @@ extern void default_banner(void);
13643 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13644 CLBR_NONE, \
13645 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13646 +
13647 +#define GET_CR0_INTO_RDI \
13648 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13649 + mov %rax,%rdi
13650 +
13651 +#define SET_RDI_INTO_CR0 \
13652 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13653 +
13654 +#define GET_CR3_INTO_RDI \
13655 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13656 + mov %rax,%rdi
13657 +
13658 +#define SET_RDI_INTO_CR3 \
13659 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13660 +
13661 #endif /* CONFIG_X86_32 */
13662
13663 #endif /* __ASSEMBLY__ */
13664 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13665 index 142236e..5446ffbc 100644
13666 --- a/arch/x86/include/asm/paravirt_types.h
13667 +++ b/arch/x86/include/asm/paravirt_types.h
13668 @@ -84,7 +84,7 @@ struct pv_init_ops {
13669 */
13670 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13671 unsigned long addr, unsigned len);
13672 -};
13673 +} __no_const;
13674
13675
13676 struct pv_lazy_ops {
13677 @@ -97,7 +97,7 @@ struct pv_time_ops {
13678 unsigned long long (*sched_clock)(void);
13679 unsigned long long (*steal_clock)(int cpu);
13680 unsigned long (*get_tsc_khz)(void);
13681 -};
13682 +} __no_const;
13683
13684 struct pv_cpu_ops {
13685 /* hooks for various privileged instructions */
13686 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
13687
13688 void (*start_context_switch)(struct task_struct *prev);
13689 void (*end_context_switch)(struct task_struct *next);
13690 -};
13691 +} __no_const;
13692
13693 struct pv_irq_ops {
13694 /*
13695 @@ -222,7 +222,7 @@ struct pv_apic_ops {
13696 unsigned long start_eip,
13697 unsigned long start_esp);
13698 #endif
13699 -};
13700 +} __no_const;
13701
13702 struct pv_mmu_ops {
13703 unsigned long (*read_cr2)(void);
13704 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
13705 struct paravirt_callee_save make_pud;
13706
13707 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13708 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13709 #endif /* PAGETABLE_LEVELS == 4 */
13710 #endif /* PAGETABLE_LEVELS >= 3 */
13711
13712 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
13713 an mfn. We can tell which is which from the index. */
13714 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13715 phys_addr_t phys, pgprot_t flags);
13716 +
13717 +#ifdef CONFIG_PAX_KERNEXEC
13718 + unsigned long (*pax_open_kernel)(void);
13719 + unsigned long (*pax_close_kernel)(void);
13720 +#endif
13721 +
13722 };
13723
13724 struct arch_spinlock;
13725 @@ -333,7 +340,7 @@ struct pv_lock_ops {
13726 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13727 int (*spin_trylock)(struct arch_spinlock *lock);
13728 void (*spin_unlock)(struct arch_spinlock *lock);
13729 -};
13730 +} __no_const;
13731
13732 /* This contains all the paravirt structures: we get a convenient
13733 * number for each function using the offset which we use to indicate
13734 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13735 index b4389a4..7024269 100644
13736 --- a/arch/x86/include/asm/pgalloc.h
13737 +++ b/arch/x86/include/asm/pgalloc.h
13738 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13739 pmd_t *pmd, pte_t *pte)
13740 {
13741 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13742 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13743 +}
13744 +
13745 +static inline void pmd_populate_user(struct mm_struct *mm,
13746 + pmd_t *pmd, pte_t *pte)
13747 +{
13748 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13749 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13750 }
13751
13752 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13753
13754 #ifdef CONFIG_X86_PAE
13755 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13756 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13757 +{
13758 + pud_populate(mm, pudp, pmd);
13759 +}
13760 #else /* !CONFIG_X86_PAE */
13761 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13762 {
13763 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13764 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13765 }
13766 +
13767 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13768 +{
13769 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13770 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13771 +}
13772 #endif /* CONFIG_X86_PAE */
13773
13774 #if PAGETABLE_LEVELS > 3
13775 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13776 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13777 }
13778
13779 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13780 +{
13781 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13782 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13783 +}
13784 +
13785 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13786 {
13787 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13788 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13789 index f2b489c..4f7e2e5 100644
13790 --- a/arch/x86/include/asm/pgtable-2level.h
13791 +++ b/arch/x86/include/asm/pgtable-2level.h
13792 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
13793
13794 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13795 {
13796 + pax_open_kernel();
13797 *pmdp = pmd;
13798 + pax_close_kernel();
13799 }
13800
13801 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13802 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
13803 index 4cc9f2b..5fd9226 100644
13804 --- a/arch/x86/include/asm/pgtable-3level.h
13805 +++ b/arch/x86/include/asm/pgtable-3level.h
13806 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13807
13808 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13809 {
13810 + pax_open_kernel();
13811 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
13812 + pax_close_kernel();
13813 }
13814
13815 static inline void native_set_pud(pud_t *pudp, pud_t pud)
13816 {
13817 + pax_open_kernel();
13818 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
13819 + pax_close_kernel();
13820 }
13821
13822 /*
13823 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
13824 index 1c1a955..50f828c 100644
13825 --- a/arch/x86/include/asm/pgtable.h
13826 +++ b/arch/x86/include/asm/pgtable.h
13827 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13828
13829 #ifndef __PAGETABLE_PUD_FOLDED
13830 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
13831 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
13832 #define pgd_clear(pgd) native_pgd_clear(pgd)
13833 #endif
13834
13835 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13836
13837 #define arch_end_context_switch(prev) do {} while(0)
13838
13839 +#define pax_open_kernel() native_pax_open_kernel()
13840 +#define pax_close_kernel() native_pax_close_kernel()
13841 #endif /* CONFIG_PARAVIRT */
13842
13843 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
13844 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
13845 +
13846 +#ifdef CONFIG_PAX_KERNEXEC
13847 +static inline unsigned long native_pax_open_kernel(void)
13848 +{
13849 + unsigned long cr0;
13850 +
13851 + preempt_disable();
13852 + barrier();
13853 + cr0 = read_cr0() ^ X86_CR0_WP;
13854 + BUG_ON(cr0 & X86_CR0_WP);
13855 + write_cr0(cr0);
13856 + return cr0 ^ X86_CR0_WP;
13857 +}
13858 +
13859 +static inline unsigned long native_pax_close_kernel(void)
13860 +{
13861 + unsigned long cr0;
13862 +
13863 + cr0 = read_cr0() ^ X86_CR0_WP;
13864 + BUG_ON(!(cr0 & X86_CR0_WP));
13865 + write_cr0(cr0);
13866 + barrier();
13867 + preempt_enable_no_resched();
13868 + return cr0 ^ X86_CR0_WP;
13869 +}
13870 +#else
13871 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
13872 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
13873 +#endif
13874 +
13875 /*
13876 * The following only work if pte_present() is true.
13877 * Undefined behaviour if not..
13878 */
13879 +static inline int pte_user(pte_t pte)
13880 +{
13881 + return pte_val(pte) & _PAGE_USER;
13882 +}
13883 +
13884 static inline int pte_dirty(pte_t pte)
13885 {
13886 return pte_flags(pte) & _PAGE_DIRTY;
13887 @@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
13888 return pte_clear_flags(pte, _PAGE_RW);
13889 }
13890
13891 +static inline pte_t pte_mkread(pte_t pte)
13892 +{
13893 + return __pte(pte_val(pte) | _PAGE_USER);
13894 +}
13895 +
13896 static inline pte_t pte_mkexec(pte_t pte)
13897 {
13898 - return pte_clear_flags(pte, _PAGE_NX);
13899 +#ifdef CONFIG_X86_PAE
13900 + if (__supported_pte_mask & _PAGE_NX)
13901 + return pte_clear_flags(pte, _PAGE_NX);
13902 + else
13903 +#endif
13904 + return pte_set_flags(pte, _PAGE_USER);
13905 +}
13906 +
13907 +static inline pte_t pte_exprotect(pte_t pte)
13908 +{
13909 +#ifdef CONFIG_X86_PAE
13910 + if (__supported_pte_mask & _PAGE_NX)
13911 + return pte_set_flags(pte, _PAGE_NX);
13912 + else
13913 +#endif
13914 + return pte_clear_flags(pte, _PAGE_USER);
13915 }
13916
13917 static inline pte_t pte_mkdirty(pte_t pte)
13918 @@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
13919 #endif
13920
13921 #ifndef __ASSEMBLY__
13922 +
13923 +#ifdef CONFIG_PAX_PER_CPU_PGD
13924 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
13925 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
13926 +{
13927 + return cpu_pgd[cpu];
13928 +}
13929 +#endif
13930 +
13931 #include <linux/mm_types.h>
13932
13933 static inline int pte_none(pte_t pte)
13934 @@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
13935
13936 static inline int pgd_bad(pgd_t pgd)
13937 {
13938 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
13939 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
13940 }
13941
13942 static inline int pgd_none(pgd_t pgd)
13943 @@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
13944 * pgd_offset() returns a (pgd_t *)
13945 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
13946 */
13947 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
13948 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
13949 +
13950 +#ifdef CONFIG_PAX_PER_CPU_PGD
13951 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
13952 +#endif
13953 +
13954 /*
13955 * a shortcut which implies the use of the kernel's pgd, instead
13956 * of a process's
13957 @@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
13958 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
13959 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
13960
13961 +#ifdef CONFIG_X86_32
13962 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
13963 +#else
13964 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
13965 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
13966 +
13967 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13968 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
13969 +#else
13970 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
13971 +#endif
13972 +
13973 +#endif
13974 +
13975 #ifndef __ASSEMBLY__
13976
13977 extern int direct_gbpages;
13978 @@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
13979 * dst and src can be on the same page, but the range must not overlap,
13980 * and must not cross a page boundary.
13981 */
13982 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
13983 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
13984 {
13985 - memcpy(dst, src, count * sizeof(pgd_t));
13986 + pax_open_kernel();
13987 + while (count--)
13988 + *dst++ = *src++;
13989 + pax_close_kernel();
13990 }
13991
13992 +#ifdef CONFIG_PAX_PER_CPU_PGD
13993 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
13994 +#endif
13995 +
13996 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13997 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
13998 +#else
13999 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14000 +#endif
14001
14002 #include <asm-generic/pgtable.h>
14003 #endif /* __ASSEMBLY__ */
14004 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14005 index 8faa215..a8a17ea 100644
14006 --- a/arch/x86/include/asm/pgtable_32.h
14007 +++ b/arch/x86/include/asm/pgtable_32.h
14008 @@ -25,9 +25,6 @@
14009 struct mm_struct;
14010 struct vm_area_struct;
14011
14012 -extern pgd_t swapper_pg_dir[1024];
14013 -extern pgd_t initial_page_table[1024];
14014 -
14015 static inline void pgtable_cache_init(void) { }
14016 static inline void check_pgt_cache(void) { }
14017 void paging_init(void);
14018 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14019 # include <asm/pgtable-2level.h>
14020 #endif
14021
14022 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14023 +extern pgd_t initial_page_table[PTRS_PER_PGD];
14024 +#ifdef CONFIG_X86_PAE
14025 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14026 +#endif
14027 +
14028 #if defined(CONFIG_HIGHPTE)
14029 #define pte_offset_map(dir, address) \
14030 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14031 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14032 /* Clear a kernel PTE and flush it from the TLB */
14033 #define kpte_clear_flush(ptep, vaddr) \
14034 do { \
14035 + pax_open_kernel(); \
14036 pte_clear(&init_mm, (vaddr), (ptep)); \
14037 + pax_close_kernel(); \
14038 __flush_tlb_one((vaddr)); \
14039 } while (0)
14040
14041 @@ -75,6 +80,9 @@ do { \
14042
14043 #endif /* !__ASSEMBLY__ */
14044
14045 +#define HAVE_ARCH_UNMAPPED_AREA
14046 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14047 +
14048 /*
14049 * kern_addr_valid() is (1) for FLATMEM and (0) for
14050 * SPARSEMEM and DISCONTIGMEM
14051 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14052 index ed5903b..c7fe163 100644
14053 --- a/arch/x86/include/asm/pgtable_32_types.h
14054 +++ b/arch/x86/include/asm/pgtable_32_types.h
14055 @@ -8,7 +8,7 @@
14056 */
14057 #ifdef CONFIG_X86_PAE
14058 # include <asm/pgtable-3level_types.h>
14059 -# define PMD_SIZE (1UL << PMD_SHIFT)
14060 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14061 # define PMD_MASK (~(PMD_SIZE - 1))
14062 #else
14063 # include <asm/pgtable-2level_types.h>
14064 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14065 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14066 #endif
14067
14068 +#ifdef CONFIG_PAX_KERNEXEC
14069 +#ifndef __ASSEMBLY__
14070 +extern unsigned char MODULES_EXEC_VADDR[];
14071 +extern unsigned char MODULES_EXEC_END[];
14072 +#endif
14073 +#include <asm/boot.h>
14074 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14075 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14076 +#else
14077 +#define ktla_ktva(addr) (addr)
14078 +#define ktva_ktla(addr) (addr)
14079 +#endif
14080 +
14081 #define MODULES_VADDR VMALLOC_START
14082 #define MODULES_END VMALLOC_END
14083 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14084 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14085 index 47356f9..deb94a2 100644
14086 --- a/arch/x86/include/asm/pgtable_64.h
14087 +++ b/arch/x86/include/asm/pgtable_64.h
14088 @@ -16,10 +16,14 @@
14089
14090 extern pud_t level3_kernel_pgt[512];
14091 extern pud_t level3_ident_pgt[512];
14092 +extern pud_t level3_vmalloc_start_pgt[512];
14093 +extern pud_t level3_vmalloc_end_pgt[512];
14094 +extern pud_t level3_vmemmap_pgt[512];
14095 +extern pud_t level2_vmemmap_pgt[512];
14096 extern pmd_t level2_kernel_pgt[512];
14097 extern pmd_t level2_fixmap_pgt[512];
14098 -extern pmd_t level2_ident_pgt[512];
14099 -extern pgd_t init_level4_pgt[];
14100 +extern pmd_t level2_ident_pgt[512*2];
14101 +extern pgd_t init_level4_pgt[512];
14102
14103 #define swapper_pg_dir init_level4_pgt
14104
14105 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14106
14107 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14108 {
14109 + pax_open_kernel();
14110 *pmdp = pmd;
14111 + pax_close_kernel();
14112 }
14113
14114 static inline void native_pmd_clear(pmd_t *pmd)
14115 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14116
14117 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14118 {
14119 + pax_open_kernel();
14120 *pudp = pud;
14121 + pax_close_kernel();
14122 }
14123
14124 static inline void native_pud_clear(pud_t *pud)
14125 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14126
14127 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14128 {
14129 + pax_open_kernel();
14130 + *pgdp = pgd;
14131 + pax_close_kernel();
14132 +}
14133 +
14134 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14135 +{
14136 *pgdp = pgd;
14137 }
14138
14139 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14140 index 766ea16..5b96cb3 100644
14141 --- a/arch/x86/include/asm/pgtable_64_types.h
14142 +++ b/arch/x86/include/asm/pgtable_64_types.h
14143 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14144 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14145 #define MODULES_END _AC(0xffffffffff000000, UL)
14146 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14147 +#define MODULES_EXEC_VADDR MODULES_VADDR
14148 +#define MODULES_EXEC_END MODULES_END
14149 +
14150 +#define ktla_ktva(addr) (addr)
14151 +#define ktva_ktla(addr) (addr)
14152
14153 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14154 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14155 index 3c32db8..1ddccf5 100644
14156 --- a/arch/x86/include/asm/pgtable_types.h
14157 +++ b/arch/x86/include/asm/pgtable_types.h
14158 @@ -16,13 +16,12 @@
14159 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14160 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14161 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14162 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14163 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14164 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14165 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14166 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14167 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14168 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14169 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14170 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14171 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14172 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14173
14174 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14175 @@ -40,7 +39,6 @@
14176 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14177 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14178 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14179 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14180 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14181 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14182 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14183 @@ -57,8 +55,10 @@
14184
14185 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14186 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14187 -#else
14188 +#elif defined(CONFIG_KMEMCHECK)
14189 #define _PAGE_NX (_AT(pteval_t, 0))
14190 +#else
14191 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14192 #endif
14193
14194 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14195 @@ -116,6 +116,9 @@
14196 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14197 _PAGE_ACCESSED)
14198
14199 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
14200 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
14201 +
14202 #define __PAGE_KERNEL_EXEC \
14203 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14204 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14205 @@ -126,7 +129,7 @@
14206 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14207 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14208 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14209 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14210 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14211 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14212 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14213 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14214 @@ -188,8 +191,8 @@
14215 * bits are combined, this will alow user to access the high address mapped
14216 * VDSO in the presence of CONFIG_COMPAT_VDSO
14217 */
14218 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14219 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14220 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14221 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14222 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14223 #endif
14224
14225 @@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14226 {
14227 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14228 }
14229 +#endif
14230
14231 +#if PAGETABLE_LEVELS == 3
14232 +#include <asm-generic/pgtable-nopud.h>
14233 +#endif
14234 +
14235 +#if PAGETABLE_LEVELS == 2
14236 +#include <asm-generic/pgtable-nopmd.h>
14237 +#endif
14238 +
14239 +#ifndef __ASSEMBLY__
14240 #if PAGETABLE_LEVELS > 3
14241 typedef struct { pudval_t pud; } pud_t;
14242
14243 @@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14244 return pud.pud;
14245 }
14246 #else
14247 -#include <asm-generic/pgtable-nopud.h>
14248 -
14249 static inline pudval_t native_pud_val(pud_t pud)
14250 {
14251 return native_pgd_val(pud.pgd);
14252 @@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14253 return pmd.pmd;
14254 }
14255 #else
14256 -#include <asm-generic/pgtable-nopmd.h>
14257 -
14258 static inline pmdval_t native_pmd_val(pmd_t pmd)
14259 {
14260 return native_pgd_val(pmd.pud.pgd);
14261 @@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14262
14263 extern pteval_t __supported_pte_mask;
14264 extern void set_nx(void);
14265 -extern int nx_enabled;
14266
14267 #define pgprot_writecombine pgprot_writecombine
14268 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14269 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14270 index 888184b..a07ac89 100644
14271 --- a/arch/x86/include/asm/processor.h
14272 +++ b/arch/x86/include/asm/processor.h
14273 @@ -287,7 +287,7 @@ struct tss_struct {
14274
14275 } ____cacheline_aligned;
14276
14277 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14278 +extern struct tss_struct init_tss[NR_CPUS];
14279
14280 /*
14281 * Save the original ist values for checking stack pointers during debugging
14282 @@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14283 */
14284 #define TASK_SIZE PAGE_OFFSET
14285 #define TASK_SIZE_MAX TASK_SIZE
14286 +
14287 +#ifdef CONFIG_PAX_SEGMEXEC
14288 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14289 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14290 +#else
14291 #define STACK_TOP TASK_SIZE
14292 -#define STACK_TOP_MAX STACK_TOP
14293 +#endif
14294 +
14295 +#define STACK_TOP_MAX TASK_SIZE
14296
14297 #define INIT_THREAD { \
14298 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14299 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14300 .vm86_info = NULL, \
14301 .sysenter_cs = __KERNEL_CS, \
14302 .io_bitmap_ptr = NULL, \
14303 @@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14304 */
14305 #define INIT_TSS { \
14306 .x86_tss = { \
14307 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14308 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14309 .ss0 = __KERNEL_DS, \
14310 .ss1 = __KERNEL_CS, \
14311 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14312 @@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14313 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14314
14315 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14316 -#define KSTK_TOP(info) \
14317 -({ \
14318 - unsigned long *__ptr = (unsigned long *)(info); \
14319 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14320 -})
14321 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14322
14323 /*
14324 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14325 @@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14326 #define task_pt_regs(task) \
14327 ({ \
14328 struct pt_regs *__regs__; \
14329 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14330 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14331 __regs__ - 1; \
14332 })
14333
14334 @@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14335 /*
14336 * User space process size. 47bits minus one guard page.
14337 */
14338 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14339 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14340
14341 /* This decides where the kernel will search for a free chunk of vm
14342 * space during mmap's.
14343 */
14344 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14345 - 0xc0000000 : 0xFFFFe000)
14346 + 0xc0000000 : 0xFFFFf000)
14347
14348 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14349 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14350 @@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14351 #define STACK_TOP_MAX TASK_SIZE_MAX
14352
14353 #define INIT_THREAD { \
14354 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14355 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14356 }
14357
14358 #define INIT_TSS { \
14359 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14360 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14361 }
14362
14363 /*
14364 @@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14365 */
14366 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14367
14368 +#ifdef CONFIG_PAX_SEGMEXEC
14369 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14370 +#endif
14371 +
14372 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14373
14374 /* Get/set a process' ability to use the timestamp counter instruction */
14375 @@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14376 #define cpu_has_amd_erratum(x) (false)
14377 #endif /* CONFIG_CPU_SUP_AMD */
14378
14379 -extern unsigned long arch_align_stack(unsigned long sp);
14380 +#define arch_align_stack(x) ((x) & ~0xfUL)
14381 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14382
14383 void default_idle(void);
14384 bool set_pm_idle_to_default(void);
14385
14386 -void stop_this_cpu(void *dummy);
14387 +void stop_this_cpu(void *dummy) __noreturn;
14388
14389 #endif /* _ASM_X86_PROCESSOR_H */
14390 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14391 index 942a086..6c26446 100644
14392 --- a/arch/x86/include/asm/ptrace.h
14393 +++ b/arch/x86/include/asm/ptrace.h
14394 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14395 }
14396
14397 /*
14398 - * user_mode_vm(regs) determines whether a register set came from user mode.
14399 + * user_mode(regs) determines whether a register set came from user mode.
14400 * This is true if V8086 mode was enabled OR if the register set was from
14401 * protected mode with RPL-3 CS value. This tricky test checks that with
14402 * one comparison. Many places in the kernel can bypass this full check
14403 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14404 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14405 + * be used.
14406 */
14407 -static inline int user_mode(struct pt_regs *regs)
14408 +static inline int user_mode_novm(struct pt_regs *regs)
14409 {
14410 #ifdef CONFIG_X86_32
14411 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14412 #else
14413 - return !!(regs->cs & 3);
14414 + return !!(regs->cs & SEGMENT_RPL_MASK);
14415 #endif
14416 }
14417
14418 -static inline int user_mode_vm(struct pt_regs *regs)
14419 +static inline int user_mode(struct pt_regs *regs)
14420 {
14421 #ifdef CONFIG_X86_32
14422 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14423 USER_RPL;
14424 #else
14425 - return user_mode(regs);
14426 + return user_mode_novm(regs);
14427 #endif
14428 }
14429
14430 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14431 #ifdef CONFIG_X86_64
14432 static inline bool user_64bit_mode(struct pt_regs *regs)
14433 {
14434 + unsigned long cs = regs->cs & 0xffff;
14435 #ifndef CONFIG_PARAVIRT
14436 /*
14437 * On non-paravirt systems, this is the only long mode CPL 3
14438 * selector. We do not allow long mode selectors in the LDT.
14439 */
14440 - return regs->cs == __USER_CS;
14441 + return cs == __USER_CS;
14442 #else
14443 /* Headers are too twisted for this to go in paravirt.h. */
14444 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14445 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14446 #endif
14447 }
14448
14449 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14450 * Traps from the kernel do not save sp and ss.
14451 * Use the helper function to retrieve sp.
14452 */
14453 - if (offset == offsetof(struct pt_regs, sp) &&
14454 - regs->cs == __KERNEL_CS)
14455 - return kernel_stack_pointer(regs);
14456 + if (offset == offsetof(struct pt_regs, sp)) {
14457 + unsigned long cs = regs->cs & 0xffff;
14458 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14459 + return kernel_stack_pointer(regs);
14460 + }
14461 #endif
14462 return *(unsigned long *)((unsigned long)regs + offset);
14463 }
14464 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14465 index fe1ec5b..dc5c3fe 100644
14466 --- a/arch/x86/include/asm/realmode.h
14467 +++ b/arch/x86/include/asm/realmode.h
14468 @@ -22,16 +22,14 @@ struct real_mode_header {
14469 #endif
14470 /* APM/BIOS reboot */
14471 u32 machine_real_restart_asm;
14472 -#ifdef CONFIG_X86_64
14473 u32 machine_real_restart_seg;
14474 -#endif
14475 };
14476
14477 /* This must match data at trampoline_32/64.S */
14478 struct trampoline_header {
14479 #ifdef CONFIG_X86_32
14480 u32 start;
14481 - u16 gdt_pad;
14482 + u16 boot_cs;
14483 u16 gdt_limit;
14484 u32 gdt_base;
14485 #else
14486 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14487 index a82c4f1..ac45053 100644
14488 --- a/arch/x86/include/asm/reboot.h
14489 +++ b/arch/x86/include/asm/reboot.h
14490 @@ -6,13 +6,13 @@
14491 struct pt_regs;
14492
14493 struct machine_ops {
14494 - void (*restart)(char *cmd);
14495 - void (*halt)(void);
14496 - void (*power_off)(void);
14497 + void (* __noreturn restart)(char *cmd);
14498 + void (* __noreturn halt)(void);
14499 + void (* __noreturn power_off)(void);
14500 void (*shutdown)(void);
14501 void (*crash_shutdown)(struct pt_regs *);
14502 - void (*emergency_restart)(void);
14503 -};
14504 + void (* __noreturn emergency_restart)(void);
14505 +} __no_const;
14506
14507 extern struct machine_ops machine_ops;
14508
14509 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14510 index 2dbe4a7..ce1db00 100644
14511 --- a/arch/x86/include/asm/rwsem.h
14512 +++ b/arch/x86/include/asm/rwsem.h
14513 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14514 {
14515 asm volatile("# beginning down_read\n\t"
14516 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14517 +
14518 +#ifdef CONFIG_PAX_REFCOUNT
14519 + "jno 0f\n"
14520 + LOCK_PREFIX _ASM_DEC "(%1)\n"
14521 + "int $4\n0:\n"
14522 + _ASM_EXTABLE(0b, 0b)
14523 +#endif
14524 +
14525 /* adds 0x00000001 */
14526 " jns 1f\n"
14527 " call call_rwsem_down_read_failed\n"
14528 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14529 "1:\n\t"
14530 " mov %1,%2\n\t"
14531 " add %3,%2\n\t"
14532 +
14533 +#ifdef CONFIG_PAX_REFCOUNT
14534 + "jno 0f\n"
14535 + "sub %3,%2\n"
14536 + "int $4\n0:\n"
14537 + _ASM_EXTABLE(0b, 0b)
14538 +#endif
14539 +
14540 " jle 2f\n\t"
14541 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14542 " jnz 1b\n\t"
14543 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14544 long tmp;
14545 asm volatile("# beginning down_write\n\t"
14546 LOCK_PREFIX " xadd %1,(%2)\n\t"
14547 +
14548 +#ifdef CONFIG_PAX_REFCOUNT
14549 + "jno 0f\n"
14550 + "mov %1,(%2)\n"
14551 + "int $4\n0:\n"
14552 + _ASM_EXTABLE(0b, 0b)
14553 +#endif
14554 +
14555 /* adds 0xffff0001, returns the old value */
14556 " test %1,%1\n\t"
14557 /* was the count 0 before? */
14558 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14559 long tmp;
14560 asm volatile("# beginning __up_read\n\t"
14561 LOCK_PREFIX " xadd %1,(%2)\n\t"
14562 +
14563 +#ifdef CONFIG_PAX_REFCOUNT
14564 + "jno 0f\n"
14565 + "mov %1,(%2)\n"
14566 + "int $4\n0:\n"
14567 + _ASM_EXTABLE(0b, 0b)
14568 +#endif
14569 +
14570 /* subtracts 1, returns the old value */
14571 " jns 1f\n\t"
14572 " call call_rwsem_wake\n" /* expects old value in %edx */
14573 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14574 long tmp;
14575 asm volatile("# beginning __up_write\n\t"
14576 LOCK_PREFIX " xadd %1,(%2)\n\t"
14577 +
14578 +#ifdef CONFIG_PAX_REFCOUNT
14579 + "jno 0f\n"
14580 + "mov %1,(%2)\n"
14581 + "int $4\n0:\n"
14582 + _ASM_EXTABLE(0b, 0b)
14583 +#endif
14584 +
14585 /* subtracts 0xffff0001, returns the old value */
14586 " jns 1f\n\t"
14587 " call call_rwsem_wake\n" /* expects old value in %edx */
14588 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14589 {
14590 asm volatile("# beginning __downgrade_write\n\t"
14591 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14592 +
14593 +#ifdef CONFIG_PAX_REFCOUNT
14594 + "jno 0f\n"
14595 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14596 + "int $4\n0:\n"
14597 + _ASM_EXTABLE(0b, 0b)
14598 +#endif
14599 +
14600 /*
14601 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14602 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14603 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14604 */
14605 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14606 {
14607 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14608 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14609 +
14610 +#ifdef CONFIG_PAX_REFCOUNT
14611 + "jno 0f\n"
14612 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
14613 + "int $4\n0:\n"
14614 + _ASM_EXTABLE(0b, 0b)
14615 +#endif
14616 +
14617 : "+m" (sem->count)
14618 : "er" (delta));
14619 }
14620 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14621 */
14622 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14623 {
14624 - return delta + xadd(&sem->count, delta);
14625 + return delta + xadd_check_overflow(&sem->count, delta);
14626 }
14627
14628 #endif /* __KERNEL__ */
14629 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14630 index c48a950..c6d7468 100644
14631 --- a/arch/x86/include/asm/segment.h
14632 +++ b/arch/x86/include/asm/segment.h
14633 @@ -64,10 +64,15 @@
14634 * 26 - ESPFIX small SS
14635 * 27 - per-cpu [ offset to per-cpu data area ]
14636 * 28 - stack_canary-20 [ for stack protector ]
14637 - * 29 - unused
14638 - * 30 - unused
14639 + * 29 - PCI BIOS CS
14640 + * 30 - PCI BIOS DS
14641 * 31 - TSS for double fault handler
14642 */
14643 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14644 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14645 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14646 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14647 +
14648 #define GDT_ENTRY_TLS_MIN 6
14649 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14650
14651 @@ -79,6 +84,8 @@
14652
14653 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14654
14655 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14656 +
14657 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14658
14659 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14660 @@ -104,6 +111,12 @@
14661 #define __KERNEL_STACK_CANARY 0
14662 #endif
14663
14664 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14665 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14666 +
14667 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14668 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14669 +
14670 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14671
14672 /*
14673 @@ -141,7 +154,7 @@
14674 */
14675
14676 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14677 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14678 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14679
14680
14681 #else
14682 @@ -165,6 +178,8 @@
14683 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14684 #define __USER32_DS __USER_DS
14685
14686 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14687 +
14688 #define GDT_ENTRY_TSS 8 /* needs two entries */
14689 #define GDT_ENTRY_LDT 10 /* needs two entries */
14690 #define GDT_ENTRY_TLS_MIN 12
14691 @@ -185,6 +200,7 @@
14692 #endif
14693
14694 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14695 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14696 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14697 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14698 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14699 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14700 {
14701 unsigned long __limit;
14702 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14703 - return __limit + 1;
14704 + return __limit;
14705 }
14706
14707 #endif /* !__ASSEMBLY__ */
14708 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14709 index b073aae..39f9bdd 100644
14710 --- a/arch/x86/include/asm/smp.h
14711 +++ b/arch/x86/include/asm/smp.h
14712 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14713 /* cpus sharing the last level cache: */
14714 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14715 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14716 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14717 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14718
14719 static inline struct cpumask *cpu_sibling_mask(int cpu)
14720 {
14721 @@ -79,7 +79,7 @@ struct smp_ops {
14722
14723 void (*send_call_func_ipi)(const struct cpumask *mask);
14724 void (*send_call_func_single_ipi)(int cpu);
14725 -};
14726 +} __no_const;
14727
14728 /* Globals due to paravirt */
14729 extern void set_cpu_sibling_map(int cpu);
14730 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14731 extern int safe_smp_processor_id(void);
14732
14733 #elif defined(CONFIG_X86_64_SMP)
14734 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14735 -
14736 -#define stack_smp_processor_id() \
14737 -({ \
14738 - struct thread_info *ti; \
14739 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14740 - ti->cpu; \
14741 -})
14742 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14743 +#define stack_smp_processor_id() raw_smp_processor_id()
14744 #define safe_smp_processor_id() smp_processor_id()
14745
14746 #endif
14747 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14748 index 33692ea..350a534 100644
14749 --- a/arch/x86/include/asm/spinlock.h
14750 +++ b/arch/x86/include/asm/spinlock.h
14751 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14752 static inline void arch_read_lock(arch_rwlock_t *rw)
14753 {
14754 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14755 +
14756 +#ifdef CONFIG_PAX_REFCOUNT
14757 + "jno 0f\n"
14758 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14759 + "int $4\n0:\n"
14760 + _ASM_EXTABLE(0b, 0b)
14761 +#endif
14762 +
14763 "jns 1f\n"
14764 "call __read_lock_failed\n\t"
14765 "1:\n"
14766 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14767 static inline void arch_write_lock(arch_rwlock_t *rw)
14768 {
14769 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14770 +
14771 +#ifdef CONFIG_PAX_REFCOUNT
14772 + "jno 0f\n"
14773 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14774 + "int $4\n0:\n"
14775 + _ASM_EXTABLE(0b, 0b)
14776 +#endif
14777 +
14778 "jz 1f\n"
14779 "call __write_lock_failed\n\t"
14780 "1:\n"
14781 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14782
14783 static inline void arch_read_unlock(arch_rwlock_t *rw)
14784 {
14785 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14786 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14787 +
14788 +#ifdef CONFIG_PAX_REFCOUNT
14789 + "jno 0f\n"
14790 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
14791 + "int $4\n0:\n"
14792 + _ASM_EXTABLE(0b, 0b)
14793 +#endif
14794 +
14795 :"+m" (rw->lock) : : "memory");
14796 }
14797
14798 static inline void arch_write_unlock(arch_rwlock_t *rw)
14799 {
14800 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
14801 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
14802 +
14803 +#ifdef CONFIG_PAX_REFCOUNT
14804 + "jno 0f\n"
14805 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
14806 + "int $4\n0:\n"
14807 + _ASM_EXTABLE(0b, 0b)
14808 +#endif
14809 +
14810 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
14811 }
14812
14813 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
14814 index 6a99859..03cb807 100644
14815 --- a/arch/x86/include/asm/stackprotector.h
14816 +++ b/arch/x86/include/asm/stackprotector.h
14817 @@ -47,7 +47,7 @@
14818 * head_32 for boot CPU and setup_per_cpu_areas() for others.
14819 */
14820 #define GDT_STACK_CANARY_INIT \
14821 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
14822 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
14823
14824 /*
14825 * Initialize the stackprotector canary value.
14826 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
14827
14828 static inline void load_stack_canary_segment(void)
14829 {
14830 -#ifdef CONFIG_X86_32
14831 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14832 asm volatile ("mov %0, %%gs" : : "r" (0));
14833 #endif
14834 }
14835 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
14836 index 70bbe39..4ae2bd4 100644
14837 --- a/arch/x86/include/asm/stacktrace.h
14838 +++ b/arch/x86/include/asm/stacktrace.h
14839 @@ -11,28 +11,20 @@
14840
14841 extern int kstack_depth_to_print;
14842
14843 -struct thread_info;
14844 +struct task_struct;
14845 struct stacktrace_ops;
14846
14847 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
14848 - unsigned long *stack,
14849 - unsigned long bp,
14850 - const struct stacktrace_ops *ops,
14851 - void *data,
14852 - unsigned long *end,
14853 - int *graph);
14854 +typedef unsigned long walk_stack_t(struct task_struct *task,
14855 + void *stack_start,
14856 + unsigned long *stack,
14857 + unsigned long bp,
14858 + const struct stacktrace_ops *ops,
14859 + void *data,
14860 + unsigned long *end,
14861 + int *graph);
14862
14863 -extern unsigned long
14864 -print_context_stack(struct thread_info *tinfo,
14865 - unsigned long *stack, unsigned long bp,
14866 - const struct stacktrace_ops *ops, void *data,
14867 - unsigned long *end, int *graph);
14868 -
14869 -extern unsigned long
14870 -print_context_stack_bp(struct thread_info *tinfo,
14871 - unsigned long *stack, unsigned long bp,
14872 - const struct stacktrace_ops *ops, void *data,
14873 - unsigned long *end, int *graph);
14874 +extern walk_stack_t print_context_stack;
14875 +extern walk_stack_t print_context_stack_bp;
14876
14877 /* Generic stack tracer with callbacks */
14878
14879 @@ -40,7 +32,7 @@ struct stacktrace_ops {
14880 void (*address)(void *data, unsigned long address, int reliable);
14881 /* On negative return stop dumping */
14882 int (*stack)(void *data, char *name);
14883 - walk_stack_t walk_stack;
14884 + walk_stack_t *walk_stack;
14885 };
14886
14887 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
14888 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
14889 index 4ec45b3..a4f0a8a 100644
14890 --- a/arch/x86/include/asm/switch_to.h
14891 +++ b/arch/x86/include/asm/switch_to.h
14892 @@ -108,7 +108,7 @@ do { \
14893 "call __switch_to\n\t" \
14894 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
14895 __switch_canary \
14896 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
14897 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
14898 "movq %%rax,%%rdi\n\t" \
14899 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
14900 "jnz ret_from_fork\n\t" \
14901 @@ -119,7 +119,7 @@ do { \
14902 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
14903 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
14904 [_tif_fork] "i" (_TIF_FORK), \
14905 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
14906 + [thread_info] "m" (current_tinfo), \
14907 [current_task] "m" (current_task) \
14908 __switch_canary_iparam \
14909 : "memory", "cc" __EXTRA_CLOBBER)
14910 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
14911 index 2d946e6..e453ec4 100644
14912 --- a/arch/x86/include/asm/thread_info.h
14913 +++ b/arch/x86/include/asm/thread_info.h
14914 @@ -10,6 +10,7 @@
14915 #include <linux/compiler.h>
14916 #include <asm/page.h>
14917 #include <asm/types.h>
14918 +#include <asm/percpu.h>
14919
14920 /*
14921 * low level task data that entry.S needs immediate access to
14922 @@ -24,7 +25,6 @@ struct exec_domain;
14923 #include <linux/atomic.h>
14924
14925 struct thread_info {
14926 - struct task_struct *task; /* main task structure */
14927 struct exec_domain *exec_domain; /* execution domain */
14928 __u32 flags; /* low level flags */
14929 __u32 status; /* thread synchronous flags */
14930 @@ -34,19 +34,13 @@ struct thread_info {
14931 mm_segment_t addr_limit;
14932 struct restart_block restart_block;
14933 void __user *sysenter_return;
14934 -#ifdef CONFIG_X86_32
14935 - unsigned long previous_esp; /* ESP of the previous stack in
14936 - case of nested (IRQ) stacks
14937 - */
14938 - __u8 supervisor_stack[0];
14939 -#endif
14940 + unsigned long lowest_stack;
14941 unsigned int sig_on_uaccess_error:1;
14942 unsigned int uaccess_err:1; /* uaccess failed */
14943 };
14944
14945 -#define INIT_THREAD_INFO(tsk) \
14946 +#define INIT_THREAD_INFO \
14947 { \
14948 - .task = &tsk, \
14949 .exec_domain = &default_exec_domain, \
14950 .flags = 0, \
14951 .cpu = 0, \
14952 @@ -57,7 +51,7 @@ struct thread_info {
14953 }, \
14954 }
14955
14956 -#define init_thread_info (init_thread_union.thread_info)
14957 +#define init_thread_info (init_thread_union.stack)
14958 #define init_stack (init_thread_union.stack)
14959
14960 #else /* !__ASSEMBLY__ */
14961 @@ -98,6 +92,7 @@ struct thread_info {
14962 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
14963 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
14964 #define TIF_X32 30 /* 32-bit native x86-64 binary */
14965 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
14966
14967 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
14968 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
14969 @@ -122,17 +117,18 @@ struct thread_info {
14970 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
14971 #define _TIF_ADDR32 (1 << TIF_ADDR32)
14972 #define _TIF_X32 (1 << TIF_X32)
14973 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
14974
14975 /* work to do in syscall_trace_enter() */
14976 #define _TIF_WORK_SYSCALL_ENTRY \
14977 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
14978 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
14979 - _TIF_NOHZ)
14980 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
14981
14982 /* work to do in syscall_trace_leave() */
14983 #define _TIF_WORK_SYSCALL_EXIT \
14984 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
14985 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
14986 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
14987
14988 /* work to do on interrupt/exception return */
14989 #define _TIF_WORK_MASK \
14990 @@ -143,7 +139,7 @@ struct thread_info {
14991 /* work to do on any return to user space */
14992 #define _TIF_ALLWORK_MASK \
14993 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
14994 - _TIF_NOHZ)
14995 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
14996
14997 /* Only used for 64 bit */
14998 #define _TIF_DO_NOTIFY_MASK \
14999 @@ -159,45 +155,40 @@ struct thread_info {
15000
15001 #define PREEMPT_ACTIVE 0x10000000
15002
15003 -#ifdef CONFIG_X86_32
15004 -
15005 -#define STACK_WARN (THREAD_SIZE/8)
15006 -/*
15007 - * macros/functions for gaining access to the thread information structure
15008 - *
15009 - * preempt_count needs to be 1 initially, until the scheduler is functional.
15010 - */
15011 -#ifndef __ASSEMBLY__
15012 -
15013 -
15014 -/* how to get the current stack pointer from C */
15015 -register unsigned long current_stack_pointer asm("esp") __used;
15016 -
15017 -/* how to get the thread information struct from C */
15018 -static inline struct thread_info *current_thread_info(void)
15019 -{
15020 - return (struct thread_info *)
15021 - (current_stack_pointer & ~(THREAD_SIZE - 1));
15022 -}
15023 -
15024 -#else /* !__ASSEMBLY__ */
15025 -
15026 +#ifdef __ASSEMBLY__
15027 /* how to get the thread information struct from ASM */
15028 #define GET_THREAD_INFO(reg) \
15029 - movl $-THREAD_SIZE, reg; \
15030 - andl %esp, reg
15031 + mov PER_CPU_VAR(current_tinfo), reg
15032
15033 /* use this one if reg already contains %esp */
15034 -#define GET_THREAD_INFO_WITH_ESP(reg) \
15035 - andl $-THREAD_SIZE, reg
15036 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15037 +#else
15038 +/* how to get the thread information struct from C */
15039 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15040 +
15041 +static __always_inline struct thread_info *current_thread_info(void)
15042 +{
15043 + return this_cpu_read_stable(current_tinfo);
15044 +}
15045 +#endif
15046 +
15047 +#ifdef CONFIG_X86_32
15048 +
15049 +#define STACK_WARN (THREAD_SIZE/8)
15050 +/*
15051 + * macros/functions for gaining access to the thread information structure
15052 + *
15053 + * preempt_count needs to be 1 initially, until the scheduler is functional.
15054 + */
15055 +#ifndef __ASSEMBLY__
15056 +
15057 +/* how to get the current stack pointer from C */
15058 +register unsigned long current_stack_pointer asm("esp") __used;
15059
15060 #endif
15061
15062 #else /* X86_32 */
15063
15064 -#include <asm/percpu.h>
15065 -#define KERNEL_STACK_OFFSET (5*8)
15066 -
15067 /*
15068 * macros/functions for gaining access to the thread information structure
15069 * preempt_count needs to be 1 initially, until the scheduler is functional.
15070 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15071 #ifndef __ASSEMBLY__
15072 DECLARE_PER_CPU(unsigned long, kernel_stack);
15073
15074 -static inline struct thread_info *current_thread_info(void)
15075 -{
15076 - struct thread_info *ti;
15077 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
15078 - KERNEL_STACK_OFFSET - THREAD_SIZE);
15079 - return ti;
15080 -}
15081 -
15082 -#else /* !__ASSEMBLY__ */
15083 -
15084 -/* how to get the thread information struct from ASM */
15085 -#define GET_THREAD_INFO(reg) \
15086 - movq PER_CPU_VAR(kernel_stack),reg ; \
15087 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15088 -
15089 -/*
15090 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15091 - * a certain register (to be used in assembler memory operands).
15092 - */
15093 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15094 -
15095 +/* how to get the current stack pointer from C */
15096 +register unsigned long current_stack_pointer asm("rsp") __used;
15097 #endif
15098
15099 #endif /* !X86_32 */
15100 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15101 extern void arch_task_cache_init(void);
15102 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15103 extern void arch_release_task_struct(struct task_struct *tsk);
15104 +
15105 +#define __HAVE_THREAD_FUNCTIONS
15106 +#define task_thread_info(task) (&(task)->tinfo)
15107 +#define task_stack_page(task) ((task)->stack)
15108 +#define setup_thread_stack(p, org) do {} while (0)
15109 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15110 +
15111 #endif
15112 #endif /* _ASM_X86_THREAD_INFO_H */
15113 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15114 index 1709801..0a60f2f 100644
15115 --- a/arch/x86/include/asm/uaccess.h
15116 +++ b/arch/x86/include/asm/uaccess.h
15117 @@ -7,6 +7,7 @@
15118 #include <linux/compiler.h>
15119 #include <linux/thread_info.h>
15120 #include <linux/string.h>
15121 +#include <linux/sched.h>
15122 #include <asm/asm.h>
15123 #include <asm/page.h>
15124 #include <asm/smap.h>
15125 @@ -29,7 +30,12 @@
15126
15127 #define get_ds() (KERNEL_DS)
15128 #define get_fs() (current_thread_info()->addr_limit)
15129 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15130 +void __set_fs(mm_segment_t x);
15131 +void set_fs(mm_segment_t x);
15132 +#else
15133 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15134 +#endif
15135
15136 #define segment_eq(a, b) ((a).seg == (b).seg)
15137
15138 @@ -77,8 +83,33 @@
15139 * checks that the pointer is in the user space range - after calling
15140 * this function, memory access functions may still return -EFAULT.
15141 */
15142 -#define access_ok(type, addr, size) \
15143 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15144 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15145 +#define access_ok(type, addr, size) \
15146 +({ \
15147 + long __size = size; \
15148 + unsigned long __addr = (unsigned long)addr; \
15149 + unsigned long __addr_ao = __addr & PAGE_MASK; \
15150 + unsigned long __end_ao = __addr + __size - 1; \
15151 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15152 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15153 + while(__addr_ao <= __end_ao) { \
15154 + char __c_ao; \
15155 + __addr_ao += PAGE_SIZE; \
15156 + if (__size > PAGE_SIZE) \
15157 + cond_resched(); \
15158 + if (__get_user(__c_ao, (char __user *)__addr)) \
15159 + break; \
15160 + if (type != VERIFY_WRITE) { \
15161 + __addr = __addr_ao; \
15162 + continue; \
15163 + } \
15164 + if (__put_user(__c_ao, (char __user *)__addr)) \
15165 + break; \
15166 + __addr = __addr_ao; \
15167 + } \
15168 + } \
15169 + __ret_ao; \
15170 +})
15171
15172 /*
15173 * The exception table consists of pairs of addresses relative to the
15174 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15175 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15176 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15177
15178 -
15179 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15180 +#define __copyuser_seg "gs;"
15181 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15182 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15183 +#else
15184 +#define __copyuser_seg
15185 +#define __COPYUSER_SET_ES
15186 +#define __COPYUSER_RESTORE_ES
15187 +#endif
15188
15189 #ifdef CONFIG_X86_32
15190 #define __put_user_asm_u64(x, addr, err, errret) \
15191 asm volatile(ASM_STAC "\n" \
15192 - "1: movl %%eax,0(%2)\n" \
15193 - "2: movl %%edx,4(%2)\n" \
15194 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15195 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15196 "3: " ASM_CLAC "\n" \
15197 ".section .fixup,\"ax\"\n" \
15198 "4: movl %3,%0\n" \
15199 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15200
15201 #define __put_user_asm_ex_u64(x, addr) \
15202 asm volatile(ASM_STAC "\n" \
15203 - "1: movl %%eax,0(%1)\n" \
15204 - "2: movl %%edx,4(%1)\n" \
15205 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15206 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15207 "3: " ASM_CLAC "\n" \
15208 _ASM_EXTABLE_EX(1b, 2b) \
15209 _ASM_EXTABLE_EX(2b, 3b) \
15210 @@ -259,7 +298,7 @@ extern void __put_user_8(void);
15211 __typeof__(*(ptr)) __pu_val; \
15212 __chk_user_ptr(ptr); \
15213 might_fault(); \
15214 - __pu_val = x; \
15215 + __pu_val = (x); \
15216 switch (sizeof(*(ptr))) { \
15217 case 1: \
15218 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15219 @@ -358,7 +397,7 @@ do { \
15220
15221 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15222 asm volatile(ASM_STAC "\n" \
15223 - "1: mov"itype" %2,%"rtype"1\n" \
15224 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15225 "2: " ASM_CLAC "\n" \
15226 ".section .fixup,\"ax\"\n" \
15227 "3: mov %3,%0\n" \
15228 @@ -366,7 +405,7 @@ do { \
15229 " jmp 2b\n" \
15230 ".previous\n" \
15231 _ASM_EXTABLE(1b, 3b) \
15232 - : "=r" (err), ltype(x) \
15233 + : "=r" (err), ltype (x) \
15234 : "m" (__m(addr)), "i" (errret), "0" (err))
15235
15236 #define __get_user_size_ex(x, ptr, size) \
15237 @@ -391,7 +430,7 @@ do { \
15238 } while (0)
15239
15240 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15241 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15242 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15243 "2:\n" \
15244 _ASM_EXTABLE_EX(1b, 2b) \
15245 : ltype(x) : "m" (__m(addr)))
15246 @@ -408,13 +447,24 @@ do { \
15247 int __gu_err; \
15248 unsigned long __gu_val; \
15249 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15250 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
15251 + (x) = (__typeof__(*(ptr)))__gu_val; \
15252 __gu_err; \
15253 })
15254
15255 /* FIXME: this hack is definitely wrong -AK */
15256 struct __large_struct { unsigned long buf[100]; };
15257 -#define __m(x) (*(struct __large_struct __user *)(x))
15258 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15259 +#define ____m(x) \
15260 +({ \
15261 + unsigned long ____x = (unsigned long)(x); \
15262 + if (____x < PAX_USER_SHADOW_BASE) \
15263 + ____x += PAX_USER_SHADOW_BASE; \
15264 + (void __user *)____x; \
15265 +})
15266 +#else
15267 +#define ____m(x) (x)
15268 +#endif
15269 +#define __m(x) (*(struct __large_struct __user *)____m(x))
15270
15271 /*
15272 * Tell gcc we read from memory instead of writing: this is because
15273 @@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15274 */
15275 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15276 asm volatile(ASM_STAC "\n" \
15277 - "1: mov"itype" %"rtype"1,%2\n" \
15278 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15279 "2: " ASM_CLAC "\n" \
15280 ".section .fixup,\"ax\"\n" \
15281 "3: mov %3,%0\n" \
15282 @@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15283 ".previous\n" \
15284 _ASM_EXTABLE(1b, 3b) \
15285 : "=r"(err) \
15286 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15287 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15288
15289 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15290 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15291 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15292 "2:\n" \
15293 _ASM_EXTABLE_EX(1b, 2b) \
15294 : : ltype(x), "m" (__m(addr)))
15295 @@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15296 * On error, the variable @x is set to zero.
15297 */
15298
15299 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15300 +#define __get_user(x, ptr) get_user((x), (ptr))
15301 +#else
15302 #define __get_user(x, ptr) \
15303 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15304 +#endif
15305
15306 /**
15307 * __put_user: - Write a simple value into user space, with less checking.
15308 @@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15309 * Returns zero on success, or -EFAULT on error.
15310 */
15311
15312 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15313 +#define __put_user(x, ptr) put_user((x), (ptr))
15314 +#else
15315 #define __put_user(x, ptr) \
15316 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15317 +#endif
15318
15319 #define __get_user_unaligned __get_user
15320 #define __put_user_unaligned __put_user
15321 @@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15322 #define get_user_ex(x, ptr) do { \
15323 unsigned long __gue_val; \
15324 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15325 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
15326 + (x) = (__typeof__(*(ptr)))__gue_val; \
15327 } while (0)
15328
15329 #define put_user_try uaccess_try
15330 @@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15331 extern __must_check long strlen_user(const char __user *str);
15332 extern __must_check long strnlen_user(const char __user *str, long n);
15333
15334 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15335 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15336 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15337 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15338
15339 /*
15340 * movsl can be slow when source and dest are not both 8-byte aligned
15341 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15342 index 7f760a9..04b1c65 100644
15343 --- a/arch/x86/include/asm/uaccess_32.h
15344 +++ b/arch/x86/include/asm/uaccess_32.h
15345 @@ -11,15 +11,15 @@
15346 #include <asm/page.h>
15347
15348 unsigned long __must_check __copy_to_user_ll
15349 - (void __user *to, const void *from, unsigned long n);
15350 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15351 unsigned long __must_check __copy_from_user_ll
15352 - (void *to, const void __user *from, unsigned long n);
15353 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15354 unsigned long __must_check __copy_from_user_ll_nozero
15355 - (void *to, const void __user *from, unsigned long n);
15356 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15357 unsigned long __must_check __copy_from_user_ll_nocache
15358 - (void *to, const void __user *from, unsigned long n);
15359 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15360 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15361 - (void *to, const void __user *from, unsigned long n);
15362 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15363
15364 /**
15365 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15366 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15367 static __always_inline unsigned long __must_check
15368 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15369 {
15370 + if ((long)n < 0)
15371 + return n;
15372 +
15373 + check_object_size(from, n, true);
15374 +
15375 if (__builtin_constant_p(n)) {
15376 unsigned long ret;
15377
15378 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15379 __copy_to_user(void __user *to, const void *from, unsigned long n)
15380 {
15381 might_fault();
15382 +
15383 return __copy_to_user_inatomic(to, from, n);
15384 }
15385
15386 static __always_inline unsigned long
15387 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15388 {
15389 + if ((long)n < 0)
15390 + return n;
15391 +
15392 /* Avoid zeroing the tail if the copy fails..
15393 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15394 * but as the zeroing behaviour is only significant when n is not
15395 @@ -137,6 +146,12 @@ static __always_inline unsigned long
15396 __copy_from_user(void *to, const void __user *from, unsigned long n)
15397 {
15398 might_fault();
15399 +
15400 + if ((long)n < 0)
15401 + return n;
15402 +
15403 + check_object_size(to, n, false);
15404 +
15405 if (__builtin_constant_p(n)) {
15406 unsigned long ret;
15407
15408 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15409 const void __user *from, unsigned long n)
15410 {
15411 might_fault();
15412 +
15413 + if ((long)n < 0)
15414 + return n;
15415 +
15416 if (__builtin_constant_p(n)) {
15417 unsigned long ret;
15418
15419 @@ -181,15 +200,19 @@ static __always_inline unsigned long
15420 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15421 unsigned long n)
15422 {
15423 - return __copy_from_user_ll_nocache_nozero(to, from, n);
15424 + if ((long)n < 0)
15425 + return n;
15426 +
15427 + return __copy_from_user_ll_nocache_nozero(to, from, n);
15428 }
15429
15430 -unsigned long __must_check copy_to_user(void __user *to,
15431 - const void *from, unsigned long n);
15432 -unsigned long __must_check _copy_from_user(void *to,
15433 - const void __user *from,
15434 - unsigned long n);
15435 -
15436 +extern void copy_to_user_overflow(void)
15437 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15438 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15439 +#else
15440 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15441 +#endif
15442 +;
15443
15444 extern void copy_from_user_overflow(void)
15445 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15446 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15447 #endif
15448 ;
15449
15450 -static inline unsigned long __must_check copy_from_user(void *to,
15451 - const void __user *from,
15452 - unsigned long n)
15453 +/**
15454 + * copy_to_user: - Copy a block of data into user space.
15455 + * @to: Destination address, in user space.
15456 + * @from: Source address, in kernel space.
15457 + * @n: Number of bytes to copy.
15458 + *
15459 + * Context: User context only. This function may sleep.
15460 + *
15461 + * Copy data from kernel space to user space.
15462 + *
15463 + * Returns number of bytes that could not be copied.
15464 + * On success, this will be zero.
15465 + */
15466 +static inline unsigned long __must_check
15467 +copy_to_user(void __user *to, const void *from, unsigned long n)
15468 {
15469 - int sz = __compiletime_object_size(to);
15470 + size_t sz = __compiletime_object_size(from);
15471
15472 - if (likely(sz == -1 || sz >= n))
15473 - n = _copy_from_user(to, from, n);
15474 - else
15475 + if (unlikely(sz != (size_t)-1 && sz < n))
15476 + copy_to_user_overflow();
15477 + else if (access_ok(VERIFY_WRITE, to, n))
15478 + n = __copy_to_user(to, from, n);
15479 + return n;
15480 +}
15481 +
15482 +/**
15483 + * copy_from_user: - Copy a block of data from user space.
15484 + * @to: Destination address, in kernel space.
15485 + * @from: Source address, in user space.
15486 + * @n: Number of bytes to copy.
15487 + *
15488 + * Context: User context only. This function may sleep.
15489 + *
15490 + * Copy data from user space to kernel space.
15491 + *
15492 + * Returns number of bytes that could not be copied.
15493 + * On success, this will be zero.
15494 + *
15495 + * If some data could not be copied, this function will pad the copied
15496 + * data to the requested size using zero bytes.
15497 + */
15498 +static inline unsigned long __must_check
15499 +copy_from_user(void *to, const void __user *from, unsigned long n)
15500 +{
15501 + size_t sz = __compiletime_object_size(to);
15502 +
15503 + check_object_size(to, n, false);
15504 +
15505 + if (unlikely(sz != (size_t)-1 && sz < n))
15506 copy_from_user_overflow();
15507 -
15508 + else if (access_ok(VERIFY_READ, from, n))
15509 + n = __copy_from_user(to, from, n);
15510 + else if ((long)n > 0)
15511 + memset(to, 0, n);
15512 return n;
15513 }
15514
15515 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15516 index 142810c..747941a 100644
15517 --- a/arch/x86/include/asm/uaccess_64.h
15518 +++ b/arch/x86/include/asm/uaccess_64.h
15519 @@ -10,6 +10,9 @@
15520 #include <asm/alternative.h>
15521 #include <asm/cpufeature.h>
15522 #include <asm/page.h>
15523 +#include <asm/pgtable.h>
15524 +
15525 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
15526
15527 /*
15528 * Copy To/From Userspace
15529 @@ -17,13 +20,13 @@
15530
15531 /* Handles exceptions in both to and from, but doesn't do access_ok */
15532 __must_check unsigned long
15533 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15534 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15535 __must_check unsigned long
15536 -copy_user_generic_string(void *to, const void *from, unsigned len);
15537 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15538 __must_check unsigned long
15539 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15540 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15541
15542 -static __always_inline __must_check unsigned long
15543 +static __always_inline __must_check __size_overflow(3) unsigned long
15544 copy_user_generic(void *to, const void *from, unsigned len)
15545 {
15546 unsigned ret;
15547 @@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15548 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15549 "=d" (len)),
15550 "1" (to), "2" (from), "3" (len)
15551 - : "memory", "rcx", "r8", "r9", "r10", "r11");
15552 + : "memory", "rcx", "r8", "r9", "r11");
15553 return ret;
15554 }
15555
15556 +static __always_inline __must_check unsigned long
15557 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15558 +static __always_inline __must_check unsigned long
15559 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15560 __must_check unsigned long
15561 -_copy_to_user(void __user *to, const void *from, unsigned len);
15562 -__must_check unsigned long
15563 -_copy_from_user(void *to, const void __user *from, unsigned len);
15564 -__must_check unsigned long
15565 -copy_in_user(void __user *to, const void __user *from, unsigned len);
15566 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15567 +
15568 +extern void copy_to_user_overflow(void)
15569 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15570 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15571 +#else
15572 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15573 +#endif
15574 +;
15575 +
15576 +extern void copy_from_user_overflow(void)
15577 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15578 + __compiletime_error("copy_from_user() buffer size is not provably correct")
15579 +#else
15580 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
15581 +#endif
15582 +;
15583
15584 static inline unsigned long __must_check copy_from_user(void *to,
15585 const void __user *from,
15586 unsigned long n)
15587 {
15588 - int sz = __compiletime_object_size(to);
15589 -
15590 might_fault();
15591 - if (likely(sz == -1 || sz >= n))
15592 - n = _copy_from_user(to, from, n);
15593 -#ifdef CONFIG_DEBUG_VM
15594 - else
15595 - WARN(1, "Buffer overflow detected!\n");
15596 -#endif
15597 +
15598 + check_object_size(to, n, false);
15599 +
15600 + if (access_ok(VERIFY_READ, from, n))
15601 + n = __copy_from_user(to, from, n);
15602 + else if (n < INT_MAX)
15603 + memset(to, 0, n);
15604 return n;
15605 }
15606
15607 static __always_inline __must_check
15608 -int copy_to_user(void __user *dst, const void *src, unsigned size)
15609 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
15610 {
15611 might_fault();
15612
15613 - return _copy_to_user(dst, src, size);
15614 + if (access_ok(VERIFY_WRITE, dst, size))
15615 + size = __copy_to_user(dst, src, size);
15616 + return size;
15617 }
15618
15619 static __always_inline __must_check
15620 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
15621 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15622 {
15623 - int ret = 0;
15624 + size_t sz = __compiletime_object_size(dst);
15625 + unsigned ret = 0;
15626
15627 might_fault();
15628 +
15629 + if (size > INT_MAX)
15630 + return size;
15631 +
15632 + check_object_size(dst, size, false);
15633 +
15634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15635 + if (!__access_ok(VERIFY_READ, src, size))
15636 + return size;
15637 +#endif
15638 +
15639 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15640 + copy_from_user_overflow();
15641 + return size;
15642 + }
15643 +
15644 if (!__builtin_constant_p(size))
15645 - return copy_user_generic(dst, (__force void *)src, size);
15646 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15647 switch (size) {
15648 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15649 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15650 ret, "b", "b", "=q", 1);
15651 return ret;
15652 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15653 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15654 ret, "w", "w", "=r", 2);
15655 return ret;
15656 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15657 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15658 ret, "l", "k", "=r", 4);
15659 return ret;
15660 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15661 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15662 ret, "q", "", "=r", 8);
15663 return ret;
15664 case 10:
15665 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15666 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15667 ret, "q", "", "=r", 10);
15668 if (unlikely(ret))
15669 return ret;
15670 __get_user_asm(*(u16 *)(8 + (char *)dst),
15671 - (u16 __user *)(8 + (char __user *)src),
15672 + (const u16 __user *)(8 + (const char __user *)src),
15673 ret, "w", "w", "=r", 2);
15674 return ret;
15675 case 16:
15676 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15677 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15678 ret, "q", "", "=r", 16);
15679 if (unlikely(ret))
15680 return ret;
15681 __get_user_asm(*(u64 *)(8 + (char *)dst),
15682 - (u64 __user *)(8 + (char __user *)src),
15683 + (const u64 __user *)(8 + (const char __user *)src),
15684 ret, "q", "", "=r", 8);
15685 return ret;
15686 default:
15687 - return copy_user_generic(dst, (__force void *)src, size);
15688 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15689 }
15690 }
15691
15692 static __always_inline __must_check
15693 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
15694 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15695 {
15696 - int ret = 0;
15697 + size_t sz = __compiletime_object_size(src);
15698 + unsigned ret = 0;
15699
15700 might_fault();
15701 +
15702 + if (size > INT_MAX)
15703 + return size;
15704 +
15705 + check_object_size(src, size, true);
15706 +
15707 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15708 + if (!__access_ok(VERIFY_WRITE, dst, size))
15709 + return size;
15710 +#endif
15711 +
15712 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15713 + copy_to_user_overflow();
15714 + return size;
15715 + }
15716 +
15717 if (!__builtin_constant_p(size))
15718 - return copy_user_generic((__force void *)dst, src, size);
15719 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15720 switch (size) {
15721 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15722 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15723 ret, "b", "b", "iq", 1);
15724 return ret;
15725 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15726 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15727 ret, "w", "w", "ir", 2);
15728 return ret;
15729 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15730 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15731 ret, "l", "k", "ir", 4);
15732 return ret;
15733 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15734 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15735 ret, "q", "", "er", 8);
15736 return ret;
15737 case 10:
15738 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15739 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15740 ret, "q", "", "er", 10);
15741 if (unlikely(ret))
15742 return ret;
15743 asm("":::"memory");
15744 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15745 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15746 ret, "w", "w", "ir", 2);
15747 return ret;
15748 case 16:
15749 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15750 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15751 ret, "q", "", "er", 16);
15752 if (unlikely(ret))
15753 return ret;
15754 asm("":::"memory");
15755 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15756 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15757 ret, "q", "", "er", 8);
15758 return ret;
15759 default:
15760 - return copy_user_generic((__force void *)dst, src, size);
15761 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15762 }
15763 }
15764
15765 static __always_inline __must_check
15766 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15767 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15768 {
15769 - int ret = 0;
15770 + unsigned ret = 0;
15771
15772 might_fault();
15773 +
15774 + if (size > INT_MAX)
15775 + return size;
15776 +
15777 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15778 + if (!__access_ok(VERIFY_READ, src, size))
15779 + return size;
15780 + if (!__access_ok(VERIFY_WRITE, dst, size))
15781 + return size;
15782 +#endif
15783 +
15784 if (!__builtin_constant_p(size))
15785 - return copy_user_generic((__force void *)dst,
15786 - (__force void *)src, size);
15787 + return copy_user_generic((__force_kernel void *)____m(dst),
15788 + (__force_kernel const void *)____m(src), size);
15789 switch (size) {
15790 case 1: {
15791 u8 tmp;
15792 - __get_user_asm(tmp, (u8 __user *)src,
15793 + __get_user_asm(tmp, (const u8 __user *)src,
15794 ret, "b", "b", "=q", 1);
15795 if (likely(!ret))
15796 __put_user_asm(tmp, (u8 __user *)dst,
15797 @@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15798 }
15799 case 2: {
15800 u16 tmp;
15801 - __get_user_asm(tmp, (u16 __user *)src,
15802 + __get_user_asm(tmp, (const u16 __user *)src,
15803 ret, "w", "w", "=r", 2);
15804 if (likely(!ret))
15805 __put_user_asm(tmp, (u16 __user *)dst,
15806 @@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15807
15808 case 4: {
15809 u32 tmp;
15810 - __get_user_asm(tmp, (u32 __user *)src,
15811 + __get_user_asm(tmp, (const u32 __user *)src,
15812 ret, "l", "k", "=r", 4);
15813 if (likely(!ret))
15814 __put_user_asm(tmp, (u32 __user *)dst,
15815 @@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15816 }
15817 case 8: {
15818 u64 tmp;
15819 - __get_user_asm(tmp, (u64 __user *)src,
15820 + __get_user_asm(tmp, (const u64 __user *)src,
15821 ret, "q", "", "=r", 8);
15822 if (likely(!ret))
15823 __put_user_asm(tmp, (u64 __user *)dst,
15824 @@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15825 return ret;
15826 }
15827 default:
15828 - return copy_user_generic((__force void *)dst,
15829 - (__force void *)src, size);
15830 + return copy_user_generic((__force_kernel void *)____m(dst),
15831 + (__force_kernel const void *)____m(src), size);
15832 }
15833 }
15834
15835 static __must_check __always_inline int
15836 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
15837 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
15838 {
15839 - return copy_user_generic(dst, (__force const void *)src, size);
15840 + if (size > INT_MAX)
15841 + return size;
15842 +
15843 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15844 + if (!__access_ok(VERIFY_READ, src, size))
15845 + return size;
15846 +#endif
15847 +
15848 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15849 }
15850
15851 -static __must_check __always_inline int
15852 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
15853 +static __must_check __always_inline unsigned long
15854 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
15855 {
15856 - return copy_user_generic((__force void *)dst, src, size);
15857 + if (size > INT_MAX)
15858 + return size;
15859 +
15860 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15861 + if (!__access_ok(VERIFY_WRITE, dst, size))
15862 + return size;
15863 +#endif
15864 +
15865 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15866 }
15867
15868 -extern long __copy_user_nocache(void *dst, const void __user *src,
15869 - unsigned size, int zerorest);
15870 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
15871 + unsigned long size, int zerorest) __size_overflow(3);
15872
15873 -static inline int
15874 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
15875 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
15876 {
15877 might_sleep();
15878 +
15879 + if (size > INT_MAX)
15880 + return size;
15881 +
15882 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15883 + if (!__access_ok(VERIFY_READ, src, size))
15884 + return size;
15885 +#endif
15886 +
15887 return __copy_user_nocache(dst, src, size, 1);
15888 }
15889
15890 -static inline int
15891 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15892 - unsigned size)
15893 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15894 + unsigned long size)
15895 {
15896 + if (size > INT_MAX)
15897 + return size;
15898 +
15899 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15900 + if (!__access_ok(VERIFY_READ, src, size))
15901 + return size;
15902 +#endif
15903 +
15904 return __copy_user_nocache(dst, src, size, 0);
15905 }
15906
15907 -unsigned long
15908 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
15909 +extern unsigned long
15910 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
15911
15912 #endif /* _ASM_X86_UACCESS_64_H */
15913 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
15914 index 5b238981..77fdd78 100644
15915 --- a/arch/x86/include/asm/word-at-a-time.h
15916 +++ b/arch/x86/include/asm/word-at-a-time.h
15917 @@ -11,7 +11,7 @@
15918 * and shift, for example.
15919 */
15920 struct word_at_a_time {
15921 - const unsigned long one_bits, high_bits;
15922 + unsigned long one_bits, high_bits;
15923 };
15924
15925 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
15926 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
15927 index 5769349..a3d3e2a 100644
15928 --- a/arch/x86/include/asm/x86_init.h
15929 +++ b/arch/x86/include/asm/x86_init.h
15930 @@ -141,7 +141,7 @@ struct x86_init_ops {
15931 struct x86_init_timers timers;
15932 struct x86_init_iommu iommu;
15933 struct x86_init_pci pci;
15934 -};
15935 +} __no_const;
15936
15937 /**
15938 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
15939 @@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
15940 void (*setup_percpu_clockev)(void);
15941 void (*early_percpu_clock_init)(void);
15942 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
15943 -};
15944 +} __no_const;
15945
15946 /**
15947 * struct x86_platform_ops - platform specific runtime functions
15948 @@ -178,7 +178,7 @@ struct x86_platform_ops {
15949 void (*save_sched_clock_state)(void);
15950 void (*restore_sched_clock_state)(void);
15951 void (*apic_post_init)(void);
15952 -};
15953 +} __no_const;
15954
15955 struct pci_dev;
15956
15957 @@ -187,14 +187,14 @@ struct x86_msi_ops {
15958 void (*teardown_msi_irq)(unsigned int irq);
15959 void (*teardown_msi_irqs)(struct pci_dev *dev);
15960 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
15961 -};
15962 +} __no_const;
15963
15964 struct x86_io_apic_ops {
15965 void (*init) (void);
15966 unsigned int (*read) (unsigned int apic, unsigned int reg);
15967 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
15968 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
15969 -};
15970 +} __no_const;
15971
15972 extern struct x86_init_ops x86_init;
15973 extern struct x86_cpuinit_ops x86_cpuinit;
15974 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
15975 index 0415cda..b43d877 100644
15976 --- a/arch/x86/include/asm/xsave.h
15977 +++ b/arch/x86/include/asm/xsave.h
15978 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15979 return -EFAULT;
15980
15981 __asm__ __volatile__(ASM_STAC "\n"
15982 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
15983 + "1:"
15984 + __copyuser_seg
15985 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
15986 "2: " ASM_CLAC "\n"
15987 ".section .fixup,\"ax\"\n"
15988 "3: movl $-1,%[err]\n"
15989 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15990 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
15991 {
15992 int err;
15993 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
15994 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
15995 u32 lmask = mask;
15996 u32 hmask = mask >> 32;
15997
15998 __asm__ __volatile__(ASM_STAC "\n"
15999 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16000 + "1:"
16001 + __copyuser_seg
16002 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16003 "2: " ASM_CLAC "\n"
16004 ".section .fixup,\"ax\"\n"
16005 "3: movl $-1,%[err]\n"
16006 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16007 index bbae024..e1528f9 100644
16008 --- a/arch/x86/include/uapi/asm/e820.h
16009 +++ b/arch/x86/include/uapi/asm/e820.h
16010 @@ -63,7 +63,7 @@ struct e820map {
16011 #define ISA_START_ADDRESS 0xa0000
16012 #define ISA_END_ADDRESS 0x100000
16013
16014 -#define BIOS_BEGIN 0x000a0000
16015 +#define BIOS_BEGIN 0x000c0000
16016 #define BIOS_END 0x00100000
16017
16018 #define BIOS_ROM_BASE 0xffe00000
16019 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16020 index 34e923a..0c6bb6e 100644
16021 --- a/arch/x86/kernel/Makefile
16022 +++ b/arch/x86/kernel/Makefile
16023 @@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16024 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16025 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16026 obj-y += probe_roms.o
16027 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16028 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16029 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16030 obj-y += syscall_$(BITS).o
16031 obj-$(CONFIG_X86_64) += vsyscall_64.o
16032 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16033 index d5e0d71..6533e08 100644
16034 --- a/arch/x86/kernel/acpi/sleep.c
16035 +++ b/arch/x86/kernel/acpi/sleep.c
16036 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16037 #else /* CONFIG_64BIT */
16038 #ifdef CONFIG_SMP
16039 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16040 +
16041 + pax_open_kernel();
16042 early_gdt_descr.address =
16043 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16044 + pax_close_kernel();
16045 +
16046 initial_gs = per_cpu_offset(smp_processor_id());
16047 #endif
16048 initial_code = (unsigned long)wakeup_long64;
16049 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16050 index 13ab720..95d5442 100644
16051 --- a/arch/x86/kernel/acpi/wakeup_32.S
16052 +++ b/arch/x86/kernel/acpi/wakeup_32.S
16053 @@ -30,13 +30,11 @@ wakeup_pmode_return:
16054 # and restore the stack ... but you need gdt for this to work
16055 movl saved_context_esp, %esp
16056
16057 - movl %cs:saved_magic, %eax
16058 - cmpl $0x12345678, %eax
16059 + cmpl $0x12345678, saved_magic
16060 jne bogus_magic
16061
16062 # jump to place where we left off
16063 - movl saved_eip, %eax
16064 - jmp *%eax
16065 + jmp *(saved_eip)
16066
16067 bogus_magic:
16068 jmp bogus_magic
16069 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16070 index ef5ccca..bd83949 100644
16071 --- a/arch/x86/kernel/alternative.c
16072 +++ b/arch/x86/kernel/alternative.c
16073 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16074 */
16075 for (a = start; a < end; a++) {
16076 instr = (u8 *)&a->instr_offset + a->instr_offset;
16077 +
16078 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16079 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16080 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16081 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16082 +#endif
16083 +
16084 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16085 BUG_ON(a->replacementlen > a->instrlen);
16086 BUG_ON(a->instrlen > sizeof(insnbuf));
16087 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16088 for (poff = start; poff < end; poff++) {
16089 u8 *ptr = (u8 *)poff + *poff;
16090
16091 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16092 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16093 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16094 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16095 +#endif
16096 +
16097 if (!*poff || ptr < text || ptr >= text_end)
16098 continue;
16099 /* turn DS segment override prefix into lock prefix */
16100 - if (*ptr == 0x3e)
16101 + if (*ktla_ktva(ptr) == 0x3e)
16102 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16103 }
16104 mutex_unlock(&text_mutex);
16105 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16106 for (poff = start; poff < end; poff++) {
16107 u8 *ptr = (u8 *)poff + *poff;
16108
16109 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16110 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16111 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16112 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16113 +#endif
16114 +
16115 if (!*poff || ptr < text || ptr >= text_end)
16116 continue;
16117 /* turn lock prefix into DS segment override prefix */
16118 - if (*ptr == 0xf0)
16119 + if (*ktla_ktva(ptr) == 0xf0)
16120 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16121 }
16122 mutex_unlock(&text_mutex);
16123 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16124
16125 BUG_ON(p->len > MAX_PATCH_LEN);
16126 /* prep the buffer with the original instructions */
16127 - memcpy(insnbuf, p->instr, p->len);
16128 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16129 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16130 (unsigned long)p->instr, p->len);
16131
16132 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16133 if (!uniproc_patched || num_possible_cpus() == 1)
16134 free_init_pages("SMP alternatives",
16135 (unsigned long)__smp_locks,
16136 - (unsigned long)__smp_locks_end);
16137 + PAGE_ALIGN((unsigned long)__smp_locks_end));
16138 #endif
16139
16140 apply_paravirt(__parainstructions, __parainstructions_end);
16141 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16142 * instructions. And on the local CPU you need to be protected again NMI or MCE
16143 * handlers seeing an inconsistent instruction while you patch.
16144 */
16145 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
16146 +void *__kprobes text_poke_early(void *addr, const void *opcode,
16147 size_t len)
16148 {
16149 unsigned long flags;
16150 local_irq_save(flags);
16151 - memcpy(addr, opcode, len);
16152 +
16153 + pax_open_kernel();
16154 + memcpy(ktla_ktva(addr), opcode, len);
16155 sync_core();
16156 + pax_close_kernel();
16157 +
16158 local_irq_restore(flags);
16159 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16160 that causes hangs on some VIA CPUs. */
16161 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16162 */
16163 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16164 {
16165 - unsigned long flags;
16166 - char *vaddr;
16167 + unsigned char *vaddr = ktla_ktva(addr);
16168 struct page *pages[2];
16169 - int i;
16170 + size_t i;
16171
16172 if (!core_kernel_text((unsigned long)addr)) {
16173 - pages[0] = vmalloc_to_page(addr);
16174 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16175 + pages[0] = vmalloc_to_page(vaddr);
16176 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16177 } else {
16178 - pages[0] = virt_to_page(addr);
16179 + pages[0] = virt_to_page(vaddr);
16180 WARN_ON(!PageReserved(pages[0]));
16181 - pages[1] = virt_to_page(addr + PAGE_SIZE);
16182 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16183 }
16184 BUG_ON(!pages[0]);
16185 - local_irq_save(flags);
16186 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16187 - if (pages[1])
16188 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16189 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16190 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16191 - clear_fixmap(FIX_TEXT_POKE0);
16192 - if (pages[1])
16193 - clear_fixmap(FIX_TEXT_POKE1);
16194 - local_flush_tlb();
16195 - sync_core();
16196 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
16197 - that causes hangs on some VIA CPUs. */
16198 + text_poke_early(addr, opcode, len);
16199 for (i = 0; i < len; i++)
16200 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16201 - local_irq_restore(flags);
16202 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16203 return addr;
16204 }
16205
16206 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16207 index b994cc8..812b537 100644
16208 --- a/arch/x86/kernel/apic/apic.c
16209 +++ b/arch/x86/kernel/apic/apic.c
16210 @@ -131,7 +131,7 @@ static int __init parse_lapic(char *arg)
16211 {
16212 if (config_enabled(CONFIG_X86_32) && !arg)
16213 force_enable_local_apic = 1;
16214 - else if (!strncmp(arg, "notscdeadline", 13))
16215 + else if (arg && !strncmp(arg, "notscdeadline", 13))
16216 setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
16217 return 0;
16218 }
16219 @@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16220 /*
16221 * Debug level, exported for io_apic.c
16222 */
16223 -unsigned int apic_verbosity;
16224 +int apic_verbosity;
16225
16226 int pic_mode;
16227
16228 @@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16229 apic_write(APIC_ESR, 0);
16230 v1 = apic_read(APIC_ESR);
16231 ack_APIC_irq();
16232 - atomic_inc(&irq_err_count);
16233 + atomic_inc_unchecked(&irq_err_count);
16234
16235 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16236 smp_processor_id(), v0 , v1);
16237 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16238 index 00c77cf..2dc6a2d 100644
16239 --- a/arch/x86/kernel/apic/apic_flat_64.c
16240 +++ b/arch/x86/kernel/apic/apic_flat_64.c
16241 @@ -157,7 +157,7 @@ static int flat_probe(void)
16242 return 1;
16243 }
16244
16245 -static struct apic apic_flat = {
16246 +static struct apic apic_flat __read_only = {
16247 .name = "flat",
16248 .probe = flat_probe,
16249 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16250 @@ -271,7 +271,7 @@ static int physflat_probe(void)
16251 return 0;
16252 }
16253
16254 -static struct apic apic_physflat = {
16255 +static struct apic apic_physflat __read_only = {
16256
16257 .name = "physical flat",
16258 .probe = physflat_probe,
16259 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16260 index d50e364..543bee3 100644
16261 --- a/arch/x86/kernel/apic/bigsmp_32.c
16262 +++ b/arch/x86/kernel/apic/bigsmp_32.c
16263 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16264 return dmi_bigsmp;
16265 }
16266
16267 -static struct apic apic_bigsmp = {
16268 +static struct apic apic_bigsmp __read_only = {
16269
16270 .name = "bigsmp",
16271 .probe = probe_bigsmp,
16272 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16273 index 0874799..24a836e 100644
16274 --- a/arch/x86/kernel/apic/es7000_32.c
16275 +++ b/arch/x86/kernel/apic/es7000_32.c
16276 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16277 return ret && es7000_apic_is_cluster();
16278 }
16279
16280 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16281 -static struct apic __refdata apic_es7000_cluster = {
16282 +static struct apic apic_es7000_cluster __read_only = {
16283
16284 .name = "es7000",
16285 .probe = probe_es7000,
16286 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16287 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16288 };
16289
16290 -static struct apic __refdata apic_es7000 = {
16291 +static struct apic __refdata apic_es7000 __read_only = {
16292
16293 .name = "es7000",
16294 .probe = probe_es7000,
16295 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16296 index b739d39..6e4f1db 100644
16297 --- a/arch/x86/kernel/apic/io_apic.c
16298 +++ b/arch/x86/kernel/apic/io_apic.c
16299 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16300 }
16301 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16302
16303 -void lock_vector_lock(void)
16304 +void lock_vector_lock(void) __acquires(vector_lock)
16305 {
16306 /* Used to the online set of cpus does not change
16307 * during assign_irq_vector.
16308 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16309 raw_spin_lock(&vector_lock);
16310 }
16311
16312 -void unlock_vector_lock(void)
16313 +void unlock_vector_lock(void) __releases(vector_lock)
16314 {
16315 raw_spin_unlock(&vector_lock);
16316 }
16317 @@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16318 ack_APIC_irq();
16319 }
16320
16321 -atomic_t irq_mis_count;
16322 +atomic_unchecked_t irq_mis_count;
16323
16324 #ifdef CONFIG_GENERIC_PENDING_IRQ
16325 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16326 @@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16327 * at the cpu.
16328 */
16329 if (!(v & (1 << (i & 0x1f)))) {
16330 - atomic_inc(&irq_mis_count);
16331 + atomic_inc_unchecked(&irq_mis_count);
16332
16333 eoi_ioapic_irq(irq, cfg);
16334 }
16335 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16336 index d661ee9..791fd33 100644
16337 --- a/arch/x86/kernel/apic/numaq_32.c
16338 +++ b/arch/x86/kernel/apic/numaq_32.c
16339 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16340 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16341 }
16342
16343 -/* Use __refdata to keep false positive warning calm. */
16344 -static struct apic __refdata apic_numaq = {
16345 +static struct apic apic_numaq __read_only = {
16346
16347 .name = "NUMAQ",
16348 .probe = probe_numaq,
16349 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16350 index eb35ef9..f184a21 100644
16351 --- a/arch/x86/kernel/apic/probe_32.c
16352 +++ b/arch/x86/kernel/apic/probe_32.c
16353 @@ -72,7 +72,7 @@ static int probe_default(void)
16354 return 1;
16355 }
16356
16357 -static struct apic apic_default = {
16358 +static struct apic apic_default __read_only = {
16359
16360 .name = "default",
16361 .probe = probe_default,
16362 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16363 index 77c95c0..434f8a4 100644
16364 --- a/arch/x86/kernel/apic/summit_32.c
16365 +++ b/arch/x86/kernel/apic/summit_32.c
16366 @@ -486,7 +486,7 @@ void setup_summit(void)
16367 }
16368 #endif
16369
16370 -static struct apic apic_summit = {
16371 +static struct apic apic_summit __read_only = {
16372
16373 .name = "summit",
16374 .probe = probe_summit,
16375 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16376 index c88baa4..757aee1 100644
16377 --- a/arch/x86/kernel/apic/x2apic_cluster.c
16378 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
16379 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16380 return notifier_from_errno(err);
16381 }
16382
16383 -static struct notifier_block __refdata x2apic_cpu_notifier = {
16384 +static struct notifier_block x2apic_cpu_notifier = {
16385 .notifier_call = update_clusterinfo,
16386 };
16387
16388 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16389 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16390 }
16391
16392 -static struct apic apic_x2apic_cluster = {
16393 +static struct apic apic_x2apic_cluster __read_only = {
16394
16395 .name = "cluster x2apic",
16396 .probe = x2apic_cluster_probe,
16397 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16398 index 562a76d..a003c0f 100644
16399 --- a/arch/x86/kernel/apic/x2apic_phys.c
16400 +++ b/arch/x86/kernel/apic/x2apic_phys.c
16401 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16402 return apic == &apic_x2apic_phys;
16403 }
16404
16405 -static struct apic apic_x2apic_phys = {
16406 +static struct apic apic_x2apic_phys __read_only = {
16407
16408 .name = "physical x2apic",
16409 .probe = x2apic_phys_probe,
16410 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16411 index 8cfade9..b9d04fc 100644
16412 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
16413 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16414 @@ -333,7 +333,7 @@ static int uv_probe(void)
16415 return apic == &apic_x2apic_uv_x;
16416 }
16417
16418 -static struct apic __refdata apic_x2apic_uv_x = {
16419 +static struct apic apic_x2apic_uv_x __read_only = {
16420
16421 .name = "UV large system",
16422 .probe = uv_probe,
16423 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16424 index d65464e..1035d31 100644
16425 --- a/arch/x86/kernel/apm_32.c
16426 +++ b/arch/x86/kernel/apm_32.c
16427 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16428 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16429 * even though they are called in protected mode.
16430 */
16431 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16432 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16433 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16434
16435 static const char driver_version[] = "1.16ac"; /* no spaces */
16436 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16437 BUG_ON(cpu != 0);
16438 gdt = get_cpu_gdt_table(cpu);
16439 save_desc_40 = gdt[0x40 / 8];
16440 +
16441 + pax_open_kernel();
16442 gdt[0x40 / 8] = bad_bios_desc;
16443 + pax_close_kernel();
16444
16445 apm_irq_save(flags);
16446 APM_DO_SAVE_SEGS;
16447 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16448 &call->esi);
16449 APM_DO_RESTORE_SEGS;
16450 apm_irq_restore(flags);
16451 +
16452 + pax_open_kernel();
16453 gdt[0x40 / 8] = save_desc_40;
16454 + pax_close_kernel();
16455 +
16456 put_cpu();
16457
16458 return call->eax & 0xff;
16459 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16460 BUG_ON(cpu != 0);
16461 gdt = get_cpu_gdt_table(cpu);
16462 save_desc_40 = gdt[0x40 / 8];
16463 +
16464 + pax_open_kernel();
16465 gdt[0x40 / 8] = bad_bios_desc;
16466 + pax_close_kernel();
16467
16468 apm_irq_save(flags);
16469 APM_DO_SAVE_SEGS;
16470 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16471 &call->eax);
16472 APM_DO_RESTORE_SEGS;
16473 apm_irq_restore(flags);
16474 +
16475 + pax_open_kernel();
16476 gdt[0x40 / 8] = save_desc_40;
16477 + pax_close_kernel();
16478 +
16479 put_cpu();
16480 return error;
16481 }
16482 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16483 * code to that CPU.
16484 */
16485 gdt = get_cpu_gdt_table(0);
16486 +
16487 + pax_open_kernel();
16488 set_desc_base(&gdt[APM_CS >> 3],
16489 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16490 set_desc_base(&gdt[APM_CS_16 >> 3],
16491 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16492 set_desc_base(&gdt[APM_DS >> 3],
16493 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16494 + pax_close_kernel();
16495
16496 proc_create("apm", 0, NULL, &apm_file_ops);
16497
16498 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16499 index 2861082..6d4718e 100644
16500 --- a/arch/x86/kernel/asm-offsets.c
16501 +++ b/arch/x86/kernel/asm-offsets.c
16502 @@ -33,6 +33,8 @@ void common(void) {
16503 OFFSET(TI_status, thread_info, status);
16504 OFFSET(TI_addr_limit, thread_info, addr_limit);
16505 OFFSET(TI_preempt_count, thread_info, preempt_count);
16506 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16507 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16508
16509 BLANK();
16510 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16511 @@ -53,8 +55,26 @@ void common(void) {
16512 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16513 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16514 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16515 +
16516 +#ifdef CONFIG_PAX_KERNEXEC
16517 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16518 #endif
16519
16520 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16521 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16522 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16523 +#ifdef CONFIG_X86_64
16524 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16525 +#endif
16526 +#endif
16527 +
16528 +#endif
16529 +
16530 + BLANK();
16531 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16532 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16533 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16534 +
16535 #ifdef CONFIG_XEN
16536 BLANK();
16537 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16538 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16539 index 1b4754f..fbb4227 100644
16540 --- a/arch/x86/kernel/asm-offsets_64.c
16541 +++ b/arch/x86/kernel/asm-offsets_64.c
16542 @@ -76,6 +76,7 @@ int main(void)
16543 BLANK();
16544 #undef ENTRY
16545
16546 + DEFINE(TSS_size, sizeof(struct tss_struct));
16547 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16548 BLANK();
16549
16550 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16551 index a0e067d..9c7db16 100644
16552 --- a/arch/x86/kernel/cpu/Makefile
16553 +++ b/arch/x86/kernel/cpu/Makefile
16554 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16555 CFLAGS_REMOVE_perf_event.o = -pg
16556 endif
16557
16558 -# Make sure load_percpu_segment has no stackprotector
16559 -nostackp := $(call cc-option, -fno-stack-protector)
16560 -CFLAGS_common.o := $(nostackp)
16561 -
16562 obj-y := intel_cacheinfo.o scattered.o topology.o
16563 obj-y += proc.o capflags.o powerflags.o common.o
16564 obj-y += vmware.o hypervisor.o mshyperv.o
16565 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16566 index 15239ff..e23e04e 100644
16567 --- a/arch/x86/kernel/cpu/amd.c
16568 +++ b/arch/x86/kernel/cpu/amd.c
16569 @@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16570 unsigned int size)
16571 {
16572 /* AMD errata T13 (order #21922) */
16573 - if ((c->x86 == 6)) {
16574 + if (c->x86 == 6) {
16575 /* Duron Rev A0 */
16576 if (c->x86_model == 3 && c->x86_mask == 0)
16577 size = 64;
16578 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16579 index 9c3ab43..51e6366 100644
16580 --- a/arch/x86/kernel/cpu/common.c
16581 +++ b/arch/x86/kernel/cpu/common.c
16582 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16583
16584 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16585
16586 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16587 -#ifdef CONFIG_X86_64
16588 - /*
16589 - * We need valid kernel segments for data and code in long mode too
16590 - * IRET will check the segment types kkeil 2000/10/28
16591 - * Also sysret mandates a special GDT layout
16592 - *
16593 - * TLS descriptors are currently at a different place compared to i386.
16594 - * Hopefully nobody expects them at a fixed place (Wine?)
16595 - */
16596 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16597 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16598 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16599 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16600 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16601 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16602 -#else
16603 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16604 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16605 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16606 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16607 - /*
16608 - * Segments used for calling PnP BIOS have byte granularity.
16609 - * They code segments and data segments have fixed 64k limits,
16610 - * the transfer segment sizes are set at run time.
16611 - */
16612 - /* 32-bit code */
16613 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16614 - /* 16-bit code */
16615 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16616 - /* 16-bit data */
16617 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16618 - /* 16-bit data */
16619 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16620 - /* 16-bit data */
16621 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16622 - /*
16623 - * The APM segments have byte granularity and their bases
16624 - * are set at run time. All have 64k limits.
16625 - */
16626 - /* 32-bit code */
16627 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16628 - /* 16-bit code */
16629 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16630 - /* data */
16631 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16632 -
16633 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16634 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16635 - GDT_STACK_CANARY_INIT
16636 -#endif
16637 -} };
16638 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16639 -
16640 static int __init x86_xsave_setup(char *s)
16641 {
16642 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16643 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16644 {
16645 struct desc_ptr gdt_descr;
16646
16647 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16648 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16649 gdt_descr.size = GDT_SIZE - 1;
16650 load_gdt(&gdt_descr);
16651 /* Reload the per-cpu base */
16652 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16653 /* Filter out anything that depends on CPUID levels we don't have */
16654 filter_cpuid_features(c, true);
16655
16656 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16657 + setup_clear_cpu_cap(X86_FEATURE_SEP);
16658 +#endif
16659 +
16660 /* If the model name is still unset, do table lookup. */
16661 if (!c->x86_model_id[0]) {
16662 const char *p;
16663 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16664 }
16665 __setup("clearcpuid=", setup_disablecpuid);
16666
16667 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16668 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
16669 +
16670 #ifdef CONFIG_X86_64
16671 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16672 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16673 - (unsigned long) nmi_idt_table };
16674 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16675
16676 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16677 irq_stack_union) __aligned(PAGE_SIZE);
16678 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16679 EXPORT_PER_CPU_SYMBOL(current_task);
16680
16681 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16682 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16683 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16684 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16685
16686 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16687 @@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16688 int i;
16689
16690 cpu = stack_smp_processor_id();
16691 - t = &per_cpu(init_tss, cpu);
16692 + t = init_tss + cpu;
16693 oist = &per_cpu(orig_ist, cpu);
16694
16695 #ifdef CONFIG_NUMA
16696 @@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16697 switch_to_new_gdt(cpu);
16698 loadsegment(fs, 0);
16699
16700 - load_idt((const struct desc_ptr *)&idt_descr);
16701 + load_idt(&idt_descr);
16702
16703 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16704 syscall_init();
16705 @@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16706 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16707 barrier();
16708
16709 - x86_configure_nx();
16710 enable_x2apic();
16711
16712 /*
16713 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16714 {
16715 int cpu = smp_processor_id();
16716 struct task_struct *curr = current;
16717 - struct tss_struct *t = &per_cpu(init_tss, cpu);
16718 + struct tss_struct *t = init_tss + cpu;
16719 struct thread_struct *thread = &curr->thread;
16720
16721 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16722 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16723 index fcaabd0..7b55a26 100644
16724 --- a/arch/x86/kernel/cpu/intel.c
16725 +++ b/arch/x86/kernel/cpu/intel.c
16726 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16727 * Update the IDT descriptor and reload the IDT so that
16728 * it uses the read-only mapped virtual address.
16729 */
16730 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16731 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16732 load_idt(&idt_descr);
16733 }
16734 #endif
16735 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16736 index 84c1309..39b7224 100644
16737 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16738 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16739 @@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16740 };
16741
16742 #ifdef CONFIG_AMD_NB
16743 +static struct attribute *default_attrs_amd_nb[] = {
16744 + &type.attr,
16745 + &level.attr,
16746 + &coherency_line_size.attr,
16747 + &physical_line_partition.attr,
16748 + &ways_of_associativity.attr,
16749 + &number_of_sets.attr,
16750 + &size.attr,
16751 + &shared_cpu_map.attr,
16752 + &shared_cpu_list.attr,
16753 + NULL,
16754 + NULL,
16755 + NULL,
16756 + NULL
16757 +};
16758 +
16759 static struct attribute ** __cpuinit amd_l3_attrs(void)
16760 {
16761 static struct attribute **attrs;
16762 @@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
16763
16764 n = ARRAY_SIZE(default_attrs);
16765
16766 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
16767 - n += 2;
16768 -
16769 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
16770 - n += 1;
16771 -
16772 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
16773 - if (attrs == NULL)
16774 - return attrs = default_attrs;
16775 -
16776 - for (n = 0; default_attrs[n]; n++)
16777 - attrs[n] = default_attrs[n];
16778 + attrs = default_attrs_amd_nb;
16779
16780 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
16781 attrs[n++] = &cache_disable_0.attr;
16782 @@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
16783 .default_attrs = default_attrs,
16784 };
16785
16786 +#ifdef CONFIG_AMD_NB
16787 +static struct kobj_type ktype_cache_amd_nb = {
16788 + .sysfs_ops = &sysfs_ops,
16789 + .default_attrs = default_attrs_amd_nb,
16790 +};
16791 +#endif
16792 +
16793 static struct kobj_type ktype_percpu_entry = {
16794 .sysfs_ops = &sysfs_ops,
16795 };
16796 @@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
16797 return retval;
16798 }
16799
16800 +#ifdef CONFIG_AMD_NB
16801 + amd_l3_attrs();
16802 +#endif
16803 +
16804 for (i = 0; i < num_cache_leaves; i++) {
16805 + struct kobj_type *ktype;
16806 +
16807 this_object = INDEX_KOBJECT_PTR(cpu, i);
16808 this_object->cpu = cpu;
16809 this_object->index = i;
16810
16811 this_leaf = CPUID4_INFO_IDX(cpu, i);
16812
16813 - ktype_cache.default_attrs = default_attrs;
16814 + ktype = &ktype_cache;
16815 #ifdef CONFIG_AMD_NB
16816 if (this_leaf->base.nb)
16817 - ktype_cache.default_attrs = amd_l3_attrs();
16818 + ktype = &ktype_cache_amd_nb;
16819 #endif
16820 retval = kobject_init_and_add(&(this_object->kobj),
16821 - &ktype_cache,
16822 + ktype,
16823 per_cpu(ici_cache_kobject, cpu),
16824 "index%1lu", i);
16825 if (unlikely(retval)) {
16826 @@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
16827 return NOTIFY_OK;
16828 }
16829
16830 -static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
16831 +static struct notifier_block cacheinfo_cpu_notifier = {
16832 .notifier_call = cacheinfo_cpu_callback,
16833 };
16834
16835 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
16836 index 80dbda8..b45ebad 100644
16837 --- a/arch/x86/kernel/cpu/mcheck/mce.c
16838 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
16839 @@ -45,6 +45,7 @@
16840 #include <asm/processor.h>
16841 #include <asm/mce.h>
16842 #include <asm/msr.h>
16843 +#include <asm/local.h>
16844
16845 #include "mce-internal.h"
16846
16847 @@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
16848 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
16849 m->cs, m->ip);
16850
16851 - if (m->cs == __KERNEL_CS)
16852 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
16853 print_symbol("{%s}", m->ip);
16854 pr_cont("\n");
16855 }
16856 @@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
16857
16858 #define PANIC_TIMEOUT 5 /* 5 seconds */
16859
16860 -static atomic_t mce_paniced;
16861 +static atomic_unchecked_t mce_paniced;
16862
16863 static int fake_panic;
16864 -static atomic_t mce_fake_paniced;
16865 +static atomic_unchecked_t mce_fake_paniced;
16866
16867 /* Panic in progress. Enable interrupts and wait for final IPI */
16868 static void wait_for_panic(void)
16869 @@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16870 /*
16871 * Make sure only one CPU runs in machine check panic
16872 */
16873 - if (atomic_inc_return(&mce_paniced) > 1)
16874 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
16875 wait_for_panic();
16876 barrier();
16877
16878 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16879 console_verbose();
16880 } else {
16881 /* Don't log too much for fake panic */
16882 - if (atomic_inc_return(&mce_fake_paniced) > 1)
16883 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
16884 return;
16885 }
16886 /* First print corrected ones that are still unlogged */
16887 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
16888 * might have been modified by someone else.
16889 */
16890 rmb();
16891 - if (atomic_read(&mce_paniced))
16892 + if (atomic_read_unchecked(&mce_paniced))
16893 wait_for_panic();
16894 if (!mca_cfg.monarch_timeout)
16895 goto out;
16896 @@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
16897 }
16898
16899 /* Call the installed machine check handler for this CPU setup. */
16900 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
16901 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
16902 unexpected_machine_check;
16903
16904 /*
16905 @@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16906 return;
16907 }
16908
16909 + pax_open_kernel();
16910 machine_check_vector = do_machine_check;
16911 + pax_close_kernel();
16912
16913 __mcheck_cpu_init_generic();
16914 __mcheck_cpu_init_vendor(c);
16915 @@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16916 */
16917
16918 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
16919 -static int mce_chrdev_open_count; /* #times opened */
16920 +static local_t mce_chrdev_open_count; /* #times opened */
16921 static int mce_chrdev_open_exclu; /* already open exclusive? */
16922
16923 static int mce_chrdev_open(struct inode *inode, struct file *file)
16924 @@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16925 spin_lock(&mce_chrdev_state_lock);
16926
16927 if (mce_chrdev_open_exclu ||
16928 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
16929 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
16930 spin_unlock(&mce_chrdev_state_lock);
16931
16932 return -EBUSY;
16933 @@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16934
16935 if (file->f_flags & O_EXCL)
16936 mce_chrdev_open_exclu = 1;
16937 - mce_chrdev_open_count++;
16938 + local_inc(&mce_chrdev_open_count);
16939
16940 spin_unlock(&mce_chrdev_state_lock);
16941
16942 @@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
16943 {
16944 spin_lock(&mce_chrdev_state_lock);
16945
16946 - mce_chrdev_open_count--;
16947 + local_dec(&mce_chrdev_open_count);
16948 mce_chrdev_open_exclu = 0;
16949
16950 spin_unlock(&mce_chrdev_state_lock);
16951 @@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
16952 return NOTIFY_OK;
16953 }
16954
16955 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
16956 +static struct notifier_block mce_cpu_notifier = {
16957 .notifier_call = mce_cpu_callback,
16958 };
16959
16960 @@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
16961 static void mce_reset(void)
16962 {
16963 cpu_missing = 0;
16964 - atomic_set(&mce_fake_paniced, 0);
16965 + atomic_set_unchecked(&mce_fake_paniced, 0);
16966 atomic_set(&mce_executing, 0);
16967 atomic_set(&mce_callin, 0);
16968 atomic_set(&global_nwo, 0);
16969 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
16970 index 2d5454c..51987eb 100644
16971 --- a/arch/x86/kernel/cpu/mcheck/p5.c
16972 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
16973 @@ -11,6 +11,7 @@
16974 #include <asm/processor.h>
16975 #include <asm/mce.h>
16976 #include <asm/msr.h>
16977 +#include <asm/pgtable.h>
16978
16979 /* By default disabled */
16980 int mce_p5_enabled __read_mostly;
16981 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
16982 if (!cpu_has(c, X86_FEATURE_MCE))
16983 return;
16984
16985 + pax_open_kernel();
16986 machine_check_vector = pentium_machine_check;
16987 + pax_close_kernel();
16988 /* Make sure the vector pointer is visible before we enable MCEs: */
16989 wmb();
16990
16991 diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16992 index 47a1870..8c019a7 100644
16993 --- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
16994 +++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16995 @@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
16996 return notifier_from_errno(err);
16997 }
16998
16999 -static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17000 +static struct notifier_block thermal_throttle_cpu_notifier =
17001 {
17002 .notifier_call = thermal_throttle_cpu_callback,
17003 };
17004 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17005 index 2d7998f..17c9de1 100644
17006 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
17007 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17008 @@ -10,6 +10,7 @@
17009 #include <asm/processor.h>
17010 #include <asm/mce.h>
17011 #include <asm/msr.h>
17012 +#include <asm/pgtable.h>
17013
17014 /* Machine check handler for WinChip C6: */
17015 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17016 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17017 {
17018 u32 lo, hi;
17019
17020 + pax_open_kernel();
17021 machine_check_vector = winchip_machine_check;
17022 + pax_close_kernel();
17023 /* Make sure the vector pointer is visible before we enable MCEs: */
17024 wmb();
17025
17026 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17027 index 726bf96..81f0526 100644
17028 --- a/arch/x86/kernel/cpu/mtrr/main.c
17029 +++ b/arch/x86/kernel/cpu/mtrr/main.c
17030 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17031 u64 size_or_mask, size_and_mask;
17032 static bool mtrr_aps_delayed_init;
17033
17034 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17035 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17036
17037 const struct mtrr_ops *mtrr_if;
17038
17039 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17040 index df5e41f..816c719 100644
17041 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17042 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17043 @@ -25,7 +25,7 @@ struct mtrr_ops {
17044 int (*validate_add_page)(unsigned long base, unsigned long size,
17045 unsigned int type);
17046 int (*have_wrcomb)(void);
17047 -};
17048 +} __do_const;
17049
17050 extern int generic_get_free_region(unsigned long base, unsigned long size,
17051 int replace_reg);
17052 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17053 index 6774c17..a691911 100644
17054 --- a/arch/x86/kernel/cpu/perf_event.c
17055 +++ b/arch/x86/kernel/cpu/perf_event.c
17056 @@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17057 if (idx > GDT_ENTRIES)
17058 return 0;
17059
17060 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17061 + desc = get_cpu_gdt_table(smp_processor_id());
17062 }
17063
17064 return get_desc_base(desc + idx);
17065 @@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17066 break;
17067
17068 perf_callchain_store(entry, frame.return_address);
17069 - fp = frame.next_frame;
17070 + fp = (const void __force_user *)frame.next_frame;
17071 }
17072 }
17073
17074 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17075 index 4914e94..60b06e3 100644
17076 --- a/arch/x86/kernel/cpu/perf_event_intel.c
17077 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
17078 @@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17079 * v2 and above have a perf capabilities MSR
17080 */
17081 if (version > 1) {
17082 - u64 capabilities;
17083 + u64 capabilities = x86_pmu.intel_cap.capabilities;
17084
17085 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17086 - x86_pmu.intel_cap.capabilities = capabilities;
17087 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17088 + x86_pmu.intel_cap.capabilities = capabilities;
17089 }
17090
17091 intel_ds_init();
17092 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17093 index b43200d..62cddfe 100644
17094 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17095 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17096 @@ -2826,7 +2826,7 @@ static int
17097 return NOTIFY_OK;
17098 }
17099
17100 -static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17101 +static struct notifier_block uncore_cpu_nb = {
17102 .notifier_call = uncore_cpu_notifier,
17103 /*
17104 * to migrate uncore events, our notifier should be executed
17105 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17106 index 60c7891..9e911d3 100644
17107 --- a/arch/x86/kernel/cpuid.c
17108 +++ b/arch/x86/kernel/cpuid.c
17109 @@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17110 return notifier_from_errno(err);
17111 }
17112
17113 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
17114 +static struct notifier_block cpuid_class_cpu_notifier =
17115 {
17116 .notifier_call = cpuid_class_cpu_callback,
17117 };
17118 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17119 index 74467fe..18793d5 100644
17120 --- a/arch/x86/kernel/crash.c
17121 +++ b/arch/x86/kernel/crash.c
17122 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17123 {
17124 #ifdef CONFIG_X86_32
17125 struct pt_regs fixed_regs;
17126 -#endif
17127
17128 -#ifdef CONFIG_X86_32
17129 - if (!user_mode_vm(regs)) {
17130 + if (!user_mode(regs)) {
17131 crash_fixup_ss_esp(&fixed_regs, regs);
17132 regs = &fixed_regs;
17133 }
17134 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17135 index 37250fe..bf2ec74 100644
17136 --- a/arch/x86/kernel/doublefault_32.c
17137 +++ b/arch/x86/kernel/doublefault_32.c
17138 @@ -11,7 +11,7 @@
17139
17140 #define DOUBLEFAULT_STACKSIZE (1024)
17141 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17142 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17143 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17144
17145 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17146
17147 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
17148 unsigned long gdt, tss;
17149
17150 store_gdt(&gdt_desc);
17151 - gdt = gdt_desc.address;
17152 + gdt = (unsigned long)gdt_desc.address;
17153
17154 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17155
17156 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17157 /* 0x2 bit is always set */
17158 .flags = X86_EFLAGS_SF | 0x2,
17159 .sp = STACK_START,
17160 - .es = __USER_DS,
17161 + .es = __KERNEL_DS,
17162 .cs = __KERNEL_CS,
17163 .ss = __KERNEL_DS,
17164 - .ds = __USER_DS,
17165 + .ds = __KERNEL_DS,
17166 .fs = __KERNEL_PERCPU,
17167
17168 .__cr3 = __pa_nodebug(swapper_pg_dir),
17169 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17170 index ae42418b..787c16b 100644
17171 --- a/arch/x86/kernel/dumpstack.c
17172 +++ b/arch/x86/kernel/dumpstack.c
17173 @@ -2,6 +2,9 @@
17174 * Copyright (C) 1991, 1992 Linus Torvalds
17175 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17176 */
17177 +#ifdef CONFIG_GRKERNSEC_HIDESYM
17178 +#define __INCLUDED_BY_HIDESYM 1
17179 +#endif
17180 #include <linux/kallsyms.h>
17181 #include <linux/kprobes.h>
17182 #include <linux/uaccess.h>
17183 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17184 static void
17185 print_ftrace_graph_addr(unsigned long addr, void *data,
17186 const struct stacktrace_ops *ops,
17187 - struct thread_info *tinfo, int *graph)
17188 + struct task_struct *task, int *graph)
17189 {
17190 - struct task_struct *task;
17191 unsigned long ret_addr;
17192 int index;
17193
17194 if (addr != (unsigned long)return_to_handler)
17195 return;
17196
17197 - task = tinfo->task;
17198 index = task->curr_ret_stack;
17199
17200 if (!task->ret_stack || index < *graph)
17201 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17202 static inline void
17203 print_ftrace_graph_addr(unsigned long addr, void *data,
17204 const struct stacktrace_ops *ops,
17205 - struct thread_info *tinfo, int *graph)
17206 + struct task_struct *task, int *graph)
17207 { }
17208 #endif
17209
17210 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17211 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17212 */
17213
17214 -static inline int valid_stack_ptr(struct thread_info *tinfo,
17215 - void *p, unsigned int size, void *end)
17216 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17217 {
17218 - void *t = tinfo;
17219 if (end) {
17220 if (p < end && p >= (end-THREAD_SIZE))
17221 return 1;
17222 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17223 }
17224
17225 unsigned long
17226 -print_context_stack(struct thread_info *tinfo,
17227 +print_context_stack(struct task_struct *task, void *stack_start,
17228 unsigned long *stack, unsigned long bp,
17229 const struct stacktrace_ops *ops, void *data,
17230 unsigned long *end, int *graph)
17231 {
17232 struct stack_frame *frame = (struct stack_frame *)bp;
17233
17234 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17235 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17236 unsigned long addr;
17237
17238 addr = *stack;
17239 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17240 } else {
17241 ops->address(data, addr, 0);
17242 }
17243 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17244 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17245 }
17246 stack++;
17247 }
17248 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17249 EXPORT_SYMBOL_GPL(print_context_stack);
17250
17251 unsigned long
17252 -print_context_stack_bp(struct thread_info *tinfo,
17253 +print_context_stack_bp(struct task_struct *task, void *stack_start,
17254 unsigned long *stack, unsigned long bp,
17255 const struct stacktrace_ops *ops, void *data,
17256 unsigned long *end, int *graph)
17257 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17258 struct stack_frame *frame = (struct stack_frame *)bp;
17259 unsigned long *ret_addr = &frame->return_address;
17260
17261 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17262 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17263 unsigned long addr = *ret_addr;
17264
17265 if (!__kernel_text_address(addr))
17266 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17267 ops->address(data, addr, 1);
17268 frame = frame->next_frame;
17269 ret_addr = &frame->return_address;
17270 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17271 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17272 }
17273
17274 return (unsigned long)frame;
17275 @@ -189,7 +188,7 @@ void dump_stack(void)
17276
17277 bp = stack_frame(current, NULL);
17278 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17279 - current->pid, current->comm, print_tainted(),
17280 + task_pid_nr(current), current->comm, print_tainted(),
17281 init_utsname()->release,
17282 (int)strcspn(init_utsname()->version, " "),
17283 init_utsname()->version);
17284 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17285 }
17286 EXPORT_SYMBOL_GPL(oops_begin);
17287
17288 +extern void gr_handle_kernel_exploit(void);
17289 +
17290 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17291 {
17292 if (regs && kexec_should_crash(current))
17293 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17294 panic("Fatal exception in interrupt");
17295 if (panic_on_oops)
17296 panic("Fatal exception");
17297 - do_exit(signr);
17298 +
17299 + gr_handle_kernel_exploit();
17300 +
17301 + do_group_exit(signr);
17302 }
17303
17304 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17305 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17306 print_modules();
17307 show_regs(regs);
17308 #ifdef CONFIG_X86_32
17309 - if (user_mode_vm(regs)) {
17310 + if (user_mode(regs)) {
17311 sp = regs->sp;
17312 ss = regs->ss & 0xffff;
17313 } else {
17314 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17315 unsigned long flags = oops_begin();
17316 int sig = SIGSEGV;
17317
17318 - if (!user_mode_vm(regs))
17319 + if (!user_mode(regs))
17320 report_bug(regs->ip, regs);
17321
17322 if (__die(str, regs, err))
17323 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17324 index 1038a41..db2c12b 100644
17325 --- a/arch/x86/kernel/dumpstack_32.c
17326 +++ b/arch/x86/kernel/dumpstack_32.c
17327 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17328 bp = stack_frame(task, regs);
17329
17330 for (;;) {
17331 - struct thread_info *context;
17332 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17333
17334 - context = (struct thread_info *)
17335 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17336 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17337 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17338
17339 - stack = (unsigned long *)context->previous_esp;
17340 - if (!stack)
17341 + if (stack_start == task_stack_page(task))
17342 break;
17343 + stack = *(unsigned long **)stack_start;
17344 if (ops->stack(data, "IRQ") < 0)
17345 break;
17346 touch_nmi_watchdog();
17347 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17348 {
17349 int i;
17350
17351 - __show_regs(regs, !user_mode_vm(regs));
17352 + __show_regs(regs, !user_mode(regs));
17353
17354 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17355 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17356 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17357 * When in-kernel, we also print out the stack and code at the
17358 * time of the fault..
17359 */
17360 - if (!user_mode_vm(regs)) {
17361 + if (!user_mode(regs)) {
17362 unsigned int code_prologue = code_bytes * 43 / 64;
17363 unsigned int code_len = code_bytes;
17364 unsigned char c;
17365 u8 *ip;
17366 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17367
17368 pr_emerg("Stack:\n");
17369 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17370
17371 pr_emerg("Code:");
17372
17373 - ip = (u8 *)regs->ip - code_prologue;
17374 + ip = (u8 *)regs->ip - code_prologue + cs_base;
17375 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17376 /* try starting at IP */
17377 - ip = (u8 *)regs->ip;
17378 + ip = (u8 *)regs->ip + cs_base;
17379 code_len = code_len - code_prologue + 1;
17380 }
17381 for (i = 0; i < code_len; i++, ip++) {
17382 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17383 pr_cont(" Bad EIP value.");
17384 break;
17385 }
17386 - if (ip == (u8 *)regs->ip)
17387 + if (ip == (u8 *)regs->ip + cs_base)
17388 pr_cont(" <%02x>", c);
17389 else
17390 pr_cont(" %02x", c);
17391 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17392 {
17393 unsigned short ud2;
17394
17395 + ip = ktla_ktva(ip);
17396 if (ip < PAGE_OFFSET)
17397 return 0;
17398 if (probe_kernel_address((unsigned short *)ip, ud2))
17399 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17400
17401 return ud2 == 0x0b0f;
17402 }
17403 +
17404 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17405 +void pax_check_alloca(unsigned long size)
17406 +{
17407 + unsigned long sp = (unsigned long)&sp, stack_left;
17408 +
17409 + /* all kernel stacks are of the same size */
17410 + stack_left = sp & (THREAD_SIZE - 1);
17411 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17412 +}
17413 +EXPORT_SYMBOL(pax_check_alloca);
17414 +#endif
17415 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17416 index b653675..51cc8c0 100644
17417 --- a/arch/x86/kernel/dumpstack_64.c
17418 +++ b/arch/x86/kernel/dumpstack_64.c
17419 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17420 unsigned long *irq_stack_end =
17421 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17422 unsigned used = 0;
17423 - struct thread_info *tinfo;
17424 int graph = 0;
17425 unsigned long dummy;
17426 + void *stack_start;
17427
17428 if (!task)
17429 task = current;
17430 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17431 * current stack address. If the stacks consist of nested
17432 * exceptions
17433 */
17434 - tinfo = task_thread_info(task);
17435 for (;;) {
17436 char *id;
17437 unsigned long *estack_end;
17438 +
17439 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17440 &used, &id);
17441
17442 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17443 if (ops->stack(data, id) < 0)
17444 break;
17445
17446 - bp = ops->walk_stack(tinfo, stack, bp, ops,
17447 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17448 data, estack_end, &graph);
17449 ops->stack(data, "<EOE>");
17450 /*
17451 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17452 * second-to-last pointer (index -2 to end) in the
17453 * exception stack:
17454 */
17455 + if ((u16)estack_end[-1] != __KERNEL_DS)
17456 + goto out;
17457 stack = (unsigned long *) estack_end[-2];
17458 continue;
17459 }
17460 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17461 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17462 if (ops->stack(data, "IRQ") < 0)
17463 break;
17464 - bp = ops->walk_stack(tinfo, stack, bp,
17465 + bp = ops->walk_stack(task, irq_stack, stack, bp,
17466 ops, data, irq_stack_end, &graph);
17467 /*
17468 * We link to the next stack (which would be
17469 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17470 /*
17471 * This handles the process stack:
17472 */
17473 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17474 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17475 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17476 +out:
17477 put_cpu();
17478 }
17479 EXPORT_SYMBOL(dump_trace);
17480 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17481 {
17482 int i;
17483 unsigned long sp;
17484 - const int cpu = smp_processor_id();
17485 + const int cpu = raw_smp_processor_id();
17486 struct task_struct *cur = current;
17487
17488 sp = regs->sp;
17489 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17490
17491 return ud2 == 0x0b0f;
17492 }
17493 +
17494 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17495 +void pax_check_alloca(unsigned long size)
17496 +{
17497 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17498 + unsigned cpu, used;
17499 + char *id;
17500 +
17501 + /* check the process stack first */
17502 + stack_start = (unsigned long)task_stack_page(current);
17503 + stack_end = stack_start + THREAD_SIZE;
17504 + if (likely(stack_start <= sp && sp < stack_end)) {
17505 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
17506 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17507 + return;
17508 + }
17509 +
17510 + cpu = get_cpu();
17511 +
17512 + /* check the irq stacks */
17513 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17514 + stack_start = stack_end - IRQ_STACK_SIZE;
17515 + if (stack_start <= sp && sp < stack_end) {
17516 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17517 + put_cpu();
17518 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17519 + return;
17520 + }
17521 +
17522 + /* check the exception stacks */
17523 + used = 0;
17524 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17525 + stack_start = stack_end - EXCEPTION_STKSZ;
17526 + if (stack_end && stack_start <= sp && sp < stack_end) {
17527 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17528 + put_cpu();
17529 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17530 + return;
17531 + }
17532 +
17533 + put_cpu();
17534 +
17535 + /* unknown stack */
17536 + BUG();
17537 +}
17538 +EXPORT_SYMBOL(pax_check_alloca);
17539 +#endif
17540 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17541 index 9b9f18b..9fcaa04 100644
17542 --- a/arch/x86/kernel/early_printk.c
17543 +++ b/arch/x86/kernel/early_printk.c
17544 @@ -7,6 +7,7 @@
17545 #include <linux/pci_regs.h>
17546 #include <linux/pci_ids.h>
17547 #include <linux/errno.h>
17548 +#include <linux/sched.h>
17549 #include <asm/io.h>
17550 #include <asm/processor.h>
17551 #include <asm/fcntl.h>
17552 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17553 index 6ed91d9..6cc365b 100644
17554 --- a/arch/x86/kernel/entry_32.S
17555 +++ b/arch/x86/kernel/entry_32.S
17556 @@ -177,13 +177,153 @@
17557 /*CFI_REL_OFFSET gs, PT_GS*/
17558 .endm
17559 .macro SET_KERNEL_GS reg
17560 +
17561 +#ifdef CONFIG_CC_STACKPROTECTOR
17562 movl $(__KERNEL_STACK_CANARY), \reg
17563 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17564 + movl $(__USER_DS), \reg
17565 +#else
17566 + xorl \reg, \reg
17567 +#endif
17568 +
17569 movl \reg, %gs
17570 .endm
17571
17572 #endif /* CONFIG_X86_32_LAZY_GS */
17573
17574 -.macro SAVE_ALL
17575 +.macro pax_enter_kernel
17576 +#ifdef CONFIG_PAX_KERNEXEC
17577 + call pax_enter_kernel
17578 +#endif
17579 +.endm
17580 +
17581 +.macro pax_exit_kernel
17582 +#ifdef CONFIG_PAX_KERNEXEC
17583 + call pax_exit_kernel
17584 +#endif
17585 +.endm
17586 +
17587 +#ifdef CONFIG_PAX_KERNEXEC
17588 +ENTRY(pax_enter_kernel)
17589 +#ifdef CONFIG_PARAVIRT
17590 + pushl %eax
17591 + pushl %ecx
17592 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17593 + mov %eax, %esi
17594 +#else
17595 + mov %cr0, %esi
17596 +#endif
17597 + bts $16, %esi
17598 + jnc 1f
17599 + mov %cs, %esi
17600 + cmp $__KERNEL_CS, %esi
17601 + jz 3f
17602 + ljmp $__KERNEL_CS, $3f
17603 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17604 +2:
17605 +#ifdef CONFIG_PARAVIRT
17606 + mov %esi, %eax
17607 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17608 +#else
17609 + mov %esi, %cr0
17610 +#endif
17611 +3:
17612 +#ifdef CONFIG_PARAVIRT
17613 + popl %ecx
17614 + popl %eax
17615 +#endif
17616 + ret
17617 +ENDPROC(pax_enter_kernel)
17618 +
17619 +ENTRY(pax_exit_kernel)
17620 +#ifdef CONFIG_PARAVIRT
17621 + pushl %eax
17622 + pushl %ecx
17623 +#endif
17624 + mov %cs, %esi
17625 + cmp $__KERNEXEC_KERNEL_CS, %esi
17626 + jnz 2f
17627 +#ifdef CONFIG_PARAVIRT
17628 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17629 + mov %eax, %esi
17630 +#else
17631 + mov %cr0, %esi
17632 +#endif
17633 + btr $16, %esi
17634 + ljmp $__KERNEL_CS, $1f
17635 +1:
17636 +#ifdef CONFIG_PARAVIRT
17637 + mov %esi, %eax
17638 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17639 +#else
17640 + mov %esi, %cr0
17641 +#endif
17642 +2:
17643 +#ifdef CONFIG_PARAVIRT
17644 + popl %ecx
17645 + popl %eax
17646 +#endif
17647 + ret
17648 +ENDPROC(pax_exit_kernel)
17649 +#endif
17650 +
17651 +.macro pax_erase_kstack
17652 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17653 + call pax_erase_kstack
17654 +#endif
17655 +.endm
17656 +
17657 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17658 +/*
17659 + * ebp: thread_info
17660 + */
17661 +ENTRY(pax_erase_kstack)
17662 + pushl %edi
17663 + pushl %ecx
17664 + pushl %eax
17665 +
17666 + mov TI_lowest_stack(%ebp), %edi
17667 + mov $-0xBEEF, %eax
17668 + std
17669 +
17670 +1: mov %edi, %ecx
17671 + and $THREAD_SIZE_asm - 1, %ecx
17672 + shr $2, %ecx
17673 + repne scasl
17674 + jecxz 2f
17675 +
17676 + cmp $2*16, %ecx
17677 + jc 2f
17678 +
17679 + mov $2*16, %ecx
17680 + repe scasl
17681 + jecxz 2f
17682 + jne 1b
17683 +
17684 +2: cld
17685 + mov %esp, %ecx
17686 + sub %edi, %ecx
17687 +
17688 + cmp $THREAD_SIZE_asm, %ecx
17689 + jb 3f
17690 + ud2
17691 +3:
17692 +
17693 + shr $2, %ecx
17694 + rep stosl
17695 +
17696 + mov TI_task_thread_sp0(%ebp), %edi
17697 + sub $128, %edi
17698 + mov %edi, TI_lowest_stack(%ebp)
17699 +
17700 + popl %eax
17701 + popl %ecx
17702 + popl %edi
17703 + ret
17704 +ENDPROC(pax_erase_kstack)
17705 +#endif
17706 +
17707 +.macro __SAVE_ALL _DS
17708 cld
17709 PUSH_GS
17710 pushl_cfi %fs
17711 @@ -206,7 +346,7 @@
17712 CFI_REL_OFFSET ecx, 0
17713 pushl_cfi %ebx
17714 CFI_REL_OFFSET ebx, 0
17715 - movl $(__USER_DS), %edx
17716 + movl $\_DS, %edx
17717 movl %edx, %ds
17718 movl %edx, %es
17719 movl $(__KERNEL_PERCPU), %edx
17720 @@ -214,6 +354,15 @@
17721 SET_KERNEL_GS %edx
17722 .endm
17723
17724 +.macro SAVE_ALL
17725 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
17726 + __SAVE_ALL __KERNEL_DS
17727 + pax_enter_kernel
17728 +#else
17729 + __SAVE_ALL __USER_DS
17730 +#endif
17731 +.endm
17732 +
17733 .macro RESTORE_INT_REGS
17734 popl_cfi %ebx
17735 CFI_RESTORE ebx
17736 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
17737 popfl_cfi
17738 jmp syscall_exit
17739 CFI_ENDPROC
17740 -END(ret_from_fork)
17741 +ENDPROC(ret_from_fork)
17742
17743 ENTRY(ret_from_kernel_thread)
17744 CFI_STARTPROC
17745 @@ -344,7 +493,15 @@ ret_from_intr:
17746 andl $SEGMENT_RPL_MASK, %eax
17747 #endif
17748 cmpl $USER_RPL, %eax
17749 +
17750 +#ifdef CONFIG_PAX_KERNEXEC
17751 + jae resume_userspace
17752 +
17753 + pax_exit_kernel
17754 + jmp resume_kernel
17755 +#else
17756 jb resume_kernel # not returning to v8086 or userspace
17757 +#endif
17758
17759 ENTRY(resume_userspace)
17760 LOCKDEP_SYS_EXIT
17761 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
17762 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
17763 # int/exception return?
17764 jne work_pending
17765 - jmp restore_all
17766 -END(ret_from_exception)
17767 + jmp restore_all_pax
17768 +ENDPROC(ret_from_exception)
17769
17770 #ifdef CONFIG_PREEMPT
17771 ENTRY(resume_kernel)
17772 @@ -372,7 +529,7 @@ need_resched:
17773 jz restore_all
17774 call preempt_schedule_irq
17775 jmp need_resched
17776 -END(resume_kernel)
17777 +ENDPROC(resume_kernel)
17778 #endif
17779 CFI_ENDPROC
17780 /*
17781 @@ -406,30 +563,45 @@ sysenter_past_esp:
17782 /*CFI_REL_OFFSET cs, 0*/
17783 /*
17784 * Push current_thread_info()->sysenter_return to the stack.
17785 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
17786 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
17787 */
17788 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
17789 + pushl_cfi $0
17790 CFI_REL_OFFSET eip, 0
17791
17792 pushl_cfi %eax
17793 SAVE_ALL
17794 + GET_THREAD_INFO(%ebp)
17795 + movl TI_sysenter_return(%ebp),%ebp
17796 + movl %ebp,PT_EIP(%esp)
17797 ENABLE_INTERRUPTS(CLBR_NONE)
17798
17799 /*
17800 * Load the potential sixth argument from user stack.
17801 * Careful about security.
17802 */
17803 + movl PT_OLDESP(%esp),%ebp
17804 +
17805 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17806 + mov PT_OLDSS(%esp),%ds
17807 +1: movl %ds:(%ebp),%ebp
17808 + push %ss
17809 + pop %ds
17810 +#else
17811 cmpl $__PAGE_OFFSET-3,%ebp
17812 jae syscall_fault
17813 ASM_STAC
17814 1: movl (%ebp),%ebp
17815 ASM_CLAC
17816 +#endif
17817 +
17818 movl %ebp,PT_EBP(%esp)
17819 _ASM_EXTABLE(1b,syscall_fault)
17820
17821 GET_THREAD_INFO(%ebp)
17822
17823 +#ifdef CONFIG_PAX_RANDKSTACK
17824 + pax_erase_kstack
17825 +#endif
17826 +
17827 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17828 jnz sysenter_audit
17829 sysenter_do_call:
17830 @@ -444,12 +616,24 @@ sysenter_do_call:
17831 testl $_TIF_ALLWORK_MASK, %ecx
17832 jne sysexit_audit
17833 sysenter_exit:
17834 +
17835 +#ifdef CONFIG_PAX_RANDKSTACK
17836 + pushl_cfi %eax
17837 + movl %esp, %eax
17838 + call pax_randomize_kstack
17839 + popl_cfi %eax
17840 +#endif
17841 +
17842 + pax_erase_kstack
17843 +
17844 /* if something modifies registers it must also disable sysexit */
17845 movl PT_EIP(%esp), %edx
17846 movl PT_OLDESP(%esp), %ecx
17847 xorl %ebp,%ebp
17848 TRACE_IRQS_ON
17849 1: mov PT_FS(%esp), %fs
17850 +2: mov PT_DS(%esp), %ds
17851 +3: mov PT_ES(%esp), %es
17852 PTGS_TO_GS
17853 ENABLE_INTERRUPTS_SYSEXIT
17854
17855 @@ -466,6 +650,9 @@ sysenter_audit:
17856 movl %eax,%edx /* 2nd arg: syscall number */
17857 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
17858 call __audit_syscall_entry
17859 +
17860 + pax_erase_kstack
17861 +
17862 pushl_cfi %ebx
17863 movl PT_EAX(%esp),%eax /* reload syscall number */
17864 jmp sysenter_do_call
17865 @@ -491,10 +678,16 @@ sysexit_audit:
17866
17867 CFI_ENDPROC
17868 .pushsection .fixup,"ax"
17869 -2: movl $0,PT_FS(%esp)
17870 +4: movl $0,PT_FS(%esp)
17871 + jmp 1b
17872 +5: movl $0,PT_DS(%esp)
17873 + jmp 1b
17874 +6: movl $0,PT_ES(%esp)
17875 jmp 1b
17876 .popsection
17877 - _ASM_EXTABLE(1b,2b)
17878 + _ASM_EXTABLE(1b,4b)
17879 + _ASM_EXTABLE(2b,5b)
17880 + _ASM_EXTABLE(3b,6b)
17881 PTGS_TO_GS_EX
17882 ENDPROC(ia32_sysenter_target)
17883
17884 @@ -509,6 +702,11 @@ ENTRY(system_call)
17885 pushl_cfi %eax # save orig_eax
17886 SAVE_ALL
17887 GET_THREAD_INFO(%ebp)
17888 +
17889 +#ifdef CONFIG_PAX_RANDKSTACK
17890 + pax_erase_kstack
17891 +#endif
17892 +
17893 # system call tracing in operation / emulation
17894 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17895 jnz syscall_trace_entry
17896 @@ -527,6 +725,15 @@ syscall_exit:
17897 testl $_TIF_ALLWORK_MASK, %ecx # current->work
17898 jne syscall_exit_work
17899
17900 +restore_all_pax:
17901 +
17902 +#ifdef CONFIG_PAX_RANDKSTACK
17903 + movl %esp, %eax
17904 + call pax_randomize_kstack
17905 +#endif
17906 +
17907 + pax_erase_kstack
17908 +
17909 restore_all:
17910 TRACE_IRQS_IRET
17911 restore_all_notrace:
17912 @@ -583,14 +790,34 @@ ldt_ss:
17913 * compensating for the offset by changing to the ESPFIX segment with
17914 * a base address that matches for the difference.
17915 */
17916 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
17917 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
17918 mov %esp, %edx /* load kernel esp */
17919 mov PT_OLDESP(%esp), %eax /* load userspace esp */
17920 mov %dx, %ax /* eax: new kernel esp */
17921 sub %eax, %edx /* offset (low word is 0) */
17922 +#ifdef CONFIG_SMP
17923 + movl PER_CPU_VAR(cpu_number), %ebx
17924 + shll $PAGE_SHIFT_asm, %ebx
17925 + addl $cpu_gdt_table, %ebx
17926 +#else
17927 + movl $cpu_gdt_table, %ebx
17928 +#endif
17929 shr $16, %edx
17930 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
17931 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
17932 +
17933 +#ifdef CONFIG_PAX_KERNEXEC
17934 + mov %cr0, %esi
17935 + btr $16, %esi
17936 + mov %esi, %cr0
17937 +#endif
17938 +
17939 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
17940 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
17941 +
17942 +#ifdef CONFIG_PAX_KERNEXEC
17943 + bts $16, %esi
17944 + mov %esi, %cr0
17945 +#endif
17946 +
17947 pushl_cfi $__ESPFIX_SS
17948 pushl_cfi %eax /* new kernel esp */
17949 /* Disable interrupts, but do not irqtrace this section: we
17950 @@ -619,20 +846,18 @@ work_resched:
17951 movl TI_flags(%ebp), %ecx
17952 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
17953 # than syscall tracing?
17954 - jz restore_all
17955 + jz restore_all_pax
17956 testb $_TIF_NEED_RESCHED, %cl
17957 jnz work_resched
17958
17959 work_notifysig: # deal with pending signals and
17960 # notify-resume requests
17961 + movl %esp, %eax
17962 #ifdef CONFIG_VM86
17963 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
17964 - movl %esp, %eax
17965 jne work_notifysig_v86 # returning to kernel-space or
17966 # vm86-space
17967 1:
17968 -#else
17969 - movl %esp, %eax
17970 #endif
17971 TRACE_IRQS_ON
17972 ENABLE_INTERRUPTS(CLBR_NONE)
17973 @@ -653,7 +878,7 @@ work_notifysig_v86:
17974 movl %eax, %esp
17975 jmp 1b
17976 #endif
17977 -END(work_pending)
17978 +ENDPROC(work_pending)
17979
17980 # perform syscall exit tracing
17981 ALIGN
17982 @@ -661,11 +886,14 @@ syscall_trace_entry:
17983 movl $-ENOSYS,PT_EAX(%esp)
17984 movl %esp, %eax
17985 call syscall_trace_enter
17986 +
17987 + pax_erase_kstack
17988 +
17989 /* What it returned is what we'll actually use. */
17990 cmpl $(NR_syscalls), %eax
17991 jnae syscall_call
17992 jmp syscall_exit
17993 -END(syscall_trace_entry)
17994 +ENDPROC(syscall_trace_entry)
17995
17996 # perform syscall exit tracing
17997 ALIGN
17998 @@ -678,21 +906,25 @@ syscall_exit_work:
17999 movl %esp, %eax
18000 call syscall_trace_leave
18001 jmp resume_userspace
18002 -END(syscall_exit_work)
18003 +ENDPROC(syscall_exit_work)
18004 CFI_ENDPROC
18005
18006 RING0_INT_FRAME # can't unwind into user space anyway
18007 syscall_fault:
18008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18009 + push %ss
18010 + pop %ds
18011 +#endif
18012 ASM_CLAC
18013 GET_THREAD_INFO(%ebp)
18014 movl $-EFAULT,PT_EAX(%esp)
18015 jmp resume_userspace
18016 -END(syscall_fault)
18017 +ENDPROC(syscall_fault)
18018
18019 syscall_badsys:
18020 movl $-ENOSYS,PT_EAX(%esp)
18021 jmp resume_userspace
18022 -END(syscall_badsys)
18023 +ENDPROC(syscall_badsys)
18024 CFI_ENDPROC
18025 /*
18026 * End of kprobes section
18027 @@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18028 * normal stack and adjusts ESP with the matching offset.
18029 */
18030 /* fixup the stack */
18031 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18032 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18033 +#ifdef CONFIG_SMP
18034 + movl PER_CPU_VAR(cpu_number), %ebx
18035 + shll $PAGE_SHIFT_asm, %ebx
18036 + addl $cpu_gdt_table, %ebx
18037 +#else
18038 + movl $cpu_gdt_table, %ebx
18039 +#endif
18040 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18041 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18042 shl $16, %eax
18043 addl %esp, %eax /* the adjusted stack pointer */
18044 pushl_cfi $__KERNEL_DS
18045 @@ -807,7 +1046,7 @@ vector=vector+1
18046 .endr
18047 2: jmp common_interrupt
18048 .endr
18049 -END(irq_entries_start)
18050 +ENDPROC(irq_entries_start)
18051
18052 .previous
18053 END(interrupt)
18054 @@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18055 pushl_cfi $do_coprocessor_error
18056 jmp error_code
18057 CFI_ENDPROC
18058 -END(coprocessor_error)
18059 +ENDPROC(coprocessor_error)
18060
18061 ENTRY(simd_coprocessor_error)
18062 RING0_INT_FRAME
18063 @@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18064 #endif
18065 jmp error_code
18066 CFI_ENDPROC
18067 -END(simd_coprocessor_error)
18068 +ENDPROC(simd_coprocessor_error)
18069
18070 ENTRY(device_not_available)
18071 RING0_INT_FRAME
18072 @@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18073 pushl_cfi $do_device_not_available
18074 jmp error_code
18075 CFI_ENDPROC
18076 -END(device_not_available)
18077 +ENDPROC(device_not_available)
18078
18079 #ifdef CONFIG_PARAVIRT
18080 ENTRY(native_iret)
18081 iret
18082 _ASM_EXTABLE(native_iret, iret_exc)
18083 -END(native_iret)
18084 +ENDPROC(native_iret)
18085
18086 ENTRY(native_irq_enable_sysexit)
18087 sti
18088 sysexit
18089 -END(native_irq_enable_sysexit)
18090 +ENDPROC(native_irq_enable_sysexit)
18091 #endif
18092
18093 ENTRY(overflow)
18094 @@ -910,7 +1149,7 @@ ENTRY(overflow)
18095 pushl_cfi $do_overflow
18096 jmp error_code
18097 CFI_ENDPROC
18098 -END(overflow)
18099 +ENDPROC(overflow)
18100
18101 ENTRY(bounds)
18102 RING0_INT_FRAME
18103 @@ -919,7 +1158,7 @@ ENTRY(bounds)
18104 pushl_cfi $do_bounds
18105 jmp error_code
18106 CFI_ENDPROC
18107 -END(bounds)
18108 +ENDPROC(bounds)
18109
18110 ENTRY(invalid_op)
18111 RING0_INT_FRAME
18112 @@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18113 pushl_cfi $do_invalid_op
18114 jmp error_code
18115 CFI_ENDPROC
18116 -END(invalid_op)
18117 +ENDPROC(invalid_op)
18118
18119 ENTRY(coprocessor_segment_overrun)
18120 RING0_INT_FRAME
18121 @@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18122 pushl_cfi $do_coprocessor_segment_overrun
18123 jmp error_code
18124 CFI_ENDPROC
18125 -END(coprocessor_segment_overrun)
18126 +ENDPROC(coprocessor_segment_overrun)
18127
18128 ENTRY(invalid_TSS)
18129 RING0_EC_FRAME
18130 @@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18131 pushl_cfi $do_invalid_TSS
18132 jmp error_code
18133 CFI_ENDPROC
18134 -END(invalid_TSS)
18135 +ENDPROC(invalid_TSS)
18136
18137 ENTRY(segment_not_present)
18138 RING0_EC_FRAME
18139 @@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18140 pushl_cfi $do_segment_not_present
18141 jmp error_code
18142 CFI_ENDPROC
18143 -END(segment_not_present)
18144 +ENDPROC(segment_not_present)
18145
18146 ENTRY(stack_segment)
18147 RING0_EC_FRAME
18148 @@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18149 pushl_cfi $do_stack_segment
18150 jmp error_code
18151 CFI_ENDPROC
18152 -END(stack_segment)
18153 +ENDPROC(stack_segment)
18154
18155 ENTRY(alignment_check)
18156 RING0_EC_FRAME
18157 @@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18158 pushl_cfi $do_alignment_check
18159 jmp error_code
18160 CFI_ENDPROC
18161 -END(alignment_check)
18162 +ENDPROC(alignment_check)
18163
18164 ENTRY(divide_error)
18165 RING0_INT_FRAME
18166 @@ -978,7 +1217,7 @@ ENTRY(divide_error)
18167 pushl_cfi $do_divide_error
18168 jmp error_code
18169 CFI_ENDPROC
18170 -END(divide_error)
18171 +ENDPROC(divide_error)
18172
18173 #ifdef CONFIG_X86_MCE
18174 ENTRY(machine_check)
18175 @@ -988,7 +1227,7 @@ ENTRY(machine_check)
18176 pushl_cfi machine_check_vector
18177 jmp error_code
18178 CFI_ENDPROC
18179 -END(machine_check)
18180 +ENDPROC(machine_check)
18181 #endif
18182
18183 ENTRY(spurious_interrupt_bug)
18184 @@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18185 pushl_cfi $do_spurious_interrupt_bug
18186 jmp error_code
18187 CFI_ENDPROC
18188 -END(spurious_interrupt_bug)
18189 +ENDPROC(spurious_interrupt_bug)
18190 /*
18191 * End of kprobes section
18192 */
18193 @@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18194
18195 ENTRY(mcount)
18196 ret
18197 -END(mcount)
18198 +ENDPROC(mcount)
18199
18200 ENTRY(ftrace_caller)
18201 cmpl $0, function_trace_stop
18202 @@ -1134,7 +1373,7 @@ ftrace_graph_call:
18203 .globl ftrace_stub
18204 ftrace_stub:
18205 ret
18206 -END(ftrace_caller)
18207 +ENDPROC(ftrace_caller)
18208
18209 ENTRY(ftrace_regs_caller)
18210 pushf /* push flags before compare (in cs location) */
18211 @@ -1235,7 +1474,7 @@ trace:
18212 popl %ecx
18213 popl %eax
18214 jmp ftrace_stub
18215 -END(mcount)
18216 +ENDPROC(mcount)
18217 #endif /* CONFIG_DYNAMIC_FTRACE */
18218 #endif /* CONFIG_FUNCTION_TRACER */
18219
18220 @@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18221 popl %ecx
18222 popl %eax
18223 ret
18224 -END(ftrace_graph_caller)
18225 +ENDPROC(ftrace_graph_caller)
18226
18227 .globl return_to_handler
18228 return_to_handler:
18229 @@ -1309,15 +1548,18 @@ error_code:
18230 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18231 REG_TO_PTGS %ecx
18232 SET_KERNEL_GS %ecx
18233 - movl $(__USER_DS), %ecx
18234 + movl $(__KERNEL_DS), %ecx
18235 movl %ecx, %ds
18236 movl %ecx, %es
18237 +
18238 + pax_enter_kernel
18239 +
18240 TRACE_IRQS_OFF
18241 movl %esp,%eax # pt_regs pointer
18242 call *%edi
18243 jmp ret_from_exception
18244 CFI_ENDPROC
18245 -END(page_fault)
18246 +ENDPROC(page_fault)
18247
18248 /*
18249 * Debug traps and NMI can happen at the one SYSENTER instruction
18250 @@ -1360,7 +1602,7 @@ debug_stack_correct:
18251 call do_debug
18252 jmp ret_from_exception
18253 CFI_ENDPROC
18254 -END(debug)
18255 +ENDPROC(debug)
18256
18257 /*
18258 * NMI is doubly nasty. It can happen _while_ we're handling
18259 @@ -1398,6 +1640,9 @@ nmi_stack_correct:
18260 xorl %edx,%edx # zero error code
18261 movl %esp,%eax # pt_regs pointer
18262 call do_nmi
18263 +
18264 + pax_exit_kernel
18265 +
18266 jmp restore_all_notrace
18267 CFI_ENDPROC
18268
18269 @@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18270 FIXUP_ESPFIX_STACK # %eax == %esp
18271 xorl %edx,%edx # zero error code
18272 call do_nmi
18273 +
18274 + pax_exit_kernel
18275 +
18276 RESTORE_REGS
18277 lss 12+4(%esp), %esp # back to espfix stack
18278 CFI_ADJUST_CFA_OFFSET -24
18279 jmp irq_return
18280 CFI_ENDPROC
18281 -END(nmi)
18282 +ENDPROC(nmi)
18283
18284 ENTRY(int3)
18285 RING0_INT_FRAME
18286 @@ -1452,14 +1700,14 @@ ENTRY(int3)
18287 call do_int3
18288 jmp ret_from_exception
18289 CFI_ENDPROC
18290 -END(int3)
18291 +ENDPROC(int3)
18292
18293 ENTRY(general_protection)
18294 RING0_EC_FRAME
18295 pushl_cfi $do_general_protection
18296 jmp error_code
18297 CFI_ENDPROC
18298 -END(general_protection)
18299 +ENDPROC(general_protection)
18300
18301 #ifdef CONFIG_KVM_GUEST
18302 ENTRY(async_page_fault)
18303 @@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18304 pushl_cfi $do_async_page_fault
18305 jmp error_code
18306 CFI_ENDPROC
18307 -END(async_page_fault)
18308 +ENDPROC(async_page_fault)
18309 #endif
18310
18311 /*
18312 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18313 index cb3c591..bc63707 100644
18314 --- a/arch/x86/kernel/entry_64.S
18315 +++ b/arch/x86/kernel/entry_64.S
18316 @@ -59,6 +59,8 @@
18317 #include <asm/context_tracking.h>
18318 #include <asm/smap.h>
18319 #include <linux/err.h>
18320 +#include <asm/pgtable.h>
18321 +#include <asm/alternative-asm.h>
18322
18323 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18324 #include <linux/elf-em.h>
18325 @@ -80,8 +82,9 @@
18326 #ifdef CONFIG_DYNAMIC_FTRACE
18327
18328 ENTRY(function_hook)
18329 + pax_force_retaddr
18330 retq
18331 -END(function_hook)
18332 +ENDPROC(function_hook)
18333
18334 /* skip is set if stack has been adjusted */
18335 .macro ftrace_caller_setup skip=0
18336 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18337 #endif
18338
18339 GLOBAL(ftrace_stub)
18340 + pax_force_retaddr
18341 retq
18342 -END(ftrace_caller)
18343 +ENDPROC(ftrace_caller)
18344
18345 ENTRY(ftrace_regs_caller)
18346 /* Save the current flags before compare (in SS location)*/
18347 @@ -191,7 +195,7 @@ ftrace_restore_flags:
18348 popfq
18349 jmp ftrace_stub
18350
18351 -END(ftrace_regs_caller)
18352 +ENDPROC(ftrace_regs_caller)
18353
18354
18355 #else /* ! CONFIG_DYNAMIC_FTRACE */
18356 @@ -212,6 +216,7 @@ ENTRY(function_hook)
18357 #endif
18358
18359 GLOBAL(ftrace_stub)
18360 + pax_force_retaddr
18361 retq
18362
18363 trace:
18364 @@ -225,12 +230,13 @@ trace:
18365 #endif
18366 subq $MCOUNT_INSN_SIZE, %rdi
18367
18368 + pax_force_fptr ftrace_trace_function
18369 call *ftrace_trace_function
18370
18371 MCOUNT_RESTORE_FRAME
18372
18373 jmp ftrace_stub
18374 -END(function_hook)
18375 +ENDPROC(function_hook)
18376 #endif /* CONFIG_DYNAMIC_FTRACE */
18377 #endif /* CONFIG_FUNCTION_TRACER */
18378
18379 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18380
18381 MCOUNT_RESTORE_FRAME
18382
18383 + pax_force_retaddr
18384 retq
18385 -END(ftrace_graph_caller)
18386 +ENDPROC(ftrace_graph_caller)
18387
18388 GLOBAL(return_to_handler)
18389 subq $24, %rsp
18390 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18391 movq 8(%rsp), %rdx
18392 movq (%rsp), %rax
18393 addq $24, %rsp
18394 + pax_force_fptr %rdi
18395 jmp *%rdi
18396 +ENDPROC(return_to_handler)
18397 #endif
18398
18399
18400 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18401 ENDPROC(native_usergs_sysret64)
18402 #endif /* CONFIG_PARAVIRT */
18403
18404 + .macro ljmpq sel, off
18405 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18406 + .byte 0x48; ljmp *1234f(%rip)
18407 + .pushsection .rodata
18408 + .align 16
18409 + 1234: .quad \off; .word \sel
18410 + .popsection
18411 +#else
18412 + pushq $\sel
18413 + pushq $\off
18414 + lretq
18415 +#endif
18416 + .endm
18417 +
18418 + .macro pax_enter_kernel
18419 + pax_set_fptr_mask
18420 +#ifdef CONFIG_PAX_KERNEXEC
18421 + call pax_enter_kernel
18422 +#endif
18423 + .endm
18424 +
18425 + .macro pax_exit_kernel
18426 +#ifdef CONFIG_PAX_KERNEXEC
18427 + call pax_exit_kernel
18428 +#endif
18429 + .endm
18430 +
18431 +#ifdef CONFIG_PAX_KERNEXEC
18432 +ENTRY(pax_enter_kernel)
18433 + pushq %rdi
18434 +
18435 +#ifdef CONFIG_PARAVIRT
18436 + PV_SAVE_REGS(CLBR_RDI)
18437 +#endif
18438 +
18439 + GET_CR0_INTO_RDI
18440 + bts $16,%rdi
18441 + jnc 3f
18442 + mov %cs,%edi
18443 + cmp $__KERNEL_CS,%edi
18444 + jnz 2f
18445 +1:
18446 +
18447 +#ifdef CONFIG_PARAVIRT
18448 + PV_RESTORE_REGS(CLBR_RDI)
18449 +#endif
18450 +
18451 + popq %rdi
18452 + pax_force_retaddr
18453 + retq
18454 +
18455 +2: ljmpq __KERNEL_CS,1f
18456 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
18457 +4: SET_RDI_INTO_CR0
18458 + jmp 1b
18459 +ENDPROC(pax_enter_kernel)
18460 +
18461 +ENTRY(pax_exit_kernel)
18462 + pushq %rdi
18463 +
18464 +#ifdef CONFIG_PARAVIRT
18465 + PV_SAVE_REGS(CLBR_RDI)
18466 +#endif
18467 +
18468 + mov %cs,%rdi
18469 + cmp $__KERNEXEC_KERNEL_CS,%edi
18470 + jz 2f
18471 +1:
18472 +
18473 +#ifdef CONFIG_PARAVIRT
18474 + PV_RESTORE_REGS(CLBR_RDI);
18475 +#endif
18476 +
18477 + popq %rdi
18478 + pax_force_retaddr
18479 + retq
18480 +
18481 +2: GET_CR0_INTO_RDI
18482 + btr $16,%rdi
18483 + ljmpq __KERNEL_CS,3f
18484 +3: SET_RDI_INTO_CR0
18485 + jmp 1b
18486 +ENDPROC(pax_exit_kernel)
18487 +#endif
18488 +
18489 + .macro pax_enter_kernel_user
18490 + pax_set_fptr_mask
18491 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18492 + call pax_enter_kernel_user
18493 +#endif
18494 + .endm
18495 +
18496 + .macro pax_exit_kernel_user
18497 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18498 + call pax_exit_kernel_user
18499 +#endif
18500 +#ifdef CONFIG_PAX_RANDKSTACK
18501 + pushq %rax
18502 + call pax_randomize_kstack
18503 + popq %rax
18504 +#endif
18505 + .endm
18506 +
18507 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18508 +ENTRY(pax_enter_kernel_user)
18509 + pushq %rdi
18510 + pushq %rbx
18511 +
18512 +#ifdef CONFIG_PARAVIRT
18513 + PV_SAVE_REGS(CLBR_RDI)
18514 +#endif
18515 +
18516 + GET_CR3_INTO_RDI
18517 + mov %rdi,%rbx
18518 + add $__START_KERNEL_map,%rbx
18519 + sub phys_base(%rip),%rbx
18520 +
18521 +#ifdef CONFIG_PARAVIRT
18522 + pushq %rdi
18523 + cmpl $0, pv_info+PARAVIRT_enabled
18524 + jz 1f
18525 + i = 0
18526 + .rept USER_PGD_PTRS
18527 + mov i*8(%rbx),%rsi
18528 + mov $0,%sil
18529 + lea i*8(%rbx),%rdi
18530 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18531 + i = i + 1
18532 + .endr
18533 + jmp 2f
18534 +1:
18535 +#endif
18536 +
18537 + i = 0
18538 + .rept USER_PGD_PTRS
18539 + movb $0,i*8(%rbx)
18540 + i = i + 1
18541 + .endr
18542 +
18543 +#ifdef CONFIG_PARAVIRT
18544 +2: popq %rdi
18545 +#endif
18546 + SET_RDI_INTO_CR3
18547 +
18548 +#ifdef CONFIG_PAX_KERNEXEC
18549 + GET_CR0_INTO_RDI
18550 + bts $16,%rdi
18551 + SET_RDI_INTO_CR0
18552 +#endif
18553 +
18554 +#ifdef CONFIG_PARAVIRT
18555 + PV_RESTORE_REGS(CLBR_RDI)
18556 +#endif
18557 +
18558 + popq %rbx
18559 + popq %rdi
18560 + pax_force_retaddr
18561 + retq
18562 +ENDPROC(pax_enter_kernel_user)
18563 +
18564 +ENTRY(pax_exit_kernel_user)
18565 + push %rdi
18566 +
18567 +#ifdef CONFIG_PARAVIRT
18568 + pushq %rbx
18569 + PV_SAVE_REGS(CLBR_RDI)
18570 +#endif
18571 +
18572 +#ifdef CONFIG_PAX_KERNEXEC
18573 + GET_CR0_INTO_RDI
18574 + btr $16,%rdi
18575 + SET_RDI_INTO_CR0
18576 +#endif
18577 +
18578 + GET_CR3_INTO_RDI
18579 + add $__START_KERNEL_map,%rdi
18580 + sub phys_base(%rip),%rdi
18581 +
18582 +#ifdef CONFIG_PARAVIRT
18583 + cmpl $0, pv_info+PARAVIRT_enabled
18584 + jz 1f
18585 + mov %rdi,%rbx
18586 + i = 0
18587 + .rept USER_PGD_PTRS
18588 + mov i*8(%rbx),%rsi
18589 + mov $0x67,%sil
18590 + lea i*8(%rbx),%rdi
18591 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18592 + i = i + 1
18593 + .endr
18594 + jmp 2f
18595 +1:
18596 +#endif
18597 +
18598 + i = 0
18599 + .rept USER_PGD_PTRS
18600 + movb $0x67,i*8(%rdi)
18601 + i = i + 1
18602 + .endr
18603 +
18604 +#ifdef CONFIG_PARAVIRT
18605 +2: PV_RESTORE_REGS(CLBR_RDI)
18606 + popq %rbx
18607 +#endif
18608 +
18609 + popq %rdi
18610 + pax_force_retaddr
18611 + retq
18612 +ENDPROC(pax_exit_kernel_user)
18613 +#endif
18614 +
18615 +.macro pax_erase_kstack
18616 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18617 + call pax_erase_kstack
18618 +#endif
18619 +.endm
18620 +
18621 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18622 +ENTRY(pax_erase_kstack)
18623 + pushq %rdi
18624 + pushq %rcx
18625 + pushq %rax
18626 + pushq %r11
18627 +
18628 + GET_THREAD_INFO(%r11)
18629 + mov TI_lowest_stack(%r11), %rdi
18630 + mov $-0xBEEF, %rax
18631 + std
18632 +
18633 +1: mov %edi, %ecx
18634 + and $THREAD_SIZE_asm - 1, %ecx
18635 + shr $3, %ecx
18636 + repne scasq
18637 + jecxz 2f
18638 +
18639 + cmp $2*8, %ecx
18640 + jc 2f
18641 +
18642 + mov $2*8, %ecx
18643 + repe scasq
18644 + jecxz 2f
18645 + jne 1b
18646 +
18647 +2: cld
18648 + mov %esp, %ecx
18649 + sub %edi, %ecx
18650 +
18651 + cmp $THREAD_SIZE_asm, %rcx
18652 + jb 3f
18653 + ud2
18654 +3:
18655 +
18656 + shr $3, %ecx
18657 + rep stosq
18658 +
18659 + mov TI_task_thread_sp0(%r11), %rdi
18660 + sub $256, %rdi
18661 + mov %rdi, TI_lowest_stack(%r11)
18662 +
18663 + popq %r11
18664 + popq %rax
18665 + popq %rcx
18666 + popq %rdi
18667 + pax_force_retaddr
18668 + ret
18669 +ENDPROC(pax_erase_kstack)
18670 +#endif
18671
18672 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18673 #ifdef CONFIG_TRACE_IRQFLAGS
18674 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18675 .endm
18676
18677 .macro UNFAKE_STACK_FRAME
18678 - addq $8*6, %rsp
18679 - CFI_ADJUST_CFA_OFFSET -(6*8)
18680 + addq $8*6 + ARG_SKIP, %rsp
18681 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18682 .endm
18683
18684 /*
18685 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18686 movq %rsp, %rsi
18687
18688 leaq -RBP(%rsp),%rdi /* arg1 for handler */
18689 - testl $3, CS-RBP(%rsi)
18690 + testb $3, CS-RBP(%rsi)
18691 je 1f
18692 SWAPGS
18693 /*
18694 @@ -498,9 +774,10 @@ ENTRY(save_rest)
18695 movq_cfi r15, R15+16
18696 movq %r11, 8(%rsp) /* return address */
18697 FIXUP_TOP_OF_STACK %r11, 16
18698 + pax_force_retaddr
18699 ret
18700 CFI_ENDPROC
18701 -END(save_rest)
18702 +ENDPROC(save_rest)
18703
18704 /* save complete stack frame */
18705 .pushsection .kprobes.text, "ax"
18706 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
18707 js 1f /* negative -> in kernel */
18708 SWAPGS
18709 xorl %ebx,%ebx
18710 -1: ret
18711 +1: pax_force_retaddr_bts
18712 + ret
18713 CFI_ENDPROC
18714 -END(save_paranoid)
18715 +ENDPROC(save_paranoid)
18716 .popsection
18717
18718 /*
18719 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
18720
18721 RESTORE_REST
18722
18723 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18724 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18725 jz 1f
18726
18727 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
18728 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
18729 RESTORE_REST
18730 jmp int_ret_from_sys_call
18731 CFI_ENDPROC
18732 -END(ret_from_fork)
18733 +ENDPROC(ret_from_fork)
18734
18735 /*
18736 * System call entry. Up to 6 arguments in registers are supported.
18737 @@ -608,7 +886,7 @@ END(ret_from_fork)
18738 ENTRY(system_call)
18739 CFI_STARTPROC simple
18740 CFI_SIGNAL_FRAME
18741 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
18742 + CFI_DEF_CFA rsp,0
18743 CFI_REGISTER rip,rcx
18744 /*CFI_REGISTER rflags,r11*/
18745 SWAPGS_UNSAFE_STACK
18746 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
18747
18748 movq %rsp,PER_CPU_VAR(old_rsp)
18749 movq PER_CPU_VAR(kernel_stack),%rsp
18750 + SAVE_ARGS 8*6,0
18751 + pax_enter_kernel_user
18752 +
18753 +#ifdef CONFIG_PAX_RANDKSTACK
18754 + pax_erase_kstack
18755 +#endif
18756 +
18757 /*
18758 * No need to follow this irqs off/on section - it's straight
18759 * and short:
18760 */
18761 ENABLE_INTERRUPTS(CLBR_NONE)
18762 - SAVE_ARGS 8,0
18763 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
18764 movq %rcx,RIP-ARGOFFSET(%rsp)
18765 CFI_REL_OFFSET rip,RIP-ARGOFFSET
18766 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18767 + GET_THREAD_INFO(%rcx)
18768 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
18769 jnz tracesys
18770 system_call_fastpath:
18771 #if __SYSCALL_MASK == ~0
18772 @@ -640,7 +925,7 @@ system_call_fastpath:
18773 cmpl $__NR_syscall_max,%eax
18774 #endif
18775 ja badsys
18776 - movq %r10,%rcx
18777 + movq R10-ARGOFFSET(%rsp),%rcx
18778 call *sys_call_table(,%rax,8) # XXX: rip relative
18779 movq %rax,RAX-ARGOFFSET(%rsp)
18780 /*
18781 @@ -654,10 +939,13 @@ sysret_check:
18782 LOCKDEP_SYS_EXIT
18783 DISABLE_INTERRUPTS(CLBR_NONE)
18784 TRACE_IRQS_OFF
18785 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
18786 + GET_THREAD_INFO(%rcx)
18787 + movl TI_flags(%rcx),%edx
18788 andl %edi,%edx
18789 jnz sysret_careful
18790 CFI_REMEMBER_STATE
18791 + pax_exit_kernel_user
18792 + pax_erase_kstack
18793 /*
18794 * sysretq will re-enable interrupts:
18795 */
18796 @@ -709,14 +997,18 @@ badsys:
18797 * jump back to the normal fast path.
18798 */
18799 auditsys:
18800 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
18801 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
18802 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
18803 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
18804 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
18805 movq %rax,%rsi /* 2nd arg: syscall number */
18806 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
18807 call __audit_syscall_entry
18808 +
18809 + pax_erase_kstack
18810 +
18811 LOAD_ARGS 0 /* reload call-clobbered registers */
18812 + pax_set_fptr_mask
18813 jmp system_call_fastpath
18814
18815 /*
18816 @@ -737,7 +1029,7 @@ sysret_audit:
18817 /* Do syscall tracing */
18818 tracesys:
18819 #ifdef CONFIG_AUDITSYSCALL
18820 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18821 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
18822 jz auditsys
18823 #endif
18824 SAVE_REST
18825 @@ -745,12 +1037,16 @@ tracesys:
18826 FIXUP_TOP_OF_STACK %rdi
18827 movq %rsp,%rdi
18828 call syscall_trace_enter
18829 +
18830 + pax_erase_kstack
18831 +
18832 /*
18833 * Reload arg registers from stack in case ptrace changed them.
18834 * We don't reload %rax because syscall_trace_enter() returned
18835 * the value it wants us to use in the table lookup.
18836 */
18837 LOAD_ARGS ARGOFFSET, 1
18838 + pax_set_fptr_mask
18839 RESTORE_REST
18840 #if __SYSCALL_MASK == ~0
18841 cmpq $__NR_syscall_max,%rax
18842 @@ -759,7 +1055,7 @@ tracesys:
18843 cmpl $__NR_syscall_max,%eax
18844 #endif
18845 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
18846 - movq %r10,%rcx /* fixup for C */
18847 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
18848 call *sys_call_table(,%rax,8)
18849 movq %rax,RAX-ARGOFFSET(%rsp)
18850 /* Use IRET because user could have changed frame */
18851 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
18852 andl %edi,%edx
18853 jnz int_careful
18854 andl $~TS_COMPAT,TI_status(%rcx)
18855 - jmp retint_swapgs
18856 + pax_exit_kernel_user
18857 + pax_erase_kstack
18858 + jmp retint_swapgs_pax
18859
18860 /* Either reschedule or signal or syscall exit tracking needed. */
18861 /* First do a reschedule test. */
18862 @@ -826,7 +1124,7 @@ int_restore_rest:
18863 TRACE_IRQS_OFF
18864 jmp int_with_check
18865 CFI_ENDPROC
18866 -END(system_call)
18867 +ENDPROC(system_call)
18868
18869 /*
18870 * Certain special system calls that need to save a complete full stack frame.
18871 @@ -842,7 +1140,7 @@ ENTRY(\label)
18872 call \func
18873 jmp ptregscall_common
18874 CFI_ENDPROC
18875 -END(\label)
18876 +ENDPROC(\label)
18877 .endm
18878
18879 .macro FORK_LIKE func
18880 @@ -856,9 +1154,10 @@ ENTRY(stub_\func)
18881 DEFAULT_FRAME 0 8 /* offset 8: return address */
18882 call sys_\func
18883 RESTORE_TOP_OF_STACK %r11, 8
18884 + pax_force_retaddr
18885 ret $REST_SKIP /* pop extended registers */
18886 CFI_ENDPROC
18887 -END(stub_\func)
18888 +ENDPROC(stub_\func)
18889 .endm
18890
18891 FORK_LIKE clone
18892 @@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
18893 movq_cfi_restore R12+8, r12
18894 movq_cfi_restore RBP+8, rbp
18895 movq_cfi_restore RBX+8, rbx
18896 + pax_force_retaddr
18897 ret $REST_SKIP /* pop extended registers */
18898 CFI_ENDPROC
18899 -END(ptregscall_common)
18900 +ENDPROC(ptregscall_common)
18901
18902 ENTRY(stub_execve)
18903 CFI_STARTPROC
18904 @@ -891,7 +1191,7 @@ ENTRY(stub_execve)
18905 RESTORE_REST
18906 jmp int_ret_from_sys_call
18907 CFI_ENDPROC
18908 -END(stub_execve)
18909 +ENDPROC(stub_execve)
18910
18911 /*
18912 * sigreturn is special because it needs to restore all registers on return.
18913 @@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
18914 RESTORE_REST
18915 jmp int_ret_from_sys_call
18916 CFI_ENDPROC
18917 -END(stub_rt_sigreturn)
18918 +ENDPROC(stub_rt_sigreturn)
18919
18920 #ifdef CONFIG_X86_X32_ABI
18921 ENTRY(stub_x32_rt_sigreturn)
18922 @@ -975,7 +1275,7 @@ vector=vector+1
18923 2: jmp common_interrupt
18924 .endr
18925 CFI_ENDPROC
18926 -END(irq_entries_start)
18927 +ENDPROC(irq_entries_start)
18928
18929 .previous
18930 END(interrupt)
18931 @@ -995,6 +1295,16 @@ END(interrupt)
18932 subq $ORIG_RAX-RBP, %rsp
18933 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
18934 SAVE_ARGS_IRQ
18935 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18936 + testb $3, CS(%rdi)
18937 + jnz 1f
18938 + pax_enter_kernel
18939 + jmp 2f
18940 +1: pax_enter_kernel_user
18941 +2:
18942 +#else
18943 + pax_enter_kernel
18944 +#endif
18945 call \func
18946 .endm
18947
18948 @@ -1027,7 +1337,7 @@ ret_from_intr:
18949
18950 exit_intr:
18951 GET_THREAD_INFO(%rcx)
18952 - testl $3,CS-ARGOFFSET(%rsp)
18953 + testb $3,CS-ARGOFFSET(%rsp)
18954 je retint_kernel
18955
18956 /* Interrupt came from user space */
18957 @@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
18958 * The iretq could re-enable interrupts:
18959 */
18960 DISABLE_INTERRUPTS(CLBR_ANY)
18961 + pax_exit_kernel_user
18962 +retint_swapgs_pax:
18963 TRACE_IRQS_IRETQ
18964 SWAPGS
18965 jmp restore_args
18966
18967 retint_restore_args: /* return to kernel space */
18968 DISABLE_INTERRUPTS(CLBR_ANY)
18969 + pax_exit_kernel
18970 + pax_force_retaddr (RIP-ARGOFFSET)
18971 /*
18972 * The iretq could re-enable interrupts:
18973 */
18974 @@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
18975 #endif
18976
18977 CFI_ENDPROC
18978 -END(common_interrupt)
18979 +ENDPROC(common_interrupt)
18980 /*
18981 * End of kprobes section
18982 */
18983 @@ -1155,7 +1469,7 @@ ENTRY(\sym)
18984 interrupt \do_sym
18985 jmp ret_from_intr
18986 CFI_ENDPROC
18987 -END(\sym)
18988 +ENDPROC(\sym)
18989 .endm
18990
18991 #ifdef CONFIG_SMP
18992 @@ -1211,12 +1525,22 @@ ENTRY(\sym)
18993 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
18994 call error_entry
18995 DEFAULT_FRAME 0
18996 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18997 + testb $3, CS(%rsp)
18998 + jnz 1f
18999 + pax_enter_kernel
19000 + jmp 2f
19001 +1: pax_enter_kernel_user
19002 +2:
19003 +#else
19004 + pax_enter_kernel
19005 +#endif
19006 movq %rsp,%rdi /* pt_regs pointer */
19007 xorl %esi,%esi /* no error code */
19008 call \do_sym
19009 jmp error_exit /* %ebx: no swapgs flag */
19010 CFI_ENDPROC
19011 -END(\sym)
19012 +ENDPROC(\sym)
19013 .endm
19014
19015 .macro paranoidzeroentry sym do_sym
19016 @@ -1229,15 +1553,25 @@ ENTRY(\sym)
19017 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19018 call save_paranoid
19019 TRACE_IRQS_OFF
19020 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19021 + testb $3, CS(%rsp)
19022 + jnz 1f
19023 + pax_enter_kernel
19024 + jmp 2f
19025 +1: pax_enter_kernel_user
19026 +2:
19027 +#else
19028 + pax_enter_kernel
19029 +#endif
19030 movq %rsp,%rdi /* pt_regs pointer */
19031 xorl %esi,%esi /* no error code */
19032 call \do_sym
19033 jmp paranoid_exit /* %ebx: no swapgs flag */
19034 CFI_ENDPROC
19035 -END(\sym)
19036 +ENDPROC(\sym)
19037 .endm
19038
19039 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19040 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19041 .macro paranoidzeroentry_ist sym do_sym ist
19042 ENTRY(\sym)
19043 INTR_FRAME
19044 @@ -1248,14 +1582,30 @@ ENTRY(\sym)
19045 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19046 call save_paranoid
19047 TRACE_IRQS_OFF_DEBUG
19048 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19049 + testb $3, CS(%rsp)
19050 + jnz 1f
19051 + pax_enter_kernel
19052 + jmp 2f
19053 +1: pax_enter_kernel_user
19054 +2:
19055 +#else
19056 + pax_enter_kernel
19057 +#endif
19058 movq %rsp,%rdi /* pt_regs pointer */
19059 xorl %esi,%esi /* no error code */
19060 +#ifdef CONFIG_SMP
19061 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19062 + lea init_tss(%r12), %r12
19063 +#else
19064 + lea init_tss(%rip), %r12
19065 +#endif
19066 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19067 call \do_sym
19068 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19069 jmp paranoid_exit /* %ebx: no swapgs flag */
19070 CFI_ENDPROC
19071 -END(\sym)
19072 +ENDPROC(\sym)
19073 .endm
19074
19075 .macro errorentry sym do_sym
19076 @@ -1267,13 +1617,23 @@ ENTRY(\sym)
19077 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19078 call error_entry
19079 DEFAULT_FRAME 0
19080 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19081 + testb $3, CS(%rsp)
19082 + jnz 1f
19083 + pax_enter_kernel
19084 + jmp 2f
19085 +1: pax_enter_kernel_user
19086 +2:
19087 +#else
19088 + pax_enter_kernel
19089 +#endif
19090 movq %rsp,%rdi /* pt_regs pointer */
19091 movq ORIG_RAX(%rsp),%rsi /* get error code */
19092 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19093 call \do_sym
19094 jmp error_exit /* %ebx: no swapgs flag */
19095 CFI_ENDPROC
19096 -END(\sym)
19097 +ENDPROC(\sym)
19098 .endm
19099
19100 /* error code is on the stack already */
19101 @@ -1287,13 +1647,23 @@ ENTRY(\sym)
19102 call save_paranoid
19103 DEFAULT_FRAME 0
19104 TRACE_IRQS_OFF
19105 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19106 + testb $3, CS(%rsp)
19107 + jnz 1f
19108 + pax_enter_kernel
19109 + jmp 2f
19110 +1: pax_enter_kernel_user
19111 +2:
19112 +#else
19113 + pax_enter_kernel
19114 +#endif
19115 movq %rsp,%rdi /* pt_regs pointer */
19116 movq ORIG_RAX(%rsp),%rsi /* get error code */
19117 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19118 call \do_sym
19119 jmp paranoid_exit /* %ebx: no swapgs flag */
19120 CFI_ENDPROC
19121 -END(\sym)
19122 +ENDPROC(\sym)
19123 .endm
19124
19125 zeroentry divide_error do_divide_error
19126 @@ -1323,9 +1693,10 @@ gs_change:
19127 2: mfence /* workaround */
19128 SWAPGS
19129 popfq_cfi
19130 + pax_force_retaddr
19131 ret
19132 CFI_ENDPROC
19133 -END(native_load_gs_index)
19134 +ENDPROC(native_load_gs_index)
19135
19136 _ASM_EXTABLE(gs_change,bad_gs)
19137 .section .fixup,"ax"
19138 @@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19139 CFI_DEF_CFA_REGISTER rsp
19140 CFI_ADJUST_CFA_OFFSET -8
19141 decl PER_CPU_VAR(irq_count)
19142 + pax_force_retaddr
19143 ret
19144 CFI_ENDPROC
19145 -END(call_softirq)
19146 +ENDPROC(call_softirq)
19147
19148 #ifdef CONFIG_XEN
19149 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19150 @@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19151 decl PER_CPU_VAR(irq_count)
19152 jmp error_exit
19153 CFI_ENDPROC
19154 -END(xen_do_hypervisor_callback)
19155 +ENDPROC(xen_do_hypervisor_callback)
19156
19157 /*
19158 * Hypervisor uses this for application faults while it executes.
19159 @@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19160 SAVE_ALL
19161 jmp error_exit
19162 CFI_ENDPROC
19163 -END(xen_failsafe_callback)
19164 +ENDPROC(xen_failsafe_callback)
19165
19166 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19167 xen_hvm_callback_vector xen_evtchn_do_upcall
19168 @@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19169 TRACE_IRQS_OFF_DEBUG
19170 testl %ebx,%ebx /* swapgs needed? */
19171 jnz paranoid_restore
19172 - testl $3,CS(%rsp)
19173 + testb $3,CS(%rsp)
19174 jnz paranoid_userspace
19175 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19176 + pax_exit_kernel
19177 + TRACE_IRQS_IRETQ 0
19178 + SWAPGS_UNSAFE_STACK
19179 + RESTORE_ALL 8
19180 + pax_force_retaddr_bts
19181 + jmp irq_return
19182 +#endif
19183 paranoid_swapgs:
19184 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19185 + pax_exit_kernel_user
19186 +#else
19187 + pax_exit_kernel
19188 +#endif
19189 TRACE_IRQS_IRETQ 0
19190 SWAPGS_UNSAFE_STACK
19191 RESTORE_ALL 8
19192 jmp irq_return
19193 paranoid_restore:
19194 + pax_exit_kernel
19195 TRACE_IRQS_IRETQ_DEBUG 0
19196 RESTORE_ALL 8
19197 + pax_force_retaddr_bts
19198 jmp irq_return
19199 paranoid_userspace:
19200 GET_THREAD_INFO(%rcx)
19201 @@ -1539,7 +1926,7 @@ paranoid_schedule:
19202 TRACE_IRQS_OFF
19203 jmp paranoid_userspace
19204 CFI_ENDPROC
19205 -END(paranoid_exit)
19206 +ENDPROC(paranoid_exit)
19207
19208 /*
19209 * Exception entry point. This expects an error code/orig_rax on the stack.
19210 @@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19211 movq_cfi r14, R14+8
19212 movq_cfi r15, R15+8
19213 xorl %ebx,%ebx
19214 - testl $3,CS+8(%rsp)
19215 + testb $3,CS+8(%rsp)
19216 je error_kernelspace
19217 error_swapgs:
19218 SWAPGS
19219 error_sti:
19220 TRACE_IRQS_OFF
19221 + pax_force_retaddr_bts
19222 ret
19223
19224 /*
19225 @@ -1598,7 +1986,7 @@ bstep_iret:
19226 movq %rcx,RIP+8(%rsp)
19227 jmp error_swapgs
19228 CFI_ENDPROC
19229 -END(error_entry)
19230 +ENDPROC(error_entry)
19231
19232
19233 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19234 @@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19235 jnz retint_careful
19236 jmp retint_swapgs
19237 CFI_ENDPROC
19238 -END(error_exit)
19239 +ENDPROC(error_exit)
19240
19241 /*
19242 * Test if a given stack is an NMI stack or not.
19243 @@ -1676,9 +2064,11 @@ ENTRY(nmi)
19244 * If %cs was not the kernel segment, then the NMI triggered in user
19245 * space, which means it is definitely not nested.
19246 */
19247 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19248 + je 1f
19249 cmpl $__KERNEL_CS, 16(%rsp)
19250 jne first_nmi
19251 -
19252 +1:
19253 /*
19254 * Check the special variable on the stack to see if NMIs are
19255 * executing.
19256 @@ -1847,6 +2237,17 @@ end_repeat_nmi:
19257 */
19258 movq %cr2, %r12
19259
19260 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19261 + testb $3, CS(%rsp)
19262 + jnz 1f
19263 + pax_enter_kernel
19264 + jmp 2f
19265 +1: pax_enter_kernel_user
19266 +2:
19267 +#else
19268 + pax_enter_kernel
19269 +#endif
19270 +
19271 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19272 movq %rsp,%rdi
19273 movq $-1,%rsi
19274 @@ -1862,23 +2263,34 @@ end_repeat_nmi:
19275 testl %ebx,%ebx /* swapgs needed? */
19276 jnz nmi_restore
19277 nmi_swapgs:
19278 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19279 + pax_exit_kernel_user
19280 +#else
19281 + pax_exit_kernel
19282 +#endif
19283 SWAPGS_UNSAFE_STACK
19284 + RESTORE_ALL 6*8
19285 + /* Clear the NMI executing stack variable */
19286 + movq $0, 5*8(%rsp)
19287 + jmp irq_return
19288 nmi_restore:
19289 + pax_exit_kernel
19290 /* Pop the extra iret frame at once */
19291 RESTORE_ALL 6*8
19292 + pax_force_retaddr_bts
19293
19294 /* Clear the NMI executing stack variable */
19295 movq $0, 5*8(%rsp)
19296 jmp irq_return
19297 CFI_ENDPROC
19298 -END(nmi)
19299 +ENDPROC(nmi)
19300
19301 ENTRY(ignore_sysret)
19302 CFI_STARTPROC
19303 mov $-ENOSYS,%eax
19304 sysret
19305 CFI_ENDPROC
19306 -END(ignore_sysret)
19307 +ENDPROC(ignore_sysret)
19308
19309 /*
19310 * End of kprobes section
19311 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19312 index 1d41402..af9a46a 100644
19313 --- a/arch/x86/kernel/ftrace.c
19314 +++ b/arch/x86/kernel/ftrace.c
19315 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19316 {
19317 unsigned char replaced[MCOUNT_INSN_SIZE];
19318
19319 + ip = ktla_ktva(ip);
19320 +
19321 /*
19322 * Note: Due to modules and __init, code can
19323 * disappear and change, we need to protect against faulting
19324 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19325 unsigned char old[MCOUNT_INSN_SIZE], *new;
19326 int ret;
19327
19328 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19329 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19330 new = ftrace_call_replace(ip, (unsigned long)func);
19331
19332 /* See comment above by declaration of modifying_ftrace_code */
19333 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19334 /* Also update the regs callback function */
19335 if (!ret) {
19336 ip = (unsigned long)(&ftrace_regs_call);
19337 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19338 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19339 new = ftrace_call_replace(ip, (unsigned long)func);
19340 ret = ftrace_modify_code(ip, old, new);
19341 }
19342 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19343 * kernel identity mapping to modify code.
19344 */
19345 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19346 - ip = (unsigned long)__va(__pa(ip));
19347 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19348
19349 return probe_kernel_write((void *)ip, val, size);
19350 }
19351 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19352 unsigned char replaced[MCOUNT_INSN_SIZE];
19353 unsigned char brk = BREAKPOINT_INSTRUCTION;
19354
19355 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19356 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19357 return -EFAULT;
19358
19359 /* Make sure it is what we expect it to be */
19360 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19361 return ret;
19362
19363 fail_update:
19364 - probe_kernel_write((void *)ip, &old_code[0], 1);
19365 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19366 goto out;
19367 }
19368
19369 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19370 {
19371 unsigned char code[MCOUNT_INSN_SIZE];
19372
19373 + ip = ktla_ktva(ip);
19374 +
19375 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19376 return -EFAULT;
19377
19378 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19379 index c18f59d..9c0c9f6 100644
19380 --- a/arch/x86/kernel/head32.c
19381 +++ b/arch/x86/kernel/head32.c
19382 @@ -18,6 +18,7 @@
19383 #include <asm/io_apic.h>
19384 #include <asm/bios_ebda.h>
19385 #include <asm/tlbflush.h>
19386 +#include <asm/boot.h>
19387
19388 static void __init i386_default_early_setup(void)
19389 {
19390 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19391
19392 void __init i386_start_kernel(void)
19393 {
19394 - memblock_reserve(__pa_symbol(&_text),
19395 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19396 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19397
19398 #ifdef CONFIG_BLK_DEV_INITRD
19399 /* Reserve INITRD */
19400 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19401 index c8932c7..d56b622 100644
19402 --- a/arch/x86/kernel/head_32.S
19403 +++ b/arch/x86/kernel/head_32.S
19404 @@ -26,6 +26,12 @@
19405 /* Physical address */
19406 #define pa(X) ((X) - __PAGE_OFFSET)
19407
19408 +#ifdef CONFIG_PAX_KERNEXEC
19409 +#define ta(X) (X)
19410 +#else
19411 +#define ta(X) ((X) - __PAGE_OFFSET)
19412 +#endif
19413 +
19414 /*
19415 * References to members of the new_cpu_data structure.
19416 */
19417 @@ -55,11 +61,7 @@
19418 * and small than max_low_pfn, otherwise will waste some page table entries
19419 */
19420
19421 -#if PTRS_PER_PMD > 1
19422 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19423 -#else
19424 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19425 -#endif
19426 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19427
19428 /* Number of possible pages in the lowmem region */
19429 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19430 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19431 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19432
19433 /*
19434 + * Real beginning of normal "text" segment
19435 + */
19436 +ENTRY(stext)
19437 +ENTRY(_stext)
19438 +
19439 +/*
19440 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19441 * %esi points to the real-mode code as a 32-bit pointer.
19442 * CS and DS must be 4 GB flat segments, but we don't depend on
19443 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19444 * can.
19445 */
19446 __HEAD
19447 +
19448 +#ifdef CONFIG_PAX_KERNEXEC
19449 + jmp startup_32
19450 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19451 +.fill PAGE_SIZE-5,1,0xcc
19452 +#endif
19453 +
19454 ENTRY(startup_32)
19455 movl pa(stack_start),%ecx
19456
19457 @@ -106,6 +121,59 @@ ENTRY(startup_32)
19458 2:
19459 leal -__PAGE_OFFSET(%ecx),%esp
19460
19461 +#ifdef CONFIG_SMP
19462 + movl $pa(cpu_gdt_table),%edi
19463 + movl $__per_cpu_load,%eax
19464 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19465 + rorl $16,%eax
19466 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19467 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19468 + movl $__per_cpu_end - 1,%eax
19469 + subl $__per_cpu_start,%eax
19470 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19471 +#endif
19472 +
19473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19474 + movl $NR_CPUS,%ecx
19475 + movl $pa(cpu_gdt_table),%edi
19476 +1:
19477 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19478 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19479 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19480 + addl $PAGE_SIZE_asm,%edi
19481 + loop 1b
19482 +#endif
19483 +
19484 +#ifdef CONFIG_PAX_KERNEXEC
19485 + movl $pa(boot_gdt),%edi
19486 + movl $__LOAD_PHYSICAL_ADDR,%eax
19487 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19488 + rorl $16,%eax
19489 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19490 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19491 + rorl $16,%eax
19492 +
19493 + ljmp $(__BOOT_CS),$1f
19494 +1:
19495 +
19496 + movl $NR_CPUS,%ecx
19497 + movl $pa(cpu_gdt_table),%edi
19498 + addl $__PAGE_OFFSET,%eax
19499 +1:
19500 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19501 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19502 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19503 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19504 + rorl $16,%eax
19505 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19506 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19507 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19508 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19509 + rorl $16,%eax
19510 + addl $PAGE_SIZE_asm,%edi
19511 + loop 1b
19512 +#endif
19513 +
19514 /*
19515 * Clear BSS first so that there are no surprises...
19516 */
19517 @@ -196,8 +264,11 @@ ENTRY(startup_32)
19518 movl %eax, pa(max_pfn_mapped)
19519
19520 /* Do early initialization of the fixmap area */
19521 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19522 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19523 +#ifdef CONFIG_COMPAT_VDSO
19524 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19525 +#else
19526 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19527 +#endif
19528 #else /* Not PAE */
19529
19530 page_pde_offset = (__PAGE_OFFSET >> 20);
19531 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19532 movl %eax, pa(max_pfn_mapped)
19533
19534 /* Do early initialization of the fixmap area */
19535 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19536 - movl %eax,pa(initial_page_table+0xffc)
19537 +#ifdef CONFIG_COMPAT_VDSO
19538 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19539 +#else
19540 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19541 +#endif
19542 #endif
19543
19544 #ifdef CONFIG_PARAVIRT
19545 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19546 cmpl $num_subarch_entries, %eax
19547 jae bad_subarch
19548
19549 - movl pa(subarch_entries)(,%eax,4), %eax
19550 - subl $__PAGE_OFFSET, %eax
19551 - jmp *%eax
19552 + jmp *pa(subarch_entries)(,%eax,4)
19553
19554 bad_subarch:
19555 WEAK(lguest_entry)
19556 @@ -256,10 +328,10 @@ WEAK(xen_entry)
19557 __INITDATA
19558
19559 subarch_entries:
19560 - .long default_entry /* normal x86/PC */
19561 - .long lguest_entry /* lguest hypervisor */
19562 - .long xen_entry /* Xen hypervisor */
19563 - .long default_entry /* Moorestown MID */
19564 + .long ta(default_entry) /* normal x86/PC */
19565 + .long ta(lguest_entry) /* lguest hypervisor */
19566 + .long ta(xen_entry) /* Xen hypervisor */
19567 + .long ta(default_entry) /* Moorestown MID */
19568 num_subarch_entries = (. - subarch_entries) / 4
19569 .previous
19570 #else
19571 @@ -335,6 +407,7 @@ default_entry:
19572 movl pa(mmu_cr4_features),%eax
19573 movl %eax,%cr4
19574
19575 +#ifdef CONFIG_X86_PAE
19576 testb $X86_CR4_PAE, %al # check if PAE is enabled
19577 jz 6f
19578
19579 @@ -363,6 +436,9 @@ default_entry:
19580 /* Make changes effective */
19581 wrmsr
19582
19583 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19584 +#endif
19585 +
19586 6:
19587
19588 /*
19589 @@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19590 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19591 movl %eax,%ss # after changing gdt.
19592
19593 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
19594 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19595 movl %eax,%ds
19596 movl %eax,%es
19597
19598 movl $(__KERNEL_PERCPU), %eax
19599 movl %eax,%fs # set this cpu's percpu
19600
19601 +#ifdef CONFIG_CC_STACKPROTECTOR
19602 movl $(__KERNEL_STACK_CANARY),%eax
19603 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19604 + movl $(__USER_DS),%eax
19605 +#else
19606 + xorl %eax,%eax
19607 +#endif
19608 movl %eax,%gs
19609
19610 xorl %eax,%eax # Clear LDT
19611 @@ -544,8 +626,11 @@ setup_once:
19612 * relocation. Manually set base address in stack canary
19613 * segment descriptor.
19614 */
19615 - movl $gdt_page,%eax
19616 + movl $cpu_gdt_table,%eax
19617 movl $stack_canary,%ecx
19618 +#ifdef CONFIG_SMP
19619 + addl $__per_cpu_load,%ecx
19620 +#endif
19621 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19622 shrl $16, %ecx
19623 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19624 @@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19625 /* This is global to keep gas from relaxing the jumps */
19626 ENTRY(early_idt_handler)
19627 cld
19628 - cmpl $2,%ss:early_recursion_flag
19629 + cmpl $1,%ss:early_recursion_flag
19630 je hlt_loop
19631 incl %ss:early_recursion_flag
19632
19633 @@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19634 pushl (20+6*4)(%esp) /* trapno */
19635 pushl $fault_msg
19636 call printk
19637 -#endif
19638 call dump_stack
19639 +#endif
19640 hlt_loop:
19641 hlt
19642 jmp hlt_loop
19643 @@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19644 /* This is the default interrupt "handler" :-) */
19645 ALIGN
19646 ignore_int:
19647 - cld
19648 #ifdef CONFIG_PRINTK
19649 + cmpl $2,%ss:early_recursion_flag
19650 + je hlt_loop
19651 + incl %ss:early_recursion_flag
19652 + cld
19653 pushl %eax
19654 pushl %ecx
19655 pushl %edx
19656 @@ -644,9 +732,6 @@ ignore_int:
19657 movl $(__KERNEL_DS),%eax
19658 movl %eax,%ds
19659 movl %eax,%es
19660 - cmpl $2,early_recursion_flag
19661 - je hlt_loop
19662 - incl early_recursion_flag
19663 pushl 16(%esp)
19664 pushl 24(%esp)
19665 pushl 32(%esp)
19666 @@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19667 /*
19668 * BSS section
19669 */
19670 -__PAGE_ALIGNED_BSS
19671 - .align PAGE_SIZE
19672 #ifdef CONFIG_X86_PAE
19673 +.section .initial_pg_pmd,"a",@progbits
19674 initial_pg_pmd:
19675 .fill 1024*KPMDS,4,0
19676 #else
19677 +.section .initial_page_table,"a",@progbits
19678 ENTRY(initial_page_table)
19679 .fill 1024,4,0
19680 #endif
19681 +.section .initial_pg_fixmap,"a",@progbits
19682 initial_pg_fixmap:
19683 .fill 1024,4,0
19684 +.section .empty_zero_page,"a",@progbits
19685 ENTRY(empty_zero_page)
19686 .fill 4096,1,0
19687 +.section .swapper_pg_dir,"a",@progbits
19688 ENTRY(swapper_pg_dir)
19689 +#ifdef CONFIG_X86_PAE
19690 + .fill 4,8,0
19691 +#else
19692 .fill 1024,4,0
19693 +#endif
19694 +
19695 +/*
19696 + * The IDT has to be page-aligned to simplify the Pentium
19697 + * F0 0F bug workaround.. We have a special link segment
19698 + * for this.
19699 + */
19700 +.section .idt,"a",@progbits
19701 +ENTRY(idt_table)
19702 + .fill 256,8,0
19703
19704 /*
19705 * This starts the data section.
19706 */
19707 #ifdef CONFIG_X86_PAE
19708 -__PAGE_ALIGNED_DATA
19709 - /* Page-aligned for the benefit of paravirt? */
19710 - .align PAGE_SIZE
19711 +.section .initial_page_table,"a",@progbits
19712 ENTRY(initial_page_table)
19713 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
19714 # if KPMDS == 3
19715 @@ -721,12 +820,20 @@ ENTRY(initial_page_table)
19716 # error "Kernel PMDs should be 1, 2 or 3"
19717 # endif
19718 .align PAGE_SIZE /* needs to be page-sized too */
19719 +
19720 +#ifdef CONFIG_PAX_PER_CPU_PGD
19721 +ENTRY(cpu_pgd)
19722 + .rept NR_CPUS
19723 + .fill 4,8,0
19724 + .endr
19725 +#endif
19726 +
19727 #endif
19728
19729 .data
19730 .balign 4
19731 ENTRY(stack_start)
19732 - .long init_thread_union+THREAD_SIZE
19733 + .long init_thread_union+THREAD_SIZE-8
19734
19735 __INITRODATA
19736 int_msg:
19737 @@ -754,7 +861,7 @@ fault_msg:
19738 * segment size, and 32-bit linear address value:
19739 */
19740
19741 - .data
19742 +.section .rodata,"a",@progbits
19743 .globl boot_gdt_descr
19744 .globl idt_descr
19745
19746 @@ -763,7 +870,7 @@ fault_msg:
19747 .word 0 # 32 bit align gdt_desc.address
19748 boot_gdt_descr:
19749 .word __BOOT_DS+7
19750 - .long boot_gdt - __PAGE_OFFSET
19751 + .long pa(boot_gdt)
19752
19753 .word 0 # 32-bit align idt_desc.address
19754 idt_descr:
19755 @@ -774,7 +881,7 @@ idt_descr:
19756 .word 0 # 32 bit align gdt_desc.address
19757 ENTRY(early_gdt_descr)
19758 .word GDT_ENTRIES*8-1
19759 - .long gdt_page /* Overwritten for secondary CPUs */
19760 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
19761
19762 /*
19763 * The boot_gdt must mirror the equivalent in setup.S and is
19764 @@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
19765 .align L1_CACHE_BYTES
19766 ENTRY(boot_gdt)
19767 .fill GDT_ENTRY_BOOT_CS,8,0
19768 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
19769 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
19770 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
19771 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
19772 +
19773 + .align PAGE_SIZE_asm
19774 +ENTRY(cpu_gdt_table)
19775 + .rept NR_CPUS
19776 + .quad 0x0000000000000000 /* NULL descriptor */
19777 + .quad 0x0000000000000000 /* 0x0b reserved */
19778 + .quad 0x0000000000000000 /* 0x13 reserved */
19779 + .quad 0x0000000000000000 /* 0x1b reserved */
19780 +
19781 +#ifdef CONFIG_PAX_KERNEXEC
19782 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
19783 +#else
19784 + .quad 0x0000000000000000 /* 0x20 unused */
19785 +#endif
19786 +
19787 + .quad 0x0000000000000000 /* 0x28 unused */
19788 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
19789 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
19790 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
19791 + .quad 0x0000000000000000 /* 0x4b reserved */
19792 + .quad 0x0000000000000000 /* 0x53 reserved */
19793 + .quad 0x0000000000000000 /* 0x5b reserved */
19794 +
19795 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
19796 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
19797 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
19798 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
19799 +
19800 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
19801 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
19802 +
19803 + /*
19804 + * Segments used for calling PnP BIOS have byte granularity.
19805 + * The code segments and data segments have fixed 64k limits,
19806 + * the transfer segment sizes are set at run time.
19807 + */
19808 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
19809 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
19810 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
19811 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
19812 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
19813 +
19814 + /*
19815 + * The APM segments have byte granularity and their bases
19816 + * are set at run time. All have 64k limits.
19817 + */
19818 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
19819 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
19820 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
19821 +
19822 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
19823 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
19824 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
19825 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
19826 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
19827 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
19828 +
19829 + /* Be sure this is zeroed to avoid false validations in Xen */
19830 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
19831 + .endr
19832 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
19833 index 980053c..74d3b44 100644
19834 --- a/arch/x86/kernel/head_64.S
19835 +++ b/arch/x86/kernel/head_64.S
19836 @@ -20,6 +20,8 @@
19837 #include <asm/processor-flags.h>
19838 #include <asm/percpu.h>
19839 #include <asm/nops.h>
19840 +#include <asm/cpufeature.h>
19841 +#include <asm/alternative-asm.h>
19842
19843 #ifdef CONFIG_PARAVIRT
19844 #include <asm/asm-offsets.h>
19845 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
19846 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
19847 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
19848 L3_START_KERNEL = pud_index(__START_KERNEL_map)
19849 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
19850 +L3_VMALLOC_START = pud_index(VMALLOC_START)
19851 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
19852 +L3_VMALLOC_END = pud_index(VMALLOC_END)
19853 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
19854 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
19855
19856 .text
19857 __HEAD
19858 @@ -88,35 +96,23 @@ startup_64:
19859 */
19860 addq %rbp, init_level4_pgt + 0(%rip)
19861 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
19862 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
19863 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
19864 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
19865 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
19866
19867 addq %rbp, level3_ident_pgt + 0(%rip)
19868 +#ifndef CONFIG_XEN
19869 + addq %rbp, level3_ident_pgt + 8(%rip)
19870 +#endif
19871
19872 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
19873 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
19874 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
19875 +
19876 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
19877 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
19878
19879 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
19880 -
19881 - /* Add an Identity mapping if I am above 1G */
19882 - leaq _text(%rip), %rdi
19883 - andq $PMD_PAGE_MASK, %rdi
19884 -
19885 - movq %rdi, %rax
19886 - shrq $PUD_SHIFT, %rax
19887 - andq $(PTRS_PER_PUD - 1), %rax
19888 - jz ident_complete
19889 -
19890 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
19891 - leaq level3_ident_pgt(%rip), %rbx
19892 - movq %rdx, 0(%rbx, %rax, 8)
19893 -
19894 - movq %rdi, %rax
19895 - shrq $PMD_SHIFT, %rax
19896 - andq $(PTRS_PER_PMD - 1), %rax
19897 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
19898 - leaq level2_spare_pgt(%rip), %rbx
19899 - movq %rdx, 0(%rbx, %rax, 8)
19900 -ident_complete:
19901 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
19902
19903 /*
19904 * Fixup the kernel text+data virtual addresses. Note that
19905 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
19906 * after the boot processor executes this code.
19907 */
19908
19909 - /* Enable PAE mode and PGE */
19910 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
19911 + /* Enable PAE mode and PSE/PGE */
19912 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19913 movq %rax, %cr4
19914
19915 /* Setup early boot stage 4 level pagetables. */
19916 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
19917 movl $MSR_EFER, %ecx
19918 rdmsr
19919 btsl $_EFER_SCE, %eax /* Enable System Call */
19920 - btl $20,%edi /* No Execute supported? */
19921 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
19922 jnc 1f
19923 btsl $_EFER_NX, %eax
19924 + leaq init_level4_pgt(%rip), %rdi
19925 +#ifndef CONFIG_EFI
19926 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
19927 +#endif
19928 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
19929 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
19930 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
19931 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
19932 1: wrmsr /* Make changes effective */
19933
19934 /* Setup cr0 */
19935 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
19936 * jump. In addition we need to ensure %cs is set so we make this
19937 * a far return.
19938 */
19939 + pax_set_fptr_mask
19940 movq initial_code(%rip),%rax
19941 pushq $0 # fake return address to stop unwinder
19942 pushq $__KERNEL_CS # set correct cs
19943 @@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
19944 bad_address:
19945 jmp bad_address
19946
19947 - .section ".init.text","ax"
19948 + __INIT
19949 .globl early_idt_handlers
19950 early_idt_handlers:
19951 # 104(%rsp) %rflags
19952 @@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
19953 call dump_stack
19954 #ifdef CONFIG_KALLSYMS
19955 leaq early_idt_ripmsg(%rip),%rdi
19956 - movq 40(%rsp),%rsi # %rip again
19957 + movq 88(%rsp),%rsi # %rip again
19958 call __print_symbol
19959 #endif
19960 #endif /* EARLY_PRINTK */
19961 @@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
19962 addq $16,%rsp # drop vector number and error code
19963 decl early_recursion_flag(%rip)
19964 INTERRUPT_RETURN
19965 + .previous
19966
19967 + __INITDATA
19968 .balign 4
19969 early_recursion_flag:
19970 .long 0
19971 + .previous
19972
19973 + .section .rodata,"a",@progbits
19974 #ifdef CONFIG_EARLY_PRINTK
19975 early_idt_msg:
19976 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
19977 @@ -376,6 +385,7 @@ early_idt_ripmsg:
19978 #endif /* CONFIG_EARLY_PRINTK */
19979 .previous
19980
19981 + .section .rodata,"a",@progbits
19982 #define NEXT_PAGE(name) \
19983 .balign PAGE_SIZE; \
19984 ENTRY(name)
19985 @@ -388,7 +398,6 @@ ENTRY(name)
19986 i = i + 1 ; \
19987 .endr
19988
19989 - .data
19990 /*
19991 * This default setting generates an ident mapping at address 0x100000
19992 * and a mapping for the kernel that precisely maps virtual address
19993 @@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
19994 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
19995 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
19996 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
19997 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
19998 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
19999 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
20000 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20001 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20002 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20003 .org init_level4_pgt + L4_START_KERNEL*8, 0
20004 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20005 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20006
20007 +#ifdef CONFIG_PAX_PER_CPU_PGD
20008 +NEXT_PAGE(cpu_pgd)
20009 + .rept NR_CPUS
20010 + .fill 512,8,0
20011 + .endr
20012 +#endif
20013 +
20014 NEXT_PAGE(level3_ident_pgt)
20015 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20016 +#ifdef CONFIG_XEN
20017 .fill 511,8,0
20018 +#else
20019 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20020 + .fill 510,8,0
20021 +#endif
20022 +
20023 +NEXT_PAGE(level3_vmalloc_start_pgt)
20024 + .fill 512,8,0
20025 +
20026 +NEXT_PAGE(level3_vmalloc_end_pgt)
20027 + .fill 512,8,0
20028 +
20029 +NEXT_PAGE(level3_vmemmap_pgt)
20030 + .fill L3_VMEMMAP_START,8,0
20031 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20032
20033 NEXT_PAGE(level3_kernel_pgt)
20034 .fill L3_START_KERNEL,8,0
20035 @@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20036 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20037 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20038
20039 +NEXT_PAGE(level2_vmemmap_pgt)
20040 + .fill 512,8,0
20041 +
20042 NEXT_PAGE(level2_fixmap_pgt)
20043 - .fill 506,8,0
20044 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20045 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20046 - .fill 5,8,0
20047 + .fill 507,8,0
20048 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20049 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20050 + .fill 4,8,0
20051
20052 -NEXT_PAGE(level1_fixmap_pgt)
20053 +NEXT_PAGE(level1_vsyscall_pgt)
20054 .fill 512,8,0
20055
20056 -NEXT_PAGE(level2_ident_pgt)
20057 - /* Since I easily can, map the first 1G.
20058 + /* Since I easily can, map the first 2G.
20059 * Don't set NX because code runs from these pages.
20060 */
20061 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20062 +NEXT_PAGE(level2_ident_pgt)
20063 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20064
20065 NEXT_PAGE(level2_kernel_pgt)
20066 /*
20067 @@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20068 * If you want to increase this then increase MODULES_VADDR
20069 * too.)
20070 */
20071 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20072 - KERNEL_IMAGE_SIZE/PMD_SIZE)
20073 -
20074 -NEXT_PAGE(level2_spare_pgt)
20075 - .fill 512, 8, 0
20076 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20077
20078 #undef PMDS
20079 #undef NEXT_PAGE
20080
20081 - .data
20082 + .align PAGE_SIZE
20083 +ENTRY(cpu_gdt_table)
20084 + .rept NR_CPUS
20085 + .quad 0x0000000000000000 /* NULL descriptor */
20086 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20087 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
20088 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
20089 + .quad 0x00cffb000000ffff /* __USER32_CS */
20090 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20091 + .quad 0x00affb000000ffff /* __USER_CS */
20092 +
20093 +#ifdef CONFIG_PAX_KERNEXEC
20094 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20095 +#else
20096 + .quad 0x0 /* unused */
20097 +#endif
20098 +
20099 + .quad 0,0 /* TSS */
20100 + .quad 0,0 /* LDT */
20101 + .quad 0,0,0 /* three TLS descriptors */
20102 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
20103 + /* asm/segment.h:GDT_ENTRIES must match this */
20104 +
20105 + /* zero the remaining page */
20106 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20107 + .endr
20108 +
20109 .align 16
20110 .globl early_gdt_descr
20111 early_gdt_descr:
20112 .word GDT_ENTRIES*8-1
20113 early_gdt_descr_base:
20114 - .quad INIT_PER_CPU_VAR(gdt_page)
20115 + .quad cpu_gdt_table
20116
20117 ENTRY(phys_base)
20118 /* This must match the first entry in level2_kernel_pgt */
20119 .quad 0x0000000000000000
20120
20121 #include "../../x86/xen/xen-head.S"
20122 -
20123 - .section .bss, "aw", @nobits
20124 +
20125 + .section .rodata,"a",@progbits
20126 .align L1_CACHE_BYTES
20127 ENTRY(idt_table)
20128 - .skip IDT_ENTRIES * 16
20129 + .fill 512,8,0
20130
20131 .align L1_CACHE_BYTES
20132 ENTRY(nmi_idt_table)
20133 - .skip IDT_ENTRIES * 16
20134 + .fill 512,8,0
20135
20136 __PAGE_ALIGNED_BSS
20137 .align PAGE_SIZE
20138 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20139 index 9c3bd4a..e1d9b35 100644
20140 --- a/arch/x86/kernel/i386_ksyms_32.c
20141 +++ b/arch/x86/kernel/i386_ksyms_32.c
20142 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20143 EXPORT_SYMBOL(cmpxchg8b_emu);
20144 #endif
20145
20146 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
20147 +
20148 /* Networking helper routines. */
20149 EXPORT_SYMBOL(csum_partial_copy_generic);
20150 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20151 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20152
20153 EXPORT_SYMBOL(__get_user_1);
20154 EXPORT_SYMBOL(__get_user_2);
20155 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20156
20157 EXPORT_SYMBOL(csum_partial);
20158 EXPORT_SYMBOL(empty_zero_page);
20159 +
20160 +#ifdef CONFIG_PAX_KERNEXEC
20161 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20162 +#endif
20163 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20164 index 245a71d..89d9ce4 100644
20165 --- a/arch/x86/kernel/i387.c
20166 +++ b/arch/x86/kernel/i387.c
20167 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20168 static inline bool interrupted_user_mode(void)
20169 {
20170 struct pt_regs *regs = get_irq_regs();
20171 - return regs && user_mode_vm(regs);
20172 + return regs && user_mode(regs);
20173 }
20174
20175 /*
20176 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20177 index 9a5c460..dc4374d 100644
20178 --- a/arch/x86/kernel/i8259.c
20179 +++ b/arch/x86/kernel/i8259.c
20180 @@ -209,7 +209,7 @@ spurious_8259A_irq:
20181 "spurious 8259A interrupt: IRQ%d.\n", irq);
20182 spurious_irq_mask |= irqmask;
20183 }
20184 - atomic_inc(&irq_err_count);
20185 + atomic_inc_unchecked(&irq_err_count);
20186 /*
20187 * Theoretically we do not have to handle this IRQ,
20188 * but in Linux this does not cause problems and is
20189 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20190 index 8c96897..be66bfa 100644
20191 --- a/arch/x86/kernel/ioport.c
20192 +++ b/arch/x86/kernel/ioport.c
20193 @@ -6,6 +6,7 @@
20194 #include <linux/sched.h>
20195 #include <linux/kernel.h>
20196 #include <linux/capability.h>
20197 +#include <linux/security.h>
20198 #include <linux/errno.h>
20199 #include <linux/types.h>
20200 #include <linux/ioport.h>
20201 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20202
20203 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20204 return -EINVAL;
20205 +#ifdef CONFIG_GRKERNSEC_IO
20206 + if (turn_on && grsec_disable_privio) {
20207 + gr_handle_ioperm();
20208 + return -EPERM;
20209 + }
20210 +#endif
20211 if (turn_on && !capable(CAP_SYS_RAWIO))
20212 return -EPERM;
20213
20214 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20215 * because the ->io_bitmap_max value must match the bitmap
20216 * contents:
20217 */
20218 - tss = &per_cpu(init_tss, get_cpu());
20219 + tss = init_tss + get_cpu();
20220
20221 if (turn_on)
20222 bitmap_clear(t->io_bitmap_ptr, from, num);
20223 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20224 return -EINVAL;
20225 /* Trying to gain more privileges? */
20226 if (level > old) {
20227 +#ifdef CONFIG_GRKERNSEC_IO
20228 + if (grsec_disable_privio) {
20229 + gr_handle_iopl();
20230 + return -EPERM;
20231 + }
20232 +#endif
20233 if (!capable(CAP_SYS_RAWIO))
20234 return -EPERM;
20235 }
20236 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20237 index e4595f1..ee3bfb8 100644
20238 --- a/arch/x86/kernel/irq.c
20239 +++ b/arch/x86/kernel/irq.c
20240 @@ -18,7 +18,7 @@
20241 #include <asm/mce.h>
20242 #include <asm/hw_irq.h>
20243
20244 -atomic_t irq_err_count;
20245 +atomic_unchecked_t irq_err_count;
20246
20247 /* Function pointer for generic interrupt vector handling */
20248 void (*x86_platform_ipi_callback)(void) = NULL;
20249 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20250 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20251 seq_printf(p, " Machine check polls\n");
20252 #endif
20253 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20254 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20255 #if defined(CONFIG_X86_IO_APIC)
20256 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20257 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20258 #endif
20259 return 0;
20260 }
20261 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20262
20263 u64 arch_irq_stat(void)
20264 {
20265 - u64 sum = atomic_read(&irq_err_count);
20266 + u64 sum = atomic_read_unchecked(&irq_err_count);
20267
20268 #ifdef CONFIG_X86_IO_APIC
20269 - sum += atomic_read(&irq_mis_count);
20270 + sum += atomic_read_unchecked(&irq_mis_count);
20271 #endif
20272 return sum;
20273 }
20274 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20275 index 344faf8..355f60d 100644
20276 --- a/arch/x86/kernel/irq_32.c
20277 +++ b/arch/x86/kernel/irq_32.c
20278 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20279 __asm__ __volatile__("andl %%esp,%0" :
20280 "=r" (sp) : "0" (THREAD_SIZE - 1));
20281
20282 - return sp < (sizeof(struct thread_info) + STACK_WARN);
20283 + return sp < STACK_WARN;
20284 }
20285
20286 static void print_stack_overflow(void)
20287 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20288 * per-CPU IRQ handling contexts (thread information and stack)
20289 */
20290 union irq_ctx {
20291 - struct thread_info tinfo;
20292 - u32 stack[THREAD_SIZE/sizeof(u32)];
20293 + unsigned long previous_esp;
20294 + u32 stack[THREAD_SIZE/sizeof(u32)];
20295 } __attribute__((aligned(THREAD_SIZE)));
20296
20297 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20298 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20299 static inline int
20300 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20301 {
20302 - union irq_ctx *curctx, *irqctx;
20303 + union irq_ctx *irqctx;
20304 u32 *isp, arg1, arg2;
20305
20306 - curctx = (union irq_ctx *) current_thread_info();
20307 irqctx = __this_cpu_read(hardirq_ctx);
20308
20309 /*
20310 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20311 * handler) we can't do that and just have to keep using the
20312 * current stack (which is the irq stack already after all)
20313 */
20314 - if (unlikely(curctx == irqctx))
20315 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20316 return 0;
20317
20318 /* build the stack frame on the IRQ stack */
20319 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20320 - irqctx->tinfo.task = curctx->tinfo.task;
20321 - irqctx->tinfo.previous_esp = current_stack_pointer;
20322 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20323 + irqctx->previous_esp = current_stack_pointer;
20324
20325 - /* Copy the preempt_count so that the [soft]irq checks work. */
20326 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20327 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20328 + __set_fs(MAKE_MM_SEG(0));
20329 +#endif
20330
20331 if (unlikely(overflow))
20332 call_on_stack(print_stack_overflow, isp);
20333 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20334 : "0" (irq), "1" (desc), "2" (isp),
20335 "D" (desc->handle_irq)
20336 : "memory", "cc", "ecx");
20337 +
20338 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20339 + __set_fs(current_thread_info()->addr_limit);
20340 +#endif
20341 +
20342 return 1;
20343 }
20344
20345 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20346 */
20347 void __cpuinit irq_ctx_init(int cpu)
20348 {
20349 - union irq_ctx *irqctx;
20350 -
20351 if (per_cpu(hardirq_ctx, cpu))
20352 return;
20353
20354 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20355 - THREADINFO_GFP,
20356 - THREAD_SIZE_ORDER));
20357 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20358 - irqctx->tinfo.cpu = cpu;
20359 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20360 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20361 -
20362 - per_cpu(hardirq_ctx, cpu) = irqctx;
20363 -
20364 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20365 - THREADINFO_GFP,
20366 - THREAD_SIZE_ORDER));
20367 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20368 - irqctx->tinfo.cpu = cpu;
20369 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20370 -
20371 - per_cpu(softirq_ctx, cpu) = irqctx;
20372 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20373 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20374 +
20375 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20376 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20377
20378 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20379 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20380 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20381 asmlinkage void do_softirq(void)
20382 {
20383 unsigned long flags;
20384 - struct thread_info *curctx;
20385 union irq_ctx *irqctx;
20386 u32 *isp;
20387
20388 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20389 local_irq_save(flags);
20390
20391 if (local_softirq_pending()) {
20392 - curctx = current_thread_info();
20393 irqctx = __this_cpu_read(softirq_ctx);
20394 - irqctx->tinfo.task = curctx->task;
20395 - irqctx->tinfo.previous_esp = current_stack_pointer;
20396 + irqctx->previous_esp = current_stack_pointer;
20397
20398 /* build the stack frame on the softirq stack */
20399 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20400 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20401 +
20402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20403 + __set_fs(MAKE_MM_SEG(0));
20404 +#endif
20405
20406 call_on_stack(__do_softirq, isp);
20407 +
20408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20409 + __set_fs(current_thread_info()->addr_limit);
20410 +#endif
20411 +
20412 /*
20413 * Shouldn't happen, we returned above if in_interrupt():
20414 */
20415 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20416 if (unlikely(!desc))
20417 return false;
20418
20419 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20420 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20421 if (unlikely(overflow))
20422 print_stack_overflow();
20423 desc->handle_irq(irq, desc);
20424 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20425 index d04d3ec..ea4b374 100644
20426 --- a/arch/x86/kernel/irq_64.c
20427 +++ b/arch/x86/kernel/irq_64.c
20428 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20429 u64 estack_top, estack_bottom;
20430 u64 curbase = (u64)task_stack_page(current);
20431
20432 - if (user_mode_vm(regs))
20433 + if (user_mode(regs))
20434 return;
20435
20436 if (regs->sp >= curbase + sizeof(struct thread_info) +
20437 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20438 index dc1404b..bbc43e7 100644
20439 --- a/arch/x86/kernel/kdebugfs.c
20440 +++ b/arch/x86/kernel/kdebugfs.c
20441 @@ -27,7 +27,7 @@ struct setup_data_node {
20442 u32 len;
20443 };
20444
20445 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20446 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20447 size_t count, loff_t *ppos)
20448 {
20449 struct setup_data_node *node = file->private_data;
20450 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20451 index 836f832..a8bda67 100644
20452 --- a/arch/x86/kernel/kgdb.c
20453 +++ b/arch/x86/kernel/kgdb.c
20454 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20455 #ifdef CONFIG_X86_32
20456 switch (regno) {
20457 case GDB_SS:
20458 - if (!user_mode_vm(regs))
20459 + if (!user_mode(regs))
20460 *(unsigned long *)mem = __KERNEL_DS;
20461 break;
20462 case GDB_SP:
20463 - if (!user_mode_vm(regs))
20464 + if (!user_mode(regs))
20465 *(unsigned long *)mem = kernel_stack_pointer(regs);
20466 break;
20467 case GDB_GS:
20468 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20469 bp->attr.bp_addr = breakinfo[breakno].addr;
20470 bp->attr.bp_len = breakinfo[breakno].len;
20471 bp->attr.bp_type = breakinfo[breakno].type;
20472 - info->address = breakinfo[breakno].addr;
20473 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20474 + info->address = ktla_ktva(breakinfo[breakno].addr);
20475 + else
20476 + info->address = breakinfo[breakno].addr;
20477 info->len = breakinfo[breakno].len;
20478 info->type = breakinfo[breakno].type;
20479 val = arch_install_hw_breakpoint(bp);
20480 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20481 case 'k':
20482 /* clear the trace bit */
20483 linux_regs->flags &= ~X86_EFLAGS_TF;
20484 - atomic_set(&kgdb_cpu_doing_single_step, -1);
20485 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20486
20487 /* set the trace bit if we're stepping */
20488 if (remcomInBuffer[0] == 's') {
20489 linux_regs->flags |= X86_EFLAGS_TF;
20490 - atomic_set(&kgdb_cpu_doing_single_step,
20491 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20492 raw_smp_processor_id());
20493 }
20494
20495 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20496
20497 switch (cmd) {
20498 case DIE_DEBUG:
20499 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20500 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20501 if (user_mode(regs))
20502 return single_step_cont(regs, args);
20503 break;
20504 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20505 #endif /* CONFIG_DEBUG_RODATA */
20506
20507 bpt->type = BP_BREAKPOINT;
20508 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20509 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20510 BREAK_INSTR_SIZE);
20511 if (err)
20512 return err;
20513 - err = probe_kernel_write((char *)bpt->bpt_addr,
20514 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20515 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20516 #ifdef CONFIG_DEBUG_RODATA
20517 if (!err)
20518 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20519 return -EBUSY;
20520 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20521 BREAK_INSTR_SIZE);
20522 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20523 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20524 if (err)
20525 return err;
20526 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20527 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20528 if (mutex_is_locked(&text_mutex))
20529 goto knl_write;
20530 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20531 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20532 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20533 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20534 goto knl_write;
20535 return err;
20536 knl_write:
20537 #endif /* CONFIG_DEBUG_RODATA */
20538 - return probe_kernel_write((char *)bpt->bpt_addr,
20539 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20540 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20541 }
20542
20543 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20544 index c5e410e..ed5a7f0 100644
20545 --- a/arch/x86/kernel/kprobes-opt.c
20546 +++ b/arch/x86/kernel/kprobes-opt.c
20547 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20548 * Verify if the address gap is in 2GB range, because this uses
20549 * a relative jump.
20550 */
20551 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20552 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20553 if (abs(rel) > 0x7fffffff)
20554 return -ERANGE;
20555
20556 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20557 op->optinsn.size = ret;
20558
20559 /* Copy arch-dep-instance from template */
20560 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20561 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20562
20563 /* Set probe information */
20564 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20565
20566 /* Set probe function call */
20567 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20568 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20569
20570 /* Set returning jmp instruction at the tail of out-of-line buffer */
20571 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20572 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20573 (u8 *)op->kp.addr + op->optinsn.size);
20574
20575 flush_icache_range((unsigned long) buf,
20576 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20577 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20578
20579 /* Backup instructions which will be replaced by jump address */
20580 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20581 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20582 RELATIVE_ADDR_SIZE);
20583
20584 insn_buf[0] = RELATIVEJUMP_OPCODE;
20585 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20586 /* This kprobe is really able to run optimized path. */
20587 op = container_of(p, struct optimized_kprobe, kp);
20588 /* Detour through copied instructions */
20589 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20590 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20591 if (!reenter)
20592 reset_current_kprobe();
20593 preempt_enable_no_resched();
20594 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20595 index 57916c0..9e0b9d0 100644
20596 --- a/arch/x86/kernel/kprobes.c
20597 +++ b/arch/x86/kernel/kprobes.c
20598 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20599 s32 raddr;
20600 } __attribute__((packed)) *insn;
20601
20602 - insn = (struct __arch_relative_insn *)from;
20603 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
20604 +
20605 + pax_open_kernel();
20606 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20607 insn->op = op;
20608 + pax_close_kernel();
20609 }
20610
20611 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20612 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20613 kprobe_opcode_t opcode;
20614 kprobe_opcode_t *orig_opcodes = opcodes;
20615
20616 - if (search_exception_tables((unsigned long)opcodes))
20617 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20618 return 0; /* Page fault may occur on this address. */
20619
20620 retry:
20621 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20622 * for the first byte, we can recover the original instruction
20623 * from it and kp->opcode.
20624 */
20625 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20626 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20627 buf[0] = kp->opcode;
20628 - return (unsigned long)buf;
20629 + return ktva_ktla((unsigned long)buf);
20630 }
20631
20632 /*
20633 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20634 /* Another subsystem puts a breakpoint, failed to recover */
20635 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20636 return 0;
20637 + pax_open_kernel();
20638 memcpy(dest, insn.kaddr, insn.length);
20639 + pax_close_kernel();
20640
20641 #ifdef CONFIG_X86_64
20642 if (insn_rip_relative(&insn)) {
20643 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20644 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20645 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20646 disp = (u8 *) dest + insn_offset_displacement(&insn);
20647 + pax_open_kernel();
20648 *(s32 *) disp = (s32) newdisp;
20649 + pax_close_kernel();
20650 }
20651 #endif
20652 return insn.length;
20653 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20654 * nor set current_kprobe, because it doesn't use single
20655 * stepping.
20656 */
20657 - regs->ip = (unsigned long)p->ainsn.insn;
20658 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20659 preempt_enable_no_resched();
20660 return;
20661 }
20662 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20663 regs->flags &= ~X86_EFLAGS_IF;
20664 /* single step inline if the instruction is an int3 */
20665 if (p->opcode == BREAKPOINT_INSTRUCTION)
20666 - regs->ip = (unsigned long)p->addr;
20667 + regs->ip = ktla_ktva((unsigned long)p->addr);
20668 else
20669 - regs->ip = (unsigned long)p->ainsn.insn;
20670 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20671 }
20672
20673 /*
20674 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
20675 setup_singlestep(p, regs, kcb, 0);
20676 return 1;
20677 }
20678 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
20679 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
20680 /*
20681 * The breakpoint instruction was removed right
20682 * after we hit it. Another cpu has removed
20683 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
20684 " movq %rax, 152(%rsp)\n"
20685 RESTORE_REGS_STRING
20686 " popfq\n"
20687 +#ifdef KERNEXEC_PLUGIN
20688 + " btsq $63,(%rsp)\n"
20689 +#endif
20690 #else
20691 " pushf\n"
20692 SAVE_REGS_STRING
20693 @@ -788,7 +798,7 @@ static void __kprobes
20694 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
20695 {
20696 unsigned long *tos = stack_addr(regs);
20697 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
20698 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
20699 unsigned long orig_ip = (unsigned long)p->addr;
20700 kprobe_opcode_t *insn = p->ainsn.insn;
20701
20702 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
20703 struct die_args *args = data;
20704 int ret = NOTIFY_DONE;
20705
20706 - if (args->regs && user_mode_vm(args->regs))
20707 + if (args->regs && user_mode(args->regs))
20708 return ret;
20709
20710 switch (val) {
20711 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
20712 index 9c2bd8b..bb1131c 100644
20713 --- a/arch/x86/kernel/kvm.c
20714 +++ b/arch/x86/kernel/kvm.c
20715 @@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
20716 return NOTIFY_OK;
20717 }
20718
20719 -static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
20720 +static struct notifier_block kvm_cpu_notifier = {
20721 .notifier_call = kvm_cpu_notify,
20722 };
20723 #endif
20724 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
20725 index ebc9873..1b9724b 100644
20726 --- a/arch/x86/kernel/ldt.c
20727 +++ b/arch/x86/kernel/ldt.c
20728 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
20729 if (reload) {
20730 #ifdef CONFIG_SMP
20731 preempt_disable();
20732 - load_LDT(pc);
20733 + load_LDT_nolock(pc);
20734 if (!cpumask_equal(mm_cpumask(current->mm),
20735 cpumask_of(smp_processor_id())))
20736 smp_call_function(flush_ldt, current->mm, 1);
20737 preempt_enable();
20738 #else
20739 - load_LDT(pc);
20740 + load_LDT_nolock(pc);
20741 #endif
20742 }
20743 if (oldsize) {
20744 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
20745 return err;
20746
20747 for (i = 0; i < old->size; i++)
20748 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
20749 + write_ldt_entry(new->ldt, i, old->ldt + i);
20750 return 0;
20751 }
20752
20753 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
20754 retval = copy_ldt(&mm->context, &old_mm->context);
20755 mutex_unlock(&old_mm->context.lock);
20756 }
20757 +
20758 + if (tsk == current) {
20759 + mm->context.vdso = 0;
20760 +
20761 +#ifdef CONFIG_X86_32
20762 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20763 + mm->context.user_cs_base = 0UL;
20764 + mm->context.user_cs_limit = ~0UL;
20765 +
20766 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
20767 + cpus_clear(mm->context.cpu_user_cs_mask);
20768 +#endif
20769 +
20770 +#endif
20771 +#endif
20772 +
20773 + }
20774 +
20775 return retval;
20776 }
20777
20778 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
20779 }
20780 }
20781
20782 +#ifdef CONFIG_PAX_SEGMEXEC
20783 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
20784 + error = -EINVAL;
20785 + goto out_unlock;
20786 + }
20787 +#endif
20788 +
20789 fill_ldt(&ldt, &ldt_info);
20790 if (oldmode)
20791 ldt.avl = 0;
20792 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
20793 index 5b19e4d..6476a76 100644
20794 --- a/arch/x86/kernel/machine_kexec_32.c
20795 +++ b/arch/x86/kernel/machine_kexec_32.c
20796 @@ -26,7 +26,7 @@
20797 #include <asm/cacheflush.h>
20798 #include <asm/debugreg.h>
20799
20800 -static void set_idt(void *newidt, __u16 limit)
20801 +static void set_idt(struct desc_struct *newidt, __u16 limit)
20802 {
20803 struct desc_ptr curidt;
20804
20805 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
20806 }
20807
20808
20809 -static void set_gdt(void *newgdt, __u16 limit)
20810 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
20811 {
20812 struct desc_ptr curgdt;
20813
20814 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
20815 }
20816
20817 control_page = page_address(image->control_code_page);
20818 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
20819 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
20820
20821 relocate_kernel_ptr = control_page;
20822 page_list[PA_CONTROL_PAGE] = __pa(control_page);
20823 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
20824 index 3a04b22..1d2eb09 100644
20825 --- a/arch/x86/kernel/microcode_core.c
20826 +++ b/arch/x86/kernel/microcode_core.c
20827 @@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
20828 return NOTIFY_OK;
20829 }
20830
20831 -static struct notifier_block __refdata mc_cpu_notifier = {
20832 +static struct notifier_block mc_cpu_notifier = {
20833 .notifier_call = mc_cpu_callback,
20834 };
20835
20836 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
20837 index 3544aed..01ddc1c 100644
20838 --- a/arch/x86/kernel/microcode_intel.c
20839 +++ b/arch/x86/kernel/microcode_intel.c
20840 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
20841
20842 static int get_ucode_user(void *to, const void *from, size_t n)
20843 {
20844 - return copy_from_user(to, from, n);
20845 + return copy_from_user(to, (const void __force_user *)from, n);
20846 }
20847
20848 static enum ucode_state
20849 request_microcode_user(int cpu, const void __user *buf, size_t size)
20850 {
20851 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
20852 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
20853 }
20854
20855 static void microcode_fini_cpu(int cpu)
20856 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
20857 index 216a4d7..228255a 100644
20858 --- a/arch/x86/kernel/module.c
20859 +++ b/arch/x86/kernel/module.c
20860 @@ -43,15 +43,60 @@ do { \
20861 } while (0)
20862 #endif
20863
20864 -void *module_alloc(unsigned long size)
20865 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
20866 {
20867 - if (PAGE_ALIGN(size) > MODULES_LEN)
20868 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
20869 return NULL;
20870 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
20871 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
20872 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
20873 -1, __builtin_return_address(0));
20874 }
20875
20876 +void *module_alloc(unsigned long size)
20877 +{
20878 +
20879 +#ifdef CONFIG_PAX_KERNEXEC
20880 + return __module_alloc(size, PAGE_KERNEL);
20881 +#else
20882 + return __module_alloc(size, PAGE_KERNEL_EXEC);
20883 +#endif
20884 +
20885 +}
20886 +
20887 +#ifdef CONFIG_PAX_KERNEXEC
20888 +#ifdef CONFIG_X86_32
20889 +void *module_alloc_exec(unsigned long size)
20890 +{
20891 + struct vm_struct *area;
20892 +
20893 + if (size == 0)
20894 + return NULL;
20895 +
20896 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
20897 + return area ? area->addr : NULL;
20898 +}
20899 +EXPORT_SYMBOL(module_alloc_exec);
20900 +
20901 +void module_free_exec(struct module *mod, void *module_region)
20902 +{
20903 + vunmap(module_region);
20904 +}
20905 +EXPORT_SYMBOL(module_free_exec);
20906 +#else
20907 +void module_free_exec(struct module *mod, void *module_region)
20908 +{
20909 + module_free(mod, module_region);
20910 +}
20911 +EXPORT_SYMBOL(module_free_exec);
20912 +
20913 +void *module_alloc_exec(unsigned long size)
20914 +{
20915 + return __module_alloc(size, PAGE_KERNEL_RX);
20916 +}
20917 +EXPORT_SYMBOL(module_alloc_exec);
20918 +#endif
20919 +#endif
20920 +
20921 #ifdef CONFIG_X86_32
20922 int apply_relocate(Elf32_Shdr *sechdrs,
20923 const char *strtab,
20924 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
20925 unsigned int i;
20926 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
20927 Elf32_Sym *sym;
20928 - uint32_t *location;
20929 + uint32_t *plocation, location;
20930
20931 DEBUGP("Applying relocate section %u to %u\n",
20932 relsec, sechdrs[relsec].sh_info);
20933 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
20934 /* This is where to make the change */
20935 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
20936 - + rel[i].r_offset;
20937 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
20938 + location = (uint32_t)plocation;
20939 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
20940 + plocation = ktla_ktva((void *)plocation);
20941 /* This is the symbol it is referring to. Note that all
20942 undefined symbols have been resolved. */
20943 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
20944 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
20945 switch (ELF32_R_TYPE(rel[i].r_info)) {
20946 case R_386_32:
20947 /* We add the value into the location given */
20948 - *location += sym->st_value;
20949 + pax_open_kernel();
20950 + *plocation += sym->st_value;
20951 + pax_close_kernel();
20952 break;
20953 case R_386_PC32:
20954 /* Add the value, subtract its position */
20955 - *location += sym->st_value - (uint32_t)location;
20956 + pax_open_kernel();
20957 + *plocation += sym->st_value - location;
20958 + pax_close_kernel();
20959 break;
20960 default:
20961 pr_err("%s: Unknown relocation: %u\n",
20962 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
20963 case R_X86_64_NONE:
20964 break;
20965 case R_X86_64_64:
20966 + pax_open_kernel();
20967 *(u64 *)loc = val;
20968 + pax_close_kernel();
20969 break;
20970 case R_X86_64_32:
20971 + pax_open_kernel();
20972 *(u32 *)loc = val;
20973 + pax_close_kernel();
20974 if (val != *(u32 *)loc)
20975 goto overflow;
20976 break;
20977 case R_X86_64_32S:
20978 + pax_open_kernel();
20979 *(s32 *)loc = val;
20980 + pax_close_kernel();
20981 if ((s64)val != *(s32 *)loc)
20982 goto overflow;
20983 break;
20984 case R_X86_64_PC32:
20985 val -= (u64)loc;
20986 + pax_open_kernel();
20987 *(u32 *)loc = val;
20988 + pax_close_kernel();
20989 +
20990 #if 0
20991 if ((s64)val != *(s32 *)loc)
20992 goto overflow;
20993 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
20994 index 4929502..686c291 100644
20995 --- a/arch/x86/kernel/msr.c
20996 +++ b/arch/x86/kernel/msr.c
20997 @@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
20998 return notifier_from_errno(err);
20999 }
21000
21001 -static struct notifier_block __refdata msr_class_cpu_notifier = {
21002 +static struct notifier_block msr_class_cpu_notifier = {
21003 .notifier_call = msr_class_cpu_callback,
21004 };
21005
21006 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21007 index f84f5c5..e27e54b 100644
21008 --- a/arch/x86/kernel/nmi.c
21009 +++ b/arch/x86/kernel/nmi.c
21010 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21011 dotraplinkage notrace __kprobes void
21012 do_nmi(struct pt_regs *regs, long error_code)
21013 {
21014 +
21015 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21016 + if (!user_mode(regs)) {
21017 + unsigned long cs = regs->cs & 0xFFFF;
21018 + unsigned long ip = ktva_ktla(regs->ip);
21019 +
21020 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21021 + regs->ip = ip;
21022 + }
21023 +#endif
21024 +
21025 nmi_nesting_preprocess(regs);
21026
21027 nmi_enter();
21028 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21029 index 676b8c7..870ba04 100644
21030 --- a/arch/x86/kernel/paravirt-spinlocks.c
21031 +++ b/arch/x86/kernel/paravirt-spinlocks.c
21032 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21033 arch_spin_lock(lock);
21034 }
21035
21036 -struct pv_lock_ops pv_lock_ops = {
21037 +struct pv_lock_ops pv_lock_ops __read_only = {
21038 #ifdef CONFIG_SMP
21039 .spin_is_locked = __ticket_spin_is_locked,
21040 .spin_is_contended = __ticket_spin_is_contended,
21041 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21042 index 17fff18..5cfa0f4 100644
21043 --- a/arch/x86/kernel/paravirt.c
21044 +++ b/arch/x86/kernel/paravirt.c
21045 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21046 {
21047 return x;
21048 }
21049 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21050 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21051 +#endif
21052
21053 void __init default_banner(void)
21054 {
21055 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21056 if (opfunc == NULL)
21057 /* If there's no function, patch it with a ud2a (BUG) */
21058 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21059 - else if (opfunc == _paravirt_nop)
21060 + else if (opfunc == (void *)_paravirt_nop)
21061 /* If the operation is a nop, then nop the callsite */
21062 ret = paravirt_patch_nop();
21063
21064 /* identity functions just return their single argument */
21065 - else if (opfunc == _paravirt_ident_32)
21066 + else if (opfunc == (void *)_paravirt_ident_32)
21067 ret = paravirt_patch_ident_32(insnbuf, len);
21068 - else if (opfunc == _paravirt_ident_64)
21069 + else if (opfunc == (void *)_paravirt_ident_64)
21070 ret = paravirt_patch_ident_64(insnbuf, len);
21071 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21072 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21073 + ret = paravirt_patch_ident_64(insnbuf, len);
21074 +#endif
21075
21076 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21077 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21078 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21079 if (insn_len > len || start == NULL)
21080 insn_len = len;
21081 else
21082 - memcpy(insnbuf, start, insn_len);
21083 + memcpy(insnbuf, ktla_ktva(start), insn_len);
21084
21085 return insn_len;
21086 }
21087 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21088 preempt_enable();
21089 }
21090
21091 -struct pv_info pv_info = {
21092 +struct pv_info pv_info __read_only = {
21093 .name = "bare hardware",
21094 .paravirt_enabled = 0,
21095 .kernel_rpl = 0,
21096 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
21097 #endif
21098 };
21099
21100 -struct pv_init_ops pv_init_ops = {
21101 +struct pv_init_ops pv_init_ops __read_only = {
21102 .patch = native_patch,
21103 };
21104
21105 -struct pv_time_ops pv_time_ops = {
21106 +struct pv_time_ops pv_time_ops __read_only = {
21107 .sched_clock = native_sched_clock,
21108 .steal_clock = native_steal_clock,
21109 };
21110
21111 -struct pv_irq_ops pv_irq_ops = {
21112 +struct pv_irq_ops pv_irq_ops __read_only = {
21113 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21114 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21115 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21116 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21117 #endif
21118 };
21119
21120 -struct pv_cpu_ops pv_cpu_ops = {
21121 +struct pv_cpu_ops pv_cpu_ops __read_only = {
21122 .cpuid = native_cpuid,
21123 .get_debugreg = native_get_debugreg,
21124 .set_debugreg = native_set_debugreg,
21125 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21126 .end_context_switch = paravirt_nop,
21127 };
21128
21129 -struct pv_apic_ops pv_apic_ops = {
21130 +struct pv_apic_ops pv_apic_ops __read_only= {
21131 #ifdef CONFIG_X86_LOCAL_APIC
21132 .startup_ipi_hook = paravirt_nop,
21133 #endif
21134 };
21135
21136 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21137 +#ifdef CONFIG_X86_32
21138 +#ifdef CONFIG_X86_PAE
21139 +/* 64-bit pagetable entries */
21140 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21141 +#else
21142 /* 32-bit pagetable entries */
21143 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21144 +#endif
21145 #else
21146 /* 64-bit pagetable entries */
21147 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21148 #endif
21149
21150 -struct pv_mmu_ops pv_mmu_ops = {
21151 +struct pv_mmu_ops pv_mmu_ops __read_only = {
21152
21153 .read_cr2 = native_read_cr2,
21154 .write_cr2 = native_write_cr2,
21155 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21156 .make_pud = PTE_IDENT,
21157
21158 .set_pgd = native_set_pgd,
21159 + .set_pgd_batched = native_set_pgd_batched,
21160 #endif
21161 #endif /* PAGETABLE_LEVELS >= 3 */
21162
21163 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21164 },
21165
21166 .set_fixmap = native_set_fixmap,
21167 +
21168 +#ifdef CONFIG_PAX_KERNEXEC
21169 + .pax_open_kernel = native_pax_open_kernel,
21170 + .pax_close_kernel = native_pax_close_kernel,
21171 +#endif
21172 +
21173 };
21174
21175 EXPORT_SYMBOL_GPL(pv_time_ops);
21176 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21177 index 35ccf75..7a15747 100644
21178 --- a/arch/x86/kernel/pci-iommu_table.c
21179 +++ b/arch/x86/kernel/pci-iommu_table.c
21180 @@ -2,7 +2,7 @@
21181 #include <asm/iommu_table.h>
21182 #include <linux/string.h>
21183 #include <linux/kallsyms.h>
21184 -
21185 +#include <linux/sched.h>
21186
21187 #define DEBUG 1
21188
21189 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21190 index 2ed787f..f70c9f6 100644
21191 --- a/arch/x86/kernel/process.c
21192 +++ b/arch/x86/kernel/process.c
21193 @@ -36,7 +36,8 @@
21194 * section. Since TSS's are completely CPU-local, we want them
21195 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21196 */
21197 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21198 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21199 +EXPORT_SYMBOL(init_tss);
21200
21201 #ifdef CONFIG_X86_64
21202 static DEFINE_PER_CPU(unsigned char, is_idle);
21203 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21204 task_xstate_cachep =
21205 kmem_cache_create("task_xstate", xstate_size,
21206 __alignof__(union thread_xstate),
21207 - SLAB_PANIC | SLAB_NOTRACK, NULL);
21208 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21209 }
21210
21211 /*
21212 @@ -105,7 +106,7 @@ void exit_thread(void)
21213 unsigned long *bp = t->io_bitmap_ptr;
21214
21215 if (bp) {
21216 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21217 + struct tss_struct *tss = init_tss + get_cpu();
21218
21219 t->io_bitmap_ptr = NULL;
21220 clear_thread_flag(TIF_IO_BITMAP);
21221 @@ -136,7 +137,7 @@ void show_regs_common(void)
21222 board = dmi_get_system_info(DMI_BOARD_NAME);
21223
21224 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21225 - current->pid, current->comm, print_tainted(),
21226 + task_pid_nr(current), current->comm, print_tainted(),
21227 init_utsname()->release,
21228 (int)strcspn(init_utsname()->version, " "),
21229 init_utsname()->version,
21230 @@ -149,6 +150,9 @@ void flush_thread(void)
21231 {
21232 struct task_struct *tsk = current;
21233
21234 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21235 + loadsegment(gs, 0);
21236 +#endif
21237 flush_ptrace_hw_breakpoint(tsk);
21238 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21239 drop_init_fpu(tsk);
21240 @@ -301,7 +305,7 @@ static void __exit_idle(void)
21241 void exit_idle(void)
21242 {
21243 /* idle loop has pid 0 */
21244 - if (current->pid)
21245 + if (task_pid_nr(current))
21246 return;
21247 __exit_idle();
21248 }
21249 @@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21250
21251 return ret;
21252 }
21253 -void stop_this_cpu(void *dummy)
21254 +__noreturn void stop_this_cpu(void *dummy)
21255 {
21256 local_irq_disable();
21257 /*
21258 @@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21259 }
21260 early_param("idle", idle_setup);
21261
21262 -unsigned long arch_align_stack(unsigned long sp)
21263 +#ifdef CONFIG_PAX_RANDKSTACK
21264 +void pax_randomize_kstack(struct pt_regs *regs)
21265 {
21266 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21267 - sp -= get_random_int() % 8192;
21268 - return sp & ~0xf;
21269 -}
21270 + struct thread_struct *thread = &current->thread;
21271 + unsigned long time;
21272
21273 -unsigned long arch_randomize_brk(struct mm_struct *mm)
21274 -{
21275 - unsigned long range_end = mm->brk + 0x02000000;
21276 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21277 -}
21278 + if (!randomize_va_space)
21279 + return;
21280 +
21281 + if (v8086_mode(regs))
21282 + return;
21283
21284 + rdtscl(time);
21285 +
21286 + /* P4 seems to return a 0 LSB, ignore it */
21287 +#ifdef CONFIG_MPENTIUM4
21288 + time &= 0x3EUL;
21289 + time <<= 2;
21290 +#elif defined(CONFIG_X86_64)
21291 + time &= 0xFUL;
21292 + time <<= 4;
21293 +#else
21294 + time &= 0x1FUL;
21295 + time <<= 3;
21296 +#endif
21297 +
21298 + thread->sp0 ^= time;
21299 + load_sp0(init_tss + smp_processor_id(), thread);
21300 +
21301 +#ifdef CONFIG_X86_64
21302 + this_cpu_write(kernel_stack, thread->sp0);
21303 +#endif
21304 +}
21305 +#endif
21306 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21307 index b5a8905..d9cacac 100644
21308 --- a/arch/x86/kernel/process_32.c
21309 +++ b/arch/x86/kernel/process_32.c
21310 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21311 unsigned long thread_saved_pc(struct task_struct *tsk)
21312 {
21313 return ((unsigned long *)tsk->thread.sp)[3];
21314 +//XXX return tsk->thread.eip;
21315 }
21316
21317 void __show_regs(struct pt_regs *regs, int all)
21318 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21319 unsigned long sp;
21320 unsigned short ss, gs;
21321
21322 - if (user_mode_vm(regs)) {
21323 + if (user_mode(regs)) {
21324 sp = regs->sp;
21325 ss = regs->ss & 0xffff;
21326 - gs = get_user_gs(regs);
21327 } else {
21328 sp = kernel_stack_pointer(regs);
21329 savesegment(ss, ss);
21330 - savesegment(gs, gs);
21331 }
21332 + gs = get_user_gs(regs);
21333
21334 show_regs_common();
21335
21336 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21337 (u16)regs->cs, regs->ip, regs->flags,
21338 - smp_processor_id());
21339 + raw_smp_processor_id());
21340 print_symbol("EIP is at %s\n", regs->ip);
21341
21342 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21343 @@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21344 int copy_thread(unsigned long clone_flags, unsigned long sp,
21345 unsigned long arg, struct task_struct *p)
21346 {
21347 - struct pt_regs *childregs = task_pt_regs(p);
21348 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21349 struct task_struct *tsk;
21350 int err;
21351
21352 p->thread.sp = (unsigned long) childregs;
21353 p->thread.sp0 = (unsigned long) (childregs+1);
21354 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21355
21356 if (unlikely(p->flags & PF_KTHREAD)) {
21357 /* kernel thread */
21358 memset(childregs, 0, sizeof(struct pt_regs));
21359 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21360 - task_user_gs(p) = __KERNEL_STACK_CANARY;
21361 - childregs->ds = __USER_DS;
21362 - childregs->es = __USER_DS;
21363 + savesegment(gs, childregs->gs);
21364 + childregs->ds = __KERNEL_DS;
21365 + childregs->es = __KERNEL_DS;
21366 childregs->fs = __KERNEL_PERCPU;
21367 childregs->bx = sp; /* function */
21368 childregs->bp = arg;
21369 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21370 struct thread_struct *prev = &prev_p->thread,
21371 *next = &next_p->thread;
21372 int cpu = smp_processor_id();
21373 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21374 + struct tss_struct *tss = init_tss + cpu;
21375 fpu_switch_t fpu;
21376
21377 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21378 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21379 */
21380 lazy_save_gs(prev->gs);
21381
21382 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21383 + __set_fs(task_thread_info(next_p)->addr_limit);
21384 +#endif
21385 +
21386 /*
21387 * Load the per-thread Thread-Local Storage descriptor.
21388 */
21389 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21390 */
21391 arch_end_context_switch(next_p);
21392
21393 + this_cpu_write(current_task, next_p);
21394 + this_cpu_write(current_tinfo, &next_p->tinfo);
21395 +
21396 /*
21397 * Restore %gs if needed (which is common)
21398 */
21399 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21400
21401 switch_fpu_finish(next_p, fpu);
21402
21403 - this_cpu_write(current_task, next_p);
21404 -
21405 return prev_p;
21406 }
21407
21408 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21409 } while (count++ < 16);
21410 return 0;
21411 }
21412 -
21413 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21414 index 6e68a61..955a9a5 100644
21415 --- a/arch/x86/kernel/process_64.c
21416 +++ b/arch/x86/kernel/process_64.c
21417 @@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21418 struct pt_regs *childregs;
21419 struct task_struct *me = current;
21420
21421 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21422 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21423 childregs = task_pt_regs(p);
21424 p->thread.sp = (unsigned long) childregs;
21425 p->thread.usersp = me->thread.usersp;
21426 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21427 set_tsk_thread_flag(p, TIF_FORK);
21428 p->fpu_counter = 0;
21429 p->thread.io_bitmap_ptr = NULL;
21430 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21431 struct thread_struct *prev = &prev_p->thread;
21432 struct thread_struct *next = &next_p->thread;
21433 int cpu = smp_processor_id();
21434 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21435 + struct tss_struct *tss = init_tss + cpu;
21436 unsigned fsindex, gsindex;
21437 fpu_switch_t fpu;
21438
21439 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21440 prev->usersp = this_cpu_read(old_rsp);
21441 this_cpu_write(old_rsp, next->usersp);
21442 this_cpu_write(current_task, next_p);
21443 + this_cpu_write(current_tinfo, &next_p->tinfo);
21444
21445 - this_cpu_write(kernel_stack,
21446 - (unsigned long)task_stack_page(next_p) +
21447 - THREAD_SIZE - KERNEL_STACK_OFFSET);
21448 + this_cpu_write(kernel_stack, next->sp0);
21449
21450 /*
21451 * Now maybe reload the debug registers and handle I/O bitmaps
21452 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21453 if (!p || p == current || p->state == TASK_RUNNING)
21454 return 0;
21455 stack = (unsigned long)task_stack_page(p);
21456 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21457 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21458 return 0;
21459 fp = *(u64 *)(p->thread.sp);
21460 do {
21461 - if (fp < (unsigned long)stack ||
21462 - fp >= (unsigned long)stack+THREAD_SIZE)
21463 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21464 return 0;
21465 ip = *(u64 *)(fp+8);
21466 if (!in_sched_functions(ip))
21467 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21468 index b629bbe..0fa615a 100644
21469 --- a/arch/x86/kernel/ptrace.c
21470 +++ b/arch/x86/kernel/ptrace.c
21471 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21472 {
21473 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21474 unsigned long sp = (unsigned long)&regs->sp;
21475 - struct thread_info *tinfo;
21476
21477 - if (context == (sp & ~(THREAD_SIZE - 1)))
21478 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21479 return sp;
21480
21481 - tinfo = (struct thread_info *)context;
21482 - if (tinfo->previous_esp)
21483 - return tinfo->previous_esp;
21484 + sp = *(unsigned long *)context;
21485 + if (sp)
21486 + return sp;
21487
21488 return (unsigned long)regs;
21489 }
21490 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21491 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21492 {
21493 int i;
21494 - int dr7 = 0;
21495 + unsigned long dr7 = 0;
21496 struct arch_hw_breakpoint *info;
21497
21498 for (i = 0; i < HBP_NUM; i++) {
21499 @@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21500 unsigned long addr, unsigned long data)
21501 {
21502 int ret;
21503 - unsigned long __user *datap = (unsigned long __user *)data;
21504 + unsigned long __user *datap = (__force unsigned long __user *)data;
21505
21506 switch (request) {
21507 /* read the word at location addr in the USER area. */
21508 @@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21509 if ((int) addr < 0)
21510 return -EIO;
21511 ret = do_get_thread_area(child, addr,
21512 - (struct user_desc __user *)data);
21513 + (__force struct user_desc __user *) data);
21514 break;
21515
21516 case PTRACE_SET_THREAD_AREA:
21517 if ((int) addr < 0)
21518 return -EIO;
21519 ret = do_set_thread_area(child, addr,
21520 - (struct user_desc __user *)data, 0);
21521 + (__force struct user_desc __user *) data, 0);
21522 break;
21523 #endif
21524
21525 @@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21526
21527 #ifdef CONFIG_X86_64
21528
21529 -static struct user_regset x86_64_regsets[] __read_mostly = {
21530 +static user_regset_no_const x86_64_regsets[] __read_only = {
21531 [REGSET_GENERAL] = {
21532 .core_note_type = NT_PRSTATUS,
21533 .n = sizeof(struct user_regs_struct) / sizeof(long),
21534 @@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21535 #endif /* CONFIG_X86_64 */
21536
21537 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21538 -static struct user_regset x86_32_regsets[] __read_mostly = {
21539 +static user_regset_no_const x86_32_regsets[] __read_only = {
21540 [REGSET_GENERAL] = {
21541 .core_note_type = NT_PRSTATUS,
21542 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21543 @@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21544 */
21545 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21546
21547 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21548 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21549 {
21550 #ifdef CONFIG_X86_64
21551 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21552 @@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21553 memset(info, 0, sizeof(*info));
21554 info->si_signo = SIGTRAP;
21555 info->si_code = si_code;
21556 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21557 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21558 }
21559
21560 void user_single_step_siginfo(struct task_struct *tsk,
21561 @@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21562 # define IS_IA32 0
21563 #endif
21564
21565 +#ifdef CONFIG_GRKERNSEC_SETXID
21566 +extern void gr_delayed_cred_worker(void);
21567 +#endif
21568 +
21569 /*
21570 * We must return the syscall number to actually look up in the table.
21571 * This can be -1L to skip running any syscall at all.
21572 @@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21573
21574 user_exit();
21575
21576 +#ifdef CONFIG_GRKERNSEC_SETXID
21577 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21578 + gr_delayed_cred_worker();
21579 +#endif
21580 +
21581 /*
21582 * If we stepped into a sysenter/syscall insn, it trapped in
21583 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21584 @@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21585 */
21586 user_exit();
21587
21588 +#ifdef CONFIG_GRKERNSEC_SETXID
21589 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21590 + gr_delayed_cred_worker();
21591 +#endif
21592 +
21593 audit_syscall_exit(regs);
21594
21595 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
21596 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
21597 index 85c3959..76b89f9 100644
21598 --- a/arch/x86/kernel/pvclock.c
21599 +++ b/arch/x86/kernel/pvclock.c
21600 @@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
21601 return pv_tsc_khz;
21602 }
21603
21604 -static atomic64_t last_value = ATOMIC64_INIT(0);
21605 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
21606
21607 void pvclock_resume(void)
21608 {
21609 - atomic64_set(&last_value, 0);
21610 + atomic64_set_unchecked(&last_value, 0);
21611 }
21612
21613 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
21614 @@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
21615 * updating at the same time, and one of them could be slightly behind,
21616 * making the assumption that last_value always go forward fail to hold.
21617 */
21618 - last = atomic64_read(&last_value);
21619 + last = atomic64_read_unchecked(&last_value);
21620 do {
21621 if (ret < last)
21622 return last;
21623 - last = atomic64_cmpxchg(&last_value, last, ret);
21624 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
21625 } while (unlikely(last != ret));
21626
21627 return ret;
21628 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
21629 index 76fa1e9..abf09ea 100644
21630 --- a/arch/x86/kernel/reboot.c
21631 +++ b/arch/x86/kernel/reboot.c
21632 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
21633 EXPORT_SYMBOL(pm_power_off);
21634
21635 static const struct desc_ptr no_idt = {};
21636 -static int reboot_mode;
21637 +static unsigned short reboot_mode;
21638 enum reboot_type reboot_type = BOOT_ACPI;
21639 int reboot_force;
21640
21641 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
21642
21643 void __noreturn machine_real_restart(unsigned int type)
21644 {
21645 +
21646 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21647 + struct desc_struct *gdt;
21648 +#endif
21649 +
21650 local_irq_disable();
21651
21652 /*
21653 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
21654
21655 /* Jump to the identity-mapped low memory code */
21656 #ifdef CONFIG_X86_32
21657 - asm volatile("jmpl *%0" : :
21658 +
21659 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21660 + gdt = get_cpu_gdt_table(smp_processor_id());
21661 + pax_open_kernel();
21662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21663 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
21664 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
21665 + loadsegment(ds, __KERNEL_DS);
21666 + loadsegment(es, __KERNEL_DS);
21667 + loadsegment(ss, __KERNEL_DS);
21668 +#endif
21669 +#ifdef CONFIG_PAX_KERNEXEC
21670 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
21671 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
21672 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
21673 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
21674 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
21675 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
21676 +#endif
21677 + pax_close_kernel();
21678 +#endif
21679 +
21680 + asm volatile("ljmpl *%0" : :
21681 "rm" (real_mode_header->machine_real_restart_asm),
21682 "a" (type));
21683 #else
21684 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
21685 * try to force a triple fault and then cycle between hitting the keyboard
21686 * controller and doing that
21687 */
21688 -static void native_machine_emergency_restart(void)
21689 +static void __noreturn native_machine_emergency_restart(void)
21690 {
21691 int i;
21692 int attempt = 0;
21693 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
21694 #endif
21695 }
21696
21697 -static void __machine_emergency_restart(int emergency)
21698 +static void __noreturn __machine_emergency_restart(int emergency)
21699 {
21700 reboot_emergency = emergency;
21701 machine_ops.emergency_restart();
21702 }
21703
21704 -static void native_machine_restart(char *__unused)
21705 +static void __noreturn native_machine_restart(char *__unused)
21706 {
21707 pr_notice("machine restart\n");
21708
21709 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
21710 __machine_emergency_restart(0);
21711 }
21712
21713 -static void native_machine_halt(void)
21714 +static void __noreturn native_machine_halt(void)
21715 {
21716 /* Stop other cpus and apics */
21717 machine_shutdown();
21718 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
21719 stop_this_cpu(NULL);
21720 }
21721
21722 -static void native_machine_power_off(void)
21723 +static void __noreturn native_machine_power_off(void)
21724 {
21725 if (pm_power_off) {
21726 if (!reboot_force)
21727 @@ -688,9 +715,10 @@ static void native_machine_power_off(void)
21728 }
21729 /* A fallback in case there is no PM info available */
21730 tboot_shutdown(TB_SHUTDOWN_HALT);
21731 + unreachable();
21732 }
21733
21734 -struct machine_ops machine_ops = {
21735 +struct machine_ops machine_ops __read_only = {
21736 .power_off = native_machine_power_off,
21737 .shutdown = native_machine_shutdown,
21738 .emergency_restart = native_machine_emergency_restart,
21739 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
21740 index 7a6f3b3..bed145d7 100644
21741 --- a/arch/x86/kernel/relocate_kernel_64.S
21742 +++ b/arch/x86/kernel/relocate_kernel_64.S
21743 @@ -11,6 +11,7 @@
21744 #include <asm/kexec.h>
21745 #include <asm/processor-flags.h>
21746 #include <asm/pgtable_types.h>
21747 +#include <asm/alternative-asm.h>
21748
21749 /*
21750 * Must be relocatable PIC code callable as a C function
21751 @@ -160,13 +161,14 @@ identity_mapped:
21752 xorq %rbp, %rbp
21753 xorq %r8, %r8
21754 xorq %r9, %r9
21755 - xorq %r10, %r9
21756 + xorq %r10, %r10
21757 xorq %r11, %r11
21758 xorq %r12, %r12
21759 xorq %r13, %r13
21760 xorq %r14, %r14
21761 xorq %r15, %r15
21762
21763 + pax_force_retaddr 0, 1
21764 ret
21765
21766 1:
21767 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
21768 index 8b24289..d37b58b 100644
21769 --- a/arch/x86/kernel/setup.c
21770 +++ b/arch/x86/kernel/setup.c
21771 @@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
21772
21773 switch (data->type) {
21774 case SETUP_E820_EXT:
21775 - parse_e820_ext(data);
21776 + parse_e820_ext((struct setup_data __force_kernel *)data);
21777 break;
21778 case SETUP_DTB:
21779 add_dtb(pa_data);
21780 @@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
21781 * area (640->1Mb) as ram even though it is not.
21782 * take them out.
21783 */
21784 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
21785 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
21786
21787 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
21788 }
21789 @@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
21790
21791 if (!boot_params.hdr.root_flags)
21792 root_mountflags &= ~MS_RDONLY;
21793 - init_mm.start_code = (unsigned long) _text;
21794 - init_mm.end_code = (unsigned long) _etext;
21795 + init_mm.start_code = ktla_ktva((unsigned long) _text);
21796 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
21797 init_mm.end_data = (unsigned long) _edata;
21798 init_mm.brk = _brk_end;
21799
21800 - code_resource.start = virt_to_phys(_text);
21801 - code_resource.end = virt_to_phys(_etext)-1;
21802 - data_resource.start = virt_to_phys(_etext);
21803 + code_resource.start = virt_to_phys(ktla_ktva(_text));
21804 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
21805 + data_resource.start = virt_to_phys(_sdata);
21806 data_resource.end = virt_to_phys(_edata)-1;
21807 bss_resource.start = virt_to_phys(&__bss_start);
21808 bss_resource.end = virt_to_phys(&__bss_stop)-1;
21809 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
21810 index 5cdff03..5810740 100644
21811 --- a/arch/x86/kernel/setup_percpu.c
21812 +++ b/arch/x86/kernel/setup_percpu.c
21813 @@ -21,19 +21,17 @@
21814 #include <asm/cpu.h>
21815 #include <asm/stackprotector.h>
21816
21817 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
21818 +#ifdef CONFIG_SMP
21819 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
21820 EXPORT_PER_CPU_SYMBOL(cpu_number);
21821 +#endif
21822
21823 -#ifdef CONFIG_X86_64
21824 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
21825 -#else
21826 -#define BOOT_PERCPU_OFFSET 0
21827 -#endif
21828
21829 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
21830 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
21831
21832 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
21833 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
21834 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
21835 };
21836 EXPORT_SYMBOL(__per_cpu_offset);
21837 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
21838 {
21839 #ifdef CONFIG_X86_32
21840 struct desc_struct gdt;
21841 + unsigned long base = per_cpu_offset(cpu);
21842
21843 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
21844 - 0x2 | DESCTYPE_S, 0x8);
21845 - gdt.s = 1;
21846 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
21847 + 0x83 | DESCTYPE_S, 0xC);
21848 write_gdt_entry(get_cpu_gdt_table(cpu),
21849 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
21850 #endif
21851 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
21852 /* alrighty, percpu areas up and running */
21853 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
21854 for_each_possible_cpu(cpu) {
21855 +#ifdef CONFIG_CC_STACKPROTECTOR
21856 +#ifdef CONFIG_X86_32
21857 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
21858 +#endif
21859 +#endif
21860 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
21861 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
21862 per_cpu(cpu_number, cpu) = cpu;
21863 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
21864 */
21865 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
21866 #endif
21867 +#ifdef CONFIG_CC_STACKPROTECTOR
21868 +#ifdef CONFIG_X86_32
21869 + if (!cpu)
21870 + per_cpu(stack_canary.canary, cpu) = canary;
21871 +#endif
21872 +#endif
21873 /*
21874 * Up to this point, the boot CPU has been using .init.data
21875 * area. Reload any changed state for the boot CPU.
21876 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
21877 index d6bf1f3..3ffce5a 100644
21878 --- a/arch/x86/kernel/signal.c
21879 +++ b/arch/x86/kernel/signal.c
21880 @@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
21881 * Align the stack pointer according to the i386 ABI,
21882 * i.e. so that on function entry ((sp + 4) & 15) == 0.
21883 */
21884 - sp = ((sp + 4) & -16ul) - 4;
21885 + sp = ((sp - 12) & -16ul) - 4;
21886 #else /* !CONFIG_X86_32 */
21887 sp = round_down(sp, 16) - 8;
21888 #endif
21889 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21890 }
21891
21892 if (current->mm->context.vdso)
21893 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21894 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21895 else
21896 - restorer = &frame->retcode;
21897 + restorer = (void __user *)&frame->retcode;
21898 if (ka->sa.sa_flags & SA_RESTORER)
21899 restorer = ka->sa.sa_restorer;
21900
21901 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21902 * reasons and because gdb uses it as a signature to notice
21903 * signal handler stack frames.
21904 */
21905 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
21906 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
21907
21908 if (err)
21909 return -EFAULT;
21910 @@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21911 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
21912
21913 /* Set up to return from userspace. */
21914 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
21915 + if (current->mm->context.vdso)
21916 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
21917 + else
21918 + restorer = (void __user *)&frame->retcode;
21919 if (ka->sa.sa_flags & SA_RESTORER)
21920 restorer = ka->sa.sa_restorer;
21921 put_user_ex(restorer, &frame->pretcode);
21922 @@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21923 * reasons and because gdb uses it as a signature to notice
21924 * signal handler stack frames.
21925 */
21926 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
21927 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
21928 } put_user_catch(err);
21929
21930 err |= copy_siginfo_to_user(&frame->info, info);
21931 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
21932 index 48d2b7d..90d328a 100644
21933 --- a/arch/x86/kernel/smp.c
21934 +++ b/arch/x86/kernel/smp.c
21935 @@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
21936
21937 __setup("nonmi_ipi", nonmi_ipi_setup);
21938
21939 -struct smp_ops smp_ops = {
21940 +struct smp_ops smp_ops __read_only = {
21941 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
21942 .smp_prepare_cpus = native_smp_prepare_cpus,
21943 .smp_cpus_done = native_smp_cpus_done,
21944 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
21945 index ed0fe38..87fc692 100644
21946 --- a/arch/x86/kernel/smpboot.c
21947 +++ b/arch/x86/kernel/smpboot.c
21948 @@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
21949 idle->thread.sp = (unsigned long) (((struct pt_regs *)
21950 (THREAD_SIZE + task_stack_page(idle))) - 1);
21951 per_cpu(current_task, cpu) = idle;
21952 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
21953
21954 #ifdef CONFIG_X86_32
21955 /* Stack for startup_32 can be just as for start_secondary onwards */
21956 @@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
21957 #else
21958 clear_tsk_thread_flag(idle, TIF_FORK);
21959 initial_gs = per_cpu_offset(cpu);
21960 - per_cpu(kernel_stack, cpu) =
21961 - (unsigned long)task_stack_page(idle) -
21962 - KERNEL_STACK_OFFSET + THREAD_SIZE;
21963 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
21964 #endif
21965 +
21966 + pax_open_kernel();
21967 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21968 + pax_close_kernel();
21969 +
21970 initial_code = (unsigned long)start_secondary;
21971 stack_start = idle->thread.sp;
21972
21973 @@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
21974 /* the FPU context is blank, nobody can own it */
21975 __cpu_disable_lazy_restore(cpu);
21976
21977 +#ifdef CONFIG_PAX_PER_CPU_PGD
21978 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
21979 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
21980 + KERNEL_PGD_PTRS);
21981 +#endif
21982 +
21983 + /* the FPU context is blank, nobody can own it */
21984 + __cpu_disable_lazy_restore(cpu);
21985 +
21986 err = do_boot_cpu(apicid, cpu, tidle);
21987 if (err) {
21988 pr_debug("do_boot_cpu failed %d\n", err);
21989 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
21990 index 9b4d51d..5d28b58 100644
21991 --- a/arch/x86/kernel/step.c
21992 +++ b/arch/x86/kernel/step.c
21993 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
21994 struct desc_struct *desc;
21995 unsigned long base;
21996
21997 - seg &= ~7UL;
21998 + seg >>= 3;
21999
22000 mutex_lock(&child->mm->context.lock);
22001 - if (unlikely((seg >> 3) >= child->mm->context.size))
22002 + if (unlikely(seg >= child->mm->context.size))
22003 addr = -1L; /* bogus selector, access would fault */
22004 else {
22005 desc = child->mm->context.ldt + seg;
22006 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22007 addr += base;
22008 }
22009 mutex_unlock(&child->mm->context.lock);
22010 - }
22011 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22012 + addr = ktla_ktva(addr);
22013
22014 return addr;
22015 }
22016 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22017 unsigned char opcode[15];
22018 unsigned long addr = convert_ip_to_linear(child, regs);
22019
22020 + if (addr == -EINVAL)
22021 + return 0;
22022 +
22023 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22024 for (i = 0; i < copied; i++) {
22025 switch (opcode[i]) {
22026 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22027 new file mode 100644
22028 index 0000000..26bb1af
22029 --- /dev/null
22030 +++ b/arch/x86/kernel/sys_i386_32.c
22031 @@ -0,0 +1,249 @@
22032 +/*
22033 + * This file contains various random system calls that
22034 + * have a non-standard calling sequence on the Linux/i386
22035 + * platform.
22036 + */
22037 +
22038 +#include <linux/errno.h>
22039 +#include <linux/sched.h>
22040 +#include <linux/mm.h>
22041 +#include <linux/fs.h>
22042 +#include <linux/smp.h>
22043 +#include <linux/sem.h>
22044 +#include <linux/msg.h>
22045 +#include <linux/shm.h>
22046 +#include <linux/stat.h>
22047 +#include <linux/syscalls.h>
22048 +#include <linux/mman.h>
22049 +#include <linux/file.h>
22050 +#include <linux/utsname.h>
22051 +#include <linux/ipc.h>
22052 +
22053 +#include <linux/uaccess.h>
22054 +#include <linux/unistd.h>
22055 +
22056 +#include <asm/syscalls.h>
22057 +
22058 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22059 +{
22060 + unsigned long pax_task_size = TASK_SIZE;
22061 +
22062 +#ifdef CONFIG_PAX_SEGMEXEC
22063 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22064 + pax_task_size = SEGMEXEC_TASK_SIZE;
22065 +#endif
22066 +
22067 + if (len > pax_task_size || addr > pax_task_size - len)
22068 + return -EINVAL;
22069 +
22070 + return 0;
22071 +}
22072 +
22073 +unsigned long
22074 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
22075 + unsigned long len, unsigned long pgoff, unsigned long flags)
22076 +{
22077 + struct mm_struct *mm = current->mm;
22078 + struct vm_area_struct *vma;
22079 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22080 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22081 +
22082 +#ifdef CONFIG_PAX_SEGMEXEC
22083 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22084 + pax_task_size = SEGMEXEC_TASK_SIZE;
22085 +#endif
22086 +
22087 + pax_task_size -= PAGE_SIZE;
22088 +
22089 + if (len > pax_task_size)
22090 + return -ENOMEM;
22091 +
22092 + if (flags & MAP_FIXED)
22093 + return addr;
22094 +
22095 +#ifdef CONFIG_PAX_RANDMMAP
22096 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22097 +#endif
22098 +
22099 + if (addr) {
22100 + addr = PAGE_ALIGN(addr);
22101 + if (pax_task_size - len >= addr) {
22102 + vma = find_vma(mm, addr);
22103 + if (check_heap_stack_gap(vma, addr, len, offset))
22104 + return addr;
22105 + }
22106 + }
22107 + if (len > mm->cached_hole_size) {
22108 + start_addr = addr = mm->free_area_cache;
22109 + } else {
22110 + start_addr = addr = mm->mmap_base;
22111 + mm->cached_hole_size = 0;
22112 + }
22113 +
22114 +#ifdef CONFIG_PAX_PAGEEXEC
22115 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22116 + start_addr = 0x00110000UL;
22117 +
22118 +#ifdef CONFIG_PAX_RANDMMAP
22119 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22120 + start_addr += mm->delta_mmap & 0x03FFF000UL;
22121 +#endif
22122 +
22123 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22124 + start_addr = addr = mm->mmap_base;
22125 + else
22126 + addr = start_addr;
22127 + }
22128 +#endif
22129 +
22130 +full_search:
22131 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22132 + /* At this point: (!vma || addr < vma->vm_end). */
22133 + if (pax_task_size - len < addr) {
22134 + /*
22135 + * Start a new search - just in case we missed
22136 + * some holes.
22137 + */
22138 + if (start_addr != mm->mmap_base) {
22139 + start_addr = addr = mm->mmap_base;
22140 + mm->cached_hole_size = 0;
22141 + goto full_search;
22142 + }
22143 + return -ENOMEM;
22144 + }
22145 + if (check_heap_stack_gap(vma, addr, len, offset))
22146 + break;
22147 + if (addr + mm->cached_hole_size < vma->vm_start)
22148 + mm->cached_hole_size = vma->vm_start - addr;
22149 + addr = vma->vm_end;
22150 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
22151 + start_addr = addr = mm->mmap_base;
22152 + mm->cached_hole_size = 0;
22153 + goto full_search;
22154 + }
22155 + }
22156 +
22157 + /*
22158 + * Remember the place where we stopped the search:
22159 + */
22160 + mm->free_area_cache = addr + len;
22161 + return addr;
22162 +}
22163 +
22164 +unsigned long
22165 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22166 + const unsigned long len, const unsigned long pgoff,
22167 + const unsigned long flags)
22168 +{
22169 + struct vm_area_struct *vma;
22170 + struct mm_struct *mm = current->mm;
22171 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22172 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22173 +
22174 +#ifdef CONFIG_PAX_SEGMEXEC
22175 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22176 + pax_task_size = SEGMEXEC_TASK_SIZE;
22177 +#endif
22178 +
22179 + pax_task_size -= PAGE_SIZE;
22180 +
22181 + /* requested length too big for entire address space */
22182 + if (len > pax_task_size)
22183 + return -ENOMEM;
22184 +
22185 + if (flags & MAP_FIXED)
22186 + return addr;
22187 +
22188 +#ifdef CONFIG_PAX_PAGEEXEC
22189 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22190 + goto bottomup;
22191 +#endif
22192 +
22193 +#ifdef CONFIG_PAX_RANDMMAP
22194 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22195 +#endif
22196 +
22197 + /* requesting a specific address */
22198 + if (addr) {
22199 + addr = PAGE_ALIGN(addr);
22200 + if (pax_task_size - len >= addr) {
22201 + vma = find_vma(mm, addr);
22202 + if (check_heap_stack_gap(vma, addr, len, offset))
22203 + return addr;
22204 + }
22205 + }
22206 +
22207 + /* check if free_area_cache is useful for us */
22208 + if (len <= mm->cached_hole_size) {
22209 + mm->cached_hole_size = 0;
22210 + mm->free_area_cache = mm->mmap_base;
22211 + }
22212 +
22213 + /* either no address requested or can't fit in requested address hole */
22214 + addr = mm->free_area_cache;
22215 +
22216 + /* make sure it can fit in the remaining address space */
22217 + if (addr > len) {
22218 + vma = find_vma(mm, addr-len);
22219 + if (check_heap_stack_gap(vma, addr - len, len, offset))
22220 + /* remember the address as a hint for next time */
22221 + return (mm->free_area_cache = addr-len);
22222 + }
22223 +
22224 + if (mm->mmap_base < len)
22225 + goto bottomup;
22226 +
22227 + addr = mm->mmap_base-len;
22228 +
22229 + do {
22230 + /*
22231 + * Lookup failure means no vma is above this address,
22232 + * else if new region fits below vma->vm_start,
22233 + * return with success:
22234 + */
22235 + vma = find_vma(mm, addr);
22236 + if (check_heap_stack_gap(vma, addr, len, offset))
22237 + /* remember the address as a hint for next time */
22238 + return (mm->free_area_cache = addr);
22239 +
22240 + /* remember the largest hole we saw so far */
22241 + if (addr + mm->cached_hole_size < vma->vm_start)
22242 + mm->cached_hole_size = vma->vm_start - addr;
22243 +
22244 + /* try just below the current vma->vm_start */
22245 + addr = skip_heap_stack_gap(vma, len, offset);
22246 + } while (!IS_ERR_VALUE(addr));
22247 +
22248 +bottomup:
22249 + /*
22250 + * A failed mmap() very likely causes application failure,
22251 + * so fall back to the bottom-up function here. This scenario
22252 + * can happen with large stack limits and large mmap()
22253 + * allocations.
22254 + */
22255 +
22256 +#ifdef CONFIG_PAX_SEGMEXEC
22257 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22258 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22259 + else
22260 +#endif
22261 +
22262 + mm->mmap_base = TASK_UNMAPPED_BASE;
22263 +
22264 +#ifdef CONFIG_PAX_RANDMMAP
22265 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22266 + mm->mmap_base += mm->delta_mmap;
22267 +#endif
22268 +
22269 + mm->free_area_cache = mm->mmap_base;
22270 + mm->cached_hole_size = ~0UL;
22271 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22272 + /*
22273 + * Restore the topdown base:
22274 + */
22275 + mm->mmap_base = base;
22276 + mm->free_area_cache = base;
22277 + mm->cached_hole_size = ~0UL;
22278 +
22279 + return addr;
22280 +}
22281 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22282 index 97ef74b..57a1882 100644
22283 --- a/arch/x86/kernel/sys_x86_64.c
22284 +++ b/arch/x86/kernel/sys_x86_64.c
22285 @@ -81,8 +81,8 @@ out:
22286 return error;
22287 }
22288
22289 -static void find_start_end(unsigned long flags, unsigned long *begin,
22290 - unsigned long *end)
22291 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
22292 + unsigned long *begin, unsigned long *end)
22293 {
22294 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22295 unsigned long new_begin;
22296 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22297 *begin = new_begin;
22298 }
22299 } else {
22300 - *begin = TASK_UNMAPPED_BASE;
22301 + *begin = mm->mmap_base;
22302 *end = TASK_SIZE;
22303 }
22304 }
22305 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22306 struct vm_area_struct *vma;
22307 struct vm_unmapped_area_info info;
22308 unsigned long begin, end;
22309 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22310
22311 if (flags & MAP_FIXED)
22312 return addr;
22313
22314 - find_start_end(flags, &begin, &end);
22315 + find_start_end(mm, flags, &begin, &end);
22316
22317 if (len > end)
22318 return -ENOMEM;
22319
22320 +#ifdef CONFIG_PAX_RANDMMAP
22321 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22322 +#endif
22323 +
22324 if (addr) {
22325 addr = PAGE_ALIGN(addr);
22326 vma = find_vma(mm, addr);
22327 - if (end - len >= addr &&
22328 - (!vma || addr + len <= vma->vm_start))
22329 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22330 return addr;
22331 }
22332
22333 @@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22334 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22335 goto bottomup;
22336
22337 +#ifdef CONFIG_PAX_RANDMMAP
22338 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22339 +#endif
22340 +
22341 /* requesting a specific address */
22342 if (addr) {
22343 addr = PAGE_ALIGN(addr);
22344 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22345 index f84fe00..f41d9f1 100644
22346 --- a/arch/x86/kernel/tboot.c
22347 +++ b/arch/x86/kernel/tboot.c
22348 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22349
22350 void tboot_shutdown(u32 shutdown_type)
22351 {
22352 - void (*shutdown)(void);
22353 + void (* __noreturn shutdown)(void);
22354
22355 if (!tboot_enabled())
22356 return;
22357 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22358
22359 switch_to_tboot_pt();
22360
22361 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22362 + shutdown = (void *)tboot->shutdown_entry;
22363 shutdown();
22364
22365 /* should not reach here */
22366 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22367 return 0;
22368 }
22369
22370 -static atomic_t ap_wfs_count;
22371 +static atomic_unchecked_t ap_wfs_count;
22372
22373 static int tboot_wait_for_aps(int num_aps)
22374 {
22375 @@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22376 {
22377 switch (action) {
22378 case CPU_DYING:
22379 - atomic_inc(&ap_wfs_count);
22380 + atomic_inc_unchecked(&ap_wfs_count);
22381 if (num_online_cpus() == 1)
22382 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22383 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22384 return NOTIFY_BAD;
22385 break;
22386 }
22387 return NOTIFY_OK;
22388 }
22389
22390 -static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22391 +static struct notifier_block tboot_cpu_notifier =
22392 {
22393 .notifier_call = tboot_cpu_callback,
22394 };
22395 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22396
22397 tboot_create_trampoline();
22398
22399 - atomic_set(&ap_wfs_count, 0);
22400 + atomic_set_unchecked(&ap_wfs_count, 0);
22401 register_hotcpu_notifier(&tboot_cpu_notifier);
22402
22403 acpi_os_set_prepare_sleep(&tboot_sleep);
22404 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22405 index 24d3c91..d06b473 100644
22406 --- a/arch/x86/kernel/time.c
22407 +++ b/arch/x86/kernel/time.c
22408 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22409 {
22410 unsigned long pc = instruction_pointer(regs);
22411
22412 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22413 + if (!user_mode(regs) && in_lock_functions(pc)) {
22414 #ifdef CONFIG_FRAME_POINTER
22415 - return *(unsigned long *)(regs->bp + sizeof(long));
22416 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22417 #else
22418 unsigned long *sp =
22419 (unsigned long *)kernel_stack_pointer(regs);
22420 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22421 * or above a saved flags. Eflags has bits 22-31 zero,
22422 * kernel addresses don't.
22423 */
22424 +
22425 +#ifdef CONFIG_PAX_KERNEXEC
22426 + return ktla_ktva(sp[0]);
22427 +#else
22428 if (sp[0] >> 22)
22429 return sp[0];
22430 if (sp[1] >> 22)
22431 return sp[1];
22432 #endif
22433 +
22434 +#endif
22435 }
22436 return pc;
22437 }
22438 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22439 index 9d9d2f9..cad418a 100644
22440 --- a/arch/x86/kernel/tls.c
22441 +++ b/arch/x86/kernel/tls.c
22442 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22443 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22444 return -EINVAL;
22445
22446 +#ifdef CONFIG_PAX_SEGMEXEC
22447 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22448 + return -EINVAL;
22449 +#endif
22450 +
22451 set_tls_desc(p, idx, &info, 1);
22452
22453 return 0;
22454 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22455
22456 if (kbuf)
22457 info = kbuf;
22458 - else if (__copy_from_user(infobuf, ubuf, count))
22459 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22460 return -EFAULT;
22461 else
22462 info = infobuf;
22463 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22464 index ecffca1..95c4d13 100644
22465 --- a/arch/x86/kernel/traps.c
22466 +++ b/arch/x86/kernel/traps.c
22467 @@ -68,12 +68,6 @@
22468 #include <asm/setup.h>
22469
22470 asmlinkage int system_call(void);
22471 -
22472 -/*
22473 - * The IDT has to be page-aligned to simplify the Pentium
22474 - * F0 0F bug workaround.
22475 - */
22476 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22477 #endif
22478
22479 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22480 @@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22481 }
22482
22483 static int __kprobes
22484 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22485 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22486 struct pt_regs *regs, long error_code)
22487 {
22488 #ifdef CONFIG_X86_32
22489 - if (regs->flags & X86_VM_MASK) {
22490 + if (v8086_mode(regs)) {
22491 /*
22492 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22493 * On nmi (interrupt 2), do_trap should not be called.
22494 @@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22495 return -1;
22496 }
22497 #endif
22498 - if (!user_mode(regs)) {
22499 + if (!user_mode_novm(regs)) {
22500 if (!fixup_exception(regs)) {
22501 tsk->thread.error_code = error_code;
22502 tsk->thread.trap_nr = trapnr;
22503 +
22504 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22505 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22506 + str = "PAX: suspicious stack segment fault";
22507 +#endif
22508 +
22509 die(str, regs, error_code);
22510 }
22511 +
22512 +#ifdef CONFIG_PAX_REFCOUNT
22513 + if (trapnr == 4)
22514 + pax_report_refcount_overflow(regs);
22515 +#endif
22516 +
22517 return 0;
22518 }
22519
22520 @@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22521 }
22522
22523 static void __kprobes
22524 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22525 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22526 long error_code, siginfo_t *info)
22527 {
22528 struct task_struct *tsk = current;
22529 @@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22530 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22531 printk_ratelimit()) {
22532 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22533 - tsk->comm, tsk->pid, str,
22534 + tsk->comm, task_pid_nr(tsk), str,
22535 regs->ip, regs->sp, error_code);
22536 print_vma_addr(" in ", regs->ip);
22537 pr_cont("\n");
22538 @@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22539 conditional_sti(regs);
22540
22541 #ifdef CONFIG_X86_32
22542 - if (regs->flags & X86_VM_MASK) {
22543 + if (v8086_mode(regs)) {
22544 local_irq_enable();
22545 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22546 goto exit;
22547 @@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22548 #endif
22549
22550 tsk = current;
22551 - if (!user_mode(regs)) {
22552 + if (!user_mode_novm(regs)) {
22553 if (fixup_exception(regs))
22554 goto exit;
22555
22556 tsk->thread.error_code = error_code;
22557 tsk->thread.trap_nr = X86_TRAP_GP;
22558 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22559 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22560 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22561 +
22562 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22563 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22564 + die("PAX: suspicious general protection fault", regs, error_code);
22565 + else
22566 +#endif
22567 +
22568 die("general protection fault", regs, error_code);
22569 + }
22570 goto exit;
22571 }
22572
22573 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22574 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22575 + struct mm_struct *mm = tsk->mm;
22576 + unsigned long limit;
22577 +
22578 + down_write(&mm->mmap_sem);
22579 + limit = mm->context.user_cs_limit;
22580 + if (limit < TASK_SIZE) {
22581 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22582 + up_write(&mm->mmap_sem);
22583 + return;
22584 + }
22585 + up_write(&mm->mmap_sem);
22586 + }
22587 +#endif
22588 +
22589 tsk->thread.error_code = error_code;
22590 tsk->thread.trap_nr = X86_TRAP_GP;
22591
22592 @@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22593 /* It's safe to allow irq's after DR6 has been saved */
22594 preempt_conditional_sti(regs);
22595
22596 - if (regs->flags & X86_VM_MASK) {
22597 + if (v8086_mode(regs)) {
22598 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
22599 X86_TRAP_DB);
22600 preempt_conditional_cli(regs);
22601 @@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22602 * We already checked v86 mode above, so we can check for kernel mode
22603 * by just checking the CPL of CS.
22604 */
22605 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
22606 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
22607 tsk->thread.debugreg6 &= ~DR_STEP;
22608 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
22609 regs->flags &= ~X86_EFLAGS_TF;
22610 @@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
22611 return;
22612 conditional_sti(regs);
22613
22614 - if (!user_mode_vm(regs))
22615 + if (!user_mode(regs))
22616 {
22617 if (!fixup_exception(regs)) {
22618 task->thread.error_code = error_code;
22619 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
22620 index c71025b..b117501 100644
22621 --- a/arch/x86/kernel/uprobes.c
22622 +++ b/arch/x86/kernel/uprobes.c
22623 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
22624 int ret = NOTIFY_DONE;
22625
22626 /* We are only interested in userspace traps */
22627 - if (regs && !user_mode_vm(regs))
22628 + if (regs && !user_mode(regs))
22629 return NOTIFY_DONE;
22630
22631 switch (val) {
22632 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
22633 index b9242ba..50c5edd 100644
22634 --- a/arch/x86/kernel/verify_cpu.S
22635 +++ b/arch/x86/kernel/verify_cpu.S
22636 @@ -20,6 +20,7 @@
22637 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
22638 * arch/x86/kernel/trampoline_64.S: secondary processor verification
22639 * arch/x86/kernel/head_32.S: processor startup
22640 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
22641 *
22642 * verify_cpu, returns the status of longmode and SSE in register %eax.
22643 * 0: Success 1: Failure
22644 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
22645 index 1dfe69c..a3df6f6 100644
22646 --- a/arch/x86/kernel/vm86_32.c
22647 +++ b/arch/x86/kernel/vm86_32.c
22648 @@ -43,6 +43,7 @@
22649 #include <linux/ptrace.h>
22650 #include <linux/audit.h>
22651 #include <linux/stddef.h>
22652 +#include <linux/grsecurity.h>
22653
22654 #include <asm/uaccess.h>
22655 #include <asm/io.h>
22656 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
22657 do_exit(SIGSEGV);
22658 }
22659
22660 - tss = &per_cpu(init_tss, get_cpu());
22661 + tss = init_tss + get_cpu();
22662 current->thread.sp0 = current->thread.saved_sp0;
22663 current->thread.sysenter_cs = __KERNEL_CS;
22664 load_sp0(tss, &current->thread);
22665 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
22666 struct task_struct *tsk;
22667 int tmp, ret = -EPERM;
22668
22669 +#ifdef CONFIG_GRKERNSEC_VM86
22670 + if (!capable(CAP_SYS_RAWIO)) {
22671 + gr_handle_vm86();
22672 + goto out;
22673 + }
22674 +#endif
22675 +
22676 tsk = current;
22677 if (tsk->thread.saved_sp0)
22678 goto out;
22679 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
22680 int tmp, ret;
22681 struct vm86plus_struct __user *v86;
22682
22683 +#ifdef CONFIG_GRKERNSEC_VM86
22684 + if (!capable(CAP_SYS_RAWIO)) {
22685 + gr_handle_vm86();
22686 + ret = -EPERM;
22687 + goto out;
22688 + }
22689 +#endif
22690 +
22691 tsk = current;
22692 switch (cmd) {
22693 case VM86_REQUEST_IRQ:
22694 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
22695 tsk->thread.saved_fs = info->regs32->fs;
22696 tsk->thread.saved_gs = get_user_gs(info->regs32);
22697
22698 - tss = &per_cpu(init_tss, get_cpu());
22699 + tss = init_tss + get_cpu();
22700 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
22701 if (cpu_has_sep)
22702 tsk->thread.sysenter_cs = 0;
22703 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
22704 goto cannot_handle;
22705 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
22706 goto cannot_handle;
22707 - intr_ptr = (unsigned long __user *) (i << 2);
22708 + intr_ptr = (__force unsigned long __user *) (i << 2);
22709 if (get_user(segoffs, intr_ptr))
22710 goto cannot_handle;
22711 if ((segoffs >> 16) == BIOSSEG)
22712 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
22713 index 22a1530..8fbaaad 100644
22714 --- a/arch/x86/kernel/vmlinux.lds.S
22715 +++ b/arch/x86/kernel/vmlinux.lds.S
22716 @@ -26,6 +26,13 @@
22717 #include <asm/page_types.h>
22718 #include <asm/cache.h>
22719 #include <asm/boot.h>
22720 +#include <asm/segment.h>
22721 +
22722 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22723 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
22724 +#else
22725 +#define __KERNEL_TEXT_OFFSET 0
22726 +#endif
22727
22728 #undef i386 /* in case the preprocessor is a 32bit one */
22729
22730 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
22731
22732 PHDRS {
22733 text PT_LOAD FLAGS(5); /* R_E */
22734 +#ifdef CONFIG_X86_32
22735 + module PT_LOAD FLAGS(5); /* R_E */
22736 +#endif
22737 +#ifdef CONFIG_XEN
22738 + rodata PT_LOAD FLAGS(5); /* R_E */
22739 +#else
22740 + rodata PT_LOAD FLAGS(4); /* R__ */
22741 +#endif
22742 data PT_LOAD FLAGS(6); /* RW_ */
22743 -#ifdef CONFIG_X86_64
22744 + init.begin PT_LOAD FLAGS(6); /* RW_ */
22745 #ifdef CONFIG_SMP
22746 percpu PT_LOAD FLAGS(6); /* RW_ */
22747 #endif
22748 + text.init PT_LOAD FLAGS(5); /* R_E */
22749 + text.exit PT_LOAD FLAGS(5); /* R_E */
22750 init PT_LOAD FLAGS(7); /* RWE */
22751 -#endif
22752 note PT_NOTE FLAGS(0); /* ___ */
22753 }
22754
22755 SECTIONS
22756 {
22757 #ifdef CONFIG_X86_32
22758 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
22759 - phys_startup_32 = startup_32 - LOAD_OFFSET;
22760 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
22761 #else
22762 - . = __START_KERNEL;
22763 - phys_startup_64 = startup_64 - LOAD_OFFSET;
22764 + . = __START_KERNEL;
22765 #endif
22766
22767 /* Text and read-only data */
22768 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
22769 - _text = .;
22770 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22771 /* bootstrapping code */
22772 +#ifdef CONFIG_X86_32
22773 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22774 +#else
22775 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22776 +#endif
22777 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22778 + _text = .;
22779 HEAD_TEXT
22780 #ifdef CONFIG_X86_32
22781 . = ALIGN(PAGE_SIZE);
22782 @@ -108,13 +128,48 @@ SECTIONS
22783 IRQENTRY_TEXT
22784 *(.fixup)
22785 *(.gnu.warning)
22786 - /* End of text section */
22787 - _etext = .;
22788 } :text = 0x9090
22789
22790 - NOTES :text :note
22791 + . += __KERNEL_TEXT_OFFSET;
22792
22793 - EXCEPTION_TABLE(16) :text = 0x9090
22794 +#ifdef CONFIG_X86_32
22795 + . = ALIGN(PAGE_SIZE);
22796 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
22797 +
22798 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
22799 + MODULES_EXEC_VADDR = .;
22800 + BYTE(0)
22801 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
22802 + . = ALIGN(HPAGE_SIZE) - 1;
22803 + MODULES_EXEC_END = .;
22804 +#endif
22805 +
22806 + } :module
22807 +#endif
22808 +
22809 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
22810 + /* End of text section */
22811 + BYTE(0)
22812 + _etext = . - __KERNEL_TEXT_OFFSET;
22813 + }
22814 +
22815 +#ifdef CONFIG_X86_32
22816 + . = ALIGN(PAGE_SIZE);
22817 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
22818 + *(.idt)
22819 + . = ALIGN(PAGE_SIZE);
22820 + *(.empty_zero_page)
22821 + *(.initial_pg_fixmap)
22822 + *(.initial_pg_pmd)
22823 + *(.initial_page_table)
22824 + *(.swapper_pg_dir)
22825 + } :rodata
22826 +#endif
22827 +
22828 + . = ALIGN(PAGE_SIZE);
22829 + NOTES :rodata :note
22830 +
22831 + EXCEPTION_TABLE(16) :rodata
22832
22833 #if defined(CONFIG_DEBUG_RODATA)
22834 /* .text should occupy whole number of pages */
22835 @@ -126,16 +181,20 @@ SECTIONS
22836
22837 /* Data */
22838 .data : AT(ADDR(.data) - LOAD_OFFSET) {
22839 +
22840 +#ifdef CONFIG_PAX_KERNEXEC
22841 + . = ALIGN(HPAGE_SIZE);
22842 +#else
22843 + . = ALIGN(PAGE_SIZE);
22844 +#endif
22845 +
22846 /* Start of data section */
22847 _sdata = .;
22848
22849 /* init_task */
22850 INIT_TASK_DATA(THREAD_SIZE)
22851
22852 -#ifdef CONFIG_X86_32
22853 - /* 32 bit has nosave before _edata */
22854 NOSAVE_DATA
22855 -#endif
22856
22857 PAGE_ALIGNED_DATA(PAGE_SIZE)
22858
22859 @@ -176,12 +235,19 @@ SECTIONS
22860 #endif /* CONFIG_X86_64 */
22861
22862 /* Init code and data - will be freed after init */
22863 - . = ALIGN(PAGE_SIZE);
22864 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
22865 + BYTE(0)
22866 +
22867 +#ifdef CONFIG_PAX_KERNEXEC
22868 + . = ALIGN(HPAGE_SIZE);
22869 +#else
22870 + . = ALIGN(PAGE_SIZE);
22871 +#endif
22872 +
22873 __init_begin = .; /* paired with __init_end */
22874 - }
22875 + } :init.begin
22876
22877 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
22878 +#ifdef CONFIG_SMP
22879 /*
22880 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
22881 * output PHDR, so the next output section - .init.text - should
22882 @@ -190,12 +256,27 @@ SECTIONS
22883 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
22884 #endif
22885
22886 - INIT_TEXT_SECTION(PAGE_SIZE)
22887 -#ifdef CONFIG_X86_64
22888 - :init
22889 -#endif
22890 + . = ALIGN(PAGE_SIZE);
22891 + init_begin = .;
22892 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
22893 + VMLINUX_SYMBOL(_sinittext) = .;
22894 + INIT_TEXT
22895 + VMLINUX_SYMBOL(_einittext) = .;
22896 + . = ALIGN(PAGE_SIZE);
22897 + } :text.init
22898
22899 - INIT_DATA_SECTION(16)
22900 + /*
22901 + * .exit.text is discard at runtime, not link time, to deal with
22902 + * references from .altinstructions and .eh_frame
22903 + */
22904 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22905 + EXIT_TEXT
22906 + . = ALIGN(16);
22907 + } :text.exit
22908 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
22909 +
22910 + . = ALIGN(PAGE_SIZE);
22911 + INIT_DATA_SECTION(16) :init
22912
22913 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
22914 __x86_cpu_dev_start = .;
22915 @@ -257,19 +338,12 @@ SECTIONS
22916 }
22917
22918 . = ALIGN(8);
22919 - /*
22920 - * .exit.text is discard at runtime, not link time, to deal with
22921 - * references from .altinstructions and .eh_frame
22922 - */
22923 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
22924 - EXIT_TEXT
22925 - }
22926
22927 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
22928 EXIT_DATA
22929 }
22930
22931 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
22932 +#ifndef CONFIG_SMP
22933 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
22934 #endif
22935
22936 @@ -288,16 +362,10 @@ SECTIONS
22937 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
22938 __smp_locks = .;
22939 *(.smp_locks)
22940 - . = ALIGN(PAGE_SIZE);
22941 __smp_locks_end = .;
22942 + . = ALIGN(PAGE_SIZE);
22943 }
22944
22945 -#ifdef CONFIG_X86_64
22946 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
22947 - NOSAVE_DATA
22948 - }
22949 -#endif
22950 -
22951 /* BSS */
22952 . = ALIGN(PAGE_SIZE);
22953 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
22954 @@ -313,6 +381,7 @@ SECTIONS
22955 __brk_base = .;
22956 . += 64 * 1024; /* 64k alignment slop space */
22957 *(.brk_reservation) /* areas brk users have reserved */
22958 + . = ALIGN(HPAGE_SIZE);
22959 __brk_limit = .;
22960 }
22961
22962 @@ -339,13 +408,12 @@ SECTIONS
22963 * for the boot processor.
22964 */
22965 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
22966 -INIT_PER_CPU(gdt_page);
22967 INIT_PER_CPU(irq_stack_union);
22968
22969 /*
22970 * Build-time check on the image size:
22971 */
22972 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
22973 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
22974 "kernel image bigger than KERNEL_IMAGE_SIZE");
22975
22976 #ifdef CONFIG_SMP
22977 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
22978 index 9a907a6..f83f921 100644
22979 --- a/arch/x86/kernel/vsyscall_64.c
22980 +++ b/arch/x86/kernel/vsyscall_64.c
22981 @@ -56,15 +56,13 @@
22982 DEFINE_VVAR(int, vgetcpu_mode);
22983 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
22984
22985 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
22986 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
22987
22988 static int __init vsyscall_setup(char *str)
22989 {
22990 if (str) {
22991 if (!strcmp("emulate", str))
22992 vsyscall_mode = EMULATE;
22993 - else if (!strcmp("native", str))
22994 - vsyscall_mode = NATIVE;
22995 else if (!strcmp("none", str))
22996 vsyscall_mode = NONE;
22997 else
22998 @@ -323,8 +321,7 @@ do_ret:
22999 return true;
23000
23001 sigsegv:
23002 - force_sig(SIGSEGV, current);
23003 - return true;
23004 + do_group_exit(SIGKILL);
23005 }
23006
23007 /*
23008 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23009 extern char __vvar_page;
23010 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23011
23012 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23013 - vsyscall_mode == NATIVE
23014 - ? PAGE_KERNEL_VSYSCALL
23015 - : PAGE_KERNEL_VVAR);
23016 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23017 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23018 (unsigned long)VSYSCALL_START);
23019
23020 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23021 index 1330dd1..d220b99 100644
23022 --- a/arch/x86/kernel/x8664_ksyms_64.c
23023 +++ b/arch/x86/kernel/x8664_ksyms_64.c
23024 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23025 EXPORT_SYMBOL(copy_user_generic_unrolled);
23026 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23027 EXPORT_SYMBOL(__copy_user_nocache);
23028 -EXPORT_SYMBOL(_copy_from_user);
23029 -EXPORT_SYMBOL(_copy_to_user);
23030
23031 EXPORT_SYMBOL(copy_page);
23032 EXPORT_SYMBOL(clear_page);
23033 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23034 index 7a3d075..6cb373d 100644
23035 --- a/arch/x86/kernel/x86_init.c
23036 +++ b/arch/x86/kernel/x86_init.c
23037 @@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23038 },
23039 };
23040
23041 -struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23042 +struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23043 .early_percpu_clock_init = x86_init_noop,
23044 .setup_percpu_clockev = setup_secondary_APIC_clock,
23045 };
23046 @@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23047 static void default_nmi_init(void) { };
23048 static int default_i8042_detect(void) { return 1; };
23049
23050 -struct x86_platform_ops x86_platform = {
23051 +struct x86_platform_ops x86_platform __read_only = {
23052 .calibrate_tsc = native_calibrate_tsc,
23053 .get_wallclock = mach_get_cmos_time,
23054 .set_wallclock = mach_set_rtc_mmss,
23055 @@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23056 };
23057
23058 EXPORT_SYMBOL_GPL(x86_platform);
23059 -struct x86_msi_ops x86_msi = {
23060 +struct x86_msi_ops x86_msi __read_only = {
23061 .setup_msi_irqs = native_setup_msi_irqs,
23062 .teardown_msi_irq = native_teardown_msi_irq,
23063 .teardown_msi_irqs = default_teardown_msi_irqs,
23064 .restore_msi_irqs = default_restore_msi_irqs,
23065 };
23066
23067 -struct x86_io_apic_ops x86_io_apic_ops = {
23068 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23069 .init = native_io_apic_init_mappings,
23070 .read = native_io_apic_read,
23071 .write = native_io_apic_write,
23072 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23073 index ada87a3..afea76d 100644
23074 --- a/arch/x86/kernel/xsave.c
23075 +++ b/arch/x86/kernel/xsave.c
23076 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23077 {
23078 int err;
23079
23080 + buf = (struct xsave_struct __user *)____m(buf);
23081 if (use_xsave())
23082 err = xsave_user(buf);
23083 else if (use_fxsr())
23084 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23085 */
23086 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23087 {
23088 + buf = (void __user *)____m(buf);
23089 if (use_xsave()) {
23090 if ((unsigned long)buf % 64 || fx_only) {
23091 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23092 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23093 index a20ecb5..d0e2194 100644
23094 --- a/arch/x86/kvm/cpuid.c
23095 +++ b/arch/x86/kvm/cpuid.c
23096 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23097 struct kvm_cpuid2 *cpuid,
23098 struct kvm_cpuid_entry2 __user *entries)
23099 {
23100 - int r;
23101 + int r, i;
23102
23103 r = -E2BIG;
23104 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23105 goto out;
23106 r = -EFAULT;
23107 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23108 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23109 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23110 goto out;
23111 + for (i = 0; i < cpuid->nent; ++i) {
23112 + struct kvm_cpuid_entry2 cpuid_entry;
23113 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23114 + goto out;
23115 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
23116 + }
23117 vcpu->arch.cpuid_nent = cpuid->nent;
23118 kvm_apic_set_version(vcpu);
23119 kvm_x86_ops->cpuid_update(vcpu);
23120 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23121 struct kvm_cpuid2 *cpuid,
23122 struct kvm_cpuid_entry2 __user *entries)
23123 {
23124 - int r;
23125 + int r, i;
23126
23127 r = -E2BIG;
23128 if (cpuid->nent < vcpu->arch.cpuid_nent)
23129 goto out;
23130 r = -EFAULT;
23131 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23132 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23133 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23134 goto out;
23135 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23136 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23137 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23138 + goto out;
23139 + }
23140 return 0;
23141
23142 out:
23143 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23144 index a27e763..54bfe43 100644
23145 --- a/arch/x86/kvm/emulate.c
23146 +++ b/arch/x86/kvm/emulate.c
23147 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23148
23149 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23150 do { \
23151 + unsigned long _tmp; \
23152 __asm__ __volatile__ ( \
23153 _PRE_EFLAGS("0", "4", "2") \
23154 _op _suffix " %"_x"3,%1; " \
23155 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23156 /* Raw emulation: instruction has two explicit operands. */
23157 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23158 do { \
23159 - unsigned long _tmp; \
23160 - \
23161 switch ((ctxt)->dst.bytes) { \
23162 case 2: \
23163 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23164 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23165
23166 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23167 do { \
23168 - unsigned long _tmp; \
23169 switch ((ctxt)->dst.bytes) { \
23170 case 1: \
23171 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23172 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23173 index 9392f52..0e56d77 100644
23174 --- a/arch/x86/kvm/lapic.c
23175 +++ b/arch/x86/kvm/lapic.c
23176 @@ -55,7 +55,7 @@
23177 #define APIC_BUS_CYCLE_NS 1
23178
23179 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23180 -#define apic_debug(fmt, arg...)
23181 +#define apic_debug(fmt, arg...) do {} while (0)
23182
23183 #define APIC_LVT_NUM 6
23184 /* 14 is the version for Xeon and Pentium 8.4.8*/
23185 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23186 index 891eb6d..e027900 100644
23187 --- a/arch/x86/kvm/paging_tmpl.h
23188 +++ b/arch/x86/kvm/paging_tmpl.h
23189 @@ -208,7 +208,7 @@ retry_walk:
23190 if (unlikely(kvm_is_error_hva(host_addr)))
23191 goto error;
23192
23193 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23194 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23195 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23196 goto error;
23197 walker->ptep_user[walker->level - 1] = ptep_user;
23198 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23199 index d29d3cd..ec9d522 100644
23200 --- a/arch/x86/kvm/svm.c
23201 +++ b/arch/x86/kvm/svm.c
23202 @@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23203 int cpu = raw_smp_processor_id();
23204
23205 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23206 +
23207 + pax_open_kernel();
23208 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23209 + pax_close_kernel();
23210 +
23211 load_TR_desc();
23212 }
23213
23214 @@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23215 #endif
23216 #endif
23217
23218 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23219 + __set_fs(current_thread_info()->addr_limit);
23220 +#endif
23221 +
23222 reload_tss(vcpu);
23223
23224 local_irq_disable();
23225 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23226 index 9120ae1..238abc0 100644
23227 --- a/arch/x86/kvm/vmx.c
23228 +++ b/arch/x86/kvm/vmx.c
23229 @@ -1370,7 +1370,11 @@ static void reload_tss(void)
23230 struct desc_struct *descs;
23231
23232 descs = (void *)gdt->address;
23233 +
23234 + pax_open_kernel();
23235 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23236 + pax_close_kernel();
23237 +
23238 load_TR_desc();
23239 }
23240
23241 @@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23242 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23243 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23244
23245 +#ifdef CONFIG_PAX_PER_CPU_PGD
23246 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23247 +#endif
23248 +
23249 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23250 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23251 vmx->loaded_vmcs->cpu = cpu;
23252 @@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23253 if (!cpu_has_vmx_flexpriority())
23254 flexpriority_enabled = 0;
23255
23256 - if (!cpu_has_vmx_tpr_shadow())
23257 - kvm_x86_ops->update_cr8_intercept = NULL;
23258 + if (!cpu_has_vmx_tpr_shadow()) {
23259 + pax_open_kernel();
23260 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23261 + pax_close_kernel();
23262 + }
23263
23264 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23265 kvm_disable_largepages();
23266 @@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23267
23268 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23269 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23270 +
23271 +#ifndef CONFIG_PAX_PER_CPU_PGD
23272 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23273 +#endif
23274
23275 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23276 #ifdef CONFIG_X86_64
23277 @@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23278 native_store_idt(&dt);
23279 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23280
23281 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23282 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23283
23284 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23285 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23286 @@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23287 "jmp 2f \n\t"
23288 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23289 "2: "
23290 +
23291 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23292 + "ljmp %[cs],$3f\n\t"
23293 + "3: "
23294 +#endif
23295 +
23296 /* Save guest registers, load host registers, keep flags */
23297 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23298 "pop %0 \n\t"
23299 @@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23300 #endif
23301 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23302 [wordsize]"i"(sizeof(ulong))
23303 +
23304 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23305 + ,[cs]"i"(__KERNEL_CS)
23306 +#endif
23307 +
23308 : "cc", "memory"
23309 #ifdef CONFIG_X86_64
23310 , "rax", "rbx", "rdi", "rsi"
23311 @@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23312 if (debugctlmsr)
23313 update_debugctlmsr(debugctlmsr);
23314
23315 -#ifndef CONFIG_X86_64
23316 +#ifdef CONFIG_X86_32
23317 /*
23318 * The sysexit path does not restore ds/es, so we must set them to
23319 * a reasonable value ourselves.
23320 @@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23321 * may be executed in interrupt context, which saves and restore segments
23322 * around it, nullifying its effect.
23323 */
23324 - loadsegment(ds, __USER_DS);
23325 - loadsegment(es, __USER_DS);
23326 + loadsegment(ds, __KERNEL_DS);
23327 + loadsegment(es, __KERNEL_DS);
23328 + loadsegment(ss, __KERNEL_DS);
23329 +
23330 +#ifdef CONFIG_PAX_KERNEXEC
23331 + loadsegment(fs, __KERNEL_PERCPU);
23332 +#endif
23333 +
23334 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23335 + __set_fs(current_thread_info()->addr_limit);
23336 +#endif
23337 +
23338 #endif
23339
23340 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23341 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23342 index c243b81..9eb193f 100644
23343 --- a/arch/x86/kvm/x86.c
23344 +++ b/arch/x86/kvm/x86.c
23345 @@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23346 {
23347 struct kvm *kvm = vcpu->kvm;
23348 int lm = is_long_mode(vcpu);
23349 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23350 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23351 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23352 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23353 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23354 : kvm->arch.xen_hvm_config.blob_size_32;
23355 u32 page_num = data & ~PAGE_MASK;
23356 @@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23357 if (n < msr_list.nmsrs)
23358 goto out;
23359 r = -EFAULT;
23360 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23361 + goto out;
23362 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23363 num_msrs_to_save * sizeof(u32)))
23364 goto out;
23365 @@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23366 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23367 struct kvm_interrupt *irq)
23368 {
23369 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23370 + if (irq->irq >= KVM_NR_INTERRUPTS)
23371 return -EINVAL;
23372 if (irqchip_in_kernel(vcpu->kvm))
23373 return -ENXIO;
23374 @@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23375 };
23376 #endif
23377
23378 -int kvm_arch_init(void *opaque)
23379 +int kvm_arch_init(const void *opaque)
23380 {
23381 int r;
23382 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23383 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23384 index df4176c..23ce092 100644
23385 --- a/arch/x86/lguest/boot.c
23386 +++ b/arch/x86/lguest/boot.c
23387 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23388 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23389 * Launcher to reboot us.
23390 */
23391 -static void lguest_restart(char *reason)
23392 +static __noreturn void lguest_restart(char *reason)
23393 {
23394 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23395 + BUG();
23396 }
23397
23398 /*G:050
23399 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23400 index 00933d5..3a64af9 100644
23401 --- a/arch/x86/lib/atomic64_386_32.S
23402 +++ b/arch/x86/lib/atomic64_386_32.S
23403 @@ -48,6 +48,10 @@ BEGIN(read)
23404 movl (v), %eax
23405 movl 4(v), %edx
23406 RET_ENDP
23407 +BEGIN(read_unchecked)
23408 + movl (v), %eax
23409 + movl 4(v), %edx
23410 +RET_ENDP
23411 #undef v
23412
23413 #define v %esi
23414 @@ -55,6 +59,10 @@ BEGIN(set)
23415 movl %ebx, (v)
23416 movl %ecx, 4(v)
23417 RET_ENDP
23418 +BEGIN(set_unchecked)
23419 + movl %ebx, (v)
23420 + movl %ecx, 4(v)
23421 +RET_ENDP
23422 #undef v
23423
23424 #define v %esi
23425 @@ -70,6 +78,20 @@ RET_ENDP
23426 BEGIN(add)
23427 addl %eax, (v)
23428 adcl %edx, 4(v)
23429 +
23430 +#ifdef CONFIG_PAX_REFCOUNT
23431 + jno 0f
23432 + subl %eax, (v)
23433 + sbbl %edx, 4(v)
23434 + int $4
23435 +0:
23436 + _ASM_EXTABLE(0b, 0b)
23437 +#endif
23438 +
23439 +RET_ENDP
23440 +BEGIN(add_unchecked)
23441 + addl %eax, (v)
23442 + adcl %edx, 4(v)
23443 RET_ENDP
23444 #undef v
23445
23446 @@ -77,6 +99,24 @@ RET_ENDP
23447 BEGIN(add_return)
23448 addl (v), %eax
23449 adcl 4(v), %edx
23450 +
23451 +#ifdef CONFIG_PAX_REFCOUNT
23452 + into
23453 +1234:
23454 + _ASM_EXTABLE(1234b, 2f)
23455 +#endif
23456 +
23457 + movl %eax, (v)
23458 + movl %edx, 4(v)
23459 +
23460 +#ifdef CONFIG_PAX_REFCOUNT
23461 +2:
23462 +#endif
23463 +
23464 +RET_ENDP
23465 +BEGIN(add_return_unchecked)
23466 + addl (v), %eax
23467 + adcl 4(v), %edx
23468 movl %eax, (v)
23469 movl %edx, 4(v)
23470 RET_ENDP
23471 @@ -86,6 +126,20 @@ RET_ENDP
23472 BEGIN(sub)
23473 subl %eax, (v)
23474 sbbl %edx, 4(v)
23475 +
23476 +#ifdef CONFIG_PAX_REFCOUNT
23477 + jno 0f
23478 + addl %eax, (v)
23479 + adcl %edx, 4(v)
23480 + int $4
23481 +0:
23482 + _ASM_EXTABLE(0b, 0b)
23483 +#endif
23484 +
23485 +RET_ENDP
23486 +BEGIN(sub_unchecked)
23487 + subl %eax, (v)
23488 + sbbl %edx, 4(v)
23489 RET_ENDP
23490 #undef v
23491
23492 @@ -96,6 +150,27 @@ BEGIN(sub_return)
23493 sbbl $0, %edx
23494 addl (v), %eax
23495 adcl 4(v), %edx
23496 +
23497 +#ifdef CONFIG_PAX_REFCOUNT
23498 + into
23499 +1234:
23500 + _ASM_EXTABLE(1234b, 2f)
23501 +#endif
23502 +
23503 + movl %eax, (v)
23504 + movl %edx, 4(v)
23505 +
23506 +#ifdef CONFIG_PAX_REFCOUNT
23507 +2:
23508 +#endif
23509 +
23510 +RET_ENDP
23511 +BEGIN(sub_return_unchecked)
23512 + negl %edx
23513 + negl %eax
23514 + sbbl $0, %edx
23515 + addl (v), %eax
23516 + adcl 4(v), %edx
23517 movl %eax, (v)
23518 movl %edx, 4(v)
23519 RET_ENDP
23520 @@ -105,6 +180,20 @@ RET_ENDP
23521 BEGIN(inc)
23522 addl $1, (v)
23523 adcl $0, 4(v)
23524 +
23525 +#ifdef CONFIG_PAX_REFCOUNT
23526 + jno 0f
23527 + subl $1, (v)
23528 + sbbl $0, 4(v)
23529 + int $4
23530 +0:
23531 + _ASM_EXTABLE(0b, 0b)
23532 +#endif
23533 +
23534 +RET_ENDP
23535 +BEGIN(inc_unchecked)
23536 + addl $1, (v)
23537 + adcl $0, 4(v)
23538 RET_ENDP
23539 #undef v
23540
23541 @@ -114,6 +203,26 @@ BEGIN(inc_return)
23542 movl 4(v), %edx
23543 addl $1, %eax
23544 adcl $0, %edx
23545 +
23546 +#ifdef CONFIG_PAX_REFCOUNT
23547 + into
23548 +1234:
23549 + _ASM_EXTABLE(1234b, 2f)
23550 +#endif
23551 +
23552 + movl %eax, (v)
23553 + movl %edx, 4(v)
23554 +
23555 +#ifdef CONFIG_PAX_REFCOUNT
23556 +2:
23557 +#endif
23558 +
23559 +RET_ENDP
23560 +BEGIN(inc_return_unchecked)
23561 + movl (v), %eax
23562 + movl 4(v), %edx
23563 + addl $1, %eax
23564 + adcl $0, %edx
23565 movl %eax, (v)
23566 movl %edx, 4(v)
23567 RET_ENDP
23568 @@ -123,6 +232,20 @@ RET_ENDP
23569 BEGIN(dec)
23570 subl $1, (v)
23571 sbbl $0, 4(v)
23572 +
23573 +#ifdef CONFIG_PAX_REFCOUNT
23574 + jno 0f
23575 + addl $1, (v)
23576 + adcl $0, 4(v)
23577 + int $4
23578 +0:
23579 + _ASM_EXTABLE(0b, 0b)
23580 +#endif
23581 +
23582 +RET_ENDP
23583 +BEGIN(dec_unchecked)
23584 + subl $1, (v)
23585 + sbbl $0, 4(v)
23586 RET_ENDP
23587 #undef v
23588
23589 @@ -132,6 +255,26 @@ BEGIN(dec_return)
23590 movl 4(v), %edx
23591 subl $1, %eax
23592 sbbl $0, %edx
23593 +
23594 +#ifdef CONFIG_PAX_REFCOUNT
23595 + into
23596 +1234:
23597 + _ASM_EXTABLE(1234b, 2f)
23598 +#endif
23599 +
23600 + movl %eax, (v)
23601 + movl %edx, 4(v)
23602 +
23603 +#ifdef CONFIG_PAX_REFCOUNT
23604 +2:
23605 +#endif
23606 +
23607 +RET_ENDP
23608 +BEGIN(dec_return_unchecked)
23609 + movl (v), %eax
23610 + movl 4(v), %edx
23611 + subl $1, %eax
23612 + sbbl $0, %edx
23613 movl %eax, (v)
23614 movl %edx, 4(v)
23615 RET_ENDP
23616 @@ -143,6 +286,13 @@ BEGIN(add_unless)
23617 adcl %edx, %edi
23618 addl (v), %eax
23619 adcl 4(v), %edx
23620 +
23621 +#ifdef CONFIG_PAX_REFCOUNT
23622 + into
23623 +1234:
23624 + _ASM_EXTABLE(1234b, 2f)
23625 +#endif
23626 +
23627 cmpl %eax, %ecx
23628 je 3f
23629 1:
23630 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
23631 1:
23632 addl $1, %eax
23633 adcl $0, %edx
23634 +
23635 +#ifdef CONFIG_PAX_REFCOUNT
23636 + into
23637 +1234:
23638 + _ASM_EXTABLE(1234b, 2f)
23639 +#endif
23640 +
23641 movl %eax, (v)
23642 movl %edx, 4(v)
23643 movl $1, %eax
23644 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
23645 movl 4(v), %edx
23646 subl $1, %eax
23647 sbbl $0, %edx
23648 +
23649 +#ifdef CONFIG_PAX_REFCOUNT
23650 + into
23651 +1234:
23652 + _ASM_EXTABLE(1234b, 1f)
23653 +#endif
23654 +
23655 js 1f
23656 movl %eax, (v)
23657 movl %edx, 4(v)
23658 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
23659 index f5cc9eb..51fa319 100644
23660 --- a/arch/x86/lib/atomic64_cx8_32.S
23661 +++ b/arch/x86/lib/atomic64_cx8_32.S
23662 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
23663 CFI_STARTPROC
23664
23665 read64 %ecx
23666 + pax_force_retaddr
23667 ret
23668 CFI_ENDPROC
23669 ENDPROC(atomic64_read_cx8)
23670
23671 +ENTRY(atomic64_read_unchecked_cx8)
23672 + CFI_STARTPROC
23673 +
23674 + read64 %ecx
23675 + pax_force_retaddr
23676 + ret
23677 + CFI_ENDPROC
23678 +ENDPROC(atomic64_read_unchecked_cx8)
23679 +
23680 ENTRY(atomic64_set_cx8)
23681 CFI_STARTPROC
23682
23683 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
23684 cmpxchg8b (%esi)
23685 jne 1b
23686
23687 + pax_force_retaddr
23688 ret
23689 CFI_ENDPROC
23690 ENDPROC(atomic64_set_cx8)
23691
23692 +ENTRY(atomic64_set_unchecked_cx8)
23693 + CFI_STARTPROC
23694 +
23695 +1:
23696 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
23697 + * are atomic on 586 and newer */
23698 + cmpxchg8b (%esi)
23699 + jne 1b
23700 +
23701 + pax_force_retaddr
23702 + ret
23703 + CFI_ENDPROC
23704 +ENDPROC(atomic64_set_unchecked_cx8)
23705 +
23706 ENTRY(atomic64_xchg_cx8)
23707 CFI_STARTPROC
23708
23709 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
23710 cmpxchg8b (%esi)
23711 jne 1b
23712
23713 + pax_force_retaddr
23714 ret
23715 CFI_ENDPROC
23716 ENDPROC(atomic64_xchg_cx8)
23717
23718 -.macro addsub_return func ins insc
23719 -ENTRY(atomic64_\func\()_return_cx8)
23720 +.macro addsub_return func ins insc unchecked=""
23721 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23722 CFI_STARTPROC
23723 SAVE ebp
23724 SAVE ebx
23725 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
23726 movl %edx, %ecx
23727 \ins\()l %esi, %ebx
23728 \insc\()l %edi, %ecx
23729 +
23730 +.ifb \unchecked
23731 +#ifdef CONFIG_PAX_REFCOUNT
23732 + into
23733 +2:
23734 + _ASM_EXTABLE(2b, 3f)
23735 +#endif
23736 +.endif
23737 +
23738 LOCK_PREFIX
23739 cmpxchg8b (%ebp)
23740 jne 1b
23741 -
23742 -10:
23743 movl %ebx, %eax
23744 movl %ecx, %edx
23745 +
23746 +.ifb \unchecked
23747 +#ifdef CONFIG_PAX_REFCOUNT
23748 +3:
23749 +#endif
23750 +.endif
23751 +
23752 RESTORE edi
23753 RESTORE esi
23754 RESTORE ebx
23755 RESTORE ebp
23756 + pax_force_retaddr
23757 ret
23758 CFI_ENDPROC
23759 -ENDPROC(atomic64_\func\()_return_cx8)
23760 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23761 .endm
23762
23763 addsub_return add add adc
23764 addsub_return sub sub sbb
23765 +addsub_return add add adc _unchecked
23766 +addsub_return sub sub sbb _unchecked
23767
23768 -.macro incdec_return func ins insc
23769 -ENTRY(atomic64_\func\()_return_cx8)
23770 +.macro incdec_return func ins insc unchecked=""
23771 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23772 CFI_STARTPROC
23773 SAVE ebx
23774
23775 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
23776 movl %edx, %ecx
23777 \ins\()l $1, %ebx
23778 \insc\()l $0, %ecx
23779 +
23780 +.ifb \unchecked
23781 +#ifdef CONFIG_PAX_REFCOUNT
23782 + into
23783 +2:
23784 + _ASM_EXTABLE(2b, 3f)
23785 +#endif
23786 +.endif
23787 +
23788 LOCK_PREFIX
23789 cmpxchg8b (%esi)
23790 jne 1b
23791
23792 -10:
23793 movl %ebx, %eax
23794 movl %ecx, %edx
23795 +
23796 +.ifb \unchecked
23797 +#ifdef CONFIG_PAX_REFCOUNT
23798 +3:
23799 +#endif
23800 +.endif
23801 +
23802 RESTORE ebx
23803 + pax_force_retaddr
23804 ret
23805 CFI_ENDPROC
23806 -ENDPROC(atomic64_\func\()_return_cx8)
23807 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23808 .endm
23809
23810 incdec_return inc add adc
23811 incdec_return dec sub sbb
23812 +incdec_return inc add adc _unchecked
23813 +incdec_return dec sub sbb _unchecked
23814
23815 ENTRY(atomic64_dec_if_positive_cx8)
23816 CFI_STARTPROC
23817 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
23818 movl %edx, %ecx
23819 subl $1, %ebx
23820 sbb $0, %ecx
23821 +
23822 +#ifdef CONFIG_PAX_REFCOUNT
23823 + into
23824 +1234:
23825 + _ASM_EXTABLE(1234b, 2f)
23826 +#endif
23827 +
23828 js 2f
23829 LOCK_PREFIX
23830 cmpxchg8b (%esi)
23831 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
23832 movl %ebx, %eax
23833 movl %ecx, %edx
23834 RESTORE ebx
23835 + pax_force_retaddr
23836 ret
23837 CFI_ENDPROC
23838 ENDPROC(atomic64_dec_if_positive_cx8)
23839 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
23840 movl %edx, %ecx
23841 addl %ebp, %ebx
23842 adcl %edi, %ecx
23843 +
23844 +#ifdef CONFIG_PAX_REFCOUNT
23845 + into
23846 +1234:
23847 + _ASM_EXTABLE(1234b, 3f)
23848 +#endif
23849 +
23850 LOCK_PREFIX
23851 cmpxchg8b (%esi)
23852 jne 1b
23853 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
23854 CFI_ADJUST_CFA_OFFSET -8
23855 RESTORE ebx
23856 RESTORE ebp
23857 + pax_force_retaddr
23858 ret
23859 4:
23860 cmpl %edx, 4(%esp)
23861 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
23862 xorl %ecx, %ecx
23863 addl $1, %ebx
23864 adcl %edx, %ecx
23865 +
23866 +#ifdef CONFIG_PAX_REFCOUNT
23867 + into
23868 +1234:
23869 + _ASM_EXTABLE(1234b, 3f)
23870 +#endif
23871 +
23872 LOCK_PREFIX
23873 cmpxchg8b (%esi)
23874 jne 1b
23875 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
23876 movl $1, %eax
23877 3:
23878 RESTORE ebx
23879 + pax_force_retaddr
23880 ret
23881 CFI_ENDPROC
23882 ENDPROC(atomic64_inc_not_zero_cx8)
23883 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
23884 index 2af5df3..62b1a5a 100644
23885 --- a/arch/x86/lib/checksum_32.S
23886 +++ b/arch/x86/lib/checksum_32.S
23887 @@ -29,7 +29,8 @@
23888 #include <asm/dwarf2.h>
23889 #include <asm/errno.h>
23890 #include <asm/asm.h>
23891 -
23892 +#include <asm/segment.h>
23893 +
23894 /*
23895 * computes a partial checksum, e.g. for TCP/UDP fragments
23896 */
23897 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
23898
23899 #define ARGBASE 16
23900 #define FP 12
23901 -
23902 -ENTRY(csum_partial_copy_generic)
23903 +
23904 +ENTRY(csum_partial_copy_generic_to_user)
23905 CFI_STARTPROC
23906 +
23907 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23908 + pushl_cfi %gs
23909 + popl_cfi %es
23910 + jmp csum_partial_copy_generic
23911 +#endif
23912 +
23913 +ENTRY(csum_partial_copy_generic_from_user)
23914 +
23915 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23916 + pushl_cfi %gs
23917 + popl_cfi %ds
23918 +#endif
23919 +
23920 +ENTRY(csum_partial_copy_generic)
23921 subl $4,%esp
23922 CFI_ADJUST_CFA_OFFSET 4
23923 pushl_cfi %edi
23924 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
23925 jmp 4f
23926 SRC(1: movw (%esi), %bx )
23927 addl $2, %esi
23928 -DST( movw %bx, (%edi) )
23929 +DST( movw %bx, %es:(%edi) )
23930 addl $2, %edi
23931 addw %bx, %ax
23932 adcl $0, %eax
23933 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
23934 SRC(1: movl (%esi), %ebx )
23935 SRC( movl 4(%esi), %edx )
23936 adcl %ebx, %eax
23937 -DST( movl %ebx, (%edi) )
23938 +DST( movl %ebx, %es:(%edi) )
23939 adcl %edx, %eax
23940 -DST( movl %edx, 4(%edi) )
23941 +DST( movl %edx, %es:4(%edi) )
23942
23943 SRC( movl 8(%esi), %ebx )
23944 SRC( movl 12(%esi), %edx )
23945 adcl %ebx, %eax
23946 -DST( movl %ebx, 8(%edi) )
23947 +DST( movl %ebx, %es:8(%edi) )
23948 adcl %edx, %eax
23949 -DST( movl %edx, 12(%edi) )
23950 +DST( movl %edx, %es:12(%edi) )
23951
23952 SRC( movl 16(%esi), %ebx )
23953 SRC( movl 20(%esi), %edx )
23954 adcl %ebx, %eax
23955 -DST( movl %ebx, 16(%edi) )
23956 +DST( movl %ebx, %es:16(%edi) )
23957 adcl %edx, %eax
23958 -DST( movl %edx, 20(%edi) )
23959 +DST( movl %edx, %es:20(%edi) )
23960
23961 SRC( movl 24(%esi), %ebx )
23962 SRC( movl 28(%esi), %edx )
23963 adcl %ebx, %eax
23964 -DST( movl %ebx, 24(%edi) )
23965 +DST( movl %ebx, %es:24(%edi) )
23966 adcl %edx, %eax
23967 -DST( movl %edx, 28(%edi) )
23968 +DST( movl %edx, %es:28(%edi) )
23969
23970 lea 32(%esi), %esi
23971 lea 32(%edi), %edi
23972 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
23973 shrl $2, %edx # This clears CF
23974 SRC(3: movl (%esi), %ebx )
23975 adcl %ebx, %eax
23976 -DST( movl %ebx, (%edi) )
23977 +DST( movl %ebx, %es:(%edi) )
23978 lea 4(%esi), %esi
23979 lea 4(%edi), %edi
23980 dec %edx
23981 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
23982 jb 5f
23983 SRC( movw (%esi), %cx )
23984 leal 2(%esi), %esi
23985 -DST( movw %cx, (%edi) )
23986 +DST( movw %cx, %es:(%edi) )
23987 leal 2(%edi), %edi
23988 je 6f
23989 shll $16,%ecx
23990 SRC(5: movb (%esi), %cl )
23991 -DST( movb %cl, (%edi) )
23992 +DST( movb %cl, %es:(%edi) )
23993 6: addl %ecx, %eax
23994 adcl $0, %eax
23995 7:
23996 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
23997
23998 6001:
23999 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24000 - movl $-EFAULT, (%ebx)
24001 + movl $-EFAULT, %ss:(%ebx)
24002
24003 # zero the complete destination - computing the rest
24004 # is too much work
24005 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24006
24007 6002:
24008 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24009 - movl $-EFAULT,(%ebx)
24010 + movl $-EFAULT,%ss:(%ebx)
24011 jmp 5000b
24012
24013 .previous
24014
24015 + pushl_cfi %ss
24016 + popl_cfi %ds
24017 + pushl_cfi %ss
24018 + popl_cfi %es
24019 popl_cfi %ebx
24020 CFI_RESTORE ebx
24021 popl_cfi %esi
24022 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24023 popl_cfi %ecx # equivalent to addl $4,%esp
24024 ret
24025 CFI_ENDPROC
24026 -ENDPROC(csum_partial_copy_generic)
24027 +ENDPROC(csum_partial_copy_generic_to_user)
24028
24029 #else
24030
24031 /* Version for PentiumII/PPro */
24032
24033 #define ROUND1(x) \
24034 + nop; nop; nop; \
24035 SRC(movl x(%esi), %ebx ) ; \
24036 addl %ebx, %eax ; \
24037 - DST(movl %ebx, x(%edi) ) ;
24038 + DST(movl %ebx, %es:x(%edi)) ;
24039
24040 #define ROUND(x) \
24041 + nop; nop; nop; \
24042 SRC(movl x(%esi), %ebx ) ; \
24043 adcl %ebx, %eax ; \
24044 - DST(movl %ebx, x(%edi) ) ;
24045 + DST(movl %ebx, %es:x(%edi)) ;
24046
24047 #define ARGBASE 12
24048 -
24049 -ENTRY(csum_partial_copy_generic)
24050 +
24051 +ENTRY(csum_partial_copy_generic_to_user)
24052 CFI_STARTPROC
24053 +
24054 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24055 + pushl_cfi %gs
24056 + popl_cfi %es
24057 + jmp csum_partial_copy_generic
24058 +#endif
24059 +
24060 +ENTRY(csum_partial_copy_generic_from_user)
24061 +
24062 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24063 + pushl_cfi %gs
24064 + popl_cfi %ds
24065 +#endif
24066 +
24067 +ENTRY(csum_partial_copy_generic)
24068 pushl_cfi %ebx
24069 CFI_REL_OFFSET ebx, 0
24070 pushl_cfi %edi
24071 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24072 subl %ebx, %edi
24073 lea -1(%esi),%edx
24074 andl $-32,%edx
24075 - lea 3f(%ebx,%ebx), %ebx
24076 + lea 3f(%ebx,%ebx,2), %ebx
24077 testl %esi, %esi
24078 jmp *%ebx
24079 1: addl $64,%esi
24080 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24081 jb 5f
24082 SRC( movw (%esi), %dx )
24083 leal 2(%esi), %esi
24084 -DST( movw %dx, (%edi) )
24085 +DST( movw %dx, %es:(%edi) )
24086 leal 2(%edi), %edi
24087 je 6f
24088 shll $16,%edx
24089 5:
24090 SRC( movb (%esi), %dl )
24091 -DST( movb %dl, (%edi) )
24092 +DST( movb %dl, %es:(%edi) )
24093 6: addl %edx, %eax
24094 adcl $0, %eax
24095 7:
24096 .section .fixup, "ax"
24097 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24098 - movl $-EFAULT, (%ebx)
24099 + movl $-EFAULT, %ss:(%ebx)
24100 # zero the complete destination (computing the rest is too much work)
24101 movl ARGBASE+8(%esp),%edi # dst
24102 movl ARGBASE+12(%esp),%ecx # len
24103 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24104 rep; stosb
24105 jmp 7b
24106 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24107 - movl $-EFAULT, (%ebx)
24108 + movl $-EFAULT, %ss:(%ebx)
24109 jmp 7b
24110 .previous
24111
24112 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24113 + pushl_cfi %ss
24114 + popl_cfi %ds
24115 + pushl_cfi %ss
24116 + popl_cfi %es
24117 +#endif
24118 +
24119 popl_cfi %esi
24120 CFI_RESTORE esi
24121 popl_cfi %edi
24122 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24123 CFI_RESTORE ebx
24124 ret
24125 CFI_ENDPROC
24126 -ENDPROC(csum_partial_copy_generic)
24127 +ENDPROC(csum_partial_copy_generic_to_user)
24128
24129 #undef ROUND
24130 #undef ROUND1
24131 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24132 index f2145cf..cea889d 100644
24133 --- a/arch/x86/lib/clear_page_64.S
24134 +++ b/arch/x86/lib/clear_page_64.S
24135 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24136 movl $4096/8,%ecx
24137 xorl %eax,%eax
24138 rep stosq
24139 + pax_force_retaddr
24140 ret
24141 CFI_ENDPROC
24142 ENDPROC(clear_page_c)
24143 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24144 movl $4096,%ecx
24145 xorl %eax,%eax
24146 rep stosb
24147 + pax_force_retaddr
24148 ret
24149 CFI_ENDPROC
24150 ENDPROC(clear_page_c_e)
24151 @@ -43,6 +45,7 @@ ENTRY(clear_page)
24152 leaq 64(%rdi),%rdi
24153 jnz .Lloop
24154 nop
24155 + pax_force_retaddr
24156 ret
24157 CFI_ENDPROC
24158 .Lclear_page_end:
24159 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
24160
24161 #include <asm/cpufeature.h>
24162
24163 - .section .altinstr_replacement,"ax"
24164 + .section .altinstr_replacement,"a"
24165 1: .byte 0xeb /* jmp <disp8> */
24166 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24167 2: .byte 0xeb /* jmp <disp8> */
24168 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24169 index 1e572c5..2a162cd 100644
24170 --- a/arch/x86/lib/cmpxchg16b_emu.S
24171 +++ b/arch/x86/lib/cmpxchg16b_emu.S
24172 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24173
24174 popf
24175 mov $1, %al
24176 + pax_force_retaddr
24177 ret
24178
24179 not_same:
24180 popf
24181 xor %al,%al
24182 + pax_force_retaddr
24183 ret
24184
24185 CFI_ENDPROC
24186 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24187 index 176cca6..1166c50 100644
24188 --- a/arch/x86/lib/copy_page_64.S
24189 +++ b/arch/x86/lib/copy_page_64.S
24190 @@ -9,6 +9,7 @@ copy_page_rep:
24191 CFI_STARTPROC
24192 movl $4096/8, %ecx
24193 rep movsq
24194 + pax_force_retaddr
24195 ret
24196 CFI_ENDPROC
24197 ENDPROC(copy_page_rep)
24198 @@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24199
24200 ENTRY(copy_page)
24201 CFI_STARTPROC
24202 - subq $2*8, %rsp
24203 - CFI_ADJUST_CFA_OFFSET 2*8
24204 + subq $3*8, %rsp
24205 + CFI_ADJUST_CFA_OFFSET 3*8
24206 movq %rbx, (%rsp)
24207 CFI_REL_OFFSET rbx, 0
24208 movq %r12, 1*8(%rsp)
24209 CFI_REL_OFFSET r12, 1*8
24210 + movq %r13, 2*8(%rsp)
24211 + CFI_REL_OFFSET r13, 2*8
24212
24213 movl $(4096/64)-5, %ecx
24214 .p2align 4
24215 @@ -36,7 +39,7 @@ ENTRY(copy_page)
24216 movq 0x8*2(%rsi), %rdx
24217 movq 0x8*3(%rsi), %r8
24218 movq 0x8*4(%rsi), %r9
24219 - movq 0x8*5(%rsi), %r10
24220 + movq 0x8*5(%rsi), %r13
24221 movq 0x8*6(%rsi), %r11
24222 movq 0x8*7(%rsi), %r12
24223
24224 @@ -47,7 +50,7 @@ ENTRY(copy_page)
24225 movq %rdx, 0x8*2(%rdi)
24226 movq %r8, 0x8*3(%rdi)
24227 movq %r9, 0x8*4(%rdi)
24228 - movq %r10, 0x8*5(%rdi)
24229 + movq %r13, 0x8*5(%rdi)
24230 movq %r11, 0x8*6(%rdi)
24231 movq %r12, 0x8*7(%rdi)
24232
24233 @@ -66,7 +69,7 @@ ENTRY(copy_page)
24234 movq 0x8*2(%rsi), %rdx
24235 movq 0x8*3(%rsi), %r8
24236 movq 0x8*4(%rsi), %r9
24237 - movq 0x8*5(%rsi), %r10
24238 + movq 0x8*5(%rsi), %r13
24239 movq 0x8*6(%rsi), %r11
24240 movq 0x8*7(%rsi), %r12
24241
24242 @@ -75,7 +78,7 @@ ENTRY(copy_page)
24243 movq %rdx, 0x8*2(%rdi)
24244 movq %r8, 0x8*3(%rdi)
24245 movq %r9, 0x8*4(%rdi)
24246 - movq %r10, 0x8*5(%rdi)
24247 + movq %r13, 0x8*5(%rdi)
24248 movq %r11, 0x8*6(%rdi)
24249 movq %r12, 0x8*7(%rdi)
24250
24251 @@ -87,8 +90,11 @@ ENTRY(copy_page)
24252 CFI_RESTORE rbx
24253 movq 1*8(%rsp), %r12
24254 CFI_RESTORE r12
24255 - addq $2*8, %rsp
24256 - CFI_ADJUST_CFA_OFFSET -2*8
24257 + movq 2*8(%rsp), %r13
24258 + CFI_RESTORE r13
24259 + addq $3*8, %rsp
24260 + CFI_ADJUST_CFA_OFFSET -3*8
24261 + pax_force_retaddr
24262 ret
24263 .Lcopy_page_end:
24264 CFI_ENDPROC
24265 @@ -99,7 +105,7 @@ ENDPROC(copy_page)
24266
24267 #include <asm/cpufeature.h>
24268
24269 - .section .altinstr_replacement,"ax"
24270 + .section .altinstr_replacement,"a"
24271 1: .byte 0xeb /* jmp <disp8> */
24272 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24273 2:
24274 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24275 index a30ca15..d25fab6 100644
24276 --- a/arch/x86/lib/copy_user_64.S
24277 +++ b/arch/x86/lib/copy_user_64.S
24278 @@ -18,6 +18,7 @@
24279 #include <asm/alternative-asm.h>
24280 #include <asm/asm.h>
24281 #include <asm/smap.h>
24282 +#include <asm/pgtable.h>
24283
24284 /*
24285 * By placing feature2 after feature1 in altinstructions section, we logically
24286 @@ -31,7 +32,7 @@
24287 .byte 0xe9 /* 32bit jump */
24288 .long \orig-1f /* by default jump to orig */
24289 1:
24290 - .section .altinstr_replacement,"ax"
24291 + .section .altinstr_replacement,"a"
24292 2: .byte 0xe9 /* near jump with 32bit immediate */
24293 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24294 3: .byte 0xe9 /* near jump with 32bit immediate */
24295 @@ -70,47 +71,20 @@
24296 #endif
24297 .endm
24298
24299 -/* Standard copy_to_user with segment limit checking */
24300 -ENTRY(_copy_to_user)
24301 - CFI_STARTPROC
24302 - GET_THREAD_INFO(%rax)
24303 - movq %rdi,%rcx
24304 - addq %rdx,%rcx
24305 - jc bad_to_user
24306 - cmpq TI_addr_limit(%rax),%rcx
24307 - ja bad_to_user
24308 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24309 - copy_user_generic_unrolled,copy_user_generic_string, \
24310 - copy_user_enhanced_fast_string
24311 - CFI_ENDPROC
24312 -ENDPROC(_copy_to_user)
24313 -
24314 -/* Standard copy_from_user with segment limit checking */
24315 -ENTRY(_copy_from_user)
24316 - CFI_STARTPROC
24317 - GET_THREAD_INFO(%rax)
24318 - movq %rsi,%rcx
24319 - addq %rdx,%rcx
24320 - jc bad_from_user
24321 - cmpq TI_addr_limit(%rax),%rcx
24322 - ja bad_from_user
24323 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24324 - copy_user_generic_unrolled,copy_user_generic_string, \
24325 - copy_user_enhanced_fast_string
24326 - CFI_ENDPROC
24327 -ENDPROC(_copy_from_user)
24328 -
24329 .section .fixup,"ax"
24330 /* must zero dest */
24331 ENTRY(bad_from_user)
24332 bad_from_user:
24333 CFI_STARTPROC
24334 + testl %edx,%edx
24335 + js bad_to_user
24336 movl %edx,%ecx
24337 xorl %eax,%eax
24338 rep
24339 stosb
24340 bad_to_user:
24341 movl %edx,%eax
24342 + pax_force_retaddr
24343 ret
24344 CFI_ENDPROC
24345 ENDPROC(bad_from_user)
24346 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24347 jz 17f
24348 1: movq (%rsi),%r8
24349 2: movq 1*8(%rsi),%r9
24350 -3: movq 2*8(%rsi),%r10
24351 +3: movq 2*8(%rsi),%rax
24352 4: movq 3*8(%rsi),%r11
24353 5: movq %r8,(%rdi)
24354 6: movq %r9,1*8(%rdi)
24355 -7: movq %r10,2*8(%rdi)
24356 +7: movq %rax,2*8(%rdi)
24357 8: movq %r11,3*8(%rdi)
24358 9: movq 4*8(%rsi),%r8
24359 10: movq 5*8(%rsi),%r9
24360 -11: movq 6*8(%rsi),%r10
24361 +11: movq 6*8(%rsi),%rax
24362 12: movq 7*8(%rsi),%r11
24363 13: movq %r8,4*8(%rdi)
24364 14: movq %r9,5*8(%rdi)
24365 -15: movq %r10,6*8(%rdi)
24366 +15: movq %rax,6*8(%rdi)
24367 16: movq %r11,7*8(%rdi)
24368 leaq 64(%rsi),%rsi
24369 leaq 64(%rdi),%rdi
24370 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24371 jnz 21b
24372 23: xor %eax,%eax
24373 ASM_CLAC
24374 + pax_force_retaddr
24375 ret
24376
24377 .section .fixup,"ax"
24378 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24379 movsb
24380 4: xorl %eax,%eax
24381 ASM_CLAC
24382 + pax_force_retaddr
24383 ret
24384
24385 .section .fixup,"ax"
24386 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24387 movsb
24388 2: xorl %eax,%eax
24389 ASM_CLAC
24390 + pax_force_retaddr
24391 ret
24392
24393 .section .fixup,"ax"
24394 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24395 index 6a4f43c..f5f9e26 100644
24396 --- a/arch/x86/lib/copy_user_nocache_64.S
24397 +++ b/arch/x86/lib/copy_user_nocache_64.S
24398 @@ -8,6 +8,7 @@
24399
24400 #include <linux/linkage.h>
24401 #include <asm/dwarf2.h>
24402 +#include <asm/alternative-asm.h>
24403
24404 #define FIX_ALIGNMENT 1
24405
24406 @@ -16,6 +17,7 @@
24407 #include <asm/thread_info.h>
24408 #include <asm/asm.h>
24409 #include <asm/smap.h>
24410 +#include <asm/pgtable.h>
24411
24412 .macro ALIGN_DESTINATION
24413 #ifdef FIX_ALIGNMENT
24414 @@ -49,6 +51,15 @@
24415 */
24416 ENTRY(__copy_user_nocache)
24417 CFI_STARTPROC
24418 +
24419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24420 + mov $PAX_USER_SHADOW_BASE,%rcx
24421 + cmp %rcx,%rsi
24422 + jae 1f
24423 + add %rcx,%rsi
24424 +1:
24425 +#endif
24426 +
24427 ASM_STAC
24428 cmpl $8,%edx
24429 jb 20f /* less then 8 bytes, go to byte copy loop */
24430 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24431 jz 17f
24432 1: movq (%rsi),%r8
24433 2: movq 1*8(%rsi),%r9
24434 -3: movq 2*8(%rsi),%r10
24435 +3: movq 2*8(%rsi),%rax
24436 4: movq 3*8(%rsi),%r11
24437 5: movnti %r8,(%rdi)
24438 6: movnti %r9,1*8(%rdi)
24439 -7: movnti %r10,2*8(%rdi)
24440 +7: movnti %rax,2*8(%rdi)
24441 8: movnti %r11,3*8(%rdi)
24442 9: movq 4*8(%rsi),%r8
24443 10: movq 5*8(%rsi),%r9
24444 -11: movq 6*8(%rsi),%r10
24445 +11: movq 6*8(%rsi),%rax
24446 12: movq 7*8(%rsi),%r11
24447 13: movnti %r8,4*8(%rdi)
24448 14: movnti %r9,5*8(%rdi)
24449 -15: movnti %r10,6*8(%rdi)
24450 +15: movnti %rax,6*8(%rdi)
24451 16: movnti %r11,7*8(%rdi)
24452 leaq 64(%rsi),%rsi
24453 leaq 64(%rdi),%rdi
24454 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24455 23: xorl %eax,%eax
24456 ASM_CLAC
24457 sfence
24458 + pax_force_retaddr
24459 ret
24460
24461 .section .fixup,"ax"
24462 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24463 index 2419d5f..953ee51 100644
24464 --- a/arch/x86/lib/csum-copy_64.S
24465 +++ b/arch/x86/lib/csum-copy_64.S
24466 @@ -9,6 +9,7 @@
24467 #include <asm/dwarf2.h>
24468 #include <asm/errno.h>
24469 #include <asm/asm.h>
24470 +#include <asm/alternative-asm.h>
24471
24472 /*
24473 * Checksum copy with exception handling.
24474 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24475 CFI_RESTORE rbp
24476 addq $7*8, %rsp
24477 CFI_ADJUST_CFA_OFFSET -7*8
24478 + pax_force_retaddr 0, 1
24479 ret
24480 CFI_RESTORE_STATE
24481
24482 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24483 index 25b7ae8..169fafc 100644
24484 --- a/arch/x86/lib/csum-wrappers_64.c
24485 +++ b/arch/x86/lib/csum-wrappers_64.c
24486 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24487 len -= 2;
24488 }
24489 }
24490 - isum = csum_partial_copy_generic((__force const void *)src,
24491 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24492 dst, len, isum, errp, NULL);
24493 if (unlikely(*errp))
24494 goto out_err;
24495 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24496 }
24497
24498 *errp = 0;
24499 - return csum_partial_copy_generic(src, (void __force *)dst,
24500 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24501 len, isum, NULL, errp);
24502 }
24503 EXPORT_SYMBOL(csum_partial_copy_to_user);
24504 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24505 index 156b9c8..b144132 100644
24506 --- a/arch/x86/lib/getuser.S
24507 +++ b/arch/x86/lib/getuser.S
24508 @@ -34,17 +34,40 @@
24509 #include <asm/thread_info.h>
24510 #include <asm/asm.h>
24511 #include <asm/smap.h>
24512 +#include <asm/segment.h>
24513 +#include <asm/pgtable.h>
24514 +#include <asm/alternative-asm.h>
24515 +
24516 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24517 +#define __copyuser_seg gs;
24518 +#else
24519 +#define __copyuser_seg
24520 +#endif
24521
24522 .text
24523 ENTRY(__get_user_1)
24524 CFI_STARTPROC
24525 +
24526 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24527 GET_THREAD_INFO(%_ASM_DX)
24528 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24529 jae bad_get_user
24530 ASM_STAC
24531 -1: movzb (%_ASM_AX),%edx
24532 +
24533 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24534 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24535 + cmp %_ASM_DX,%_ASM_AX
24536 + jae 1234f
24537 + add %_ASM_DX,%_ASM_AX
24538 +1234:
24539 +#endif
24540 +
24541 +#endif
24542 +
24543 +1: __copyuser_seg movzb (%_ASM_AX),%edx
24544 xor %eax,%eax
24545 ASM_CLAC
24546 + pax_force_retaddr
24547 ret
24548 CFI_ENDPROC
24549 ENDPROC(__get_user_1)
24550 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24551 ENTRY(__get_user_2)
24552 CFI_STARTPROC
24553 add $1,%_ASM_AX
24554 +
24555 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24556 jc bad_get_user
24557 GET_THREAD_INFO(%_ASM_DX)
24558 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24559 jae bad_get_user
24560 ASM_STAC
24561 -2: movzwl -1(%_ASM_AX),%edx
24562 +
24563 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24564 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24565 + cmp %_ASM_DX,%_ASM_AX
24566 + jae 1234f
24567 + add %_ASM_DX,%_ASM_AX
24568 +1234:
24569 +#endif
24570 +
24571 +#endif
24572 +
24573 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24574 xor %eax,%eax
24575 ASM_CLAC
24576 + pax_force_retaddr
24577 ret
24578 CFI_ENDPROC
24579 ENDPROC(__get_user_2)
24580 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24581 ENTRY(__get_user_4)
24582 CFI_STARTPROC
24583 add $3,%_ASM_AX
24584 +
24585 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24586 jc bad_get_user
24587 GET_THREAD_INFO(%_ASM_DX)
24588 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24589 jae bad_get_user
24590 ASM_STAC
24591 -3: mov -3(%_ASM_AX),%edx
24592 +
24593 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24594 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24595 + cmp %_ASM_DX,%_ASM_AX
24596 + jae 1234f
24597 + add %_ASM_DX,%_ASM_AX
24598 +1234:
24599 +#endif
24600 +
24601 +#endif
24602 +
24603 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
24604 xor %eax,%eax
24605 ASM_CLAC
24606 + pax_force_retaddr
24607 ret
24608 CFI_ENDPROC
24609 ENDPROC(__get_user_4)
24610 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
24611 GET_THREAD_INFO(%_ASM_DX)
24612 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24613 jae bad_get_user
24614 +
24615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24616 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24617 + cmp %_ASM_DX,%_ASM_AX
24618 + jae 1234f
24619 + add %_ASM_DX,%_ASM_AX
24620 +1234:
24621 +#endif
24622 +
24623 ASM_STAC
24624 4: movq -7(%_ASM_AX),%_ASM_DX
24625 xor %eax,%eax
24626 ASM_CLAC
24627 + pax_force_retaddr
24628 ret
24629 CFI_ENDPROC
24630 ENDPROC(__get_user_8)
24631 @@ -101,6 +162,7 @@ bad_get_user:
24632 xor %edx,%edx
24633 mov $(-EFAULT),%_ASM_AX
24634 ASM_CLAC
24635 + pax_force_retaddr
24636 ret
24637 CFI_ENDPROC
24638 END(bad_get_user)
24639 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
24640 index 54fcffe..7be149e 100644
24641 --- a/arch/x86/lib/insn.c
24642 +++ b/arch/x86/lib/insn.c
24643 @@ -20,8 +20,10 @@
24644
24645 #ifdef __KERNEL__
24646 #include <linux/string.h>
24647 +#include <asm/pgtable_types.h>
24648 #else
24649 #include <string.h>
24650 +#define ktla_ktva(addr) addr
24651 #endif
24652 #include <asm/inat.h>
24653 #include <asm/insn.h>
24654 @@ -53,8 +55,8 @@
24655 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
24656 {
24657 memset(insn, 0, sizeof(*insn));
24658 - insn->kaddr = kaddr;
24659 - insn->next_byte = kaddr;
24660 + insn->kaddr = ktla_ktva(kaddr);
24661 + insn->next_byte = ktla_ktva(kaddr);
24662 insn->x86_64 = x86_64 ? 1 : 0;
24663 insn->opnd_bytes = 4;
24664 if (x86_64)
24665 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
24666 index 05a95e7..326f2fa 100644
24667 --- a/arch/x86/lib/iomap_copy_64.S
24668 +++ b/arch/x86/lib/iomap_copy_64.S
24669 @@ -17,6 +17,7 @@
24670
24671 #include <linux/linkage.h>
24672 #include <asm/dwarf2.h>
24673 +#include <asm/alternative-asm.h>
24674
24675 /*
24676 * override generic version in lib/iomap_copy.c
24677 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
24678 CFI_STARTPROC
24679 movl %edx,%ecx
24680 rep movsd
24681 + pax_force_retaddr
24682 ret
24683 CFI_ENDPROC
24684 ENDPROC(__iowrite32_copy)
24685 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
24686 index 1c273be..da9cc0e 100644
24687 --- a/arch/x86/lib/memcpy_64.S
24688 +++ b/arch/x86/lib/memcpy_64.S
24689 @@ -33,6 +33,7 @@
24690 rep movsq
24691 movl %edx, %ecx
24692 rep movsb
24693 + pax_force_retaddr
24694 ret
24695 .Lmemcpy_e:
24696 .previous
24697 @@ -49,6 +50,7 @@
24698 movq %rdi, %rax
24699 movq %rdx, %rcx
24700 rep movsb
24701 + pax_force_retaddr
24702 ret
24703 .Lmemcpy_e_e:
24704 .previous
24705 @@ -76,13 +78,13 @@ ENTRY(memcpy)
24706 */
24707 movq 0*8(%rsi), %r8
24708 movq 1*8(%rsi), %r9
24709 - movq 2*8(%rsi), %r10
24710 + movq 2*8(%rsi), %rcx
24711 movq 3*8(%rsi), %r11
24712 leaq 4*8(%rsi), %rsi
24713
24714 movq %r8, 0*8(%rdi)
24715 movq %r9, 1*8(%rdi)
24716 - movq %r10, 2*8(%rdi)
24717 + movq %rcx, 2*8(%rdi)
24718 movq %r11, 3*8(%rdi)
24719 leaq 4*8(%rdi), %rdi
24720 jae .Lcopy_forward_loop
24721 @@ -105,12 +107,12 @@ ENTRY(memcpy)
24722 subq $0x20, %rdx
24723 movq -1*8(%rsi), %r8
24724 movq -2*8(%rsi), %r9
24725 - movq -3*8(%rsi), %r10
24726 + movq -3*8(%rsi), %rcx
24727 movq -4*8(%rsi), %r11
24728 leaq -4*8(%rsi), %rsi
24729 movq %r8, -1*8(%rdi)
24730 movq %r9, -2*8(%rdi)
24731 - movq %r10, -3*8(%rdi)
24732 + movq %rcx, -3*8(%rdi)
24733 movq %r11, -4*8(%rdi)
24734 leaq -4*8(%rdi), %rdi
24735 jae .Lcopy_backward_loop
24736 @@ -130,12 +132,13 @@ ENTRY(memcpy)
24737 */
24738 movq 0*8(%rsi), %r8
24739 movq 1*8(%rsi), %r9
24740 - movq -2*8(%rsi, %rdx), %r10
24741 + movq -2*8(%rsi, %rdx), %rcx
24742 movq -1*8(%rsi, %rdx), %r11
24743 movq %r8, 0*8(%rdi)
24744 movq %r9, 1*8(%rdi)
24745 - movq %r10, -2*8(%rdi, %rdx)
24746 + movq %rcx, -2*8(%rdi, %rdx)
24747 movq %r11, -1*8(%rdi, %rdx)
24748 + pax_force_retaddr
24749 retq
24750 .p2align 4
24751 .Lless_16bytes:
24752 @@ -148,6 +151,7 @@ ENTRY(memcpy)
24753 movq -1*8(%rsi, %rdx), %r9
24754 movq %r8, 0*8(%rdi)
24755 movq %r9, -1*8(%rdi, %rdx)
24756 + pax_force_retaddr
24757 retq
24758 .p2align 4
24759 .Lless_8bytes:
24760 @@ -161,6 +165,7 @@ ENTRY(memcpy)
24761 movl -4(%rsi, %rdx), %r8d
24762 movl %ecx, (%rdi)
24763 movl %r8d, -4(%rdi, %rdx)
24764 + pax_force_retaddr
24765 retq
24766 .p2align 4
24767 .Lless_3bytes:
24768 @@ -179,6 +184,7 @@ ENTRY(memcpy)
24769 movb %cl, (%rdi)
24770
24771 .Lend:
24772 + pax_force_retaddr
24773 retq
24774 CFI_ENDPROC
24775 ENDPROC(memcpy)
24776 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
24777 index ee16461..c39c199 100644
24778 --- a/arch/x86/lib/memmove_64.S
24779 +++ b/arch/x86/lib/memmove_64.S
24780 @@ -61,13 +61,13 @@ ENTRY(memmove)
24781 5:
24782 sub $0x20, %rdx
24783 movq 0*8(%rsi), %r11
24784 - movq 1*8(%rsi), %r10
24785 + movq 1*8(%rsi), %rcx
24786 movq 2*8(%rsi), %r9
24787 movq 3*8(%rsi), %r8
24788 leaq 4*8(%rsi), %rsi
24789
24790 movq %r11, 0*8(%rdi)
24791 - movq %r10, 1*8(%rdi)
24792 + movq %rcx, 1*8(%rdi)
24793 movq %r9, 2*8(%rdi)
24794 movq %r8, 3*8(%rdi)
24795 leaq 4*8(%rdi), %rdi
24796 @@ -81,10 +81,10 @@ ENTRY(memmove)
24797 4:
24798 movq %rdx, %rcx
24799 movq -8(%rsi, %rdx), %r11
24800 - lea -8(%rdi, %rdx), %r10
24801 + lea -8(%rdi, %rdx), %r9
24802 shrq $3, %rcx
24803 rep movsq
24804 - movq %r11, (%r10)
24805 + movq %r11, (%r9)
24806 jmp 13f
24807 .Lmemmove_end_forward:
24808
24809 @@ -95,14 +95,14 @@ ENTRY(memmove)
24810 7:
24811 movq %rdx, %rcx
24812 movq (%rsi), %r11
24813 - movq %rdi, %r10
24814 + movq %rdi, %r9
24815 leaq -8(%rsi, %rdx), %rsi
24816 leaq -8(%rdi, %rdx), %rdi
24817 shrq $3, %rcx
24818 std
24819 rep movsq
24820 cld
24821 - movq %r11, (%r10)
24822 + movq %r11, (%r9)
24823 jmp 13f
24824
24825 /*
24826 @@ -127,13 +127,13 @@ ENTRY(memmove)
24827 8:
24828 subq $0x20, %rdx
24829 movq -1*8(%rsi), %r11
24830 - movq -2*8(%rsi), %r10
24831 + movq -2*8(%rsi), %rcx
24832 movq -3*8(%rsi), %r9
24833 movq -4*8(%rsi), %r8
24834 leaq -4*8(%rsi), %rsi
24835
24836 movq %r11, -1*8(%rdi)
24837 - movq %r10, -2*8(%rdi)
24838 + movq %rcx, -2*8(%rdi)
24839 movq %r9, -3*8(%rdi)
24840 movq %r8, -4*8(%rdi)
24841 leaq -4*8(%rdi), %rdi
24842 @@ -151,11 +151,11 @@ ENTRY(memmove)
24843 * Move data from 16 bytes to 31 bytes.
24844 */
24845 movq 0*8(%rsi), %r11
24846 - movq 1*8(%rsi), %r10
24847 + movq 1*8(%rsi), %rcx
24848 movq -2*8(%rsi, %rdx), %r9
24849 movq -1*8(%rsi, %rdx), %r8
24850 movq %r11, 0*8(%rdi)
24851 - movq %r10, 1*8(%rdi)
24852 + movq %rcx, 1*8(%rdi)
24853 movq %r9, -2*8(%rdi, %rdx)
24854 movq %r8, -1*8(%rdi, %rdx)
24855 jmp 13f
24856 @@ -167,9 +167,9 @@ ENTRY(memmove)
24857 * Move data from 8 bytes to 15 bytes.
24858 */
24859 movq 0*8(%rsi), %r11
24860 - movq -1*8(%rsi, %rdx), %r10
24861 + movq -1*8(%rsi, %rdx), %r9
24862 movq %r11, 0*8(%rdi)
24863 - movq %r10, -1*8(%rdi, %rdx)
24864 + movq %r9, -1*8(%rdi, %rdx)
24865 jmp 13f
24866 10:
24867 cmpq $4, %rdx
24868 @@ -178,9 +178,9 @@ ENTRY(memmove)
24869 * Move data from 4 bytes to 7 bytes.
24870 */
24871 movl (%rsi), %r11d
24872 - movl -4(%rsi, %rdx), %r10d
24873 + movl -4(%rsi, %rdx), %r9d
24874 movl %r11d, (%rdi)
24875 - movl %r10d, -4(%rdi, %rdx)
24876 + movl %r9d, -4(%rdi, %rdx)
24877 jmp 13f
24878 11:
24879 cmp $2, %rdx
24880 @@ -189,9 +189,9 @@ ENTRY(memmove)
24881 * Move data from 2 bytes to 3 bytes.
24882 */
24883 movw (%rsi), %r11w
24884 - movw -2(%rsi, %rdx), %r10w
24885 + movw -2(%rsi, %rdx), %r9w
24886 movw %r11w, (%rdi)
24887 - movw %r10w, -2(%rdi, %rdx)
24888 + movw %r9w, -2(%rdi, %rdx)
24889 jmp 13f
24890 12:
24891 cmp $1, %rdx
24892 @@ -202,6 +202,7 @@ ENTRY(memmove)
24893 movb (%rsi), %r11b
24894 movb %r11b, (%rdi)
24895 13:
24896 + pax_force_retaddr
24897 retq
24898 CFI_ENDPROC
24899
24900 @@ -210,6 +211,7 @@ ENTRY(memmove)
24901 /* Forward moving data. */
24902 movq %rdx, %rcx
24903 rep movsb
24904 + pax_force_retaddr
24905 retq
24906 .Lmemmove_end_forward_efs:
24907 .previous
24908 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
24909 index 2dcb380..963660a 100644
24910 --- a/arch/x86/lib/memset_64.S
24911 +++ b/arch/x86/lib/memset_64.S
24912 @@ -30,6 +30,7 @@
24913 movl %edx,%ecx
24914 rep stosb
24915 movq %r9,%rax
24916 + pax_force_retaddr
24917 ret
24918 .Lmemset_e:
24919 .previous
24920 @@ -52,6 +53,7 @@
24921 movq %rdx,%rcx
24922 rep stosb
24923 movq %r9,%rax
24924 + pax_force_retaddr
24925 ret
24926 .Lmemset_e_e:
24927 .previous
24928 @@ -59,7 +61,7 @@
24929 ENTRY(memset)
24930 ENTRY(__memset)
24931 CFI_STARTPROC
24932 - movq %rdi,%r10
24933 + movq %rdi,%r11
24934
24935 /* expand byte value */
24936 movzbl %sil,%ecx
24937 @@ -117,7 +119,8 @@ ENTRY(__memset)
24938 jnz .Lloop_1
24939
24940 .Lende:
24941 - movq %r10,%rax
24942 + movq %r11,%rax
24943 + pax_force_retaddr
24944 ret
24945
24946 CFI_RESTORE_STATE
24947 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
24948 index c9f2d9b..e7fd2c0 100644
24949 --- a/arch/x86/lib/mmx_32.c
24950 +++ b/arch/x86/lib/mmx_32.c
24951 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
24952 {
24953 void *p;
24954 int i;
24955 + unsigned long cr0;
24956
24957 if (unlikely(in_interrupt()))
24958 return __memcpy(to, from, len);
24959 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
24960 kernel_fpu_begin();
24961
24962 __asm__ __volatile__ (
24963 - "1: prefetch (%0)\n" /* This set is 28 bytes */
24964 - " prefetch 64(%0)\n"
24965 - " prefetch 128(%0)\n"
24966 - " prefetch 192(%0)\n"
24967 - " prefetch 256(%0)\n"
24968 + "1: prefetch (%1)\n" /* This set is 28 bytes */
24969 + " prefetch 64(%1)\n"
24970 + " prefetch 128(%1)\n"
24971 + " prefetch 192(%1)\n"
24972 + " prefetch 256(%1)\n"
24973 "2: \n"
24974 ".section .fixup, \"ax\"\n"
24975 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24976 + "3: \n"
24977 +
24978 +#ifdef CONFIG_PAX_KERNEXEC
24979 + " movl %%cr0, %0\n"
24980 + " movl %0, %%eax\n"
24981 + " andl $0xFFFEFFFF, %%eax\n"
24982 + " movl %%eax, %%cr0\n"
24983 +#endif
24984 +
24985 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24986 +
24987 +#ifdef CONFIG_PAX_KERNEXEC
24988 + " movl %0, %%cr0\n"
24989 +#endif
24990 +
24991 " jmp 2b\n"
24992 ".previous\n"
24993 _ASM_EXTABLE(1b, 3b)
24994 - : : "r" (from));
24995 + : "=&r" (cr0) : "r" (from) : "ax");
24996
24997 for ( ; i > 5; i--) {
24998 __asm__ __volatile__ (
24999 - "1: prefetch 320(%0)\n"
25000 - "2: movq (%0), %%mm0\n"
25001 - " movq 8(%0), %%mm1\n"
25002 - " movq 16(%0), %%mm2\n"
25003 - " movq 24(%0), %%mm3\n"
25004 - " movq %%mm0, (%1)\n"
25005 - " movq %%mm1, 8(%1)\n"
25006 - " movq %%mm2, 16(%1)\n"
25007 - " movq %%mm3, 24(%1)\n"
25008 - " movq 32(%0), %%mm0\n"
25009 - " movq 40(%0), %%mm1\n"
25010 - " movq 48(%0), %%mm2\n"
25011 - " movq 56(%0), %%mm3\n"
25012 - " movq %%mm0, 32(%1)\n"
25013 - " movq %%mm1, 40(%1)\n"
25014 - " movq %%mm2, 48(%1)\n"
25015 - " movq %%mm3, 56(%1)\n"
25016 + "1: prefetch 320(%1)\n"
25017 + "2: movq (%1), %%mm0\n"
25018 + " movq 8(%1), %%mm1\n"
25019 + " movq 16(%1), %%mm2\n"
25020 + " movq 24(%1), %%mm3\n"
25021 + " movq %%mm0, (%2)\n"
25022 + " movq %%mm1, 8(%2)\n"
25023 + " movq %%mm2, 16(%2)\n"
25024 + " movq %%mm3, 24(%2)\n"
25025 + " movq 32(%1), %%mm0\n"
25026 + " movq 40(%1), %%mm1\n"
25027 + " movq 48(%1), %%mm2\n"
25028 + " movq 56(%1), %%mm3\n"
25029 + " movq %%mm0, 32(%2)\n"
25030 + " movq %%mm1, 40(%2)\n"
25031 + " movq %%mm2, 48(%2)\n"
25032 + " movq %%mm3, 56(%2)\n"
25033 ".section .fixup, \"ax\"\n"
25034 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25035 + "3:\n"
25036 +
25037 +#ifdef CONFIG_PAX_KERNEXEC
25038 + " movl %%cr0, %0\n"
25039 + " movl %0, %%eax\n"
25040 + " andl $0xFFFEFFFF, %%eax\n"
25041 + " movl %%eax, %%cr0\n"
25042 +#endif
25043 +
25044 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25045 +
25046 +#ifdef CONFIG_PAX_KERNEXEC
25047 + " movl %0, %%cr0\n"
25048 +#endif
25049 +
25050 " jmp 2b\n"
25051 ".previous\n"
25052 _ASM_EXTABLE(1b, 3b)
25053 - : : "r" (from), "r" (to) : "memory");
25054 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25055
25056 from += 64;
25057 to += 64;
25058 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25059 static void fast_copy_page(void *to, void *from)
25060 {
25061 int i;
25062 + unsigned long cr0;
25063
25064 kernel_fpu_begin();
25065
25066 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25067 * but that is for later. -AV
25068 */
25069 __asm__ __volatile__(
25070 - "1: prefetch (%0)\n"
25071 - " prefetch 64(%0)\n"
25072 - " prefetch 128(%0)\n"
25073 - " prefetch 192(%0)\n"
25074 - " prefetch 256(%0)\n"
25075 + "1: prefetch (%1)\n"
25076 + " prefetch 64(%1)\n"
25077 + " prefetch 128(%1)\n"
25078 + " prefetch 192(%1)\n"
25079 + " prefetch 256(%1)\n"
25080 "2: \n"
25081 ".section .fixup, \"ax\"\n"
25082 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25083 + "3: \n"
25084 +
25085 +#ifdef CONFIG_PAX_KERNEXEC
25086 + " movl %%cr0, %0\n"
25087 + " movl %0, %%eax\n"
25088 + " andl $0xFFFEFFFF, %%eax\n"
25089 + " movl %%eax, %%cr0\n"
25090 +#endif
25091 +
25092 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25093 +
25094 +#ifdef CONFIG_PAX_KERNEXEC
25095 + " movl %0, %%cr0\n"
25096 +#endif
25097 +
25098 " jmp 2b\n"
25099 ".previous\n"
25100 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25101 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25102
25103 for (i = 0; i < (4096-320)/64; i++) {
25104 __asm__ __volatile__ (
25105 - "1: prefetch 320(%0)\n"
25106 - "2: movq (%0), %%mm0\n"
25107 - " movntq %%mm0, (%1)\n"
25108 - " movq 8(%0), %%mm1\n"
25109 - " movntq %%mm1, 8(%1)\n"
25110 - " movq 16(%0), %%mm2\n"
25111 - " movntq %%mm2, 16(%1)\n"
25112 - " movq 24(%0), %%mm3\n"
25113 - " movntq %%mm3, 24(%1)\n"
25114 - " movq 32(%0), %%mm4\n"
25115 - " movntq %%mm4, 32(%1)\n"
25116 - " movq 40(%0), %%mm5\n"
25117 - " movntq %%mm5, 40(%1)\n"
25118 - " movq 48(%0), %%mm6\n"
25119 - " movntq %%mm6, 48(%1)\n"
25120 - " movq 56(%0), %%mm7\n"
25121 - " movntq %%mm7, 56(%1)\n"
25122 + "1: prefetch 320(%1)\n"
25123 + "2: movq (%1), %%mm0\n"
25124 + " movntq %%mm0, (%2)\n"
25125 + " movq 8(%1), %%mm1\n"
25126 + " movntq %%mm1, 8(%2)\n"
25127 + " movq 16(%1), %%mm2\n"
25128 + " movntq %%mm2, 16(%2)\n"
25129 + " movq 24(%1), %%mm3\n"
25130 + " movntq %%mm3, 24(%2)\n"
25131 + " movq 32(%1), %%mm4\n"
25132 + " movntq %%mm4, 32(%2)\n"
25133 + " movq 40(%1), %%mm5\n"
25134 + " movntq %%mm5, 40(%2)\n"
25135 + " movq 48(%1), %%mm6\n"
25136 + " movntq %%mm6, 48(%2)\n"
25137 + " movq 56(%1), %%mm7\n"
25138 + " movntq %%mm7, 56(%2)\n"
25139 ".section .fixup, \"ax\"\n"
25140 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25141 + "3:\n"
25142 +
25143 +#ifdef CONFIG_PAX_KERNEXEC
25144 + " movl %%cr0, %0\n"
25145 + " movl %0, %%eax\n"
25146 + " andl $0xFFFEFFFF, %%eax\n"
25147 + " movl %%eax, %%cr0\n"
25148 +#endif
25149 +
25150 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25151 +
25152 +#ifdef CONFIG_PAX_KERNEXEC
25153 + " movl %0, %%cr0\n"
25154 +#endif
25155 +
25156 " jmp 2b\n"
25157 ".previous\n"
25158 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25159 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25160
25161 from += 64;
25162 to += 64;
25163 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25164 static void fast_copy_page(void *to, void *from)
25165 {
25166 int i;
25167 + unsigned long cr0;
25168
25169 kernel_fpu_begin();
25170
25171 __asm__ __volatile__ (
25172 - "1: prefetch (%0)\n"
25173 - " prefetch 64(%0)\n"
25174 - " prefetch 128(%0)\n"
25175 - " prefetch 192(%0)\n"
25176 - " prefetch 256(%0)\n"
25177 + "1: prefetch (%1)\n"
25178 + " prefetch 64(%1)\n"
25179 + " prefetch 128(%1)\n"
25180 + " prefetch 192(%1)\n"
25181 + " prefetch 256(%1)\n"
25182 "2: \n"
25183 ".section .fixup, \"ax\"\n"
25184 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25185 + "3: \n"
25186 +
25187 +#ifdef CONFIG_PAX_KERNEXEC
25188 + " movl %%cr0, %0\n"
25189 + " movl %0, %%eax\n"
25190 + " andl $0xFFFEFFFF, %%eax\n"
25191 + " movl %%eax, %%cr0\n"
25192 +#endif
25193 +
25194 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25195 +
25196 +#ifdef CONFIG_PAX_KERNEXEC
25197 + " movl %0, %%cr0\n"
25198 +#endif
25199 +
25200 " jmp 2b\n"
25201 ".previous\n"
25202 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25203 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25204
25205 for (i = 0; i < 4096/64; i++) {
25206 __asm__ __volatile__ (
25207 - "1: prefetch 320(%0)\n"
25208 - "2: movq (%0), %%mm0\n"
25209 - " movq 8(%0), %%mm1\n"
25210 - " movq 16(%0), %%mm2\n"
25211 - " movq 24(%0), %%mm3\n"
25212 - " movq %%mm0, (%1)\n"
25213 - " movq %%mm1, 8(%1)\n"
25214 - " movq %%mm2, 16(%1)\n"
25215 - " movq %%mm3, 24(%1)\n"
25216 - " movq 32(%0), %%mm0\n"
25217 - " movq 40(%0), %%mm1\n"
25218 - " movq 48(%0), %%mm2\n"
25219 - " movq 56(%0), %%mm3\n"
25220 - " movq %%mm0, 32(%1)\n"
25221 - " movq %%mm1, 40(%1)\n"
25222 - " movq %%mm2, 48(%1)\n"
25223 - " movq %%mm3, 56(%1)\n"
25224 + "1: prefetch 320(%1)\n"
25225 + "2: movq (%1), %%mm0\n"
25226 + " movq 8(%1), %%mm1\n"
25227 + " movq 16(%1), %%mm2\n"
25228 + " movq 24(%1), %%mm3\n"
25229 + " movq %%mm0, (%2)\n"
25230 + " movq %%mm1, 8(%2)\n"
25231 + " movq %%mm2, 16(%2)\n"
25232 + " movq %%mm3, 24(%2)\n"
25233 + " movq 32(%1), %%mm0\n"
25234 + " movq 40(%1), %%mm1\n"
25235 + " movq 48(%1), %%mm2\n"
25236 + " movq 56(%1), %%mm3\n"
25237 + " movq %%mm0, 32(%2)\n"
25238 + " movq %%mm1, 40(%2)\n"
25239 + " movq %%mm2, 48(%2)\n"
25240 + " movq %%mm3, 56(%2)\n"
25241 ".section .fixup, \"ax\"\n"
25242 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25243 + "3:\n"
25244 +
25245 +#ifdef CONFIG_PAX_KERNEXEC
25246 + " movl %%cr0, %0\n"
25247 + " movl %0, %%eax\n"
25248 + " andl $0xFFFEFFFF, %%eax\n"
25249 + " movl %%eax, %%cr0\n"
25250 +#endif
25251 +
25252 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25253 +
25254 +#ifdef CONFIG_PAX_KERNEXEC
25255 + " movl %0, %%cr0\n"
25256 +#endif
25257 +
25258 " jmp 2b\n"
25259 ".previous\n"
25260 _ASM_EXTABLE(1b, 3b)
25261 - : : "r" (from), "r" (to) : "memory");
25262 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25263
25264 from += 64;
25265 to += 64;
25266 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25267 index f6d13ee..aca5f0b 100644
25268 --- a/arch/x86/lib/msr-reg.S
25269 +++ b/arch/x86/lib/msr-reg.S
25270 @@ -3,6 +3,7 @@
25271 #include <asm/dwarf2.h>
25272 #include <asm/asm.h>
25273 #include <asm/msr.h>
25274 +#include <asm/alternative-asm.h>
25275
25276 #ifdef CONFIG_X86_64
25277 /*
25278 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25279 CFI_STARTPROC
25280 pushq_cfi %rbx
25281 pushq_cfi %rbp
25282 - movq %rdi, %r10 /* Save pointer */
25283 + movq %rdi, %r9 /* Save pointer */
25284 xorl %r11d, %r11d /* Return value */
25285 movl (%rdi), %eax
25286 movl 4(%rdi), %ecx
25287 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25288 movl 28(%rdi), %edi
25289 CFI_REMEMBER_STATE
25290 1: \op
25291 -2: movl %eax, (%r10)
25292 +2: movl %eax, (%r9)
25293 movl %r11d, %eax /* Return value */
25294 - movl %ecx, 4(%r10)
25295 - movl %edx, 8(%r10)
25296 - movl %ebx, 12(%r10)
25297 - movl %ebp, 20(%r10)
25298 - movl %esi, 24(%r10)
25299 - movl %edi, 28(%r10)
25300 + movl %ecx, 4(%r9)
25301 + movl %edx, 8(%r9)
25302 + movl %ebx, 12(%r9)
25303 + movl %ebp, 20(%r9)
25304 + movl %esi, 24(%r9)
25305 + movl %edi, 28(%r9)
25306 popq_cfi %rbp
25307 popq_cfi %rbx
25308 + pax_force_retaddr
25309 ret
25310 3:
25311 CFI_RESTORE_STATE
25312 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25313 index fc6ba17..04471c5 100644
25314 --- a/arch/x86/lib/putuser.S
25315 +++ b/arch/x86/lib/putuser.S
25316 @@ -16,7 +16,9 @@
25317 #include <asm/errno.h>
25318 #include <asm/asm.h>
25319 #include <asm/smap.h>
25320 -
25321 +#include <asm/segment.h>
25322 +#include <asm/pgtable.h>
25323 +#include <asm/alternative-asm.h>
25324
25325 /*
25326 * __put_user_X
25327 @@ -30,57 +32,125 @@
25328 * as they get called from within inline assembly.
25329 */
25330
25331 -#define ENTER CFI_STARTPROC ; \
25332 - GET_THREAD_INFO(%_ASM_BX)
25333 -#define EXIT ASM_CLAC ; \
25334 - ret ; \
25335 +#define ENTER CFI_STARTPROC
25336 +#define EXIT ASM_CLAC ; \
25337 + pax_force_retaddr ; \
25338 + ret ; \
25339 CFI_ENDPROC
25340
25341 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25342 +#define _DEST %_ASM_CX,%_ASM_BX
25343 +#else
25344 +#define _DEST %_ASM_CX
25345 +#endif
25346 +
25347 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25348 +#define __copyuser_seg gs;
25349 +#else
25350 +#define __copyuser_seg
25351 +#endif
25352 +
25353 .text
25354 ENTRY(__put_user_1)
25355 ENTER
25356 +
25357 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25358 + GET_THREAD_INFO(%_ASM_BX)
25359 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25360 jae bad_put_user
25361 ASM_STAC
25362 -1: movb %al,(%_ASM_CX)
25363 +
25364 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25365 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25366 + cmp %_ASM_BX,%_ASM_CX
25367 + jb 1234f
25368 + xor %ebx,%ebx
25369 +1234:
25370 +#endif
25371 +
25372 +#endif
25373 +
25374 +1: __copyuser_seg movb %al,(_DEST)
25375 xor %eax,%eax
25376 EXIT
25377 ENDPROC(__put_user_1)
25378
25379 ENTRY(__put_user_2)
25380 ENTER
25381 +
25382 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25383 + GET_THREAD_INFO(%_ASM_BX)
25384 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25385 sub $1,%_ASM_BX
25386 cmp %_ASM_BX,%_ASM_CX
25387 jae bad_put_user
25388 ASM_STAC
25389 -2: movw %ax,(%_ASM_CX)
25390 +
25391 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25392 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25393 + cmp %_ASM_BX,%_ASM_CX
25394 + jb 1234f
25395 + xor %ebx,%ebx
25396 +1234:
25397 +#endif
25398 +
25399 +#endif
25400 +
25401 +2: __copyuser_seg movw %ax,(_DEST)
25402 xor %eax,%eax
25403 EXIT
25404 ENDPROC(__put_user_2)
25405
25406 ENTRY(__put_user_4)
25407 ENTER
25408 +
25409 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25410 + GET_THREAD_INFO(%_ASM_BX)
25411 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25412 sub $3,%_ASM_BX
25413 cmp %_ASM_BX,%_ASM_CX
25414 jae bad_put_user
25415 ASM_STAC
25416 -3: movl %eax,(%_ASM_CX)
25417 +
25418 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25419 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25420 + cmp %_ASM_BX,%_ASM_CX
25421 + jb 1234f
25422 + xor %ebx,%ebx
25423 +1234:
25424 +#endif
25425 +
25426 +#endif
25427 +
25428 +3: __copyuser_seg movl %eax,(_DEST)
25429 xor %eax,%eax
25430 EXIT
25431 ENDPROC(__put_user_4)
25432
25433 ENTRY(__put_user_8)
25434 ENTER
25435 +
25436 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25437 + GET_THREAD_INFO(%_ASM_BX)
25438 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25439 sub $7,%_ASM_BX
25440 cmp %_ASM_BX,%_ASM_CX
25441 jae bad_put_user
25442 ASM_STAC
25443 -4: mov %_ASM_AX,(%_ASM_CX)
25444 +
25445 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25446 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25447 + cmp %_ASM_BX,%_ASM_CX
25448 + jb 1234f
25449 + xor %ebx,%ebx
25450 +1234:
25451 +#endif
25452 +
25453 +#endif
25454 +
25455 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
25456 #ifdef CONFIG_X86_32
25457 -5: movl %edx,4(%_ASM_CX)
25458 +5: __copyuser_seg movl %edx,4(_DEST)
25459 #endif
25460 xor %eax,%eax
25461 EXIT
25462 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25463 index 1cad221..de671ee 100644
25464 --- a/arch/x86/lib/rwlock.S
25465 +++ b/arch/x86/lib/rwlock.S
25466 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25467 FRAME
25468 0: LOCK_PREFIX
25469 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25470 +
25471 +#ifdef CONFIG_PAX_REFCOUNT
25472 + jno 1234f
25473 + LOCK_PREFIX
25474 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25475 + int $4
25476 +1234:
25477 + _ASM_EXTABLE(1234b, 1234b)
25478 +#endif
25479 +
25480 1: rep; nop
25481 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25482 jne 1b
25483 LOCK_PREFIX
25484 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25485 +
25486 +#ifdef CONFIG_PAX_REFCOUNT
25487 + jno 1234f
25488 + LOCK_PREFIX
25489 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25490 + int $4
25491 +1234:
25492 + _ASM_EXTABLE(1234b, 1234b)
25493 +#endif
25494 +
25495 jnz 0b
25496 ENDFRAME
25497 + pax_force_retaddr
25498 ret
25499 CFI_ENDPROC
25500 END(__write_lock_failed)
25501 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25502 FRAME
25503 0: LOCK_PREFIX
25504 READ_LOCK_SIZE(inc) (%__lock_ptr)
25505 +
25506 +#ifdef CONFIG_PAX_REFCOUNT
25507 + jno 1234f
25508 + LOCK_PREFIX
25509 + READ_LOCK_SIZE(dec) (%__lock_ptr)
25510 + int $4
25511 +1234:
25512 + _ASM_EXTABLE(1234b, 1234b)
25513 +#endif
25514 +
25515 1: rep; nop
25516 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25517 js 1b
25518 LOCK_PREFIX
25519 READ_LOCK_SIZE(dec) (%__lock_ptr)
25520 +
25521 +#ifdef CONFIG_PAX_REFCOUNT
25522 + jno 1234f
25523 + LOCK_PREFIX
25524 + READ_LOCK_SIZE(inc) (%__lock_ptr)
25525 + int $4
25526 +1234:
25527 + _ASM_EXTABLE(1234b, 1234b)
25528 +#endif
25529 +
25530 js 0b
25531 ENDFRAME
25532 + pax_force_retaddr
25533 ret
25534 CFI_ENDPROC
25535 END(__read_lock_failed)
25536 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25537 index 5dff5f0..cadebf4 100644
25538 --- a/arch/x86/lib/rwsem.S
25539 +++ b/arch/x86/lib/rwsem.S
25540 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25541 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25542 CFI_RESTORE __ASM_REG(dx)
25543 restore_common_regs
25544 + pax_force_retaddr
25545 ret
25546 CFI_ENDPROC
25547 ENDPROC(call_rwsem_down_read_failed)
25548 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25549 movq %rax,%rdi
25550 call rwsem_down_write_failed
25551 restore_common_regs
25552 + pax_force_retaddr
25553 ret
25554 CFI_ENDPROC
25555 ENDPROC(call_rwsem_down_write_failed)
25556 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25557 movq %rax,%rdi
25558 call rwsem_wake
25559 restore_common_regs
25560 -1: ret
25561 +1: pax_force_retaddr
25562 + ret
25563 CFI_ENDPROC
25564 ENDPROC(call_rwsem_wake)
25565
25566 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25567 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25568 CFI_RESTORE __ASM_REG(dx)
25569 restore_common_regs
25570 + pax_force_retaddr
25571 ret
25572 CFI_ENDPROC
25573 ENDPROC(call_rwsem_downgrade_wake)
25574 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25575 index a63efd6..ccecad8 100644
25576 --- a/arch/x86/lib/thunk_64.S
25577 +++ b/arch/x86/lib/thunk_64.S
25578 @@ -8,6 +8,7 @@
25579 #include <linux/linkage.h>
25580 #include <asm/dwarf2.h>
25581 #include <asm/calling.h>
25582 +#include <asm/alternative-asm.h>
25583
25584 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25585 .macro THUNK name, func, put_ret_addr_in_rdi=0
25586 @@ -41,5 +42,6 @@
25587 SAVE_ARGS
25588 restore:
25589 RESTORE_ARGS
25590 + pax_force_retaddr
25591 ret
25592 CFI_ENDPROC
25593 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
25594 index f0312d7..9c39d63 100644
25595 --- a/arch/x86/lib/usercopy_32.c
25596 +++ b/arch/x86/lib/usercopy_32.c
25597 @@ -42,11 +42,13 @@ do { \
25598 int __d0; \
25599 might_fault(); \
25600 __asm__ __volatile__( \
25601 + __COPYUSER_SET_ES \
25602 ASM_STAC "\n" \
25603 "0: rep; stosl\n" \
25604 " movl %2,%0\n" \
25605 "1: rep; stosb\n" \
25606 "2: " ASM_CLAC "\n" \
25607 + __COPYUSER_RESTORE_ES \
25608 ".section .fixup,\"ax\"\n" \
25609 "3: lea 0(%2,%0,4),%0\n" \
25610 " jmp 2b\n" \
25611 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
25612
25613 #ifdef CONFIG_X86_INTEL_USERCOPY
25614 static unsigned long
25615 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
25616 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
25617 {
25618 int d0, d1;
25619 __asm__ __volatile__(
25620 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25621 " .align 2,0x90\n"
25622 "3: movl 0(%4), %%eax\n"
25623 "4: movl 4(%4), %%edx\n"
25624 - "5: movl %%eax, 0(%3)\n"
25625 - "6: movl %%edx, 4(%3)\n"
25626 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
25627 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
25628 "7: movl 8(%4), %%eax\n"
25629 "8: movl 12(%4),%%edx\n"
25630 - "9: movl %%eax, 8(%3)\n"
25631 - "10: movl %%edx, 12(%3)\n"
25632 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
25633 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
25634 "11: movl 16(%4), %%eax\n"
25635 "12: movl 20(%4), %%edx\n"
25636 - "13: movl %%eax, 16(%3)\n"
25637 - "14: movl %%edx, 20(%3)\n"
25638 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
25639 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
25640 "15: movl 24(%4), %%eax\n"
25641 "16: movl 28(%4), %%edx\n"
25642 - "17: movl %%eax, 24(%3)\n"
25643 - "18: movl %%edx, 28(%3)\n"
25644 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
25645 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
25646 "19: movl 32(%4), %%eax\n"
25647 "20: movl 36(%4), %%edx\n"
25648 - "21: movl %%eax, 32(%3)\n"
25649 - "22: movl %%edx, 36(%3)\n"
25650 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
25651 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
25652 "23: movl 40(%4), %%eax\n"
25653 "24: movl 44(%4), %%edx\n"
25654 - "25: movl %%eax, 40(%3)\n"
25655 - "26: movl %%edx, 44(%3)\n"
25656 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
25657 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
25658 "27: movl 48(%4), %%eax\n"
25659 "28: movl 52(%4), %%edx\n"
25660 - "29: movl %%eax, 48(%3)\n"
25661 - "30: movl %%edx, 52(%3)\n"
25662 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
25663 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
25664 "31: movl 56(%4), %%eax\n"
25665 "32: movl 60(%4), %%edx\n"
25666 - "33: movl %%eax, 56(%3)\n"
25667 - "34: movl %%edx, 60(%3)\n"
25668 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
25669 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
25670 " addl $-64, %0\n"
25671 " addl $64, %4\n"
25672 " addl $64, %3\n"
25673 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25674 " shrl $2, %0\n"
25675 " andl $3, %%eax\n"
25676 " cld\n"
25677 + __COPYUSER_SET_ES
25678 "99: rep; movsl\n"
25679 "36: movl %%eax, %0\n"
25680 "37: rep; movsb\n"
25681 "100:\n"
25682 + __COPYUSER_RESTORE_ES
25683 ".section .fixup,\"ax\"\n"
25684 "101: lea 0(%%eax,%0,4),%0\n"
25685 " jmp 100b\n"
25686 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25687 }
25688
25689 static unsigned long
25690 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
25691 +{
25692 + int d0, d1;
25693 + __asm__ __volatile__(
25694 + " .align 2,0x90\n"
25695 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
25696 + " cmpl $67, %0\n"
25697 + " jbe 3f\n"
25698 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
25699 + " .align 2,0x90\n"
25700 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
25701 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
25702 + "5: movl %%eax, 0(%3)\n"
25703 + "6: movl %%edx, 4(%3)\n"
25704 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
25705 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
25706 + "9: movl %%eax, 8(%3)\n"
25707 + "10: movl %%edx, 12(%3)\n"
25708 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
25709 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
25710 + "13: movl %%eax, 16(%3)\n"
25711 + "14: movl %%edx, 20(%3)\n"
25712 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
25713 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
25714 + "17: movl %%eax, 24(%3)\n"
25715 + "18: movl %%edx, 28(%3)\n"
25716 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
25717 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
25718 + "21: movl %%eax, 32(%3)\n"
25719 + "22: movl %%edx, 36(%3)\n"
25720 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
25721 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
25722 + "25: movl %%eax, 40(%3)\n"
25723 + "26: movl %%edx, 44(%3)\n"
25724 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
25725 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
25726 + "29: movl %%eax, 48(%3)\n"
25727 + "30: movl %%edx, 52(%3)\n"
25728 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
25729 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
25730 + "33: movl %%eax, 56(%3)\n"
25731 + "34: movl %%edx, 60(%3)\n"
25732 + " addl $-64, %0\n"
25733 + " addl $64, %4\n"
25734 + " addl $64, %3\n"
25735 + " cmpl $63, %0\n"
25736 + " ja 1b\n"
25737 + "35: movl %0, %%eax\n"
25738 + " shrl $2, %0\n"
25739 + " andl $3, %%eax\n"
25740 + " cld\n"
25741 + "99: rep; "__copyuser_seg" movsl\n"
25742 + "36: movl %%eax, %0\n"
25743 + "37: rep; "__copyuser_seg" movsb\n"
25744 + "100:\n"
25745 + ".section .fixup,\"ax\"\n"
25746 + "101: lea 0(%%eax,%0,4),%0\n"
25747 + " jmp 100b\n"
25748 + ".previous\n"
25749 + _ASM_EXTABLE(1b,100b)
25750 + _ASM_EXTABLE(2b,100b)
25751 + _ASM_EXTABLE(3b,100b)
25752 + _ASM_EXTABLE(4b,100b)
25753 + _ASM_EXTABLE(5b,100b)
25754 + _ASM_EXTABLE(6b,100b)
25755 + _ASM_EXTABLE(7b,100b)
25756 + _ASM_EXTABLE(8b,100b)
25757 + _ASM_EXTABLE(9b,100b)
25758 + _ASM_EXTABLE(10b,100b)
25759 + _ASM_EXTABLE(11b,100b)
25760 + _ASM_EXTABLE(12b,100b)
25761 + _ASM_EXTABLE(13b,100b)
25762 + _ASM_EXTABLE(14b,100b)
25763 + _ASM_EXTABLE(15b,100b)
25764 + _ASM_EXTABLE(16b,100b)
25765 + _ASM_EXTABLE(17b,100b)
25766 + _ASM_EXTABLE(18b,100b)
25767 + _ASM_EXTABLE(19b,100b)
25768 + _ASM_EXTABLE(20b,100b)
25769 + _ASM_EXTABLE(21b,100b)
25770 + _ASM_EXTABLE(22b,100b)
25771 + _ASM_EXTABLE(23b,100b)
25772 + _ASM_EXTABLE(24b,100b)
25773 + _ASM_EXTABLE(25b,100b)
25774 + _ASM_EXTABLE(26b,100b)
25775 + _ASM_EXTABLE(27b,100b)
25776 + _ASM_EXTABLE(28b,100b)
25777 + _ASM_EXTABLE(29b,100b)
25778 + _ASM_EXTABLE(30b,100b)
25779 + _ASM_EXTABLE(31b,100b)
25780 + _ASM_EXTABLE(32b,100b)
25781 + _ASM_EXTABLE(33b,100b)
25782 + _ASM_EXTABLE(34b,100b)
25783 + _ASM_EXTABLE(35b,100b)
25784 + _ASM_EXTABLE(36b,100b)
25785 + _ASM_EXTABLE(37b,100b)
25786 + _ASM_EXTABLE(99b,101b)
25787 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
25788 + : "1"(to), "2"(from), "0"(size)
25789 + : "eax", "edx", "memory");
25790 + return size;
25791 +}
25792 +
25793 +static unsigned long __size_overflow(3)
25794 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25795 {
25796 int d0, d1;
25797 __asm__ __volatile__(
25798 " .align 2,0x90\n"
25799 - "0: movl 32(%4), %%eax\n"
25800 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25801 " cmpl $67, %0\n"
25802 " jbe 2f\n"
25803 - "1: movl 64(%4), %%eax\n"
25804 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25805 " .align 2,0x90\n"
25806 - "2: movl 0(%4), %%eax\n"
25807 - "21: movl 4(%4), %%edx\n"
25808 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25809 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25810 " movl %%eax, 0(%3)\n"
25811 " movl %%edx, 4(%3)\n"
25812 - "3: movl 8(%4), %%eax\n"
25813 - "31: movl 12(%4),%%edx\n"
25814 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25815 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25816 " movl %%eax, 8(%3)\n"
25817 " movl %%edx, 12(%3)\n"
25818 - "4: movl 16(%4), %%eax\n"
25819 - "41: movl 20(%4), %%edx\n"
25820 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25821 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25822 " movl %%eax, 16(%3)\n"
25823 " movl %%edx, 20(%3)\n"
25824 - "10: movl 24(%4), %%eax\n"
25825 - "51: movl 28(%4), %%edx\n"
25826 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25827 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25828 " movl %%eax, 24(%3)\n"
25829 " movl %%edx, 28(%3)\n"
25830 - "11: movl 32(%4), %%eax\n"
25831 - "61: movl 36(%4), %%edx\n"
25832 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25833 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25834 " movl %%eax, 32(%3)\n"
25835 " movl %%edx, 36(%3)\n"
25836 - "12: movl 40(%4), %%eax\n"
25837 - "71: movl 44(%4), %%edx\n"
25838 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25839 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25840 " movl %%eax, 40(%3)\n"
25841 " movl %%edx, 44(%3)\n"
25842 - "13: movl 48(%4), %%eax\n"
25843 - "81: movl 52(%4), %%edx\n"
25844 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25845 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25846 " movl %%eax, 48(%3)\n"
25847 " movl %%edx, 52(%3)\n"
25848 - "14: movl 56(%4), %%eax\n"
25849 - "91: movl 60(%4), %%edx\n"
25850 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25851 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25852 " movl %%eax, 56(%3)\n"
25853 " movl %%edx, 60(%3)\n"
25854 " addl $-64, %0\n"
25855 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25856 " shrl $2, %0\n"
25857 " andl $3, %%eax\n"
25858 " cld\n"
25859 - "6: rep; movsl\n"
25860 + "6: rep; "__copyuser_seg" movsl\n"
25861 " movl %%eax,%0\n"
25862 - "7: rep; movsb\n"
25863 + "7: rep; "__copyuser_seg" movsb\n"
25864 "8:\n"
25865 ".section .fixup,\"ax\"\n"
25866 "9: lea 0(%%eax,%0,4),%0\n"
25867 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25868 * hyoshiok@miraclelinux.com
25869 */
25870
25871 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25872 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
25873 const void __user *from, unsigned long size)
25874 {
25875 int d0, d1;
25876
25877 __asm__ __volatile__(
25878 " .align 2,0x90\n"
25879 - "0: movl 32(%4), %%eax\n"
25880 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25881 " cmpl $67, %0\n"
25882 " jbe 2f\n"
25883 - "1: movl 64(%4), %%eax\n"
25884 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25885 " .align 2,0x90\n"
25886 - "2: movl 0(%4), %%eax\n"
25887 - "21: movl 4(%4), %%edx\n"
25888 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25889 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25890 " movnti %%eax, 0(%3)\n"
25891 " movnti %%edx, 4(%3)\n"
25892 - "3: movl 8(%4), %%eax\n"
25893 - "31: movl 12(%4),%%edx\n"
25894 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25895 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25896 " movnti %%eax, 8(%3)\n"
25897 " movnti %%edx, 12(%3)\n"
25898 - "4: movl 16(%4), %%eax\n"
25899 - "41: movl 20(%4), %%edx\n"
25900 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25901 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25902 " movnti %%eax, 16(%3)\n"
25903 " movnti %%edx, 20(%3)\n"
25904 - "10: movl 24(%4), %%eax\n"
25905 - "51: movl 28(%4), %%edx\n"
25906 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25907 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25908 " movnti %%eax, 24(%3)\n"
25909 " movnti %%edx, 28(%3)\n"
25910 - "11: movl 32(%4), %%eax\n"
25911 - "61: movl 36(%4), %%edx\n"
25912 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25913 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25914 " movnti %%eax, 32(%3)\n"
25915 " movnti %%edx, 36(%3)\n"
25916 - "12: movl 40(%4), %%eax\n"
25917 - "71: movl 44(%4), %%edx\n"
25918 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25919 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25920 " movnti %%eax, 40(%3)\n"
25921 " movnti %%edx, 44(%3)\n"
25922 - "13: movl 48(%4), %%eax\n"
25923 - "81: movl 52(%4), %%edx\n"
25924 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25925 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25926 " movnti %%eax, 48(%3)\n"
25927 " movnti %%edx, 52(%3)\n"
25928 - "14: movl 56(%4), %%eax\n"
25929 - "91: movl 60(%4), %%edx\n"
25930 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25931 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25932 " movnti %%eax, 56(%3)\n"
25933 " movnti %%edx, 60(%3)\n"
25934 " addl $-64, %0\n"
25935 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25936 " shrl $2, %0\n"
25937 " andl $3, %%eax\n"
25938 " cld\n"
25939 - "6: rep; movsl\n"
25940 + "6: rep; "__copyuser_seg" movsl\n"
25941 " movl %%eax,%0\n"
25942 - "7: rep; movsb\n"
25943 + "7: rep; "__copyuser_seg" movsb\n"
25944 "8:\n"
25945 ".section .fixup,\"ax\"\n"
25946 "9: lea 0(%%eax,%0,4),%0\n"
25947 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25948 return size;
25949 }
25950
25951 -static unsigned long __copy_user_intel_nocache(void *to,
25952 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
25953 const void __user *from, unsigned long size)
25954 {
25955 int d0, d1;
25956
25957 __asm__ __volatile__(
25958 " .align 2,0x90\n"
25959 - "0: movl 32(%4), %%eax\n"
25960 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25961 " cmpl $67, %0\n"
25962 " jbe 2f\n"
25963 - "1: movl 64(%4), %%eax\n"
25964 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25965 " .align 2,0x90\n"
25966 - "2: movl 0(%4), %%eax\n"
25967 - "21: movl 4(%4), %%edx\n"
25968 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25969 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25970 " movnti %%eax, 0(%3)\n"
25971 " movnti %%edx, 4(%3)\n"
25972 - "3: movl 8(%4), %%eax\n"
25973 - "31: movl 12(%4),%%edx\n"
25974 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25975 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25976 " movnti %%eax, 8(%3)\n"
25977 " movnti %%edx, 12(%3)\n"
25978 - "4: movl 16(%4), %%eax\n"
25979 - "41: movl 20(%4), %%edx\n"
25980 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25981 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25982 " movnti %%eax, 16(%3)\n"
25983 " movnti %%edx, 20(%3)\n"
25984 - "10: movl 24(%4), %%eax\n"
25985 - "51: movl 28(%4), %%edx\n"
25986 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25987 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25988 " movnti %%eax, 24(%3)\n"
25989 " movnti %%edx, 28(%3)\n"
25990 - "11: movl 32(%4), %%eax\n"
25991 - "61: movl 36(%4), %%edx\n"
25992 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25993 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25994 " movnti %%eax, 32(%3)\n"
25995 " movnti %%edx, 36(%3)\n"
25996 - "12: movl 40(%4), %%eax\n"
25997 - "71: movl 44(%4), %%edx\n"
25998 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25999 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26000 " movnti %%eax, 40(%3)\n"
26001 " movnti %%edx, 44(%3)\n"
26002 - "13: movl 48(%4), %%eax\n"
26003 - "81: movl 52(%4), %%edx\n"
26004 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26005 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26006 " movnti %%eax, 48(%3)\n"
26007 " movnti %%edx, 52(%3)\n"
26008 - "14: movl 56(%4), %%eax\n"
26009 - "91: movl 60(%4), %%edx\n"
26010 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26011 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26012 " movnti %%eax, 56(%3)\n"
26013 " movnti %%edx, 60(%3)\n"
26014 " addl $-64, %0\n"
26015 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26016 " shrl $2, %0\n"
26017 " andl $3, %%eax\n"
26018 " cld\n"
26019 - "6: rep; movsl\n"
26020 + "6: rep; "__copyuser_seg" movsl\n"
26021 " movl %%eax,%0\n"
26022 - "7: rep; movsb\n"
26023 + "7: rep; "__copyuser_seg" movsb\n"
26024 "8:\n"
26025 ".section .fixup,\"ax\"\n"
26026 "9: lea 0(%%eax,%0,4),%0\n"
26027 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26028 */
26029 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26030 unsigned long size);
26031 -unsigned long __copy_user_intel(void __user *to, const void *from,
26032 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26033 + unsigned long size);
26034 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26035 unsigned long size);
26036 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26037 const void __user *from, unsigned long size);
26038 #endif /* CONFIG_X86_INTEL_USERCOPY */
26039
26040 /* Generic arbitrary sized copy. */
26041 -#define __copy_user(to, from, size) \
26042 +#define __copy_user(to, from, size, prefix, set, restore) \
26043 do { \
26044 int __d0, __d1, __d2; \
26045 __asm__ __volatile__( \
26046 + set \
26047 " cmp $7,%0\n" \
26048 " jbe 1f\n" \
26049 " movl %1,%0\n" \
26050 " negl %0\n" \
26051 " andl $7,%0\n" \
26052 " subl %0,%3\n" \
26053 - "4: rep; movsb\n" \
26054 + "4: rep; "prefix"movsb\n" \
26055 " movl %3,%0\n" \
26056 " shrl $2,%0\n" \
26057 " andl $3,%3\n" \
26058 " .align 2,0x90\n" \
26059 - "0: rep; movsl\n" \
26060 + "0: rep; "prefix"movsl\n" \
26061 " movl %3,%0\n" \
26062 - "1: rep; movsb\n" \
26063 + "1: rep; "prefix"movsb\n" \
26064 "2:\n" \
26065 + restore \
26066 ".section .fixup,\"ax\"\n" \
26067 "5: addl %3,%0\n" \
26068 " jmp 2b\n" \
26069 @@ -538,14 +650,14 @@ do { \
26070 " negl %0\n" \
26071 " andl $7,%0\n" \
26072 " subl %0,%3\n" \
26073 - "4: rep; movsb\n" \
26074 + "4: rep; "__copyuser_seg"movsb\n" \
26075 " movl %3,%0\n" \
26076 " shrl $2,%0\n" \
26077 " andl $3,%3\n" \
26078 " .align 2,0x90\n" \
26079 - "0: rep; movsl\n" \
26080 + "0: rep; "__copyuser_seg"movsl\n" \
26081 " movl %3,%0\n" \
26082 - "1: rep; movsb\n" \
26083 + "1: rep; "__copyuser_seg"movsb\n" \
26084 "2:\n" \
26085 ".section .fixup,\"ax\"\n" \
26086 "5: addl %3,%0\n" \
26087 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26088 {
26089 stac();
26090 if (movsl_is_ok(to, from, n))
26091 - __copy_user(to, from, n);
26092 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26093 else
26094 - n = __copy_user_intel(to, from, n);
26095 + n = __generic_copy_to_user_intel(to, from, n);
26096 clac();
26097 return n;
26098 }
26099 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26100 {
26101 stac();
26102 if (movsl_is_ok(to, from, n))
26103 - __copy_user(to, from, n);
26104 + __copy_user(to, from, n, __copyuser_seg, "", "");
26105 else
26106 - n = __copy_user_intel((void __user *)to,
26107 - (const void *)from, n);
26108 + n = __generic_copy_from_user_intel(to, from, n);
26109 clac();
26110 return n;
26111 }
26112 @@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26113 if (n > 64 && cpu_has_xmm2)
26114 n = __copy_user_intel_nocache(to, from, n);
26115 else
26116 - __copy_user(to, from, n);
26117 + __copy_user(to, from, n, __copyuser_seg, "", "");
26118 #else
26119 - __copy_user(to, from, n);
26120 + __copy_user(to, from, n, __copyuser_seg, "", "");
26121 #endif
26122 clac();
26123 return n;
26124 }
26125 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26126
26127 -/**
26128 - * copy_to_user: - Copy a block of data into user space.
26129 - * @to: Destination address, in user space.
26130 - * @from: Source address, in kernel space.
26131 - * @n: Number of bytes to copy.
26132 - *
26133 - * Context: User context only. This function may sleep.
26134 - *
26135 - * Copy data from kernel space to user space.
26136 - *
26137 - * Returns number of bytes that could not be copied.
26138 - * On success, this will be zero.
26139 - */
26140 -unsigned long
26141 -copy_to_user(void __user *to, const void *from, unsigned long n)
26142 -{
26143 - if (access_ok(VERIFY_WRITE, to, n))
26144 - n = __copy_to_user(to, from, n);
26145 - return n;
26146 -}
26147 -EXPORT_SYMBOL(copy_to_user);
26148 -
26149 -/**
26150 - * copy_from_user: - Copy a block of data from user space.
26151 - * @to: Destination address, in kernel space.
26152 - * @from: Source address, in user space.
26153 - * @n: Number of bytes to copy.
26154 - *
26155 - * Context: User context only. This function may sleep.
26156 - *
26157 - * Copy data from user space to kernel space.
26158 - *
26159 - * Returns number of bytes that could not be copied.
26160 - * On success, this will be zero.
26161 - *
26162 - * If some data could not be copied, this function will pad the copied
26163 - * data to the requested size using zero bytes.
26164 - */
26165 -unsigned long
26166 -_copy_from_user(void *to, const void __user *from, unsigned long n)
26167 -{
26168 - if (access_ok(VERIFY_READ, from, n))
26169 - n = __copy_from_user(to, from, n);
26170 - else
26171 - memset(to, 0, n);
26172 - return n;
26173 -}
26174 -EXPORT_SYMBOL(_copy_from_user);
26175 -
26176 void copy_from_user_overflow(void)
26177 {
26178 WARN(1, "Buffer overflow detected!\n");
26179 }
26180 EXPORT_SYMBOL(copy_from_user_overflow);
26181 +
26182 +void copy_to_user_overflow(void)
26183 +{
26184 + WARN(1, "Buffer overflow detected!\n");
26185 +}
26186 +EXPORT_SYMBOL(copy_to_user_overflow);
26187 +
26188 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26189 +void __set_fs(mm_segment_t x)
26190 +{
26191 + switch (x.seg) {
26192 + case 0:
26193 + loadsegment(gs, 0);
26194 + break;
26195 + case TASK_SIZE_MAX:
26196 + loadsegment(gs, __USER_DS);
26197 + break;
26198 + case -1UL:
26199 + loadsegment(gs, __KERNEL_DS);
26200 + break;
26201 + default:
26202 + BUG();
26203 + }
26204 + return;
26205 +}
26206 +EXPORT_SYMBOL(__set_fs);
26207 +
26208 +void set_fs(mm_segment_t x)
26209 +{
26210 + current_thread_info()->addr_limit = x;
26211 + __set_fs(x);
26212 +}
26213 +EXPORT_SYMBOL(set_fs);
26214 +#endif
26215 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26216 index 05928aa..b33dea1 100644
26217 --- a/arch/x86/lib/usercopy_64.c
26218 +++ b/arch/x86/lib/usercopy_64.c
26219 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26220 _ASM_EXTABLE(0b,3b)
26221 _ASM_EXTABLE(1b,2b)
26222 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26223 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26224 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26225 [zero] "r" (0UL), [eight] "r" (8UL));
26226 clac();
26227 return size;
26228 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26229 }
26230 EXPORT_SYMBOL(clear_user);
26231
26232 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26233 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26234 {
26235 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26236 - return copy_user_generic((__force void *)to, (__force void *)from, len);
26237 - }
26238 - return len;
26239 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26240 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26241 + return len;
26242 }
26243 EXPORT_SYMBOL(copy_in_user);
26244
26245 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26246 * it is not necessary to optimize tail handling.
26247 */
26248 unsigned long
26249 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26250 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26251 {
26252 char c;
26253 unsigned zero_len;
26254 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26255 clac();
26256 return len;
26257 }
26258 +
26259 +void copy_from_user_overflow(void)
26260 +{
26261 + WARN(1, "Buffer overflow detected!\n");
26262 +}
26263 +EXPORT_SYMBOL(copy_from_user_overflow);
26264 +
26265 +void copy_to_user_overflow(void)
26266 +{
26267 + WARN(1, "Buffer overflow detected!\n");
26268 +}
26269 +EXPORT_SYMBOL(copy_to_user_overflow);
26270 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26271 index 903ec1e..c4166b2 100644
26272 --- a/arch/x86/mm/extable.c
26273 +++ b/arch/x86/mm/extable.c
26274 @@ -6,12 +6,24 @@
26275 static inline unsigned long
26276 ex_insn_addr(const struct exception_table_entry *x)
26277 {
26278 - return (unsigned long)&x->insn + x->insn;
26279 + unsigned long reloc = 0;
26280 +
26281 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26282 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26283 +#endif
26284 +
26285 + return (unsigned long)&x->insn + x->insn + reloc;
26286 }
26287 static inline unsigned long
26288 ex_fixup_addr(const struct exception_table_entry *x)
26289 {
26290 - return (unsigned long)&x->fixup + x->fixup;
26291 + unsigned long reloc = 0;
26292 +
26293 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26294 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26295 +#endif
26296 +
26297 + return (unsigned long)&x->fixup + x->fixup + reloc;
26298 }
26299
26300 int fixup_exception(struct pt_regs *regs)
26301 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26302 unsigned long new_ip;
26303
26304 #ifdef CONFIG_PNPBIOS
26305 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26306 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26307 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26308 extern u32 pnp_bios_is_utter_crap;
26309 pnp_bios_is_utter_crap = 1;
26310 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26311 i += 4;
26312 p->fixup -= i;
26313 i += 4;
26314 +
26315 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26316 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26317 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26318 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26319 +#endif
26320 +
26321 }
26322 }
26323
26324 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26325 index fb674fd..272f369 100644
26326 --- a/arch/x86/mm/fault.c
26327 +++ b/arch/x86/mm/fault.c
26328 @@ -13,12 +13,19 @@
26329 #include <linux/perf_event.h> /* perf_sw_event */
26330 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26331 #include <linux/prefetch.h> /* prefetchw */
26332 +#include <linux/unistd.h>
26333 +#include <linux/compiler.h>
26334
26335 #include <asm/traps.h> /* dotraplinkage, ... */
26336 #include <asm/pgalloc.h> /* pgd_*(), ... */
26337 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26338 #include <asm/fixmap.h> /* VSYSCALL_START */
26339 #include <asm/context_tracking.h> /* exception_enter(), ... */
26340 +#include <asm/tlbflush.h>
26341 +
26342 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26343 +#include <asm/stacktrace.h>
26344 +#endif
26345
26346 /*
26347 * Page fault error code bits:
26348 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26349 int ret = 0;
26350
26351 /* kprobe_running() needs smp_processor_id() */
26352 - if (kprobes_built_in() && !user_mode_vm(regs)) {
26353 + if (kprobes_built_in() && !user_mode(regs)) {
26354 preempt_disable();
26355 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26356 ret = 1;
26357 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26358 return !instr_lo || (instr_lo>>1) == 1;
26359 case 0x00:
26360 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26361 - if (probe_kernel_address(instr, opcode))
26362 + if (user_mode(regs)) {
26363 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26364 + return 0;
26365 + } else if (probe_kernel_address(instr, opcode))
26366 return 0;
26367
26368 *prefetch = (instr_lo == 0xF) &&
26369 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26370 while (instr < max_instr) {
26371 unsigned char opcode;
26372
26373 - if (probe_kernel_address(instr, opcode))
26374 + if (user_mode(regs)) {
26375 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26376 + break;
26377 + } else if (probe_kernel_address(instr, opcode))
26378 break;
26379
26380 instr++;
26381 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26382 force_sig_info(si_signo, &info, tsk);
26383 }
26384
26385 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26386 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26387 +#endif
26388 +
26389 +#ifdef CONFIG_PAX_EMUTRAMP
26390 +static int pax_handle_fetch_fault(struct pt_regs *regs);
26391 +#endif
26392 +
26393 +#ifdef CONFIG_PAX_PAGEEXEC
26394 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26395 +{
26396 + pgd_t *pgd;
26397 + pud_t *pud;
26398 + pmd_t *pmd;
26399 +
26400 + pgd = pgd_offset(mm, address);
26401 + if (!pgd_present(*pgd))
26402 + return NULL;
26403 + pud = pud_offset(pgd, address);
26404 + if (!pud_present(*pud))
26405 + return NULL;
26406 + pmd = pmd_offset(pud, address);
26407 + if (!pmd_present(*pmd))
26408 + return NULL;
26409 + return pmd;
26410 +}
26411 +#endif
26412 +
26413 DEFINE_SPINLOCK(pgd_lock);
26414 LIST_HEAD(pgd_list);
26415
26416 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26417 for (address = VMALLOC_START & PMD_MASK;
26418 address >= TASK_SIZE && address < FIXADDR_TOP;
26419 address += PMD_SIZE) {
26420 +
26421 +#ifdef CONFIG_PAX_PER_CPU_PGD
26422 + unsigned long cpu;
26423 +#else
26424 struct page *page;
26425 +#endif
26426
26427 spin_lock(&pgd_lock);
26428 +
26429 +#ifdef CONFIG_PAX_PER_CPU_PGD
26430 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26431 + pgd_t *pgd = get_cpu_pgd(cpu);
26432 + pmd_t *ret;
26433 +#else
26434 list_for_each_entry(page, &pgd_list, lru) {
26435 + pgd_t *pgd = page_address(page);
26436 spinlock_t *pgt_lock;
26437 pmd_t *ret;
26438
26439 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26440 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26441
26442 spin_lock(pgt_lock);
26443 - ret = vmalloc_sync_one(page_address(page), address);
26444 +#endif
26445 +
26446 + ret = vmalloc_sync_one(pgd, address);
26447 +
26448 +#ifndef CONFIG_PAX_PER_CPU_PGD
26449 spin_unlock(pgt_lock);
26450 +#endif
26451
26452 if (!ret)
26453 break;
26454 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26455 * an interrupt in the middle of a task switch..
26456 */
26457 pgd_paddr = read_cr3();
26458 +
26459 +#ifdef CONFIG_PAX_PER_CPU_PGD
26460 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26461 +#endif
26462 +
26463 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26464 if (!pmd_k)
26465 return -1;
26466 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26467 * happen within a race in page table update. In the later
26468 * case just flush:
26469 */
26470 +
26471 +#ifdef CONFIG_PAX_PER_CPU_PGD
26472 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26473 + pgd = pgd_offset_cpu(smp_processor_id(), address);
26474 +#else
26475 pgd = pgd_offset(current->active_mm, address);
26476 +#endif
26477 +
26478 pgd_ref = pgd_offset_k(address);
26479 if (pgd_none(*pgd_ref))
26480 return -1;
26481 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26482 static int is_errata100(struct pt_regs *regs, unsigned long address)
26483 {
26484 #ifdef CONFIG_X86_64
26485 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26486 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26487 return 1;
26488 #endif
26489 return 0;
26490 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26491 }
26492
26493 static const char nx_warning[] = KERN_CRIT
26494 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26495 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26496
26497 static void
26498 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26499 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26500 if (!oops_may_print())
26501 return;
26502
26503 - if (error_code & PF_INSTR) {
26504 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26505 unsigned int level;
26506
26507 pte_t *pte = lookup_address(address, &level);
26508
26509 if (pte && pte_present(*pte) && !pte_exec(*pte))
26510 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26511 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26512 }
26513
26514 +#ifdef CONFIG_PAX_KERNEXEC
26515 + if (init_mm.start_code <= address && address < init_mm.end_code) {
26516 + if (current->signal->curr_ip)
26517 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26518 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
26519 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26520 + else
26521 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26522 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26523 + }
26524 +#endif
26525 +
26526 printk(KERN_ALERT "BUG: unable to handle kernel ");
26527 if (address < PAGE_SIZE)
26528 printk(KERN_CONT "NULL pointer dereference");
26529 @@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26530 return;
26531 }
26532 #endif
26533 +
26534 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26535 + if (pax_is_fetch_fault(regs, error_code, address)) {
26536 +
26537 +#ifdef CONFIG_PAX_EMUTRAMP
26538 + switch (pax_handle_fetch_fault(regs)) {
26539 + case 2:
26540 + return;
26541 + }
26542 +#endif
26543 +
26544 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26545 + do_group_exit(SIGKILL);
26546 + }
26547 +#endif
26548 +
26549 /* Kernel addresses are always protection faults: */
26550 if (address >= TASK_SIZE)
26551 error_code |= PF_PROT;
26552 @@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26553 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26554 printk(KERN_ERR
26555 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26556 - tsk->comm, tsk->pid, address);
26557 + tsk->comm, task_pid_nr(tsk), address);
26558 code = BUS_MCEERR_AR;
26559 }
26560 #endif
26561 @@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26562 return 1;
26563 }
26564
26565 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26566 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26567 +{
26568 + pte_t *pte;
26569 + pmd_t *pmd;
26570 + spinlock_t *ptl;
26571 + unsigned char pte_mask;
26572 +
26573 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26574 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
26575 + return 0;
26576 +
26577 + /* PaX: it's our fault, let's handle it if we can */
26578 +
26579 + /* PaX: take a look at read faults before acquiring any locks */
26580 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26581 + /* instruction fetch attempt from a protected page in user mode */
26582 + up_read(&mm->mmap_sem);
26583 +
26584 +#ifdef CONFIG_PAX_EMUTRAMP
26585 + switch (pax_handle_fetch_fault(regs)) {
26586 + case 2:
26587 + return 1;
26588 + }
26589 +#endif
26590 +
26591 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26592 + do_group_exit(SIGKILL);
26593 + }
26594 +
26595 + pmd = pax_get_pmd(mm, address);
26596 + if (unlikely(!pmd))
26597 + return 0;
26598 +
26599 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
26600 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
26601 + pte_unmap_unlock(pte, ptl);
26602 + return 0;
26603 + }
26604 +
26605 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
26606 + /* write attempt to a protected page in user mode */
26607 + pte_unmap_unlock(pte, ptl);
26608 + return 0;
26609 + }
26610 +
26611 +#ifdef CONFIG_SMP
26612 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
26613 +#else
26614 + if (likely(address > get_limit(regs->cs)))
26615 +#endif
26616 + {
26617 + set_pte(pte, pte_mkread(*pte));
26618 + __flush_tlb_one(address);
26619 + pte_unmap_unlock(pte, ptl);
26620 + up_read(&mm->mmap_sem);
26621 + return 1;
26622 + }
26623 +
26624 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
26625 +
26626 + /*
26627 + * PaX: fill DTLB with user rights and retry
26628 + */
26629 + __asm__ __volatile__ (
26630 + "orb %2,(%1)\n"
26631 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
26632 +/*
26633 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
26634 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
26635 + * page fault when examined during a TLB load attempt. this is true not only
26636 + * for PTEs holding a non-present entry but also present entries that will
26637 + * raise a page fault (such as those set up by PaX, or the copy-on-write
26638 + * mechanism). in effect it means that we do *not* need to flush the TLBs
26639 + * for our target pages since their PTEs are simply not in the TLBs at all.
26640 +
26641 + * the best thing in omitting it is that we gain around 15-20% speed in the
26642 + * fast path of the page fault handler and can get rid of tracing since we
26643 + * can no longer flush unintended entries.
26644 + */
26645 + "invlpg (%0)\n"
26646 +#endif
26647 + __copyuser_seg"testb $0,(%0)\n"
26648 + "xorb %3,(%1)\n"
26649 + :
26650 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
26651 + : "memory", "cc");
26652 + pte_unmap_unlock(pte, ptl);
26653 + up_read(&mm->mmap_sem);
26654 + return 1;
26655 +}
26656 +#endif
26657 +
26658 /*
26659 * Handle a spurious fault caused by a stale TLB entry.
26660 *
26661 @@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
26662 static inline int
26663 access_error(unsigned long error_code, struct vm_area_struct *vma)
26664 {
26665 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
26666 + return 1;
26667 +
26668 if (error_code & PF_WRITE) {
26669 /* write, present and write, not present: */
26670 if (unlikely(!(vma->vm_flags & VM_WRITE)))
26671 @@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
26672 if (error_code & PF_USER)
26673 return false;
26674
26675 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
26676 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
26677 return false;
26678
26679 return true;
26680 @@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26681 {
26682 struct vm_area_struct *vma;
26683 struct task_struct *tsk;
26684 - unsigned long address;
26685 struct mm_struct *mm;
26686 int fault;
26687 int write = error_code & PF_WRITE;
26688 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
26689 (write ? FAULT_FLAG_WRITE : 0);
26690
26691 - tsk = current;
26692 - mm = tsk->mm;
26693 -
26694 /* Get the faulting address: */
26695 - address = read_cr2();
26696 + unsigned long address = read_cr2();
26697 +
26698 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26699 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
26700 + if (!search_exception_tables(regs->ip)) {
26701 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26702 + bad_area_nosemaphore(regs, error_code, address);
26703 + return;
26704 + }
26705 + if (address < PAX_USER_SHADOW_BASE) {
26706 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26707 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
26708 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
26709 + } else
26710 + address -= PAX_USER_SHADOW_BASE;
26711 + }
26712 +#endif
26713 +
26714 + tsk = current;
26715 + mm = tsk->mm;
26716
26717 /*
26718 * Detect and handle instructions that would cause a page fault for
26719 @@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26720 * User-mode registers count as a user access even for any
26721 * potential system fault or CPU buglet:
26722 */
26723 - if (user_mode_vm(regs)) {
26724 + if (user_mode(regs)) {
26725 local_irq_enable();
26726 error_code |= PF_USER;
26727 } else {
26728 @@ -1146,6 +1355,11 @@ retry:
26729 might_sleep();
26730 }
26731
26732 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26733 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
26734 + return;
26735 +#endif
26736 +
26737 vma = find_vma(mm, address);
26738 if (unlikely(!vma)) {
26739 bad_area(regs, error_code, address);
26740 @@ -1157,18 +1371,24 @@ retry:
26741 bad_area(regs, error_code, address);
26742 return;
26743 }
26744 - if (error_code & PF_USER) {
26745 - /*
26746 - * Accessing the stack below %sp is always a bug.
26747 - * The large cushion allows instructions like enter
26748 - * and pusha to work. ("enter $65535, $31" pushes
26749 - * 32 pointers and then decrements %sp by 65535.)
26750 - */
26751 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
26752 - bad_area(regs, error_code, address);
26753 - return;
26754 - }
26755 + /*
26756 + * Accessing the stack below %sp is always a bug.
26757 + * The large cushion allows instructions like enter
26758 + * and pusha to work. ("enter $65535, $31" pushes
26759 + * 32 pointers and then decrements %sp by 65535.)
26760 + */
26761 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
26762 + bad_area(regs, error_code, address);
26763 + return;
26764 }
26765 +
26766 +#ifdef CONFIG_PAX_SEGMEXEC
26767 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
26768 + bad_area(regs, error_code, address);
26769 + return;
26770 + }
26771 +#endif
26772 +
26773 if (unlikely(expand_stack(vma, address))) {
26774 bad_area(regs, error_code, address);
26775 return;
26776 @@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
26777 __do_page_fault(regs, error_code);
26778 exception_exit(regs);
26779 }
26780 +
26781 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26782 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
26783 +{
26784 + struct mm_struct *mm = current->mm;
26785 + unsigned long ip = regs->ip;
26786 +
26787 + if (v8086_mode(regs))
26788 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
26789 +
26790 +#ifdef CONFIG_PAX_PAGEEXEC
26791 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
26792 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
26793 + return true;
26794 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
26795 + return true;
26796 + return false;
26797 + }
26798 +#endif
26799 +
26800 +#ifdef CONFIG_PAX_SEGMEXEC
26801 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
26802 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
26803 + return true;
26804 + return false;
26805 + }
26806 +#endif
26807 +
26808 + return false;
26809 +}
26810 +#endif
26811 +
26812 +#ifdef CONFIG_PAX_EMUTRAMP
26813 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
26814 +{
26815 + int err;
26816 +
26817 + do { /* PaX: libffi trampoline emulation */
26818 + unsigned char mov, jmp;
26819 + unsigned int addr1, addr2;
26820 +
26821 +#ifdef CONFIG_X86_64
26822 + if ((regs->ip + 9) >> 32)
26823 + break;
26824 +#endif
26825 +
26826 + err = get_user(mov, (unsigned char __user *)regs->ip);
26827 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26828 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26829 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26830 +
26831 + if (err)
26832 + break;
26833 +
26834 + if (mov == 0xB8 && jmp == 0xE9) {
26835 + regs->ax = addr1;
26836 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26837 + return 2;
26838 + }
26839 + } while (0);
26840 +
26841 + do { /* PaX: gcc trampoline emulation #1 */
26842 + unsigned char mov1, mov2;
26843 + unsigned short jmp;
26844 + unsigned int addr1, addr2;
26845 +
26846 +#ifdef CONFIG_X86_64
26847 + if ((regs->ip + 11) >> 32)
26848 + break;
26849 +#endif
26850 +
26851 + err = get_user(mov1, (unsigned char __user *)regs->ip);
26852 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26853 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
26854 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26855 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
26856 +
26857 + if (err)
26858 + break;
26859 +
26860 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
26861 + regs->cx = addr1;
26862 + regs->ax = addr2;
26863 + regs->ip = addr2;
26864 + return 2;
26865 + }
26866 + } while (0);
26867 +
26868 + do { /* PaX: gcc trampoline emulation #2 */
26869 + unsigned char mov, jmp;
26870 + unsigned int addr1, addr2;
26871 +
26872 +#ifdef CONFIG_X86_64
26873 + if ((regs->ip + 9) >> 32)
26874 + break;
26875 +#endif
26876 +
26877 + err = get_user(mov, (unsigned char __user *)regs->ip);
26878 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26879 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26880 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26881 +
26882 + if (err)
26883 + break;
26884 +
26885 + if (mov == 0xB9 && jmp == 0xE9) {
26886 + regs->cx = addr1;
26887 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26888 + return 2;
26889 + }
26890 + } while (0);
26891 +
26892 + return 1; /* PaX in action */
26893 +}
26894 +
26895 +#ifdef CONFIG_X86_64
26896 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
26897 +{
26898 + int err;
26899 +
26900 + do { /* PaX: libffi trampoline emulation */
26901 + unsigned short mov1, mov2, jmp1;
26902 + unsigned char stcclc, jmp2;
26903 + unsigned long addr1, addr2;
26904 +
26905 + err = get_user(mov1, (unsigned short __user *)regs->ip);
26906 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26907 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26908 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26909 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
26910 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
26911 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
26912 +
26913 + if (err)
26914 + break;
26915 +
26916 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26917 + regs->r11 = addr1;
26918 + regs->r10 = addr2;
26919 + if (stcclc == 0xF8)
26920 + regs->flags &= ~X86_EFLAGS_CF;
26921 + else
26922 + regs->flags |= X86_EFLAGS_CF;
26923 + regs->ip = addr1;
26924 + return 2;
26925 + }
26926 + } while (0);
26927 +
26928 + do { /* PaX: gcc trampoline emulation #1 */
26929 + unsigned short mov1, mov2, jmp1;
26930 + unsigned char jmp2;
26931 + unsigned int addr1;
26932 + unsigned long addr2;
26933 +
26934 + err = get_user(mov1, (unsigned short __user *)regs->ip);
26935 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
26936 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
26937 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
26938 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
26939 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
26940 +
26941 + if (err)
26942 + break;
26943 +
26944 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26945 + regs->r11 = addr1;
26946 + regs->r10 = addr2;
26947 + regs->ip = addr1;
26948 + return 2;
26949 + }
26950 + } while (0);
26951 +
26952 + do { /* PaX: gcc trampoline emulation #2 */
26953 + unsigned short mov1, mov2, jmp1;
26954 + unsigned char jmp2;
26955 + unsigned long addr1, addr2;
26956 +
26957 + err = get_user(mov1, (unsigned short __user *)regs->ip);
26958 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26959 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26960 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26961 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
26962 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
26963 +
26964 + if (err)
26965 + break;
26966 +
26967 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26968 + regs->r11 = addr1;
26969 + regs->r10 = addr2;
26970 + regs->ip = addr1;
26971 + return 2;
26972 + }
26973 + } while (0);
26974 +
26975 + return 1; /* PaX in action */
26976 +}
26977 +#endif
26978 +
26979 +/*
26980 + * PaX: decide what to do with offenders (regs->ip = fault address)
26981 + *
26982 + * returns 1 when task should be killed
26983 + * 2 when gcc trampoline was detected
26984 + */
26985 +static int pax_handle_fetch_fault(struct pt_regs *regs)
26986 +{
26987 + if (v8086_mode(regs))
26988 + return 1;
26989 +
26990 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
26991 + return 1;
26992 +
26993 +#ifdef CONFIG_X86_32
26994 + return pax_handle_fetch_fault_32(regs);
26995 +#else
26996 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
26997 + return pax_handle_fetch_fault_32(regs);
26998 + else
26999 + return pax_handle_fetch_fault_64(regs);
27000 +#endif
27001 +}
27002 +#endif
27003 +
27004 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27005 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27006 +{
27007 + long i;
27008 +
27009 + printk(KERN_ERR "PAX: bytes at PC: ");
27010 + for (i = 0; i < 20; i++) {
27011 + unsigned char c;
27012 + if (get_user(c, (unsigned char __force_user *)pc+i))
27013 + printk(KERN_CONT "?? ");
27014 + else
27015 + printk(KERN_CONT "%02x ", c);
27016 + }
27017 + printk("\n");
27018 +
27019 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27020 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
27021 + unsigned long c;
27022 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
27023 +#ifdef CONFIG_X86_32
27024 + printk(KERN_CONT "???????? ");
27025 +#else
27026 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27027 + printk(KERN_CONT "???????? ???????? ");
27028 + else
27029 + printk(KERN_CONT "???????????????? ");
27030 +#endif
27031 + } else {
27032 +#ifdef CONFIG_X86_64
27033 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27034 + printk(KERN_CONT "%08x ", (unsigned int)c);
27035 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27036 + } else
27037 +#endif
27038 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27039 + }
27040 + }
27041 + printk("\n");
27042 +}
27043 +#endif
27044 +
27045 +/**
27046 + * probe_kernel_write(): safely attempt to write to a location
27047 + * @dst: address to write to
27048 + * @src: pointer to the data that shall be written
27049 + * @size: size of the data chunk
27050 + *
27051 + * Safely write to address @dst from the buffer at @src. If a kernel fault
27052 + * happens, handle that and return -EFAULT.
27053 + */
27054 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27055 +{
27056 + long ret;
27057 + mm_segment_t old_fs = get_fs();
27058 +
27059 + set_fs(KERNEL_DS);
27060 + pagefault_disable();
27061 + pax_open_kernel();
27062 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27063 + pax_close_kernel();
27064 + pagefault_enable();
27065 + set_fs(old_fs);
27066 +
27067 + return ret ? -EFAULT : 0;
27068 +}
27069 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27070 index dd74e46..7d26398 100644
27071 --- a/arch/x86/mm/gup.c
27072 +++ b/arch/x86/mm/gup.c
27073 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27074 addr = start;
27075 len = (unsigned long) nr_pages << PAGE_SHIFT;
27076 end = start + len;
27077 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27078 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27079 (void __user *)start, len)))
27080 return 0;
27081
27082 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27083 index 6f31ee5..8ee4164 100644
27084 --- a/arch/x86/mm/highmem_32.c
27085 +++ b/arch/x86/mm/highmem_32.c
27086 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27087 idx = type + KM_TYPE_NR*smp_processor_id();
27088 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27089 BUG_ON(!pte_none(*(kmap_pte-idx)));
27090 +
27091 + pax_open_kernel();
27092 set_pte(kmap_pte-idx, mk_pte(page, prot));
27093 + pax_close_kernel();
27094 +
27095 arch_flush_lazy_mmu_mode();
27096
27097 return (void *)vaddr;
27098 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27099 index ae1aa71..56316db 100644
27100 --- a/arch/x86/mm/hugetlbpage.c
27101 +++ b/arch/x86/mm/hugetlbpage.c
27102 @@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27103 info.flags = 0;
27104 info.length = len;
27105 info.low_limit = TASK_UNMAPPED_BASE;
27106 +
27107 +#ifdef CONFIG_PAX_RANDMMAP
27108 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27109 + info.low_limit += current->mm->delta_mmap;
27110 +#endif
27111 +
27112 info.high_limit = TASK_SIZE;
27113 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27114 info.align_offset = 0;
27115 @@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27116 VM_BUG_ON(addr != -ENOMEM);
27117 info.flags = 0;
27118 info.low_limit = TASK_UNMAPPED_BASE;
27119 +
27120 +#ifdef CONFIG_PAX_RANDMMAP
27121 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27122 + info.low_limit += current->mm->delta_mmap;
27123 +#endif
27124 +
27125 info.high_limit = TASK_SIZE;
27126 addr = vm_unmapped_area(&info);
27127 }
27128 @@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27129 struct hstate *h = hstate_file(file);
27130 struct mm_struct *mm = current->mm;
27131 struct vm_area_struct *vma;
27132 + unsigned long pax_task_size = TASK_SIZE;
27133 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27134
27135 if (len & ~huge_page_mask(h))
27136 return -EINVAL;
27137 - if (len > TASK_SIZE)
27138 +
27139 +#ifdef CONFIG_PAX_SEGMEXEC
27140 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27141 + pax_task_size = SEGMEXEC_TASK_SIZE;
27142 +#endif
27143 +
27144 + pax_task_size -= PAGE_SIZE;
27145 +
27146 + if (len > pax_task_size)
27147 return -ENOMEM;
27148
27149 if (flags & MAP_FIXED) {
27150 @@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27151 return addr;
27152 }
27153
27154 +#ifdef CONFIG_PAX_RANDMMAP
27155 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27156 +#endif
27157 +
27158 if (addr) {
27159 addr = ALIGN(addr, huge_page_size(h));
27160 vma = find_vma(mm, addr);
27161 - if (TASK_SIZE - len >= addr &&
27162 - (!vma || addr + len <= vma->vm_start))
27163 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27164 return addr;
27165 }
27166 if (mm->get_unmapped_area == arch_get_unmapped_area)
27167 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27168 index d7aea41..0fc945b 100644
27169 --- a/arch/x86/mm/init.c
27170 +++ b/arch/x86/mm/init.c
27171 @@ -4,6 +4,7 @@
27172 #include <linux/swap.h>
27173 #include <linux/memblock.h>
27174 #include <linux/bootmem.h> /* for max_low_pfn */
27175 +#include <linux/tboot.h>
27176
27177 #include <asm/cacheflush.h>
27178 #include <asm/e820.h>
27179 @@ -16,6 +17,8 @@
27180 #include <asm/tlb.h>
27181 #include <asm/proto.h>
27182 #include <asm/dma.h> /* for MAX_DMA_PFN */
27183 +#include <asm/desc.h>
27184 +#include <asm/bios_ebda.h>
27185
27186 unsigned long __initdata pgt_buf_start;
27187 unsigned long __meminitdata pgt_buf_end;
27188 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27189 {
27190 int i;
27191 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27192 - unsigned long start = 0, good_end;
27193 + unsigned long start = 0x100000, good_end;
27194 phys_addr_t base;
27195
27196 for (i = 0; i < nr_range; i++) {
27197 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27198 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27199 * mmio resources as well as potential bios/acpi data regions.
27200 */
27201 +
27202 +#ifdef CONFIG_GRKERNSEC_KMEM
27203 +static unsigned int ebda_start __read_only;
27204 +static unsigned int ebda_end __read_only;
27205 +#endif
27206 +
27207 int devmem_is_allowed(unsigned long pagenr)
27208 {
27209 - if (pagenr < 256)
27210 +#ifdef CONFIG_GRKERNSEC_KMEM
27211 + /* allow BDA */
27212 + if (!pagenr)
27213 return 1;
27214 + /* allow EBDA */
27215 + if (pagenr >= ebda_start && pagenr < ebda_end)
27216 + return 1;
27217 + /* if tboot is in use, allow access to its hardcoded serial log range */
27218 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27219 + return 1;
27220 +#else
27221 + if (!pagenr)
27222 + return 1;
27223 +#ifdef CONFIG_VM86
27224 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27225 + return 1;
27226 +#endif
27227 +#endif
27228 +
27229 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27230 + return 1;
27231 +#ifdef CONFIG_GRKERNSEC_KMEM
27232 + /* throw out everything else below 1MB */
27233 + if (pagenr <= 256)
27234 + return 0;
27235 +#endif
27236 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27237 return 0;
27238 if (!page_is_ram(pagenr))
27239 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27240 #endif
27241 }
27242
27243 +#ifdef CONFIG_GRKERNSEC_KMEM
27244 +static inline void gr_init_ebda(void)
27245 +{
27246 + unsigned int ebda_addr;
27247 + unsigned int ebda_size = 0;
27248 +
27249 + ebda_addr = get_bios_ebda();
27250 + if (ebda_addr) {
27251 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27252 + ebda_size <<= 10;
27253 + }
27254 + if (ebda_addr && ebda_size) {
27255 + ebda_start = ebda_addr >> PAGE_SHIFT;
27256 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27257 + } else {
27258 + ebda_start = 0x9f000 >> PAGE_SHIFT;
27259 + ebda_end = 0xa0000 >> PAGE_SHIFT;
27260 + }
27261 +}
27262 +#else
27263 +static inline void gr_init_ebda(void) { }
27264 +#endif
27265 +
27266 void free_initmem(void)
27267 {
27268 +#ifdef CONFIG_PAX_KERNEXEC
27269 +#ifdef CONFIG_X86_32
27270 + /* PaX: limit KERNEL_CS to actual size */
27271 + unsigned long addr, limit;
27272 + struct desc_struct d;
27273 + int cpu;
27274 +#else
27275 + pgd_t *pgd;
27276 + pud_t *pud;
27277 + pmd_t *pmd;
27278 + unsigned long addr, end;
27279 +#endif
27280 +#endif
27281 +
27282 + gr_init_ebda();
27283 +
27284 +#ifdef CONFIG_PAX_KERNEXEC
27285 +#ifdef CONFIG_X86_32
27286 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27287 + limit = (limit - 1UL) >> PAGE_SHIFT;
27288 +
27289 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27290 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27291 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27292 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27293 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27294 + }
27295 +
27296 + /* PaX: make KERNEL_CS read-only */
27297 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27298 + if (!paravirt_enabled())
27299 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27300 +/*
27301 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27302 + pgd = pgd_offset_k(addr);
27303 + pud = pud_offset(pgd, addr);
27304 + pmd = pmd_offset(pud, addr);
27305 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27306 + }
27307 +*/
27308 +#ifdef CONFIG_X86_PAE
27309 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27310 +/*
27311 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27312 + pgd = pgd_offset_k(addr);
27313 + pud = pud_offset(pgd, addr);
27314 + pmd = pmd_offset(pud, addr);
27315 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27316 + }
27317 +*/
27318 +#endif
27319 +
27320 +#ifdef CONFIG_MODULES
27321 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27322 +#endif
27323 +
27324 +#else
27325 + /* PaX: make kernel code/rodata read-only, rest non-executable */
27326 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27327 + pgd = pgd_offset_k(addr);
27328 + pud = pud_offset(pgd, addr);
27329 + pmd = pmd_offset(pud, addr);
27330 + if (!pmd_present(*pmd))
27331 + continue;
27332 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27333 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27334 + else
27335 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27336 + }
27337 +
27338 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27339 + end = addr + KERNEL_IMAGE_SIZE;
27340 + for (; addr < end; addr += PMD_SIZE) {
27341 + pgd = pgd_offset_k(addr);
27342 + pud = pud_offset(pgd, addr);
27343 + pmd = pmd_offset(pud, addr);
27344 + if (!pmd_present(*pmd))
27345 + continue;
27346 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27347 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27348 + }
27349 +#endif
27350 +
27351 + flush_tlb_all();
27352 +#endif
27353 +
27354 free_init_pages("unused kernel memory",
27355 (unsigned long)(&__init_begin),
27356 (unsigned long)(&__init_end));
27357 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27358 index 745d66b..56bf568 100644
27359 --- a/arch/x86/mm/init_32.c
27360 +++ b/arch/x86/mm/init_32.c
27361 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27362 }
27363
27364 /*
27365 - * Creates a middle page table and puts a pointer to it in the
27366 - * given global directory entry. This only returns the gd entry
27367 - * in non-PAE compilation mode, since the middle layer is folded.
27368 - */
27369 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
27370 -{
27371 - pud_t *pud;
27372 - pmd_t *pmd_table;
27373 -
27374 -#ifdef CONFIG_X86_PAE
27375 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27376 - if (after_bootmem)
27377 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27378 - else
27379 - pmd_table = (pmd_t *)alloc_low_page();
27380 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27381 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27382 - pud = pud_offset(pgd, 0);
27383 - BUG_ON(pmd_table != pmd_offset(pud, 0));
27384 -
27385 - return pmd_table;
27386 - }
27387 -#endif
27388 - pud = pud_offset(pgd, 0);
27389 - pmd_table = pmd_offset(pud, 0);
27390 -
27391 - return pmd_table;
27392 -}
27393 -
27394 -/*
27395 * Create a page table and place a pointer to it in a middle page
27396 * directory entry:
27397 */
27398 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27399 page_table = (pte_t *)alloc_low_page();
27400
27401 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27402 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27403 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27404 +#else
27405 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27406 +#endif
27407 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27408 }
27409
27410 return pte_offset_kernel(pmd, 0);
27411 }
27412
27413 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
27414 +{
27415 + pud_t *pud;
27416 + pmd_t *pmd_table;
27417 +
27418 + pud = pud_offset(pgd, 0);
27419 + pmd_table = pmd_offset(pud, 0);
27420 +
27421 + return pmd_table;
27422 +}
27423 +
27424 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27425 {
27426 int pgd_idx = pgd_index(vaddr);
27427 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27428 int pgd_idx, pmd_idx;
27429 unsigned long vaddr;
27430 pgd_t *pgd;
27431 + pud_t *pud;
27432 pmd_t *pmd;
27433 pte_t *pte = NULL;
27434
27435 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27436 pgd = pgd_base + pgd_idx;
27437
27438 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27439 - pmd = one_md_table_init(pgd);
27440 - pmd = pmd + pmd_index(vaddr);
27441 + pud = pud_offset(pgd, vaddr);
27442 + pmd = pmd_offset(pud, vaddr);
27443 +
27444 +#ifdef CONFIG_X86_PAE
27445 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27446 +#endif
27447 +
27448 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27449 pmd++, pmd_idx++) {
27450 pte = page_table_kmap_check(one_page_table_init(pmd),
27451 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27452 }
27453 }
27454
27455 -static inline int is_kernel_text(unsigned long addr)
27456 +static inline int is_kernel_text(unsigned long start, unsigned long end)
27457 {
27458 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27459 - return 1;
27460 - return 0;
27461 + if ((start > ktla_ktva((unsigned long)_etext) ||
27462 + end <= ktla_ktva((unsigned long)_stext)) &&
27463 + (start > ktla_ktva((unsigned long)_einittext) ||
27464 + end <= ktla_ktva((unsigned long)_sinittext)) &&
27465 +
27466 +#ifdef CONFIG_ACPI_SLEEP
27467 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27468 +#endif
27469 +
27470 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27471 + return 0;
27472 + return 1;
27473 }
27474
27475 /*
27476 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27477 unsigned long last_map_addr = end;
27478 unsigned long start_pfn, end_pfn;
27479 pgd_t *pgd_base = swapper_pg_dir;
27480 - int pgd_idx, pmd_idx, pte_ofs;
27481 + unsigned int pgd_idx, pmd_idx, pte_ofs;
27482 unsigned long pfn;
27483 pgd_t *pgd;
27484 + pud_t *pud;
27485 pmd_t *pmd;
27486 pte_t *pte;
27487 unsigned pages_2m, pages_4k;
27488 @@ -280,8 +281,13 @@ repeat:
27489 pfn = start_pfn;
27490 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27491 pgd = pgd_base + pgd_idx;
27492 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27493 - pmd = one_md_table_init(pgd);
27494 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27495 + pud = pud_offset(pgd, 0);
27496 + pmd = pmd_offset(pud, 0);
27497 +
27498 +#ifdef CONFIG_X86_PAE
27499 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27500 +#endif
27501
27502 if (pfn >= end_pfn)
27503 continue;
27504 @@ -293,14 +299,13 @@ repeat:
27505 #endif
27506 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27507 pmd++, pmd_idx++) {
27508 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27509 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27510
27511 /*
27512 * Map with big pages if possible, otherwise
27513 * create normal page tables:
27514 */
27515 if (use_pse) {
27516 - unsigned int addr2;
27517 pgprot_t prot = PAGE_KERNEL_LARGE;
27518 /*
27519 * first pass will use the same initial
27520 @@ -310,11 +315,7 @@ repeat:
27521 __pgprot(PTE_IDENT_ATTR |
27522 _PAGE_PSE);
27523
27524 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27525 - PAGE_OFFSET + PAGE_SIZE-1;
27526 -
27527 - if (is_kernel_text(addr) ||
27528 - is_kernel_text(addr2))
27529 + if (is_kernel_text(address, address + PMD_SIZE))
27530 prot = PAGE_KERNEL_LARGE_EXEC;
27531
27532 pages_2m++;
27533 @@ -331,7 +332,7 @@ repeat:
27534 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27535 pte += pte_ofs;
27536 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27537 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27538 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27539 pgprot_t prot = PAGE_KERNEL;
27540 /*
27541 * first pass will use the same initial
27542 @@ -339,7 +340,7 @@ repeat:
27543 */
27544 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27545
27546 - if (is_kernel_text(addr))
27547 + if (is_kernel_text(address, address + PAGE_SIZE))
27548 prot = PAGE_KERNEL_EXEC;
27549
27550 pages_4k++;
27551 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27552
27553 pud = pud_offset(pgd, va);
27554 pmd = pmd_offset(pud, va);
27555 - if (!pmd_present(*pmd))
27556 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
27557 break;
27558
27559 pte = pte_offset_kernel(pmd, va);
27560 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27561
27562 static void __init pagetable_init(void)
27563 {
27564 - pgd_t *pgd_base = swapper_pg_dir;
27565 -
27566 - permanent_kmaps_init(pgd_base);
27567 + permanent_kmaps_init(swapper_pg_dir);
27568 }
27569
27570 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27571 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27572 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27573
27574 /* user-defined highmem size */
27575 @@ -728,6 +727,12 @@ void __init mem_init(void)
27576
27577 pci_iommu_alloc();
27578
27579 +#ifdef CONFIG_PAX_PER_CPU_PGD
27580 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27581 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27582 + KERNEL_PGD_PTRS);
27583 +#endif
27584 +
27585 #ifdef CONFIG_FLATMEM
27586 BUG_ON(!mem_map);
27587 #endif
27588 @@ -754,7 +759,7 @@ void __init mem_init(void)
27589 reservedpages++;
27590
27591 codesize = (unsigned long) &_etext - (unsigned long) &_text;
27592 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
27593 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
27594 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
27595
27596 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
27597 @@ -795,10 +800,10 @@ void __init mem_init(void)
27598 ((unsigned long)&__init_end -
27599 (unsigned long)&__init_begin) >> 10,
27600
27601 - (unsigned long)&_etext, (unsigned long)&_edata,
27602 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
27603 + (unsigned long)&_sdata, (unsigned long)&_edata,
27604 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
27605
27606 - (unsigned long)&_text, (unsigned long)&_etext,
27607 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
27608 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
27609
27610 /*
27611 @@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
27612 if (!kernel_set_to_readonly)
27613 return;
27614
27615 + start = ktla_ktva(start);
27616 pr_debug("Set kernel text: %lx - %lx for read write\n",
27617 start, start+size);
27618
27619 @@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
27620 if (!kernel_set_to_readonly)
27621 return;
27622
27623 + start = ktla_ktva(start);
27624 pr_debug("Set kernel text: %lx - %lx for read only\n",
27625 start, start+size);
27626
27627 @@ -918,6 +925,7 @@ void mark_rodata_ro(void)
27628 unsigned long start = PFN_ALIGN(_text);
27629 unsigned long size = PFN_ALIGN(_etext) - start;
27630
27631 + start = ktla_ktva(start);
27632 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
27633 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
27634 size >> 10);
27635 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
27636 index 75c9a6a..498d677 100644
27637 --- a/arch/x86/mm/init_64.c
27638 +++ b/arch/x86/mm/init_64.c
27639 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
27640 * around without checking the pgd every time.
27641 */
27642
27643 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
27644 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
27645 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27646
27647 int force_personality32;
27648 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27649
27650 for (address = start; address <= end; address += PGDIR_SIZE) {
27651 const pgd_t *pgd_ref = pgd_offset_k(address);
27652 +
27653 +#ifdef CONFIG_PAX_PER_CPU_PGD
27654 + unsigned long cpu;
27655 +#else
27656 struct page *page;
27657 +#endif
27658
27659 if (pgd_none(*pgd_ref))
27660 continue;
27661
27662 spin_lock(&pgd_lock);
27663 +
27664 +#ifdef CONFIG_PAX_PER_CPU_PGD
27665 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27666 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
27667 +#else
27668 list_for_each_entry(page, &pgd_list, lru) {
27669 pgd_t *pgd;
27670 spinlock_t *pgt_lock;
27671 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27672 /* the pgt_lock only for Xen */
27673 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27674 spin_lock(pgt_lock);
27675 +#endif
27676
27677 if (pgd_none(*pgd))
27678 set_pgd(pgd, *pgd_ref);
27679 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27680 BUG_ON(pgd_page_vaddr(*pgd)
27681 != pgd_page_vaddr(*pgd_ref));
27682
27683 +#ifndef CONFIG_PAX_PER_CPU_PGD
27684 spin_unlock(pgt_lock);
27685 +#endif
27686 +
27687 }
27688 spin_unlock(&pgd_lock);
27689 }
27690 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
27691 {
27692 if (pgd_none(*pgd)) {
27693 pud_t *pud = (pud_t *)spp_getpage();
27694 - pgd_populate(&init_mm, pgd, pud);
27695 + pgd_populate_kernel(&init_mm, pgd, pud);
27696 if (pud != pud_offset(pgd, 0))
27697 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
27698 pud, pud_offset(pgd, 0));
27699 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
27700 {
27701 if (pud_none(*pud)) {
27702 pmd_t *pmd = (pmd_t *) spp_getpage();
27703 - pud_populate(&init_mm, pud, pmd);
27704 + pud_populate_kernel(&init_mm, pud, pmd);
27705 if (pmd != pmd_offset(pud, 0))
27706 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
27707 pmd, pmd_offset(pud, 0));
27708 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
27709 pmd = fill_pmd(pud, vaddr);
27710 pte = fill_pte(pmd, vaddr);
27711
27712 + pax_open_kernel();
27713 set_pte(pte, new_pte);
27714 + pax_close_kernel();
27715
27716 /*
27717 * It's enough to flush this one mapping.
27718 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
27719 pgd = pgd_offset_k((unsigned long)__va(phys));
27720 if (pgd_none(*pgd)) {
27721 pud = (pud_t *) spp_getpage();
27722 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
27723 - _PAGE_USER));
27724 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
27725 }
27726 pud = pud_offset(pgd, (unsigned long)__va(phys));
27727 if (pud_none(*pud)) {
27728 pmd = (pmd_t *) spp_getpage();
27729 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
27730 - _PAGE_USER));
27731 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
27732 }
27733 pmd = pmd_offset(pud, phys);
27734 BUG_ON(!pmd_none(*pmd));
27735 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
27736 if (pfn >= pgt_buf_top)
27737 panic("alloc_low_page: ran out of memory");
27738
27739 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27740 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27741 clear_page(adr);
27742 *phys = pfn * PAGE_SIZE;
27743 return adr;
27744 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
27745
27746 phys = __pa(virt);
27747 left = phys & (PAGE_SIZE - 1);
27748 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27749 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27750 adr = (void *)(((unsigned long)adr) | left);
27751
27752 return adr;
27753 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
27754 unmap_low_page(pmd);
27755
27756 spin_lock(&init_mm.page_table_lock);
27757 - pud_populate(&init_mm, pud, __va(pmd_phys));
27758 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
27759 spin_unlock(&init_mm.page_table_lock);
27760 }
27761 __flush_tlb_all();
27762 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
27763 unmap_low_page(pud);
27764
27765 spin_lock(&init_mm.page_table_lock);
27766 - pgd_populate(&init_mm, pgd, __va(pud_phys));
27767 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
27768 spin_unlock(&init_mm.page_table_lock);
27769 pgd_changed = true;
27770 }
27771 @@ -693,6 +707,12 @@ void __init mem_init(void)
27772
27773 pci_iommu_alloc();
27774
27775 +#ifdef CONFIG_PAX_PER_CPU_PGD
27776 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27777 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27778 + KERNEL_PGD_PTRS);
27779 +#endif
27780 +
27781 /* clear_bss() already clear the empty_zero_page */
27782
27783 reservedpages = 0;
27784 @@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
27785 static struct vm_area_struct gate_vma = {
27786 .vm_start = VSYSCALL_START,
27787 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
27788 - .vm_page_prot = PAGE_READONLY_EXEC,
27789 - .vm_flags = VM_READ | VM_EXEC
27790 + .vm_page_prot = PAGE_READONLY,
27791 + .vm_flags = VM_READ
27792 };
27793
27794 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27795 @@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
27796
27797 const char *arch_vma_name(struct vm_area_struct *vma)
27798 {
27799 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27800 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27801 return "[vdso]";
27802 if (vma == &gate_vma)
27803 return "[vsyscall]";
27804 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
27805 index 7b179b4..6bd1777 100644
27806 --- a/arch/x86/mm/iomap_32.c
27807 +++ b/arch/x86/mm/iomap_32.c
27808 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
27809 type = kmap_atomic_idx_push();
27810 idx = type + KM_TYPE_NR * smp_processor_id();
27811 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27812 +
27813 + pax_open_kernel();
27814 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
27815 + pax_close_kernel();
27816 +
27817 arch_flush_lazy_mmu_mode();
27818
27819 return (void *)vaddr;
27820 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
27821 index 78fe3f1..2f9433c 100644
27822 --- a/arch/x86/mm/ioremap.c
27823 +++ b/arch/x86/mm/ioremap.c
27824 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
27825 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
27826 int is_ram = page_is_ram(pfn);
27827
27828 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
27829 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
27830 return NULL;
27831 WARN_ON_ONCE(is_ram);
27832 }
27833 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
27834 *
27835 * Caller must ensure there is only one unmapping for the same pointer.
27836 */
27837 -void iounmap(volatile void __iomem *addr)
27838 +void iounmap(const volatile void __iomem *addr)
27839 {
27840 struct vm_struct *p, *o;
27841
27842 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
27843
27844 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
27845 if (page_is_ram(start >> PAGE_SHIFT))
27846 +#ifdef CONFIG_HIGHMEM
27847 + if ((start >> PAGE_SHIFT) < max_low_pfn)
27848 +#endif
27849 return __va(phys);
27850
27851 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
27852 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
27853 early_param("early_ioremap_debug", early_ioremap_debug_setup);
27854
27855 static __initdata int after_paging_init;
27856 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
27857 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
27858
27859 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
27860 {
27861 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
27862 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
27863
27864 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
27865 - memset(bm_pte, 0, sizeof(bm_pte));
27866 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
27867 + pmd_populate_user(&init_mm, pmd, bm_pte);
27868
27869 /*
27870 * The boot-ioremap range spans multiple pmds, for which
27871 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
27872 index d87dd6d..bf3fa66 100644
27873 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
27874 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
27875 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
27876 * memory (e.g. tracked pages)? For now, we need this to avoid
27877 * invoking kmemcheck for PnP BIOS calls.
27878 */
27879 - if (regs->flags & X86_VM_MASK)
27880 + if (v8086_mode(regs))
27881 return false;
27882 - if (regs->cs != __KERNEL_CS)
27883 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
27884 return false;
27885
27886 pte = kmemcheck_pte_lookup(address);
27887 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
27888 index 845df68..1d8d29f 100644
27889 --- a/arch/x86/mm/mmap.c
27890 +++ b/arch/x86/mm/mmap.c
27891 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
27892 * Leave an at least ~128 MB hole with possible stack randomization.
27893 */
27894 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
27895 -#define MAX_GAP (TASK_SIZE/6*5)
27896 +#define MAX_GAP (pax_task_size/6*5)
27897
27898 static int mmap_is_legacy(void)
27899 {
27900 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
27901 return rnd << PAGE_SHIFT;
27902 }
27903
27904 -static unsigned long mmap_base(void)
27905 +static unsigned long mmap_base(struct mm_struct *mm)
27906 {
27907 unsigned long gap = rlimit(RLIMIT_STACK);
27908 + unsigned long pax_task_size = TASK_SIZE;
27909 +
27910 +#ifdef CONFIG_PAX_SEGMEXEC
27911 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27912 + pax_task_size = SEGMEXEC_TASK_SIZE;
27913 +#endif
27914
27915 if (gap < MIN_GAP)
27916 gap = MIN_GAP;
27917 else if (gap > MAX_GAP)
27918 gap = MAX_GAP;
27919
27920 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
27921 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
27922 }
27923
27924 /*
27925 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
27926 * does, but not when emulating X86_32
27927 */
27928 -static unsigned long mmap_legacy_base(void)
27929 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
27930 {
27931 - if (mmap_is_ia32())
27932 + if (mmap_is_ia32()) {
27933 +
27934 +#ifdef CONFIG_PAX_SEGMEXEC
27935 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27936 + return SEGMEXEC_TASK_UNMAPPED_BASE;
27937 + else
27938 +#endif
27939 +
27940 return TASK_UNMAPPED_BASE;
27941 - else
27942 + } else
27943 return TASK_UNMAPPED_BASE + mmap_rnd();
27944 }
27945
27946 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
27947 void arch_pick_mmap_layout(struct mm_struct *mm)
27948 {
27949 if (mmap_is_legacy()) {
27950 - mm->mmap_base = mmap_legacy_base();
27951 + mm->mmap_base = mmap_legacy_base(mm);
27952 +
27953 +#ifdef CONFIG_PAX_RANDMMAP
27954 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27955 + mm->mmap_base += mm->delta_mmap;
27956 +#endif
27957 +
27958 mm->get_unmapped_area = arch_get_unmapped_area;
27959 mm->unmap_area = arch_unmap_area;
27960 } else {
27961 - mm->mmap_base = mmap_base();
27962 + mm->mmap_base = mmap_base(mm);
27963 +
27964 +#ifdef CONFIG_PAX_RANDMMAP
27965 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27966 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
27967 +#endif
27968 +
27969 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
27970 mm->unmap_area = arch_unmap_area_topdown;
27971 }
27972 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
27973 index dc0b727..f612039 100644
27974 --- a/arch/x86/mm/mmio-mod.c
27975 +++ b/arch/x86/mm/mmio-mod.c
27976 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
27977 break;
27978 default:
27979 {
27980 - unsigned char *ip = (unsigned char *)instptr;
27981 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
27982 my_trace->opcode = MMIO_UNKNOWN_OP;
27983 my_trace->width = 0;
27984 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
27985 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
27986 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
27987 void __iomem *addr)
27988 {
27989 - static atomic_t next_id;
27990 + static atomic_unchecked_t next_id;
27991 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
27992 /* These are page-unaligned. */
27993 struct mmiotrace_map map = {
27994 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
27995 .private = trace
27996 },
27997 .phys = offset,
27998 - .id = atomic_inc_return(&next_id)
27999 + .id = atomic_inc_return_unchecked(&next_id)
28000 };
28001 map.map_id = trace->id;
28002
28003 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28004 ioremap_trace_core(offset, size, addr);
28005 }
28006
28007 -static void iounmap_trace_core(volatile void __iomem *addr)
28008 +static void iounmap_trace_core(const volatile void __iomem *addr)
28009 {
28010 struct mmiotrace_map map = {
28011 .phys = 0,
28012 @@ -328,7 +328,7 @@ not_enabled:
28013 }
28014 }
28015
28016 -void mmiotrace_iounmap(volatile void __iomem *addr)
28017 +void mmiotrace_iounmap(const volatile void __iomem *addr)
28018 {
28019 might_sleep();
28020 if (is_enabled()) /* recheck and proper locking in *_core() */
28021 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28022 index b008656..773eac2 100644
28023 --- a/arch/x86/mm/pageattr-test.c
28024 +++ b/arch/x86/mm/pageattr-test.c
28025 @@ -36,7 +36,7 @@ enum {
28026
28027 static int pte_testbit(pte_t pte)
28028 {
28029 - return pte_flags(pte) & _PAGE_UNUSED1;
28030 + return pte_flags(pte) & _PAGE_CPA_TEST;
28031 }
28032
28033 struct split_state {
28034 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28035 index a718e0d..77419bc 100644
28036 --- a/arch/x86/mm/pageattr.c
28037 +++ b/arch/x86/mm/pageattr.c
28038 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28039 */
28040 #ifdef CONFIG_PCI_BIOS
28041 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28042 - pgprot_val(forbidden) |= _PAGE_NX;
28043 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28044 #endif
28045
28046 /*
28047 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28048 * Does not cover __inittext since that is gone later on. On
28049 * 64bit we do not enforce !NX on the low mapping
28050 */
28051 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
28052 - pgprot_val(forbidden) |= _PAGE_NX;
28053 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28054 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28055
28056 +#ifdef CONFIG_DEBUG_RODATA
28057 /*
28058 * The .rodata section needs to be read-only. Using the pfn
28059 * catches all aliases.
28060 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28061 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28062 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28063 pgprot_val(forbidden) |= _PAGE_RW;
28064 +#endif
28065
28066 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28067 /*
28068 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28069 }
28070 #endif
28071
28072 +#ifdef CONFIG_PAX_KERNEXEC
28073 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28074 + pgprot_val(forbidden) |= _PAGE_RW;
28075 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28076 + }
28077 +#endif
28078 +
28079 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28080
28081 return prot;
28082 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28083 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28084 {
28085 /* change init_mm */
28086 + pax_open_kernel();
28087 set_pte_atomic(kpte, pte);
28088 +
28089 #ifdef CONFIG_X86_32
28090 if (!SHARED_KERNEL_PMD) {
28091 +
28092 +#ifdef CONFIG_PAX_PER_CPU_PGD
28093 + unsigned long cpu;
28094 +#else
28095 struct page *page;
28096 +#endif
28097
28098 +#ifdef CONFIG_PAX_PER_CPU_PGD
28099 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28100 + pgd_t *pgd = get_cpu_pgd(cpu);
28101 +#else
28102 list_for_each_entry(page, &pgd_list, lru) {
28103 - pgd_t *pgd;
28104 + pgd_t *pgd = (pgd_t *)page_address(page);
28105 +#endif
28106 +
28107 pud_t *pud;
28108 pmd_t *pmd;
28109
28110 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
28111 + pgd += pgd_index(address);
28112 pud = pud_offset(pgd, address);
28113 pmd = pmd_offset(pud, address);
28114 set_pte_atomic((pte_t *)pmd, pte);
28115 }
28116 }
28117 #endif
28118 + pax_close_kernel();
28119 }
28120
28121 static int
28122 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28123 index 0eb572e..92f5c1e 100644
28124 --- a/arch/x86/mm/pat.c
28125 +++ b/arch/x86/mm/pat.c
28126 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28127
28128 if (!entry) {
28129 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28130 - current->comm, current->pid, start, end - 1);
28131 + current->comm, task_pid_nr(current), start, end - 1);
28132 return -EINVAL;
28133 }
28134
28135 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28136
28137 while (cursor < to) {
28138 if (!devmem_is_allowed(pfn)) {
28139 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28140 - current->comm, from, to - 1);
28141 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28142 + current->comm, from, to - 1, cursor);
28143 return 0;
28144 }
28145 cursor += PAGE_SIZE;
28146 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28147 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28148 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28149 "for [mem %#010Lx-%#010Lx]\n",
28150 - current->comm, current->pid,
28151 + current->comm, task_pid_nr(current),
28152 cattr_name(flags),
28153 base, (unsigned long long)(base + size-1));
28154 return -EINVAL;
28155 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28156 flags = lookup_memtype(paddr);
28157 if (want_flags != flags) {
28158 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28159 - current->comm, current->pid,
28160 + current->comm, task_pid_nr(current),
28161 cattr_name(want_flags),
28162 (unsigned long long)paddr,
28163 (unsigned long long)(paddr + size - 1),
28164 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28165 free_memtype(paddr, paddr + size);
28166 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28167 " for [mem %#010Lx-%#010Lx], got %s\n",
28168 - current->comm, current->pid,
28169 + current->comm, task_pid_nr(current),
28170 cattr_name(want_flags),
28171 (unsigned long long)paddr,
28172 (unsigned long long)(paddr + size - 1),
28173 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28174 index 9f0614d..92ae64a 100644
28175 --- a/arch/x86/mm/pf_in.c
28176 +++ b/arch/x86/mm/pf_in.c
28177 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28178 int i;
28179 enum reason_type rv = OTHERS;
28180
28181 - p = (unsigned char *)ins_addr;
28182 + p = (unsigned char *)ktla_ktva(ins_addr);
28183 p += skip_prefix(p, &prf);
28184 p += get_opcode(p, &opcode);
28185
28186 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28187 struct prefix_bits prf;
28188 int i;
28189
28190 - p = (unsigned char *)ins_addr;
28191 + p = (unsigned char *)ktla_ktva(ins_addr);
28192 p += skip_prefix(p, &prf);
28193 p += get_opcode(p, &opcode);
28194
28195 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28196 struct prefix_bits prf;
28197 int i;
28198
28199 - p = (unsigned char *)ins_addr;
28200 + p = (unsigned char *)ktla_ktva(ins_addr);
28201 p += skip_prefix(p, &prf);
28202 p += get_opcode(p, &opcode);
28203
28204 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28205 struct prefix_bits prf;
28206 int i;
28207
28208 - p = (unsigned char *)ins_addr;
28209 + p = (unsigned char *)ktla_ktva(ins_addr);
28210 p += skip_prefix(p, &prf);
28211 p += get_opcode(p, &opcode);
28212 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28213 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28214 struct prefix_bits prf;
28215 int i;
28216
28217 - p = (unsigned char *)ins_addr;
28218 + p = (unsigned char *)ktla_ktva(ins_addr);
28219 p += skip_prefix(p, &prf);
28220 p += get_opcode(p, &opcode);
28221 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28222 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28223 index e27fbf8..8b56dc9 100644
28224 --- a/arch/x86/mm/pgtable.c
28225 +++ b/arch/x86/mm/pgtable.c
28226 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28227 list_del(&page->lru);
28228 }
28229
28230 -#define UNSHARED_PTRS_PER_PGD \
28231 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28232 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28233 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28234
28235 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28236 +{
28237 + unsigned int count = USER_PGD_PTRS;
28238
28239 + while (count--)
28240 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28241 +}
28242 +#endif
28243 +
28244 +#ifdef CONFIG_PAX_PER_CPU_PGD
28245 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28246 +{
28247 + unsigned int count = USER_PGD_PTRS;
28248 +
28249 + while (count--) {
28250 + pgd_t pgd;
28251 +
28252 +#ifdef CONFIG_X86_64
28253 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28254 +#else
28255 + pgd = *src++;
28256 +#endif
28257 +
28258 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28259 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28260 +#endif
28261 +
28262 + *dst++ = pgd;
28263 + }
28264 +
28265 +}
28266 +#endif
28267 +
28268 +#ifdef CONFIG_X86_64
28269 +#define pxd_t pud_t
28270 +#define pyd_t pgd_t
28271 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28272 +#define pxd_free(mm, pud) pud_free((mm), (pud))
28273 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28274 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
28275 +#define PYD_SIZE PGDIR_SIZE
28276 +#else
28277 +#define pxd_t pmd_t
28278 +#define pyd_t pud_t
28279 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28280 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
28281 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28282 +#define pyd_offset(mm, address) pud_offset((mm), (address))
28283 +#define PYD_SIZE PUD_SIZE
28284 +#endif
28285 +
28286 +#ifdef CONFIG_PAX_PER_CPU_PGD
28287 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28288 +static inline void pgd_dtor(pgd_t *pgd) {}
28289 +#else
28290 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28291 {
28292 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28293 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28294 pgd_list_del(pgd);
28295 spin_unlock(&pgd_lock);
28296 }
28297 +#endif
28298
28299 /*
28300 * List of all pgd's needed for non-PAE so it can invalidate entries
28301 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28302 * -- nyc
28303 */
28304
28305 -#ifdef CONFIG_X86_PAE
28306 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28307 /*
28308 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28309 * updating the top-level pagetable entries to guarantee the
28310 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28311 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28312 * and initialize the kernel pmds here.
28313 */
28314 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28315 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28316
28317 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28318 {
28319 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28320 */
28321 flush_tlb_mm(mm);
28322 }
28323 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28324 +#define PREALLOCATED_PXDS USER_PGD_PTRS
28325 #else /* !CONFIG_X86_PAE */
28326
28327 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28328 -#define PREALLOCATED_PMDS 0
28329 +#define PREALLOCATED_PXDS 0
28330
28331 #endif /* CONFIG_X86_PAE */
28332
28333 -static void free_pmds(pmd_t *pmds[])
28334 +static void free_pxds(pxd_t *pxds[])
28335 {
28336 int i;
28337
28338 - for(i = 0; i < PREALLOCATED_PMDS; i++)
28339 - if (pmds[i])
28340 - free_page((unsigned long)pmds[i]);
28341 + for(i = 0; i < PREALLOCATED_PXDS; i++)
28342 + if (pxds[i])
28343 + free_page((unsigned long)pxds[i]);
28344 }
28345
28346 -static int preallocate_pmds(pmd_t *pmds[])
28347 +static int preallocate_pxds(pxd_t *pxds[])
28348 {
28349 int i;
28350 bool failed = false;
28351
28352 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28353 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28354 - if (pmd == NULL)
28355 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28356 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28357 + if (pxd == NULL)
28358 failed = true;
28359 - pmds[i] = pmd;
28360 + pxds[i] = pxd;
28361 }
28362
28363 if (failed) {
28364 - free_pmds(pmds);
28365 + free_pxds(pxds);
28366 return -ENOMEM;
28367 }
28368
28369 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28370 * preallocate which never got a corresponding vma will need to be
28371 * freed manually.
28372 */
28373 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28374 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28375 {
28376 int i;
28377
28378 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28379 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28380 pgd_t pgd = pgdp[i];
28381
28382 if (pgd_val(pgd) != 0) {
28383 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28384 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28385
28386 - pgdp[i] = native_make_pgd(0);
28387 + set_pgd(pgdp + i, native_make_pgd(0));
28388
28389 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28390 - pmd_free(mm, pmd);
28391 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28392 + pxd_free(mm, pxd);
28393 }
28394 }
28395 }
28396
28397 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28398 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28399 {
28400 - pud_t *pud;
28401 + pyd_t *pyd;
28402 unsigned long addr;
28403 int i;
28404
28405 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28406 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28407 return;
28408
28409 - pud = pud_offset(pgd, 0);
28410 +#ifdef CONFIG_X86_64
28411 + pyd = pyd_offset(mm, 0L);
28412 +#else
28413 + pyd = pyd_offset(pgd, 0L);
28414 +#endif
28415
28416 - for (addr = i = 0; i < PREALLOCATED_PMDS;
28417 - i++, pud++, addr += PUD_SIZE) {
28418 - pmd_t *pmd = pmds[i];
28419 + for (addr = i = 0; i < PREALLOCATED_PXDS;
28420 + i++, pyd++, addr += PYD_SIZE) {
28421 + pxd_t *pxd = pxds[i];
28422
28423 if (i >= KERNEL_PGD_BOUNDARY)
28424 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28425 - sizeof(pmd_t) * PTRS_PER_PMD);
28426 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28427 + sizeof(pxd_t) * PTRS_PER_PMD);
28428
28429 - pud_populate(mm, pud, pmd);
28430 + pyd_populate(mm, pyd, pxd);
28431 }
28432 }
28433
28434 pgd_t *pgd_alloc(struct mm_struct *mm)
28435 {
28436 pgd_t *pgd;
28437 - pmd_t *pmds[PREALLOCATED_PMDS];
28438 + pxd_t *pxds[PREALLOCATED_PXDS];
28439
28440 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28441
28442 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28443
28444 mm->pgd = pgd;
28445
28446 - if (preallocate_pmds(pmds) != 0)
28447 + if (preallocate_pxds(pxds) != 0)
28448 goto out_free_pgd;
28449
28450 if (paravirt_pgd_alloc(mm) != 0)
28451 - goto out_free_pmds;
28452 + goto out_free_pxds;
28453
28454 /*
28455 * Make sure that pre-populating the pmds is atomic with
28456 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28457 spin_lock(&pgd_lock);
28458
28459 pgd_ctor(mm, pgd);
28460 - pgd_prepopulate_pmd(mm, pgd, pmds);
28461 + pgd_prepopulate_pxd(mm, pgd, pxds);
28462
28463 spin_unlock(&pgd_lock);
28464
28465 return pgd;
28466
28467 -out_free_pmds:
28468 - free_pmds(pmds);
28469 +out_free_pxds:
28470 + free_pxds(pxds);
28471 out_free_pgd:
28472 free_page((unsigned long)pgd);
28473 out:
28474 @@ -295,7 +356,7 @@ out:
28475
28476 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28477 {
28478 - pgd_mop_up_pmds(mm, pgd);
28479 + pgd_mop_up_pxds(mm, pgd);
28480 pgd_dtor(pgd);
28481 paravirt_pgd_free(mm, pgd);
28482 free_page((unsigned long)pgd);
28483 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28484 index a69bcb8..19068ab 100644
28485 --- a/arch/x86/mm/pgtable_32.c
28486 +++ b/arch/x86/mm/pgtable_32.c
28487 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28488 return;
28489 }
28490 pte = pte_offset_kernel(pmd, vaddr);
28491 +
28492 + pax_open_kernel();
28493 if (pte_val(pteval))
28494 set_pte_at(&init_mm, vaddr, pte, pteval);
28495 else
28496 pte_clear(&init_mm, vaddr, pte);
28497 + pax_close_kernel();
28498
28499 /*
28500 * It's enough to flush this one mapping.
28501 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28502 index 410531d..0f16030 100644
28503 --- a/arch/x86/mm/setup_nx.c
28504 +++ b/arch/x86/mm/setup_nx.c
28505 @@ -5,8 +5,10 @@
28506 #include <asm/pgtable.h>
28507 #include <asm/proto.h>
28508
28509 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28510 static int disable_nx __cpuinitdata;
28511
28512 +#ifndef CONFIG_PAX_PAGEEXEC
28513 /*
28514 * noexec = on|off
28515 *
28516 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28517 return 0;
28518 }
28519 early_param("noexec", noexec_setup);
28520 +#endif
28521 +
28522 +#endif
28523
28524 void __cpuinit x86_configure_nx(void)
28525 {
28526 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28527 if (cpu_has_nx && !disable_nx)
28528 __supported_pte_mask |= _PAGE_NX;
28529 else
28530 +#endif
28531 __supported_pte_mask &= ~_PAGE_NX;
28532 }
28533
28534 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28535 index 13a6b29..c2fff23 100644
28536 --- a/arch/x86/mm/tlb.c
28537 +++ b/arch/x86/mm/tlb.c
28538 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
28539 BUG();
28540 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28541 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28542 +
28543 +#ifndef CONFIG_PAX_PER_CPU_PGD
28544 load_cr3(swapper_pg_dir);
28545 +#endif
28546 +
28547 }
28548 }
28549 EXPORT_SYMBOL_GPL(leave_mm);
28550 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28551 index 877b9a1..a8ecf42 100644
28552 --- a/arch/x86/net/bpf_jit.S
28553 +++ b/arch/x86/net/bpf_jit.S
28554 @@ -9,6 +9,7 @@
28555 */
28556 #include <linux/linkage.h>
28557 #include <asm/dwarf2.h>
28558 +#include <asm/alternative-asm.h>
28559
28560 /*
28561 * Calling convention :
28562 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28563 jle bpf_slow_path_word
28564 mov (SKBDATA,%rsi),%eax
28565 bswap %eax /* ntohl() */
28566 + pax_force_retaddr
28567 ret
28568
28569 sk_load_half:
28570 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28571 jle bpf_slow_path_half
28572 movzwl (SKBDATA,%rsi),%eax
28573 rol $8,%ax # ntohs()
28574 + pax_force_retaddr
28575 ret
28576
28577 sk_load_byte:
28578 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28579 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28580 jle bpf_slow_path_byte
28581 movzbl (SKBDATA,%rsi),%eax
28582 + pax_force_retaddr
28583 ret
28584
28585 /**
28586 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28587 movzbl (SKBDATA,%rsi),%ebx
28588 and $15,%bl
28589 shl $2,%bl
28590 + pax_force_retaddr
28591 ret
28592
28593 /* rsi contains offset and can be scratched */
28594 @@ -109,6 +114,7 @@ bpf_slow_path_word:
28595 js bpf_error
28596 mov -12(%rbp),%eax
28597 bswap %eax
28598 + pax_force_retaddr
28599 ret
28600
28601 bpf_slow_path_half:
28602 @@ -117,12 +123,14 @@ bpf_slow_path_half:
28603 mov -12(%rbp),%ax
28604 rol $8,%ax
28605 movzwl %ax,%eax
28606 + pax_force_retaddr
28607 ret
28608
28609 bpf_slow_path_byte:
28610 bpf_slow_path_common(1)
28611 js bpf_error
28612 movzbl -12(%rbp),%eax
28613 + pax_force_retaddr
28614 ret
28615
28616 bpf_slow_path_byte_msh:
28617 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
28618 and $15,%al
28619 shl $2,%al
28620 xchg %eax,%ebx
28621 + pax_force_retaddr
28622 ret
28623
28624 #define sk_negative_common(SIZE) \
28625 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
28626 sk_negative_common(4)
28627 mov (%rax), %eax
28628 bswap %eax
28629 + pax_force_retaddr
28630 ret
28631
28632 bpf_slow_path_half_neg:
28633 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
28634 mov (%rax),%ax
28635 rol $8,%ax
28636 movzwl %ax,%eax
28637 + pax_force_retaddr
28638 ret
28639
28640 bpf_slow_path_byte_neg:
28641 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
28642 .globl sk_load_byte_negative_offset
28643 sk_negative_common(1)
28644 movzbl (%rax), %eax
28645 + pax_force_retaddr
28646 ret
28647
28648 bpf_slow_path_byte_msh_neg:
28649 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
28650 and $15,%al
28651 shl $2,%al
28652 xchg %eax,%ebx
28653 + pax_force_retaddr
28654 ret
28655
28656 bpf_error:
28657 @@ -197,4 +210,5 @@ bpf_error:
28658 xor %eax,%eax
28659 mov -8(%rbp),%rbx
28660 leaveq
28661 + pax_force_retaddr
28662 ret
28663 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
28664 index d11a470..3f9adff3 100644
28665 --- a/arch/x86/net/bpf_jit_comp.c
28666 +++ b/arch/x86/net/bpf_jit_comp.c
28667 @@ -12,6 +12,7 @@
28668 #include <linux/netdevice.h>
28669 #include <linux/filter.h>
28670 #include <linux/if_vlan.h>
28671 +#include <linux/random.h>
28672
28673 /*
28674 * Conventions :
28675 @@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
28676 return ptr + len;
28677 }
28678
28679 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28680 +#define MAX_INSTR_CODE_SIZE 96
28681 +#else
28682 +#define MAX_INSTR_CODE_SIZE 64
28683 +#endif
28684 +
28685 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
28686
28687 #define EMIT1(b1) EMIT(b1, 1)
28688 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
28689 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
28690 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
28691 +
28692 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28693 +/* original constant will appear in ecx */
28694 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
28695 +do { \
28696 + /* mov ecx, randkey */ \
28697 + EMIT1(0xb9); \
28698 + EMIT(_key, 4); \
28699 + /* xor ecx, randkey ^ off */ \
28700 + EMIT2(0x81, 0xf1); \
28701 + EMIT((_key) ^ (_off), 4); \
28702 +} while (0)
28703 +
28704 +#define EMIT1_off32(b1, _off) \
28705 +do { \
28706 + switch (b1) { \
28707 + case 0x05: /* add eax, imm32 */ \
28708 + case 0x2d: /* sub eax, imm32 */ \
28709 + case 0x25: /* and eax, imm32 */ \
28710 + case 0x0d: /* or eax, imm32 */ \
28711 + case 0xb8: /* mov eax, imm32 */ \
28712 + case 0x3d: /* cmp eax, imm32 */ \
28713 + case 0xa9: /* test eax, imm32 */ \
28714 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28715 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
28716 + break; \
28717 + case 0xbb: /* mov ebx, imm32 */ \
28718 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28719 + /* mov ebx, ecx */ \
28720 + EMIT2(0x89, 0xcb); \
28721 + break; \
28722 + case 0xbe: /* mov esi, imm32 */ \
28723 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28724 + /* mov esi, ecx */ \
28725 + EMIT2(0x89, 0xce); \
28726 + break; \
28727 + case 0xe9: /* jmp rel imm32 */ \
28728 + EMIT1(b1); \
28729 + EMIT(_off, 4); \
28730 + /* prevent fall-through, we're not called if off = 0 */ \
28731 + EMIT(0xcccccccc, 4); \
28732 + EMIT(0xcccccccc, 4); \
28733 + break; \
28734 + default: \
28735 + EMIT1(b1); \
28736 + EMIT(_off, 4); \
28737 + } \
28738 +} while (0)
28739 +
28740 +#define EMIT2_off32(b1, b2, _off) \
28741 +do { \
28742 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
28743 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
28744 + EMIT(randkey, 4); \
28745 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
28746 + EMIT((_off) - randkey, 4); \
28747 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
28748 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28749 + /* imul eax, ecx */ \
28750 + EMIT3(0x0f, 0xaf, 0xc1); \
28751 + } else { \
28752 + EMIT2(b1, b2); \
28753 + EMIT(_off, 4); \
28754 + } \
28755 +} while (0)
28756 +#else
28757 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
28758 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
28759 +#endif
28760
28761 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
28762 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
28763 @@ -90,6 +165,24 @@ do { \
28764 #define X86_JBE 0x76
28765 #define X86_JA 0x77
28766
28767 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28768 +#define APPEND_FLOW_VERIFY() \
28769 +do { \
28770 + /* mov ecx, randkey */ \
28771 + EMIT1(0xb9); \
28772 + EMIT(randkey, 4); \
28773 + /* cmp ecx, randkey */ \
28774 + EMIT2(0x81, 0xf9); \
28775 + EMIT(randkey, 4); \
28776 + /* jz after 8 int 3s */ \
28777 + EMIT2(0x74, 0x08); \
28778 + EMIT(0xcccccccc, 4); \
28779 + EMIT(0xcccccccc, 4); \
28780 +} while (0)
28781 +#else
28782 +#define APPEND_FLOW_VERIFY() do { } while (0)
28783 +#endif
28784 +
28785 #define EMIT_COND_JMP(op, offset) \
28786 do { \
28787 if (is_near(offset)) \
28788 @@ -97,6 +190,7 @@ do { \
28789 else { \
28790 EMIT2(0x0f, op + 0x10); \
28791 EMIT(offset, 4); /* jxx .+off32 */ \
28792 + APPEND_FLOW_VERIFY(); \
28793 } \
28794 } while (0)
28795
28796 @@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
28797 set_fs(old_fs);
28798 }
28799
28800 +struct bpf_jit_work {
28801 + struct work_struct work;
28802 + void *image;
28803 +};
28804 +
28805 #define CHOOSE_LOAD_FUNC(K, func) \
28806 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
28807
28808 void bpf_jit_compile(struct sk_filter *fp)
28809 {
28810 - u8 temp[64];
28811 + u8 temp[MAX_INSTR_CODE_SIZE];
28812 u8 *prog;
28813 unsigned int proglen, oldproglen = 0;
28814 int ilen, i;
28815 @@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
28816 unsigned int *addrs;
28817 const struct sock_filter *filter = fp->insns;
28818 int flen = fp->len;
28819 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28820 + unsigned int randkey;
28821 +#endif
28822
28823 if (!bpf_jit_enable)
28824 return;
28825 @@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
28826 if (addrs == NULL)
28827 return;
28828
28829 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
28830 + if (!fp->work)
28831 + goto out;
28832 +
28833 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28834 + randkey = get_random_int();
28835 +#endif
28836 +
28837 /* Before first pass, make a rough estimation of addrs[]
28838 - * each bpf instruction is translated to less than 64 bytes
28839 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
28840 */
28841 for (proglen = 0, i = 0; i < flen; i++) {
28842 - proglen += 64;
28843 + proglen += MAX_INSTR_CODE_SIZE;
28844 addrs[i] = proglen;
28845 }
28846 cleanup_addr = proglen; /* epilogue address */
28847 @@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
28848 case BPF_S_ALU_MUL_K: /* A *= K */
28849 if (is_imm8(K))
28850 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
28851 - else {
28852 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
28853 - EMIT(K, 4);
28854 - }
28855 + else
28856 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
28857 break;
28858 case BPF_S_ALU_DIV_X: /* A /= X; */
28859 seen |= SEEN_XREG;
28860 @@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
28861 break;
28862 case BPF_S_ALU_MOD_K: /* A %= K; */
28863 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
28864 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28865 + DILUTE_CONST_SEQUENCE(K, randkey);
28866 +#else
28867 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
28868 +#endif
28869 EMIT2(0xf7, 0xf1); /* div %ecx */
28870 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
28871 break;
28872 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
28873 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28874 + DILUTE_CONST_SEQUENCE(K, randkey);
28875 + // imul rax, rcx
28876 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
28877 +#else
28878 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
28879 EMIT(K, 4);
28880 +#endif
28881 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
28882 break;
28883 case BPF_S_ALU_AND_X:
28884 @@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
28885 if (is_imm8(K)) {
28886 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
28887 } else {
28888 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
28889 - EMIT(K, 4);
28890 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
28891 }
28892 } else {
28893 EMIT2(0x89,0xde); /* mov %ebx,%esi */
28894 @@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28895 break;
28896 default:
28897 /* hmm, too complex filter, give up with jit compiler */
28898 - goto out;
28899 + goto error;
28900 }
28901 ilen = prog - temp;
28902 if (image) {
28903 if (unlikely(proglen + ilen > oldproglen)) {
28904 pr_err("bpb_jit_compile fatal error\n");
28905 - kfree(addrs);
28906 - module_free(NULL, image);
28907 - return;
28908 + module_free_exec(NULL, image);
28909 + goto error;
28910 }
28911 + pax_open_kernel();
28912 memcpy(image + proglen, temp, ilen);
28913 + pax_close_kernel();
28914 }
28915 proglen += ilen;
28916 addrs[i] = proglen;
28917 @@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28918 break;
28919 }
28920 if (proglen == oldproglen) {
28921 - image = module_alloc(max_t(unsigned int,
28922 - proglen,
28923 - sizeof(struct work_struct)));
28924 + image = module_alloc_exec(proglen);
28925 if (!image)
28926 - goto out;
28927 + goto error;
28928 }
28929 oldproglen = proglen;
28930 }
28931 @@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28932 bpf_flush_icache(image, image + proglen);
28933
28934 fp->bpf_func = (void *)image;
28935 - }
28936 + } else
28937 +error:
28938 + kfree(fp->work);
28939 +
28940 out:
28941 kfree(addrs);
28942 return;
28943 @@ -707,18 +826,20 @@ out:
28944
28945 static void jit_free_defer(struct work_struct *arg)
28946 {
28947 - module_free(NULL, arg);
28948 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
28949 + kfree(arg);
28950 }
28951
28952 /* run from softirq, we must use a work_struct to call
28953 - * module_free() from process context
28954 + * module_free_exec() from process context
28955 */
28956 void bpf_jit_free(struct sk_filter *fp)
28957 {
28958 if (fp->bpf_func != sk_run_filter) {
28959 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
28960 + struct work_struct *work = &fp->work->work;
28961
28962 INIT_WORK(work, jit_free_defer);
28963 + fp->work->image = fp->bpf_func;
28964 schedule_work(work);
28965 }
28966 }
28967 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
28968 index d6aa6e8..266395a 100644
28969 --- a/arch/x86/oprofile/backtrace.c
28970 +++ b/arch/x86/oprofile/backtrace.c
28971 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
28972 struct stack_frame_ia32 *fp;
28973 unsigned long bytes;
28974
28975 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
28976 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
28977 if (bytes != sizeof(bufhead))
28978 return NULL;
28979
28980 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
28981 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
28982
28983 oprofile_add_trace(bufhead[0].return_address);
28984
28985 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
28986 struct stack_frame bufhead[2];
28987 unsigned long bytes;
28988
28989 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
28990 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
28991 if (bytes != sizeof(bufhead))
28992 return NULL;
28993
28994 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
28995 {
28996 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
28997
28998 - if (!user_mode_vm(regs)) {
28999 + if (!user_mode(regs)) {
29000 unsigned long stack = kernel_stack_pointer(regs);
29001 if (depth)
29002 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29003 diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29004 index e9e6ed5..e47ae67 100644
29005 --- a/arch/x86/pci/amd_bus.c
29006 +++ b/arch/x86/pci/amd_bus.c
29007 @@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29008 return NOTIFY_OK;
29009 }
29010
29011 -static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29012 +static struct notifier_block amd_cpu_notifier = {
29013 .notifier_call = amd_cpu_notify,
29014 };
29015
29016 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29017 index 6eb18c4..20d83de 100644
29018 --- a/arch/x86/pci/mrst.c
29019 +++ b/arch/x86/pci/mrst.c
29020 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29021 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29022 pci_mmcfg_late_init();
29023 pcibios_enable_irq = mrst_pci_irq_enable;
29024 - pci_root_ops = pci_mrst_ops;
29025 + pax_open_kernel();
29026 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29027 + pax_close_kernel();
29028 pci_soc_mode = 1;
29029 /* Continue with standard init */
29030 return 1;
29031 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29032 index c77b24a..c979855 100644
29033 --- a/arch/x86/pci/pcbios.c
29034 +++ b/arch/x86/pci/pcbios.c
29035 @@ -79,7 +79,7 @@ union bios32 {
29036 static struct {
29037 unsigned long address;
29038 unsigned short segment;
29039 -} bios32_indirect = { 0, __KERNEL_CS };
29040 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29041
29042 /*
29043 * Returns the entry point for the given service, NULL on error
29044 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29045 unsigned long length; /* %ecx */
29046 unsigned long entry; /* %edx */
29047 unsigned long flags;
29048 + struct desc_struct d, *gdt;
29049
29050 local_irq_save(flags);
29051 - __asm__("lcall *(%%edi); cld"
29052 +
29053 + gdt = get_cpu_gdt_table(smp_processor_id());
29054 +
29055 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29056 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29057 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29058 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29059 +
29060 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29061 : "=a" (return_code),
29062 "=b" (address),
29063 "=c" (length),
29064 "=d" (entry)
29065 : "0" (service),
29066 "1" (0),
29067 - "D" (&bios32_indirect));
29068 + "D" (&bios32_indirect),
29069 + "r"(__PCIBIOS_DS)
29070 + : "memory");
29071 +
29072 + pax_open_kernel();
29073 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29074 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29075 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29076 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29077 + pax_close_kernel();
29078 +
29079 local_irq_restore(flags);
29080
29081 switch (return_code) {
29082 - case 0:
29083 - return address + entry;
29084 - case 0x80: /* Not present */
29085 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29086 - return 0;
29087 - default: /* Shouldn't happen */
29088 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29089 - service, return_code);
29090 + case 0: {
29091 + int cpu;
29092 + unsigned char flags;
29093 +
29094 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29095 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29096 + printk(KERN_WARNING "bios32_service: not valid\n");
29097 return 0;
29098 + }
29099 + address = address + PAGE_OFFSET;
29100 + length += 16UL; /* some BIOSs underreport this... */
29101 + flags = 4;
29102 + if (length >= 64*1024*1024) {
29103 + length >>= PAGE_SHIFT;
29104 + flags |= 8;
29105 + }
29106 +
29107 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29108 + gdt = get_cpu_gdt_table(cpu);
29109 + pack_descriptor(&d, address, length, 0x9b, flags);
29110 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29111 + pack_descriptor(&d, address, length, 0x93, flags);
29112 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29113 + }
29114 + return entry;
29115 + }
29116 + case 0x80: /* Not present */
29117 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29118 + return 0;
29119 + default: /* Shouldn't happen */
29120 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29121 + service, return_code);
29122 + return 0;
29123 }
29124 }
29125
29126 static struct {
29127 unsigned long address;
29128 unsigned short segment;
29129 -} pci_indirect = { 0, __KERNEL_CS };
29130 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29131
29132 -static int pci_bios_present;
29133 +static int pci_bios_present __read_only;
29134
29135 static int check_pcibios(void)
29136 {
29137 @@ -131,11 +174,13 @@ static int check_pcibios(void)
29138 unsigned long flags, pcibios_entry;
29139
29140 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29141 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29142 + pci_indirect.address = pcibios_entry;
29143
29144 local_irq_save(flags);
29145 - __asm__(
29146 - "lcall *(%%edi); cld\n\t"
29147 + __asm__("movw %w6, %%ds\n\t"
29148 + "lcall *%%ss:(%%edi); cld\n\t"
29149 + "push %%ss\n\t"
29150 + "pop %%ds\n\t"
29151 "jc 1f\n\t"
29152 "xor %%ah, %%ah\n"
29153 "1:"
29154 @@ -144,7 +189,8 @@ static int check_pcibios(void)
29155 "=b" (ebx),
29156 "=c" (ecx)
29157 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29158 - "D" (&pci_indirect)
29159 + "D" (&pci_indirect),
29160 + "r" (__PCIBIOS_DS)
29161 : "memory");
29162 local_irq_restore(flags);
29163
29164 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29165
29166 switch (len) {
29167 case 1:
29168 - __asm__("lcall *(%%esi); cld\n\t"
29169 + __asm__("movw %w6, %%ds\n\t"
29170 + "lcall *%%ss:(%%esi); cld\n\t"
29171 + "push %%ss\n\t"
29172 + "pop %%ds\n\t"
29173 "jc 1f\n\t"
29174 "xor %%ah, %%ah\n"
29175 "1:"
29176 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29177 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29178 "b" (bx),
29179 "D" ((long)reg),
29180 - "S" (&pci_indirect));
29181 + "S" (&pci_indirect),
29182 + "r" (__PCIBIOS_DS));
29183 /*
29184 * Zero-extend the result beyond 8 bits, do not trust the
29185 * BIOS having done it:
29186 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29187 *value &= 0xff;
29188 break;
29189 case 2:
29190 - __asm__("lcall *(%%esi); cld\n\t"
29191 + __asm__("movw %w6, %%ds\n\t"
29192 + "lcall *%%ss:(%%esi); cld\n\t"
29193 + "push %%ss\n\t"
29194 + "pop %%ds\n\t"
29195 "jc 1f\n\t"
29196 "xor %%ah, %%ah\n"
29197 "1:"
29198 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29199 : "1" (PCIBIOS_READ_CONFIG_WORD),
29200 "b" (bx),
29201 "D" ((long)reg),
29202 - "S" (&pci_indirect));
29203 + "S" (&pci_indirect),
29204 + "r" (__PCIBIOS_DS));
29205 /*
29206 * Zero-extend the result beyond 16 bits, do not trust the
29207 * BIOS having done it:
29208 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29209 *value &= 0xffff;
29210 break;
29211 case 4:
29212 - __asm__("lcall *(%%esi); cld\n\t"
29213 + __asm__("movw %w6, %%ds\n\t"
29214 + "lcall *%%ss:(%%esi); cld\n\t"
29215 + "push %%ss\n\t"
29216 + "pop %%ds\n\t"
29217 "jc 1f\n\t"
29218 "xor %%ah, %%ah\n"
29219 "1:"
29220 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29221 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29222 "b" (bx),
29223 "D" ((long)reg),
29224 - "S" (&pci_indirect));
29225 + "S" (&pci_indirect),
29226 + "r" (__PCIBIOS_DS));
29227 break;
29228 }
29229
29230 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29231
29232 switch (len) {
29233 case 1:
29234 - __asm__("lcall *(%%esi); cld\n\t"
29235 + __asm__("movw %w6, %%ds\n\t"
29236 + "lcall *%%ss:(%%esi); cld\n\t"
29237 + "push %%ss\n\t"
29238 + "pop %%ds\n\t"
29239 "jc 1f\n\t"
29240 "xor %%ah, %%ah\n"
29241 "1:"
29242 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29243 "c" (value),
29244 "b" (bx),
29245 "D" ((long)reg),
29246 - "S" (&pci_indirect));
29247 + "S" (&pci_indirect),
29248 + "r" (__PCIBIOS_DS));
29249 break;
29250 case 2:
29251 - __asm__("lcall *(%%esi); cld\n\t"
29252 + __asm__("movw %w6, %%ds\n\t"
29253 + "lcall *%%ss:(%%esi); cld\n\t"
29254 + "push %%ss\n\t"
29255 + "pop %%ds\n\t"
29256 "jc 1f\n\t"
29257 "xor %%ah, %%ah\n"
29258 "1:"
29259 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29260 "c" (value),
29261 "b" (bx),
29262 "D" ((long)reg),
29263 - "S" (&pci_indirect));
29264 + "S" (&pci_indirect),
29265 + "r" (__PCIBIOS_DS));
29266 break;
29267 case 4:
29268 - __asm__("lcall *(%%esi); cld\n\t"
29269 + __asm__("movw %w6, %%ds\n\t"
29270 + "lcall *%%ss:(%%esi); cld\n\t"
29271 + "push %%ss\n\t"
29272 + "pop %%ds\n\t"
29273 "jc 1f\n\t"
29274 "xor %%ah, %%ah\n"
29275 "1:"
29276 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29277 "c" (value),
29278 "b" (bx),
29279 "D" ((long)reg),
29280 - "S" (&pci_indirect));
29281 + "S" (&pci_indirect),
29282 + "r" (__PCIBIOS_DS));
29283 break;
29284 }
29285
29286 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29287
29288 DBG("PCI: Fetching IRQ routing table... ");
29289 __asm__("push %%es\n\t"
29290 + "movw %w8, %%ds\n\t"
29291 "push %%ds\n\t"
29292 "pop %%es\n\t"
29293 - "lcall *(%%esi); cld\n\t"
29294 + "lcall *%%ss:(%%esi); cld\n\t"
29295 "pop %%es\n\t"
29296 + "push %%ss\n\t"
29297 + "pop %%ds\n"
29298 "jc 1f\n\t"
29299 "xor %%ah, %%ah\n"
29300 "1:"
29301 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29302 "1" (0),
29303 "D" ((long) &opt),
29304 "S" (&pci_indirect),
29305 - "m" (opt)
29306 + "m" (opt),
29307 + "r" (__PCIBIOS_DS)
29308 : "memory");
29309 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29310 if (ret & 0xff00)
29311 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29312 {
29313 int ret;
29314
29315 - __asm__("lcall *(%%esi); cld\n\t"
29316 + __asm__("movw %w5, %%ds\n\t"
29317 + "lcall *%%ss:(%%esi); cld\n\t"
29318 + "push %%ss\n\t"
29319 + "pop %%ds\n"
29320 "jc 1f\n\t"
29321 "xor %%ah, %%ah\n"
29322 "1:"
29323 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29324 : "0" (PCIBIOS_SET_PCI_HW_INT),
29325 "b" ((dev->bus->number << 8) | dev->devfn),
29326 "c" ((irq << 8) | (pin + 10)),
29327 - "S" (&pci_indirect));
29328 + "S" (&pci_indirect),
29329 + "r" (__PCIBIOS_DS));
29330 return !(ret & 0xff00);
29331 }
29332 EXPORT_SYMBOL(pcibios_set_irq_routing);
29333 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29334 index 40e4469..1ab536e 100644
29335 --- a/arch/x86/platform/efi/efi_32.c
29336 +++ b/arch/x86/platform/efi/efi_32.c
29337 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29338 {
29339 struct desc_ptr gdt_descr;
29340
29341 +#ifdef CONFIG_PAX_KERNEXEC
29342 + struct desc_struct d;
29343 +#endif
29344 +
29345 local_irq_save(efi_rt_eflags);
29346
29347 load_cr3(initial_page_table);
29348 __flush_tlb_all();
29349
29350 +#ifdef CONFIG_PAX_KERNEXEC
29351 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29352 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29353 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29354 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29355 +#endif
29356 +
29357 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29358 gdt_descr.size = GDT_SIZE - 1;
29359 load_gdt(&gdt_descr);
29360 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29361 {
29362 struct desc_ptr gdt_descr;
29363
29364 +#ifdef CONFIG_PAX_KERNEXEC
29365 + struct desc_struct d;
29366 +
29367 + memset(&d, 0, sizeof d);
29368 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29369 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29370 +#endif
29371 +
29372 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29373 gdt_descr.size = GDT_SIZE - 1;
29374 load_gdt(&gdt_descr);
29375 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29376 index fbe66e6..eae5e38 100644
29377 --- a/arch/x86/platform/efi/efi_stub_32.S
29378 +++ b/arch/x86/platform/efi/efi_stub_32.S
29379 @@ -6,7 +6,9 @@
29380 */
29381
29382 #include <linux/linkage.h>
29383 +#include <linux/init.h>
29384 #include <asm/page_types.h>
29385 +#include <asm/segment.h>
29386
29387 /*
29388 * efi_call_phys(void *, ...) is a function with variable parameters.
29389 @@ -20,7 +22,7 @@
29390 * service functions will comply with gcc calling convention, too.
29391 */
29392
29393 -.text
29394 +__INIT
29395 ENTRY(efi_call_phys)
29396 /*
29397 * 0. The function can only be called in Linux kernel. So CS has been
29398 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29399 * The mapping of lower virtual memory has been created in prelog and
29400 * epilog.
29401 */
29402 - movl $1f, %edx
29403 - subl $__PAGE_OFFSET, %edx
29404 - jmp *%edx
29405 +#ifdef CONFIG_PAX_KERNEXEC
29406 + movl $(__KERNEXEC_EFI_DS), %edx
29407 + mov %edx, %ds
29408 + mov %edx, %es
29409 + mov %edx, %ss
29410 + addl $2f,(1f)
29411 + ljmp *(1f)
29412 +
29413 +__INITDATA
29414 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29415 +.previous
29416 +
29417 +2:
29418 + subl $2b,(1b)
29419 +#else
29420 + jmp 1f-__PAGE_OFFSET
29421 1:
29422 +#endif
29423
29424 /*
29425 * 2. Now on the top of stack is the return
29426 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29427 * parameter 2, ..., param n. To make things easy, we save the return
29428 * address of efi_call_phys in a global variable.
29429 */
29430 - popl %edx
29431 - movl %edx, saved_return_addr
29432 - /* get the function pointer into ECX*/
29433 - popl %ecx
29434 - movl %ecx, efi_rt_function_ptr
29435 - movl $2f, %edx
29436 - subl $__PAGE_OFFSET, %edx
29437 - pushl %edx
29438 + popl (saved_return_addr)
29439 + popl (efi_rt_function_ptr)
29440
29441 /*
29442 * 3. Clear PG bit in %CR0.
29443 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29444 /*
29445 * 5. Call the physical function.
29446 */
29447 - jmp *%ecx
29448 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
29449
29450 -2:
29451 /*
29452 * 6. After EFI runtime service returns, control will return to
29453 * following instruction. We'd better readjust stack pointer first.
29454 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29455 movl %cr0, %edx
29456 orl $0x80000000, %edx
29457 movl %edx, %cr0
29458 - jmp 1f
29459 -1:
29460 +
29461 /*
29462 * 8. Now restore the virtual mode from flat mode by
29463 * adding EIP with PAGE_OFFSET.
29464 */
29465 - movl $1f, %edx
29466 - jmp *%edx
29467 +#ifdef CONFIG_PAX_KERNEXEC
29468 + movl $(__KERNEL_DS), %edx
29469 + mov %edx, %ds
29470 + mov %edx, %es
29471 + mov %edx, %ss
29472 + ljmp $(__KERNEL_CS),$1f
29473 +#else
29474 + jmp 1f+__PAGE_OFFSET
29475 +#endif
29476 1:
29477
29478 /*
29479 * 9. Balance the stack. And because EAX contain the return value,
29480 * we'd better not clobber it.
29481 */
29482 - leal efi_rt_function_ptr, %edx
29483 - movl (%edx), %ecx
29484 - pushl %ecx
29485 + pushl (efi_rt_function_ptr)
29486
29487 /*
29488 - * 10. Push the saved return address onto the stack and return.
29489 + * 10. Return to the saved return address.
29490 */
29491 - leal saved_return_addr, %edx
29492 - movl (%edx), %ecx
29493 - pushl %ecx
29494 - ret
29495 + jmpl *(saved_return_addr)
29496 ENDPROC(efi_call_phys)
29497 .previous
29498
29499 -.data
29500 +__INITDATA
29501 saved_return_addr:
29502 .long 0
29503 efi_rt_function_ptr:
29504 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
29505 index 4c07cca..2c8427d 100644
29506 --- a/arch/x86/platform/efi/efi_stub_64.S
29507 +++ b/arch/x86/platform/efi/efi_stub_64.S
29508 @@ -7,6 +7,7 @@
29509 */
29510
29511 #include <linux/linkage.h>
29512 +#include <asm/alternative-asm.h>
29513
29514 #define SAVE_XMM \
29515 mov %rsp, %rax; \
29516 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
29517 call *%rdi
29518 addq $32, %rsp
29519 RESTORE_XMM
29520 + pax_force_retaddr 0, 1
29521 ret
29522 ENDPROC(efi_call0)
29523
29524 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
29525 call *%rdi
29526 addq $32, %rsp
29527 RESTORE_XMM
29528 + pax_force_retaddr 0, 1
29529 ret
29530 ENDPROC(efi_call1)
29531
29532 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
29533 call *%rdi
29534 addq $32, %rsp
29535 RESTORE_XMM
29536 + pax_force_retaddr 0, 1
29537 ret
29538 ENDPROC(efi_call2)
29539
29540 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
29541 call *%rdi
29542 addq $32, %rsp
29543 RESTORE_XMM
29544 + pax_force_retaddr 0, 1
29545 ret
29546 ENDPROC(efi_call3)
29547
29548 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
29549 call *%rdi
29550 addq $32, %rsp
29551 RESTORE_XMM
29552 + pax_force_retaddr 0, 1
29553 ret
29554 ENDPROC(efi_call4)
29555
29556 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
29557 call *%rdi
29558 addq $48, %rsp
29559 RESTORE_XMM
29560 + pax_force_retaddr 0, 1
29561 ret
29562 ENDPROC(efi_call5)
29563
29564 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
29565 call *%rdi
29566 addq $48, %rsp
29567 RESTORE_XMM
29568 + pax_force_retaddr 0, 1
29569 ret
29570 ENDPROC(efi_call6)
29571 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
29572 index e31bcd8..f12dc46 100644
29573 --- a/arch/x86/platform/mrst/mrst.c
29574 +++ b/arch/x86/platform/mrst/mrst.c
29575 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
29576 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
29577 int sfi_mrtc_num;
29578
29579 -static void mrst_power_off(void)
29580 +static __noreturn void mrst_power_off(void)
29581 {
29582 + BUG();
29583 }
29584
29585 -static void mrst_reboot(void)
29586 +static __noreturn void mrst_reboot(void)
29587 {
29588 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
29589 + BUG();
29590 }
29591
29592 /* parse all the mtimer info to a static mtimer array */
29593 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
29594 index d6ee929..3637cb5 100644
29595 --- a/arch/x86/platform/olpc/olpc_dt.c
29596 +++ b/arch/x86/platform/olpc/olpc_dt.c
29597 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
29598 return res;
29599 }
29600
29601 -static struct of_pdt_ops prom_olpc_ops __initdata = {
29602 +static struct of_pdt_ops prom_olpc_ops __initconst = {
29603 .nextprop = olpc_dt_nextprop,
29604 .getproplen = olpc_dt_getproplen,
29605 .getproperty = olpc_dt_getproperty,
29606 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
29607 index 120cee1..b2db75a 100644
29608 --- a/arch/x86/power/cpu.c
29609 +++ b/arch/x86/power/cpu.c
29610 @@ -133,7 +133,7 @@ static void do_fpu_end(void)
29611 static void fix_processor_context(void)
29612 {
29613 int cpu = smp_processor_id();
29614 - struct tss_struct *t = &per_cpu(init_tss, cpu);
29615 + struct tss_struct *t = init_tss + cpu;
29616
29617 set_tss_desc(cpu, t); /*
29618 * This just modifies memory; should not be
29619 @@ -143,8 +143,6 @@ static void fix_processor_context(void)
29620 */
29621
29622 #ifdef CONFIG_X86_64
29623 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
29624 -
29625 syscall_init(); /* This sets MSR_*STAR and related */
29626 #endif
29627 load_TR_desc(); /* This does ltr */
29628 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
29629 index cbca565..bae7133 100644
29630 --- a/arch/x86/realmode/init.c
29631 +++ b/arch/x86/realmode/init.c
29632 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
29633 __va(real_mode_header->trampoline_header);
29634
29635 #ifdef CONFIG_X86_32
29636 - trampoline_header->start = __pa(startup_32_smp);
29637 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
29638 +
29639 +#ifdef CONFIG_PAX_KERNEXEC
29640 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
29641 +#endif
29642 +
29643 + trampoline_header->boot_cs = __BOOT_CS;
29644 trampoline_header->gdt_limit = __BOOT_DS + 7;
29645 trampoline_header->gdt_base = __pa(boot_gdt);
29646 #else
29647 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
29648 index 8869287..d577672 100644
29649 --- a/arch/x86/realmode/rm/Makefile
29650 +++ b/arch/x86/realmode/rm/Makefile
29651 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
29652 $(call cc-option, -fno-unit-at-a-time)) \
29653 $(call cc-option, -fno-stack-protector) \
29654 $(call cc-option, -mpreferred-stack-boundary=2)
29655 +ifdef CONSTIFY_PLUGIN
29656 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
29657 +endif
29658 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
29659 GCOV_PROFILE := n
29660 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
29661 index a28221d..93c40f1 100644
29662 --- a/arch/x86/realmode/rm/header.S
29663 +++ b/arch/x86/realmode/rm/header.S
29664 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
29665 #endif
29666 /* APM/BIOS reboot */
29667 .long pa_machine_real_restart_asm
29668 -#ifdef CONFIG_X86_64
29669 +#ifdef CONFIG_X86_32
29670 + .long __KERNEL_CS
29671 +#else
29672 .long __KERNEL32_CS
29673 #endif
29674 END(real_mode_header)
29675 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
29676 index c1b2791..f9e31c7 100644
29677 --- a/arch/x86/realmode/rm/trampoline_32.S
29678 +++ b/arch/x86/realmode/rm/trampoline_32.S
29679 @@ -25,6 +25,12 @@
29680 #include <asm/page_types.h>
29681 #include "realmode.h"
29682
29683 +#ifdef CONFIG_PAX_KERNEXEC
29684 +#define ta(X) (X)
29685 +#else
29686 +#define ta(X) (pa_ ## X)
29687 +#endif
29688 +
29689 .text
29690 .code16
29691
29692 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
29693
29694 cli # We should be safe anyway
29695
29696 - movl tr_start, %eax # where we need to go
29697 -
29698 movl $0xA5A5A5A5, trampoline_status
29699 # write marker for master knows we're running
29700
29701 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
29702 movw $1, %dx # protected mode (PE) bit
29703 lmsw %dx # into protected mode
29704
29705 - ljmpl $__BOOT_CS, $pa_startup_32
29706 + ljmpl *(trampoline_header)
29707
29708 .section ".text32","ax"
29709 .code32
29710 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
29711 .balign 8
29712 GLOBAL(trampoline_header)
29713 tr_start: .space 4
29714 - tr_gdt_pad: .space 2
29715 + tr_boot_cs: .space 2
29716 tr_gdt: .space 6
29717 END(trampoline_header)
29718
29719 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
29720 index bb360dc..3e5945f 100644
29721 --- a/arch/x86/realmode/rm/trampoline_64.S
29722 +++ b/arch/x86/realmode/rm/trampoline_64.S
29723 @@ -107,7 +107,7 @@ ENTRY(startup_32)
29724 wrmsr
29725
29726 # Enable paging and in turn activate Long Mode
29727 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
29728 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
29729 movl %eax, %cr0
29730
29731 /*
29732 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
29733 index 79d67bd..c7e1b90 100644
29734 --- a/arch/x86/tools/relocs.c
29735 +++ b/arch/x86/tools/relocs.c
29736 @@ -12,10 +12,13 @@
29737 #include <regex.h>
29738 #include <tools/le_byteshift.h>
29739
29740 +#include "../../../include/generated/autoconf.h"
29741 +
29742 static void die(char *fmt, ...);
29743
29744 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29745 static Elf32_Ehdr ehdr;
29746 +static Elf32_Phdr *phdr;
29747 static unsigned long reloc_count, reloc_idx;
29748 static unsigned long *relocs;
29749 static unsigned long reloc16_count, reloc16_idx;
29750 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
29751 }
29752 }
29753
29754 +static void read_phdrs(FILE *fp)
29755 +{
29756 + unsigned int i;
29757 +
29758 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
29759 + if (!phdr) {
29760 + die("Unable to allocate %d program headers\n",
29761 + ehdr.e_phnum);
29762 + }
29763 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
29764 + die("Seek to %d failed: %s\n",
29765 + ehdr.e_phoff, strerror(errno));
29766 + }
29767 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
29768 + die("Cannot read ELF program headers: %s\n",
29769 + strerror(errno));
29770 + }
29771 + for(i = 0; i < ehdr.e_phnum; i++) {
29772 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
29773 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
29774 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
29775 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
29776 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
29777 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
29778 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
29779 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
29780 + }
29781 +
29782 +}
29783 +
29784 static void read_shdrs(FILE *fp)
29785 {
29786 - int i;
29787 + unsigned int i;
29788 Elf32_Shdr shdr;
29789
29790 secs = calloc(ehdr.e_shnum, sizeof(struct section));
29791 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
29792
29793 static void read_strtabs(FILE *fp)
29794 {
29795 - int i;
29796 + unsigned int i;
29797 for (i = 0; i < ehdr.e_shnum; i++) {
29798 struct section *sec = &secs[i];
29799 if (sec->shdr.sh_type != SHT_STRTAB) {
29800 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
29801
29802 static void read_symtabs(FILE *fp)
29803 {
29804 - int i,j;
29805 + unsigned int i,j;
29806 for (i = 0; i < ehdr.e_shnum; i++) {
29807 struct section *sec = &secs[i];
29808 if (sec->shdr.sh_type != SHT_SYMTAB) {
29809 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
29810 }
29811
29812
29813 -static void read_relocs(FILE *fp)
29814 +static void read_relocs(FILE *fp, int use_real_mode)
29815 {
29816 - int i,j;
29817 + unsigned int i,j;
29818 + uint32_t base;
29819 +
29820 for (i = 0; i < ehdr.e_shnum; i++) {
29821 struct section *sec = &secs[i];
29822 if (sec->shdr.sh_type != SHT_REL) {
29823 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
29824 die("Cannot read symbol table: %s\n",
29825 strerror(errno));
29826 }
29827 + base = 0;
29828 +
29829 +#ifdef CONFIG_X86_32
29830 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
29831 + if (phdr[j].p_type != PT_LOAD )
29832 + continue;
29833 + 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)
29834 + continue;
29835 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
29836 + break;
29837 + }
29838 +#endif
29839 +
29840 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
29841 Elf32_Rel *rel = &sec->reltab[j];
29842 - rel->r_offset = elf32_to_cpu(rel->r_offset);
29843 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
29844 rel->r_info = elf32_to_cpu(rel->r_info);
29845 }
29846 }
29847 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
29848
29849 static void print_absolute_symbols(void)
29850 {
29851 - int i;
29852 + unsigned int i;
29853 printf("Absolute symbols\n");
29854 printf(" Num: Value Size Type Bind Visibility Name\n");
29855 for (i = 0; i < ehdr.e_shnum; i++) {
29856 struct section *sec = &secs[i];
29857 char *sym_strtab;
29858 - int j;
29859 + unsigned int j;
29860
29861 if (sec->shdr.sh_type != SHT_SYMTAB) {
29862 continue;
29863 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
29864
29865 static void print_absolute_relocs(void)
29866 {
29867 - int i, printed = 0;
29868 + unsigned int i, printed = 0;
29869
29870 for (i = 0; i < ehdr.e_shnum; i++) {
29871 struct section *sec = &secs[i];
29872 struct section *sec_applies, *sec_symtab;
29873 char *sym_strtab;
29874 Elf32_Sym *sh_symtab;
29875 - int j;
29876 + unsigned int j;
29877 if (sec->shdr.sh_type != SHT_REL) {
29878 continue;
29879 }
29880 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
29881 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29882 int use_real_mode)
29883 {
29884 - int i;
29885 + unsigned int i;
29886 /* Walk through the relocations */
29887 for (i = 0; i < ehdr.e_shnum; i++) {
29888 char *sym_strtab;
29889 Elf32_Sym *sh_symtab;
29890 struct section *sec_applies, *sec_symtab;
29891 - int j;
29892 + unsigned int j;
29893 struct section *sec = &secs[i];
29894
29895 if (sec->shdr.sh_type != SHT_REL) {
29896 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29897 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29898 r_type = ELF32_R_TYPE(rel->r_info);
29899
29900 + if (!use_real_mode) {
29901 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29902 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29903 + continue;
29904 +
29905 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29906 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29907 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29908 + continue;
29909 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29910 + continue;
29911 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29912 + continue;
29913 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29914 + continue;
29915 +#endif
29916 + }
29917 +
29918 shn_abs = sym->st_shndx == SHN_ABS;
29919
29920 switch (r_type) {
29921 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29922
29923 static void emit_relocs(int as_text, int use_real_mode)
29924 {
29925 - int i;
29926 + unsigned int i;
29927 /* Count how many relocations I have and allocate space for them. */
29928 reloc_count = 0;
29929 walk_relocs(count_reloc, use_real_mode);
29930 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
29931 fname, strerror(errno));
29932 }
29933 read_ehdr(fp);
29934 + read_phdrs(fp);
29935 read_shdrs(fp);
29936 read_strtabs(fp);
29937 read_symtabs(fp);
29938 - read_relocs(fp);
29939 + read_relocs(fp, use_real_mode);
29940 if (show_absolute_syms) {
29941 print_absolute_symbols();
29942 goto out;
29943 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29944 index fd14be1..e3c79c0 100644
29945 --- a/arch/x86/vdso/Makefile
29946 +++ b/arch/x86/vdso/Makefile
29947 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29948 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29949 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29950
29951 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29952 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29953 GCOV_PROFILE := n
29954
29955 #
29956 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29957 index 0faad64..39ef157 100644
29958 --- a/arch/x86/vdso/vdso32-setup.c
29959 +++ b/arch/x86/vdso/vdso32-setup.c
29960 @@ -25,6 +25,7 @@
29961 #include <asm/tlbflush.h>
29962 #include <asm/vdso.h>
29963 #include <asm/proto.h>
29964 +#include <asm/mman.h>
29965
29966 enum {
29967 VDSO_DISABLED = 0,
29968 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29969 void enable_sep_cpu(void)
29970 {
29971 int cpu = get_cpu();
29972 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
29973 + struct tss_struct *tss = init_tss + cpu;
29974
29975 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29976 put_cpu();
29977 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29978 gate_vma.vm_start = FIXADDR_USER_START;
29979 gate_vma.vm_end = FIXADDR_USER_END;
29980 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29981 - gate_vma.vm_page_prot = __P101;
29982 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29983
29984 return 0;
29985 }
29986 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29987 if (compat)
29988 addr = VDSO_HIGH_BASE;
29989 else {
29990 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29991 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29992 if (IS_ERR_VALUE(addr)) {
29993 ret = addr;
29994 goto up_fail;
29995 }
29996 }
29997
29998 - current->mm->context.vdso = (void *)addr;
29999 + current->mm->context.vdso = addr;
30000
30001 if (compat_uses_vma || !compat) {
30002 /*
30003 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30004 }
30005
30006 current_thread_info()->sysenter_return =
30007 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30008 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30009
30010 up_fail:
30011 if (ret)
30012 - current->mm->context.vdso = NULL;
30013 + current->mm->context.vdso = 0;
30014
30015 up_write(&mm->mmap_sem);
30016
30017 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30018
30019 const char *arch_vma_name(struct vm_area_struct *vma)
30020 {
30021 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30022 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30023 return "[vdso]";
30024 +
30025 +#ifdef CONFIG_PAX_SEGMEXEC
30026 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30027 + return "[vdso]";
30028 +#endif
30029 +
30030 return NULL;
30031 }
30032
30033 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30034 * Check to see if the corresponding task was created in compat vdso
30035 * mode.
30036 */
30037 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30038 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30039 return &gate_vma;
30040 return NULL;
30041 }
30042 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30043 index 431e875..cbb23f3 100644
30044 --- a/arch/x86/vdso/vma.c
30045 +++ b/arch/x86/vdso/vma.c
30046 @@ -16,8 +16,6 @@
30047 #include <asm/vdso.h>
30048 #include <asm/page.h>
30049
30050 -unsigned int __read_mostly vdso_enabled = 1;
30051 -
30052 extern char vdso_start[], vdso_end[];
30053 extern unsigned short vdso_sync_cpuid;
30054
30055 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30056 * unaligned here as a result of stack start randomization.
30057 */
30058 addr = PAGE_ALIGN(addr);
30059 - addr = align_vdso_addr(addr);
30060
30061 return addr;
30062 }
30063 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30064 unsigned size)
30065 {
30066 struct mm_struct *mm = current->mm;
30067 - unsigned long addr;
30068 + unsigned long addr = 0;
30069 int ret;
30070
30071 - if (!vdso_enabled)
30072 - return 0;
30073 -
30074 down_write(&mm->mmap_sem);
30075 +
30076 +#ifdef CONFIG_PAX_RANDMMAP
30077 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30078 +#endif
30079 +
30080 addr = vdso_addr(mm->start_stack, size);
30081 + addr = align_vdso_addr(addr);
30082 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30083 if (IS_ERR_VALUE(addr)) {
30084 ret = addr;
30085 goto up_fail;
30086 }
30087
30088 - current->mm->context.vdso = (void *)addr;
30089 + mm->context.vdso = addr;
30090
30091 ret = install_special_mapping(mm, addr, size,
30092 VM_READ|VM_EXEC|
30093 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30094 pages);
30095 - if (ret) {
30096 - current->mm->context.vdso = NULL;
30097 - goto up_fail;
30098 - }
30099 + if (ret)
30100 + mm->context.vdso = 0;
30101
30102 up_fail:
30103 up_write(&mm->mmap_sem);
30104 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30105 vdsox32_size);
30106 }
30107 #endif
30108 -
30109 -static __init int vdso_setup(char *s)
30110 -{
30111 - vdso_enabled = simple_strtoul(s, NULL, 0);
30112 - return 0;
30113 -}
30114 -__setup("vdso=", vdso_setup);
30115 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30116 index e014092..c76ab69 100644
30117 --- a/arch/x86/xen/enlighten.c
30118 +++ b/arch/x86/xen/enlighten.c
30119 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30120
30121 struct shared_info xen_dummy_shared_info;
30122
30123 -void *xen_initial_gdt;
30124 -
30125 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30126 __read_mostly int xen_have_vector_callback;
30127 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30128 @@ -495,8 +493,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30129 {
30130 unsigned long va = dtr->address;
30131 unsigned int size = dtr->size + 1;
30132 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30133 - unsigned long frames[pages];
30134 + unsigned long frames[65536 / PAGE_SIZE];
30135 int f;
30136
30137 /*
30138 @@ -544,8 +541,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30139 {
30140 unsigned long va = dtr->address;
30141 unsigned int size = dtr->size + 1;
30142 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30143 - unsigned long frames[pages];
30144 + unsigned long frames[65536 / PAGE_SIZE];
30145 int f;
30146
30147 /*
30148 @@ -938,7 +934,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30149 return 0;
30150 }
30151
30152 -static void set_xen_basic_apic_ops(void)
30153 +static void __init set_xen_basic_apic_ops(void)
30154 {
30155 apic->read = xen_apic_read;
30156 apic->write = xen_apic_write;
30157 @@ -1244,30 +1240,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30158 #endif
30159 };
30160
30161 -static void xen_reboot(int reason)
30162 +static __noreturn void xen_reboot(int reason)
30163 {
30164 struct sched_shutdown r = { .reason = reason };
30165
30166 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30167 - BUG();
30168 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30169 + BUG();
30170 }
30171
30172 -static void xen_restart(char *msg)
30173 +static __noreturn void xen_restart(char *msg)
30174 {
30175 xen_reboot(SHUTDOWN_reboot);
30176 }
30177
30178 -static void xen_emergency_restart(void)
30179 +static __noreturn void xen_emergency_restart(void)
30180 {
30181 xen_reboot(SHUTDOWN_reboot);
30182 }
30183
30184 -static void xen_machine_halt(void)
30185 +static __noreturn void xen_machine_halt(void)
30186 {
30187 xen_reboot(SHUTDOWN_poweroff);
30188 }
30189
30190 -static void xen_machine_power_off(void)
30191 +static __noreturn void xen_machine_power_off(void)
30192 {
30193 if (pm_power_off)
30194 pm_power_off();
30195 @@ -1369,7 +1365,17 @@ asmlinkage void __init xen_start_kernel(void)
30196 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30197
30198 /* Work out if we support NX */
30199 - x86_configure_nx();
30200 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30201 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30202 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30203 + unsigned l, h;
30204 +
30205 + __supported_pte_mask |= _PAGE_NX;
30206 + rdmsr(MSR_EFER, l, h);
30207 + l |= EFER_NX;
30208 + wrmsr(MSR_EFER, l, h);
30209 + }
30210 +#endif
30211
30212 xen_setup_features();
30213
30214 @@ -1398,14 +1404,7 @@ asmlinkage void __init xen_start_kernel(void)
30215 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30216 }
30217
30218 - machine_ops = xen_machine_ops;
30219 -
30220 - /*
30221 - * The only reliable way to retain the initial address of the
30222 - * percpu gdt_page is to remember it here, so we can go and
30223 - * mark it RW later, when the initial percpu area is freed.
30224 - */
30225 - xen_initial_gdt = &per_cpu(gdt_page, 0);
30226 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30227
30228 xen_smp_init();
30229
30230 @@ -1590,7 +1589,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30231 return NOTIFY_OK;
30232 }
30233
30234 -static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30235 +static struct notifier_block xen_hvm_cpu_notifier = {
30236 .notifier_call = xen_hvm_cpu_notify,
30237 };
30238
30239 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30240 index 01de35c..0bda07b 100644
30241 --- a/arch/x86/xen/mmu.c
30242 +++ b/arch/x86/xen/mmu.c
30243 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30244 /* L3_k[510] -> level2_kernel_pgt
30245 * L3_i[511] -> level2_fixmap_pgt */
30246 convert_pfn_mfn(level3_kernel_pgt);
30247 + convert_pfn_mfn(level3_vmalloc_start_pgt);
30248 + convert_pfn_mfn(level3_vmalloc_end_pgt);
30249 + convert_pfn_mfn(level3_vmemmap_pgt);
30250
30251 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30252 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30253 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30254 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30255 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30256 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30257 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30258 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30259 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30260 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30261 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30262 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30263 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30264 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30265
30266 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30267 pv_mmu_ops.set_pud = xen_set_pud;
30268 #if PAGETABLE_LEVELS == 4
30269 pv_mmu_ops.set_pgd = xen_set_pgd;
30270 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30271 #endif
30272
30273 /* This will work as long as patching hasn't happened yet
30274 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30275 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30276 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30277 .set_pgd = xen_set_pgd_hyper,
30278 + .set_pgd_batched = xen_set_pgd_hyper,
30279
30280 .alloc_pud = xen_alloc_pmd_init,
30281 .release_pud = xen_release_pmd_init,
30282 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30283 index 34bc4ce..c34aa24 100644
30284 --- a/arch/x86/xen/smp.c
30285 +++ b/arch/x86/xen/smp.c
30286 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30287 {
30288 BUG_ON(smp_processor_id() != 0);
30289 native_smp_prepare_boot_cpu();
30290 -
30291 - /* We've switched to the "real" per-cpu gdt, so make sure the
30292 - old memory can be recycled */
30293 - make_lowmem_page_readwrite(xen_initial_gdt);
30294 -
30295 xen_filter_cpu_maps();
30296 xen_setup_vcpu_info_placement();
30297 }
30298 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30299 gdt = get_cpu_gdt_table(cpu);
30300
30301 ctxt->flags = VGCF_IN_KERNEL;
30302 - ctxt->user_regs.ds = __USER_DS;
30303 - ctxt->user_regs.es = __USER_DS;
30304 + ctxt->user_regs.ds = __KERNEL_DS;
30305 + ctxt->user_regs.es = __KERNEL_DS;
30306 ctxt->user_regs.ss = __KERNEL_DS;
30307 #ifdef CONFIG_X86_32
30308 ctxt->user_regs.fs = __KERNEL_PERCPU;
30309 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30310 + savesegment(gs, ctxt->user_regs.gs);
30311 #else
30312 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30313 #endif
30314 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30315 int rc;
30316
30317 per_cpu(current_task, cpu) = idle;
30318 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
30319 #ifdef CONFIG_X86_32
30320 irq_ctx_init(cpu);
30321 #else
30322 clear_tsk_thread_flag(idle, TIF_FORK);
30323 - per_cpu(kernel_stack, cpu) =
30324 - (unsigned long)task_stack_page(idle) -
30325 - KERNEL_STACK_OFFSET + THREAD_SIZE;
30326 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30327 #endif
30328 xen_setup_runstate_info(cpu);
30329 xen_setup_timer(cpu);
30330 @@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30331
30332 void __init xen_smp_init(void)
30333 {
30334 - smp_ops = xen_smp_ops;
30335 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30336 xen_fill_possible_map();
30337 xen_init_spinlocks();
30338 }
30339 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30340 index 33ca6e4..0ded929 100644
30341 --- a/arch/x86/xen/xen-asm_32.S
30342 +++ b/arch/x86/xen/xen-asm_32.S
30343 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
30344 ESP_OFFSET=4 # bytes pushed onto stack
30345
30346 /*
30347 - * Store vcpu_info pointer for easy access. Do it this way to
30348 - * avoid having to reload %fs
30349 + * Store vcpu_info pointer for easy access.
30350 */
30351 #ifdef CONFIG_SMP
30352 - GET_THREAD_INFO(%eax)
30353 - movl %ss:TI_cpu(%eax), %eax
30354 - movl %ss:__per_cpu_offset(,%eax,4), %eax
30355 - mov %ss:xen_vcpu(%eax), %eax
30356 + push %fs
30357 + mov $(__KERNEL_PERCPU), %eax
30358 + mov %eax, %fs
30359 + mov PER_CPU_VAR(xen_vcpu), %eax
30360 + pop %fs
30361 #else
30362 movl %ss:xen_vcpu, %eax
30363 #endif
30364 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30365 index 7faed58..ba4427c 100644
30366 --- a/arch/x86/xen/xen-head.S
30367 +++ b/arch/x86/xen/xen-head.S
30368 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
30369 #ifdef CONFIG_X86_32
30370 mov %esi,xen_start_info
30371 mov $init_thread_union+THREAD_SIZE,%esp
30372 +#ifdef CONFIG_SMP
30373 + movl $cpu_gdt_table,%edi
30374 + movl $__per_cpu_load,%eax
30375 + movw %ax,__KERNEL_PERCPU + 2(%edi)
30376 + rorl $16,%eax
30377 + movb %al,__KERNEL_PERCPU + 4(%edi)
30378 + movb %ah,__KERNEL_PERCPU + 7(%edi)
30379 + movl $__per_cpu_end - 1,%eax
30380 + subl $__per_cpu_start,%eax
30381 + movw %ax,__KERNEL_PERCPU + 0(%edi)
30382 +#endif
30383 #else
30384 mov %rsi,xen_start_info
30385 mov $init_thread_union+THREAD_SIZE,%rsp
30386 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30387 index a95b417..b6dbd0b 100644
30388 --- a/arch/x86/xen/xen-ops.h
30389 +++ b/arch/x86/xen/xen-ops.h
30390 @@ -10,8 +10,6 @@
30391 extern const char xen_hypervisor_callback[];
30392 extern const char xen_failsafe_callback[];
30393
30394 -extern void *xen_initial_gdt;
30395 -
30396 struct trap_info;
30397 void xen_copy_trap_info(struct trap_info *traps);
30398
30399 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30400 index 525bd3d..ef888b1 100644
30401 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
30402 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30403 @@ -119,9 +119,9 @@
30404 ----------------------------------------------------------------------*/
30405
30406 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30407 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30408 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30409 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30410 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30411
30412 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30413 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30414 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30415 index 2f33760..835e50a 100644
30416 --- a/arch/xtensa/variants/fsf/include/variant/core.h
30417 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
30418 @@ -11,6 +11,7 @@
30419 #ifndef _XTENSA_CORE_H
30420 #define _XTENSA_CORE_H
30421
30422 +#include <linux/const.h>
30423
30424 /****************************************************************************
30425 Parameters Useful for Any Code, USER or PRIVILEGED
30426 @@ -112,9 +113,9 @@
30427 ----------------------------------------------------------------------*/
30428
30429 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30430 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30431 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30432 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30433 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30434
30435 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30436 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30437 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30438 index af00795..2bb8105 100644
30439 --- a/arch/xtensa/variants/s6000/include/variant/core.h
30440 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
30441 @@ -11,6 +11,7 @@
30442 #ifndef _XTENSA_CORE_CONFIGURATION_H
30443 #define _XTENSA_CORE_CONFIGURATION_H
30444
30445 +#include <linux/const.h>
30446
30447 /****************************************************************************
30448 Parameters Useful for Any Code, USER or PRIVILEGED
30449 @@ -118,9 +119,9 @@
30450 ----------------------------------------------------------------------*/
30451
30452 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30453 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30454 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30455 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30456 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30457
30458 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30459 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30460 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30461 index 58916af..eb9dbcf6 100644
30462 --- a/block/blk-iopoll.c
30463 +++ b/block/blk-iopoll.c
30464 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30465 }
30466 EXPORT_SYMBOL(blk_iopoll_complete);
30467
30468 -static void blk_iopoll_softirq(struct softirq_action *h)
30469 +static void blk_iopoll_softirq(void)
30470 {
30471 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
30472 int rearm = 0, budget = blk_iopoll_budget;
30473 @@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
30474 return NOTIFY_OK;
30475 }
30476
30477 -static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
30478 +static struct notifier_block blk_iopoll_cpu_notifier = {
30479 .notifier_call = blk_iopoll_cpu_notify,
30480 };
30481
30482 diff --git a/block/blk-map.c b/block/blk-map.c
30483 index 623e1cd..ca1e109 100644
30484 --- a/block/blk-map.c
30485 +++ b/block/blk-map.c
30486 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
30487 if (!len || !kbuf)
30488 return -EINVAL;
30489
30490 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
30491 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
30492 if (do_copy)
30493 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
30494 else
30495 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
30496 index 467c8de..f3628c5 100644
30497 --- a/block/blk-softirq.c
30498 +++ b/block/blk-softirq.c
30499 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
30500 * Softirq action handler - move entries to local list and loop over them
30501 * while passing them to the queue registered handler.
30502 */
30503 -static void blk_done_softirq(struct softirq_action *h)
30504 +static void blk_done_softirq(void)
30505 {
30506 struct list_head *cpu_list, local_list;
30507
30508 @@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
30509 return NOTIFY_OK;
30510 }
30511
30512 -static struct notifier_block __cpuinitdata blk_cpu_notifier = {
30513 +static struct notifier_block blk_cpu_notifier = {
30514 .notifier_call = blk_cpu_notify,
30515 };
30516
30517 diff --git a/block/bsg.c b/block/bsg.c
30518 index ff64ae3..593560c 100644
30519 --- a/block/bsg.c
30520 +++ b/block/bsg.c
30521 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
30522 struct sg_io_v4 *hdr, struct bsg_device *bd,
30523 fmode_t has_write_perm)
30524 {
30525 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30526 + unsigned char *cmdptr;
30527 +
30528 if (hdr->request_len > BLK_MAX_CDB) {
30529 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
30530 if (!rq->cmd)
30531 return -ENOMEM;
30532 - }
30533 + cmdptr = rq->cmd;
30534 + } else
30535 + cmdptr = tmpcmd;
30536
30537 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
30538 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
30539 hdr->request_len))
30540 return -EFAULT;
30541
30542 + if (cmdptr != rq->cmd)
30543 + memcpy(rq->cmd, cmdptr, hdr->request_len);
30544 +
30545 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
30546 if (blk_verify_command(rq->cmd, has_write_perm))
30547 return -EPERM;
30548 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
30549 index 7c668c8..db3521c 100644
30550 --- a/block/compat_ioctl.c
30551 +++ b/block/compat_ioctl.c
30552 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
30553 err |= __get_user(f->spec1, &uf->spec1);
30554 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
30555 err |= __get_user(name, &uf->name);
30556 - f->name = compat_ptr(name);
30557 + f->name = (void __force_kernel *)compat_ptr(name);
30558 if (err) {
30559 err = -EFAULT;
30560 goto out;
30561 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
30562 index b62fb88..bdab4c4 100644
30563 --- a/block/partitions/efi.c
30564 +++ b/block/partitions/efi.c
30565 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
30566 if (!gpt)
30567 return NULL;
30568
30569 + if (!le32_to_cpu(gpt->num_partition_entries))
30570 + return NULL;
30571 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
30572 + if (!pte)
30573 + return NULL;
30574 +
30575 count = le32_to_cpu(gpt->num_partition_entries) *
30576 le32_to_cpu(gpt->sizeof_partition_entry);
30577 - if (!count)
30578 - return NULL;
30579 - pte = kzalloc(count, GFP_KERNEL);
30580 - if (!pte)
30581 - return NULL;
30582 -
30583 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
30584 (u8 *) pte,
30585 count) < count) {
30586 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
30587 index 9a87daa..fb17486 100644
30588 --- a/block/scsi_ioctl.c
30589 +++ b/block/scsi_ioctl.c
30590 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
30591 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
30592 struct sg_io_hdr *hdr, fmode_t mode)
30593 {
30594 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
30595 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30596 + unsigned char *cmdptr;
30597 +
30598 + if (rq->cmd != rq->__cmd)
30599 + cmdptr = rq->cmd;
30600 + else
30601 + cmdptr = tmpcmd;
30602 +
30603 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
30604 return -EFAULT;
30605 +
30606 + if (cmdptr != rq->cmd)
30607 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
30608 +
30609 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
30610 return -EPERM;
30611
30612 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30613 int err;
30614 unsigned int in_len, out_len, bytes, opcode, cmdlen;
30615 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
30616 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30617 + unsigned char *cmdptr;
30618
30619 if (!sic)
30620 return -EINVAL;
30621 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30622 */
30623 err = -EFAULT;
30624 rq->cmd_len = cmdlen;
30625 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
30626 +
30627 + if (rq->cmd != rq->__cmd)
30628 + cmdptr = rq->cmd;
30629 + else
30630 + cmdptr = tmpcmd;
30631 +
30632 + if (copy_from_user(cmdptr, sic->data, cmdlen))
30633 goto error;
30634
30635 + if (rq->cmd != cmdptr)
30636 + memcpy(rq->cmd, cmdptr, cmdlen);
30637 +
30638 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
30639 goto error;
30640
30641 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
30642 index 533de95..7d4a8d2 100644
30643 --- a/crypto/ablkcipher.c
30644 +++ b/crypto/ablkcipher.c
30645 @@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30646 {
30647 struct crypto_report_blkcipher rblkcipher;
30648
30649 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
30650 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30651 - alg->cra_ablkcipher.geniv ?: "<default>");
30652 + strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
30653 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
30654 + sizeof(rblkcipher.geniv));
30655
30656 rblkcipher.blocksize = alg->cra_blocksize;
30657 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30658 @@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30659 {
30660 struct crypto_report_blkcipher rblkcipher;
30661
30662 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
30663 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30664 - alg->cra_ablkcipher.geniv ?: "<built-in>");
30665 + strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
30666 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
30667 + sizeof(rblkcipher.geniv));
30668
30669 rblkcipher.blocksize = alg->cra_blocksize;
30670 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30671 diff --git a/crypto/aead.c b/crypto/aead.c
30672 index 0b8121e..27bc487 100644
30673 --- a/crypto/aead.c
30674 +++ b/crypto/aead.c
30675 @@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
30676 struct crypto_report_aead raead;
30677 struct aead_alg *aead = &alg->cra_aead;
30678
30679 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
30680 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30681 - aead->geniv ?: "<built-in>");
30682 + strncpy(raead.type, "aead", sizeof(raead.type));
30683 + strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
30684
30685 raead.blocksize = alg->cra_blocksize;
30686 raead.maxauthsize = aead->maxauthsize;
30687 @@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
30688 struct crypto_report_aead raead;
30689 struct aead_alg *aead = &alg->cra_aead;
30690
30691 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
30692 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
30693 + strncpy(raead.type, "nivaead", sizeof(raead.type));
30694 + strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
30695
30696 raead.blocksize = alg->cra_blocksize;
30697 raead.maxauthsize = aead->maxauthsize;
30698 diff --git a/crypto/ahash.c b/crypto/ahash.c
30699 index 3887856..793a27f 100644
30700 --- a/crypto/ahash.c
30701 +++ b/crypto/ahash.c
30702 @@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
30703 {
30704 struct crypto_report_hash rhash;
30705
30706 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
30707 + strncpy(rhash.type, "ahash", sizeof(rhash.type));
30708
30709 rhash.blocksize = alg->cra_blocksize;
30710 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
30711 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
30712 index a8d85a1..c44e014 100644
30713 --- a/crypto/blkcipher.c
30714 +++ b/crypto/blkcipher.c
30715 @@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30716 {
30717 struct crypto_report_blkcipher rblkcipher;
30718
30719 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
30720 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30721 - alg->cra_blkcipher.geniv ?: "<default>");
30722 + strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
30723 + strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
30724 + sizeof(rblkcipher.geniv));
30725
30726 rblkcipher.blocksize = alg->cra_blocksize;
30727 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
30728 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
30729 index 7bdd61b..afec999 100644
30730 --- a/crypto/cryptd.c
30731 +++ b/crypto/cryptd.c
30732 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
30733
30734 struct cryptd_blkcipher_request_ctx {
30735 crypto_completion_t complete;
30736 -};
30737 +} __no_const;
30738
30739 struct cryptd_hash_ctx {
30740 struct crypto_shash *child;
30741 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
30742
30743 struct cryptd_aead_request_ctx {
30744 crypto_completion_t complete;
30745 -};
30746 +} __no_const;
30747
30748 static void cryptd_queue_worker(struct work_struct *work);
30749
30750 diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
30751 index 35d700a..dfd511f 100644
30752 --- a/crypto/crypto_user.c
30753 +++ b/crypto/crypto_user.c
30754 @@ -30,6 +30,8 @@
30755
30756 #include "internal.h"
30757
30758 +#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
30759 +
30760 static DEFINE_MUTEX(crypto_cfg_mutex);
30761
30762 /* The crypto netlink socket */
30763 @@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
30764 {
30765 struct crypto_report_cipher rcipher;
30766
30767 - snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
30768 + strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
30769
30770 rcipher.blocksize = alg->cra_blocksize;
30771 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
30772 @@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
30773 {
30774 struct crypto_report_comp rcomp;
30775
30776 - snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
30777 -
30778 + strncpy(rcomp.type, "compression", sizeof(rcomp.type));
30779 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30780 sizeof(struct crypto_report_comp), &rcomp))
30781 goto nla_put_failure;
30782 @@ -108,12 +109,14 @@ nla_put_failure:
30783 static int crypto_report_one(struct crypto_alg *alg,
30784 struct crypto_user_alg *ualg, struct sk_buff *skb)
30785 {
30786 - memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
30787 - memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
30788 - sizeof(ualg->cru_driver_name));
30789 - memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
30790 - CRYPTO_MAX_ALG_NAME);
30791 + strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
30792 + strncpy(ualg->cru_driver_name, alg->cra_driver_name,
30793 + sizeof(ualg->cru_driver_name));
30794 + strncpy(ualg->cru_module_name, module_name(alg->cra_module),
30795 + sizeof(ualg->cru_module_name));
30796
30797 + ualg->cru_type = 0;
30798 + ualg->cru_mask = 0;
30799 ualg->cru_flags = alg->cra_flags;
30800 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
30801
30802 @@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
30803 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
30804 struct crypto_report_larval rl;
30805
30806 - snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
30807 -
30808 + strncpy(rl.type, "larval", sizeof(rl.type));
30809 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
30810 sizeof(struct crypto_report_larval), &rl))
30811 goto nla_put_failure;
30812 @@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
30813 struct crypto_dump_info info;
30814 int err;
30815
30816 - if (!p->cru_driver_name)
30817 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30818 + return -EINVAL;
30819 +
30820 + if (!p->cru_driver_name[0])
30821 return -EINVAL;
30822
30823 alg = crypto_alg_match(p, 1);
30824 @@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30825 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30826 LIST_HEAD(list);
30827
30828 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30829 + return -EINVAL;
30830 +
30831 if (priority && !strlen(p->cru_driver_name))
30832 return -EINVAL;
30833
30834 @@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30835 struct crypto_alg *alg;
30836 struct crypto_user_alg *p = nlmsg_data(nlh);
30837
30838 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30839 + return -EINVAL;
30840 +
30841 alg = crypto_alg_match(p, 1);
30842 if (!alg)
30843 return -ENOENT;
30844 @@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30845 struct crypto_user_alg *p = nlmsg_data(nlh);
30846 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30847
30848 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30849 + return -EINVAL;
30850 +
30851 if (strlen(p->cru_driver_name))
30852 exact = 1;
30853
30854 diff --git a/crypto/pcompress.c b/crypto/pcompress.c
30855 index 04e083f..7140fe7 100644
30856 --- a/crypto/pcompress.c
30857 +++ b/crypto/pcompress.c
30858 @@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
30859 {
30860 struct crypto_report_comp rpcomp;
30861
30862 - snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
30863 -
30864 + strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
30865 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30866 sizeof(struct crypto_report_comp), &rpcomp))
30867 goto nla_put_failure;
30868 diff --git a/crypto/rng.c b/crypto/rng.c
30869 index f3b7894..e0a25c2 100644
30870 --- a/crypto/rng.c
30871 +++ b/crypto/rng.c
30872 @@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
30873 {
30874 struct crypto_report_rng rrng;
30875
30876 - snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
30877 + strncpy(rrng.type, "rng", sizeof(rrng.type));
30878
30879 rrng.seedsize = alg->cra_rng.seedsize;
30880
30881 diff --git a/crypto/shash.c b/crypto/shash.c
30882 index f426330f..929058a 100644
30883 --- a/crypto/shash.c
30884 +++ b/crypto/shash.c
30885 @@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
30886 struct crypto_report_hash rhash;
30887 struct shash_alg *salg = __crypto_shash_alg(alg);
30888
30889 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
30890 + strncpy(rhash.type, "shash", sizeof(rhash.type));
30891 +
30892 rhash.blocksize = alg->cra_blocksize;
30893 rhash.digestsize = salg->digestsize;
30894
30895 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
30896 index e6defd8..c26a225 100644
30897 --- a/drivers/acpi/apei/cper.c
30898 +++ b/drivers/acpi/apei/cper.c
30899 @@ -38,12 +38,12 @@
30900 */
30901 u64 cper_next_record_id(void)
30902 {
30903 - static atomic64_t seq;
30904 + static atomic64_unchecked_t seq;
30905
30906 - if (!atomic64_read(&seq))
30907 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
30908 + if (!atomic64_read_unchecked(&seq))
30909 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
30910
30911 - return atomic64_inc_return(&seq);
30912 + return atomic64_inc_return_unchecked(&seq);
30913 }
30914 EXPORT_SYMBOL_GPL(cper_next_record_id);
30915
30916 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
30917 index 7586544..636a2f0 100644
30918 --- a/drivers/acpi/ec_sys.c
30919 +++ b/drivers/acpi/ec_sys.c
30920 @@ -12,6 +12,7 @@
30921 #include <linux/acpi.h>
30922 #include <linux/debugfs.h>
30923 #include <linux/module.h>
30924 +#include <linux/uaccess.h>
30925 #include "internal.h"
30926
30927 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
30928 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30929 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
30930 */
30931 unsigned int size = EC_SPACE_SIZE;
30932 - u8 *data = (u8 *) buf;
30933 + u8 data;
30934 loff_t init_off = *off;
30935 int err = 0;
30936
30937 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30938 size = count;
30939
30940 while (size) {
30941 - err = ec_read(*off, &data[*off - init_off]);
30942 + err = ec_read(*off, &data);
30943 if (err)
30944 return err;
30945 + if (put_user(data, &buf[*off - init_off]))
30946 + return -EFAULT;
30947 *off += 1;
30948 size--;
30949 }
30950 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30951
30952 unsigned int size = count;
30953 loff_t init_off = *off;
30954 - u8 *data = (u8 *) buf;
30955 int err = 0;
30956
30957 if (*off >= EC_SPACE_SIZE)
30958 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30959 }
30960
30961 while (size) {
30962 - u8 byte_write = data[*off - init_off];
30963 + u8 byte_write;
30964 + if (get_user(byte_write, &buf[*off - init_off]))
30965 + return -EFAULT;
30966 err = ec_write(*off, byte_write);
30967 if (err)
30968 return err;
30969 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30970 index e83311b..142b5cc 100644
30971 --- a/drivers/acpi/processor_driver.c
30972 +++ b/drivers/acpi/processor_driver.c
30973 @@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30974 return 0;
30975 #endif
30976
30977 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30978 + BUG_ON(pr->id >= nr_cpu_ids);
30979
30980 /*
30981 * Buggy BIOS check
30982 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30983 index 46cd3f4..0871ad0 100644
30984 --- a/drivers/ata/libata-core.c
30985 +++ b/drivers/ata/libata-core.c
30986 @@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30987 struct ata_port *ap;
30988 unsigned int tag;
30989
30990 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30991 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30992 ap = qc->ap;
30993
30994 qc->flags = 0;
30995 @@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30996 struct ata_port *ap;
30997 struct ata_link *link;
30998
30999 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31000 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31001 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31002 ap = qc->ap;
31003 link = qc->dev->link;
31004 @@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31005 return;
31006
31007 spin_lock(&lock);
31008 + pax_open_kernel();
31009
31010 for (cur = ops->inherits; cur; cur = cur->inherits) {
31011 void **inherit = (void **)cur;
31012 @@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31013 if (IS_ERR(*pp))
31014 *pp = NULL;
31015
31016 - ops->inherits = NULL;
31017 + *(struct ata_port_operations **)&ops->inherits = NULL;
31018
31019 + pax_close_kernel();
31020 spin_unlock(&lock);
31021 }
31022
31023 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31024 index 405022d..fb70e53 100644
31025 --- a/drivers/ata/pata_arasan_cf.c
31026 +++ b/drivers/ata/pata_arasan_cf.c
31027 @@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31028 /* Handle platform specific quirks */
31029 if (pdata->quirk) {
31030 if (pdata->quirk & CF_BROKEN_PIO) {
31031 - ap->ops->set_piomode = NULL;
31032 + pax_open_kernel();
31033 + *(void **)&ap->ops->set_piomode = NULL;
31034 + pax_close_kernel();
31035 ap->pio_mask = 0;
31036 }
31037 if (pdata->quirk & CF_BROKEN_MWDMA)
31038 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31039 index f9b983a..887b9d8 100644
31040 --- a/drivers/atm/adummy.c
31041 +++ b/drivers/atm/adummy.c
31042 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31043 vcc->pop(vcc, skb);
31044 else
31045 dev_kfree_skb_any(skb);
31046 - atomic_inc(&vcc->stats->tx);
31047 + atomic_inc_unchecked(&vcc->stats->tx);
31048
31049 return 0;
31050 }
31051 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31052 index 77a7480..05cde58 100644
31053 --- a/drivers/atm/ambassador.c
31054 +++ b/drivers/atm/ambassador.c
31055 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31056 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31057
31058 // VC layer stats
31059 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31060 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31061
31062 // free the descriptor
31063 kfree (tx_descr);
31064 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31065 dump_skb ("<<<", vc, skb);
31066
31067 // VC layer stats
31068 - atomic_inc(&atm_vcc->stats->rx);
31069 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31070 __net_timestamp(skb);
31071 // end of our responsibility
31072 atm_vcc->push (atm_vcc, skb);
31073 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31074 } else {
31075 PRINTK (KERN_INFO, "dropped over-size frame");
31076 // should we count this?
31077 - atomic_inc(&atm_vcc->stats->rx_drop);
31078 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31079 }
31080
31081 } else {
31082 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31083 }
31084
31085 if (check_area (skb->data, skb->len)) {
31086 - atomic_inc(&atm_vcc->stats->tx_err);
31087 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31088 return -ENOMEM; // ?
31089 }
31090
31091 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31092 index b22d71c..d6e1049 100644
31093 --- a/drivers/atm/atmtcp.c
31094 +++ b/drivers/atm/atmtcp.c
31095 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31096 if (vcc->pop) vcc->pop(vcc,skb);
31097 else dev_kfree_skb(skb);
31098 if (dev_data) return 0;
31099 - atomic_inc(&vcc->stats->tx_err);
31100 + atomic_inc_unchecked(&vcc->stats->tx_err);
31101 return -ENOLINK;
31102 }
31103 size = skb->len+sizeof(struct atmtcp_hdr);
31104 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31105 if (!new_skb) {
31106 if (vcc->pop) vcc->pop(vcc,skb);
31107 else dev_kfree_skb(skb);
31108 - atomic_inc(&vcc->stats->tx_err);
31109 + atomic_inc_unchecked(&vcc->stats->tx_err);
31110 return -ENOBUFS;
31111 }
31112 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31113 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31114 if (vcc->pop) vcc->pop(vcc,skb);
31115 else dev_kfree_skb(skb);
31116 out_vcc->push(out_vcc,new_skb);
31117 - atomic_inc(&vcc->stats->tx);
31118 - atomic_inc(&out_vcc->stats->rx);
31119 + atomic_inc_unchecked(&vcc->stats->tx);
31120 + atomic_inc_unchecked(&out_vcc->stats->rx);
31121 return 0;
31122 }
31123
31124 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31125 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31126 read_unlock(&vcc_sklist_lock);
31127 if (!out_vcc) {
31128 - atomic_inc(&vcc->stats->tx_err);
31129 + atomic_inc_unchecked(&vcc->stats->tx_err);
31130 goto done;
31131 }
31132 skb_pull(skb,sizeof(struct atmtcp_hdr));
31133 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31134 __net_timestamp(new_skb);
31135 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31136 out_vcc->push(out_vcc,new_skb);
31137 - atomic_inc(&vcc->stats->tx);
31138 - atomic_inc(&out_vcc->stats->rx);
31139 + atomic_inc_unchecked(&vcc->stats->tx);
31140 + atomic_inc_unchecked(&out_vcc->stats->rx);
31141 done:
31142 if (vcc->pop) vcc->pop(vcc,skb);
31143 else dev_kfree_skb(skb);
31144 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31145 index c1eb6fa..4c71be9 100644
31146 --- a/drivers/atm/eni.c
31147 +++ b/drivers/atm/eni.c
31148 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31149 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31150 vcc->dev->number);
31151 length = 0;
31152 - atomic_inc(&vcc->stats->rx_err);
31153 + atomic_inc_unchecked(&vcc->stats->rx_err);
31154 }
31155 else {
31156 length = ATM_CELL_SIZE-1; /* no HEC */
31157 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31158 size);
31159 }
31160 eff = length = 0;
31161 - atomic_inc(&vcc->stats->rx_err);
31162 + atomic_inc_unchecked(&vcc->stats->rx_err);
31163 }
31164 else {
31165 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31166 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31167 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31168 vcc->dev->number,vcc->vci,length,size << 2,descr);
31169 length = eff = 0;
31170 - atomic_inc(&vcc->stats->rx_err);
31171 + atomic_inc_unchecked(&vcc->stats->rx_err);
31172 }
31173 }
31174 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31175 @@ -767,7 +767,7 @@ rx_dequeued++;
31176 vcc->push(vcc,skb);
31177 pushed++;
31178 }
31179 - atomic_inc(&vcc->stats->rx);
31180 + atomic_inc_unchecked(&vcc->stats->rx);
31181 }
31182 wake_up(&eni_dev->rx_wait);
31183 }
31184 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31185 PCI_DMA_TODEVICE);
31186 if (vcc->pop) vcc->pop(vcc,skb);
31187 else dev_kfree_skb_irq(skb);
31188 - atomic_inc(&vcc->stats->tx);
31189 + atomic_inc_unchecked(&vcc->stats->tx);
31190 wake_up(&eni_dev->tx_wait);
31191 dma_complete++;
31192 }
31193 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31194 index b41c948..a002b17 100644
31195 --- a/drivers/atm/firestream.c
31196 +++ b/drivers/atm/firestream.c
31197 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31198 }
31199 }
31200
31201 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31202 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31203
31204 fs_dprintk (FS_DEBUG_TXMEM, "i");
31205 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31206 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31207 #endif
31208 skb_put (skb, qe->p1 & 0xffff);
31209 ATM_SKB(skb)->vcc = atm_vcc;
31210 - atomic_inc(&atm_vcc->stats->rx);
31211 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31212 __net_timestamp(skb);
31213 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31214 atm_vcc->push (atm_vcc, skb);
31215 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31216 kfree (pe);
31217 }
31218 if (atm_vcc)
31219 - atomic_inc(&atm_vcc->stats->rx_drop);
31220 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31221 break;
31222 case 0x1f: /* Reassembly abort: no buffers. */
31223 /* Silently increment error counter. */
31224 if (atm_vcc)
31225 - atomic_inc(&atm_vcc->stats->rx_drop);
31226 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31227 break;
31228 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31229 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31230 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31231 index 204814e..cede831 100644
31232 --- a/drivers/atm/fore200e.c
31233 +++ b/drivers/atm/fore200e.c
31234 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31235 #endif
31236 /* check error condition */
31237 if (*entry->status & STATUS_ERROR)
31238 - atomic_inc(&vcc->stats->tx_err);
31239 + atomic_inc_unchecked(&vcc->stats->tx_err);
31240 else
31241 - atomic_inc(&vcc->stats->tx);
31242 + atomic_inc_unchecked(&vcc->stats->tx);
31243 }
31244 }
31245
31246 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31247 if (skb == NULL) {
31248 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31249
31250 - atomic_inc(&vcc->stats->rx_drop);
31251 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31252 return -ENOMEM;
31253 }
31254
31255 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31256
31257 dev_kfree_skb_any(skb);
31258
31259 - atomic_inc(&vcc->stats->rx_drop);
31260 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31261 return -ENOMEM;
31262 }
31263
31264 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31265
31266 vcc->push(vcc, skb);
31267 - atomic_inc(&vcc->stats->rx);
31268 + atomic_inc_unchecked(&vcc->stats->rx);
31269
31270 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31271
31272 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31273 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31274 fore200e->atm_dev->number,
31275 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31276 - atomic_inc(&vcc->stats->rx_err);
31277 + atomic_inc_unchecked(&vcc->stats->rx_err);
31278 }
31279 }
31280
31281 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31282 goto retry_here;
31283 }
31284
31285 - atomic_inc(&vcc->stats->tx_err);
31286 + atomic_inc_unchecked(&vcc->stats->tx_err);
31287
31288 fore200e->tx_sat++;
31289 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31290 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31291 index 72b6960..cf9167a 100644
31292 --- a/drivers/atm/he.c
31293 +++ b/drivers/atm/he.c
31294 @@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31295
31296 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31297 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31298 - atomic_inc(&vcc->stats->rx_drop);
31299 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31300 goto return_host_buffers;
31301 }
31302
31303 @@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31304 RBRQ_LEN_ERR(he_dev->rbrq_head)
31305 ? "LEN_ERR" : "",
31306 vcc->vpi, vcc->vci);
31307 - atomic_inc(&vcc->stats->rx_err);
31308 + atomic_inc_unchecked(&vcc->stats->rx_err);
31309 goto return_host_buffers;
31310 }
31311
31312 @@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31313 vcc->push(vcc, skb);
31314 spin_lock(&he_dev->global_lock);
31315
31316 - atomic_inc(&vcc->stats->rx);
31317 + atomic_inc_unchecked(&vcc->stats->rx);
31318
31319 return_host_buffers:
31320 ++pdus_assembled;
31321 @@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31322 tpd->vcc->pop(tpd->vcc, tpd->skb);
31323 else
31324 dev_kfree_skb_any(tpd->skb);
31325 - atomic_inc(&tpd->vcc->stats->tx_err);
31326 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31327 }
31328 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31329 return;
31330 @@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31331 vcc->pop(vcc, skb);
31332 else
31333 dev_kfree_skb_any(skb);
31334 - atomic_inc(&vcc->stats->tx_err);
31335 + atomic_inc_unchecked(&vcc->stats->tx_err);
31336 return -EINVAL;
31337 }
31338
31339 @@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31340 vcc->pop(vcc, skb);
31341 else
31342 dev_kfree_skb_any(skb);
31343 - atomic_inc(&vcc->stats->tx_err);
31344 + atomic_inc_unchecked(&vcc->stats->tx_err);
31345 return -EINVAL;
31346 }
31347 #endif
31348 @@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31349 vcc->pop(vcc, skb);
31350 else
31351 dev_kfree_skb_any(skb);
31352 - atomic_inc(&vcc->stats->tx_err);
31353 + atomic_inc_unchecked(&vcc->stats->tx_err);
31354 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31355 return -ENOMEM;
31356 }
31357 @@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31358 vcc->pop(vcc, skb);
31359 else
31360 dev_kfree_skb_any(skb);
31361 - atomic_inc(&vcc->stats->tx_err);
31362 + atomic_inc_unchecked(&vcc->stats->tx_err);
31363 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31364 return -ENOMEM;
31365 }
31366 @@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31367 __enqueue_tpd(he_dev, tpd, cid);
31368 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31369
31370 - atomic_inc(&vcc->stats->tx);
31371 + atomic_inc_unchecked(&vcc->stats->tx);
31372
31373 return 0;
31374 }
31375 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31376 index 1dc0519..1aadaf7 100644
31377 --- a/drivers/atm/horizon.c
31378 +++ b/drivers/atm/horizon.c
31379 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31380 {
31381 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31382 // VC layer stats
31383 - atomic_inc(&vcc->stats->rx);
31384 + atomic_inc_unchecked(&vcc->stats->rx);
31385 __net_timestamp(skb);
31386 // end of our responsibility
31387 vcc->push (vcc, skb);
31388 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31389 dev->tx_iovec = NULL;
31390
31391 // VC layer stats
31392 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31393 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31394
31395 // free the skb
31396 hrz_kfree_skb (skb);
31397 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31398 index 272f009..a18ba55 100644
31399 --- a/drivers/atm/idt77252.c
31400 +++ b/drivers/atm/idt77252.c
31401 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31402 else
31403 dev_kfree_skb(skb);
31404
31405 - atomic_inc(&vcc->stats->tx);
31406 + atomic_inc_unchecked(&vcc->stats->tx);
31407 }
31408
31409 atomic_dec(&scq->used);
31410 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31411 if ((sb = dev_alloc_skb(64)) == NULL) {
31412 printk("%s: Can't allocate buffers for aal0.\n",
31413 card->name);
31414 - atomic_add(i, &vcc->stats->rx_drop);
31415 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
31416 break;
31417 }
31418 if (!atm_charge(vcc, sb->truesize)) {
31419 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31420 card->name);
31421 - atomic_add(i - 1, &vcc->stats->rx_drop);
31422 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31423 dev_kfree_skb(sb);
31424 break;
31425 }
31426 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31427 ATM_SKB(sb)->vcc = vcc;
31428 __net_timestamp(sb);
31429 vcc->push(vcc, sb);
31430 - atomic_inc(&vcc->stats->rx);
31431 + atomic_inc_unchecked(&vcc->stats->rx);
31432
31433 cell += ATM_CELL_PAYLOAD;
31434 }
31435 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31436 "(CDC: %08x)\n",
31437 card->name, len, rpp->len, readl(SAR_REG_CDC));
31438 recycle_rx_pool_skb(card, rpp);
31439 - atomic_inc(&vcc->stats->rx_err);
31440 + atomic_inc_unchecked(&vcc->stats->rx_err);
31441 return;
31442 }
31443 if (stat & SAR_RSQE_CRC) {
31444 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31445 recycle_rx_pool_skb(card, rpp);
31446 - atomic_inc(&vcc->stats->rx_err);
31447 + atomic_inc_unchecked(&vcc->stats->rx_err);
31448 return;
31449 }
31450 if (skb_queue_len(&rpp->queue) > 1) {
31451 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31452 RXPRINTK("%s: Can't alloc RX skb.\n",
31453 card->name);
31454 recycle_rx_pool_skb(card, rpp);
31455 - atomic_inc(&vcc->stats->rx_err);
31456 + atomic_inc_unchecked(&vcc->stats->rx_err);
31457 return;
31458 }
31459 if (!atm_charge(vcc, skb->truesize)) {
31460 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31461 __net_timestamp(skb);
31462
31463 vcc->push(vcc, skb);
31464 - atomic_inc(&vcc->stats->rx);
31465 + atomic_inc_unchecked(&vcc->stats->rx);
31466
31467 return;
31468 }
31469 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31470 __net_timestamp(skb);
31471
31472 vcc->push(vcc, skb);
31473 - atomic_inc(&vcc->stats->rx);
31474 + atomic_inc_unchecked(&vcc->stats->rx);
31475
31476 if (skb->truesize > SAR_FB_SIZE_3)
31477 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
31478 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
31479 if (vcc->qos.aal != ATM_AAL0) {
31480 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
31481 card->name, vpi, vci);
31482 - atomic_inc(&vcc->stats->rx_drop);
31483 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31484 goto drop;
31485 }
31486
31487 if ((sb = dev_alloc_skb(64)) == NULL) {
31488 printk("%s: Can't allocate buffers for AAL0.\n",
31489 card->name);
31490 - atomic_inc(&vcc->stats->rx_err);
31491 + atomic_inc_unchecked(&vcc->stats->rx_err);
31492 goto drop;
31493 }
31494
31495 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
31496 ATM_SKB(sb)->vcc = vcc;
31497 __net_timestamp(sb);
31498 vcc->push(vcc, sb);
31499 - atomic_inc(&vcc->stats->rx);
31500 + atomic_inc_unchecked(&vcc->stats->rx);
31501
31502 drop:
31503 skb_pull(queue, 64);
31504 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31505
31506 if (vc == NULL) {
31507 printk("%s: NULL connection in send().\n", card->name);
31508 - atomic_inc(&vcc->stats->tx_err);
31509 + atomic_inc_unchecked(&vcc->stats->tx_err);
31510 dev_kfree_skb(skb);
31511 return -EINVAL;
31512 }
31513 if (!test_bit(VCF_TX, &vc->flags)) {
31514 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
31515 - atomic_inc(&vcc->stats->tx_err);
31516 + atomic_inc_unchecked(&vcc->stats->tx_err);
31517 dev_kfree_skb(skb);
31518 return -EINVAL;
31519 }
31520 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31521 break;
31522 default:
31523 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
31524 - atomic_inc(&vcc->stats->tx_err);
31525 + atomic_inc_unchecked(&vcc->stats->tx_err);
31526 dev_kfree_skb(skb);
31527 return -EINVAL;
31528 }
31529
31530 if (skb_shinfo(skb)->nr_frags != 0) {
31531 printk("%s: No scatter-gather yet.\n", card->name);
31532 - atomic_inc(&vcc->stats->tx_err);
31533 + atomic_inc_unchecked(&vcc->stats->tx_err);
31534 dev_kfree_skb(skb);
31535 return -EINVAL;
31536 }
31537 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31538
31539 err = queue_skb(card, vc, skb, oam);
31540 if (err) {
31541 - atomic_inc(&vcc->stats->tx_err);
31542 + atomic_inc_unchecked(&vcc->stats->tx_err);
31543 dev_kfree_skb(skb);
31544 return err;
31545 }
31546 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
31547 skb = dev_alloc_skb(64);
31548 if (!skb) {
31549 printk("%s: Out of memory in send_oam().\n", card->name);
31550 - atomic_inc(&vcc->stats->tx_err);
31551 + atomic_inc_unchecked(&vcc->stats->tx_err);
31552 return -ENOMEM;
31553 }
31554 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
31555 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
31556 index 4217f29..88f547a 100644
31557 --- a/drivers/atm/iphase.c
31558 +++ b/drivers/atm/iphase.c
31559 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
31560 status = (u_short) (buf_desc_ptr->desc_mode);
31561 if (status & (RX_CER | RX_PTE | RX_OFL))
31562 {
31563 - atomic_inc(&vcc->stats->rx_err);
31564 + atomic_inc_unchecked(&vcc->stats->rx_err);
31565 IF_ERR(printk("IA: bad packet, dropping it");)
31566 if (status & RX_CER) {
31567 IF_ERR(printk(" cause: packet CRC error\n");)
31568 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
31569 len = dma_addr - buf_addr;
31570 if (len > iadev->rx_buf_sz) {
31571 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
31572 - atomic_inc(&vcc->stats->rx_err);
31573 + atomic_inc_unchecked(&vcc->stats->rx_err);
31574 goto out_free_desc;
31575 }
31576
31577 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31578 ia_vcc = INPH_IA_VCC(vcc);
31579 if (ia_vcc == NULL)
31580 {
31581 - atomic_inc(&vcc->stats->rx_err);
31582 + atomic_inc_unchecked(&vcc->stats->rx_err);
31583 atm_return(vcc, skb->truesize);
31584 dev_kfree_skb_any(skb);
31585 goto INCR_DLE;
31586 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31587 if ((length > iadev->rx_buf_sz) || (length >
31588 (skb->len - sizeof(struct cpcs_trailer))))
31589 {
31590 - atomic_inc(&vcc->stats->rx_err);
31591 + atomic_inc_unchecked(&vcc->stats->rx_err);
31592 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
31593 length, skb->len);)
31594 atm_return(vcc, skb->truesize);
31595 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31596
31597 IF_RX(printk("rx_dle_intr: skb push");)
31598 vcc->push(vcc,skb);
31599 - atomic_inc(&vcc->stats->rx);
31600 + atomic_inc_unchecked(&vcc->stats->rx);
31601 iadev->rx_pkt_cnt++;
31602 }
31603 INCR_DLE:
31604 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
31605 {
31606 struct k_sonet_stats *stats;
31607 stats = &PRIV(_ia_dev[board])->sonet_stats;
31608 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
31609 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
31610 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
31611 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
31612 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
31613 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
31614 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
31615 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
31616 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
31617 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
31618 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
31619 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
31620 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
31621 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
31622 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
31623 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
31624 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
31625 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
31626 }
31627 ia_cmds.status = 0;
31628 break;
31629 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31630 if ((desc == 0) || (desc > iadev->num_tx_desc))
31631 {
31632 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
31633 - atomic_inc(&vcc->stats->tx);
31634 + atomic_inc_unchecked(&vcc->stats->tx);
31635 if (vcc->pop)
31636 vcc->pop(vcc, skb);
31637 else
31638 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31639 ATM_DESC(skb) = vcc->vci;
31640 skb_queue_tail(&iadev->tx_dma_q, skb);
31641
31642 - atomic_inc(&vcc->stats->tx);
31643 + atomic_inc_unchecked(&vcc->stats->tx);
31644 iadev->tx_pkt_cnt++;
31645 /* Increment transaction counter */
31646 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
31647
31648 #if 0
31649 /* add flow control logic */
31650 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
31651 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
31652 if (iavcc->vc_desc_cnt > 10) {
31653 vcc->tx_quota = vcc->tx_quota * 3 / 4;
31654 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
31655 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
31656 index fa7d701..1e404c7 100644
31657 --- a/drivers/atm/lanai.c
31658 +++ b/drivers/atm/lanai.c
31659 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
31660 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
31661 lanai_endtx(lanai, lvcc);
31662 lanai_free_skb(lvcc->tx.atmvcc, skb);
31663 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
31664 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
31665 }
31666
31667 /* Try to fill the buffer - don't call unless there is backlog */
31668 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
31669 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
31670 __net_timestamp(skb);
31671 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
31672 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
31673 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
31674 out:
31675 lvcc->rx.buf.ptr = end;
31676 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
31677 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31678 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
31679 "vcc %d\n", lanai->number, (unsigned int) s, vci);
31680 lanai->stats.service_rxnotaal5++;
31681 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31682 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31683 return 0;
31684 }
31685 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
31686 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31687 int bytes;
31688 read_unlock(&vcc_sklist_lock);
31689 DPRINTK("got trashed rx pdu on vci %d\n", vci);
31690 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31691 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31692 lvcc->stats.x.aal5.service_trash++;
31693 bytes = (SERVICE_GET_END(s) * 16) -
31694 (((unsigned long) lvcc->rx.buf.ptr) -
31695 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31696 }
31697 if (s & SERVICE_STREAM) {
31698 read_unlock(&vcc_sklist_lock);
31699 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31700 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31701 lvcc->stats.x.aal5.service_stream++;
31702 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
31703 "PDU on VCI %d!\n", lanai->number, vci);
31704 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31705 return 0;
31706 }
31707 DPRINTK("got rx crc error on vci %d\n", vci);
31708 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31709 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31710 lvcc->stats.x.aal5.service_rxcrc++;
31711 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
31712 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
31713 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
31714 index ed1d2b7..8cffc1f 100644
31715 --- a/drivers/atm/nicstar.c
31716 +++ b/drivers/atm/nicstar.c
31717 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31718 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
31719 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
31720 card->index);
31721 - atomic_inc(&vcc->stats->tx_err);
31722 + atomic_inc_unchecked(&vcc->stats->tx_err);
31723 dev_kfree_skb_any(skb);
31724 return -EINVAL;
31725 }
31726 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31727 if (!vc->tx) {
31728 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
31729 card->index);
31730 - atomic_inc(&vcc->stats->tx_err);
31731 + atomic_inc_unchecked(&vcc->stats->tx_err);
31732 dev_kfree_skb_any(skb);
31733 return -EINVAL;
31734 }
31735 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31736 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
31737 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
31738 card->index);
31739 - atomic_inc(&vcc->stats->tx_err);
31740 + atomic_inc_unchecked(&vcc->stats->tx_err);
31741 dev_kfree_skb_any(skb);
31742 return -EINVAL;
31743 }
31744
31745 if (skb_shinfo(skb)->nr_frags != 0) {
31746 printk("nicstar%d: No scatter-gather yet.\n", card->index);
31747 - atomic_inc(&vcc->stats->tx_err);
31748 + atomic_inc_unchecked(&vcc->stats->tx_err);
31749 dev_kfree_skb_any(skb);
31750 return -EINVAL;
31751 }
31752 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31753 }
31754
31755 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
31756 - atomic_inc(&vcc->stats->tx_err);
31757 + atomic_inc_unchecked(&vcc->stats->tx_err);
31758 dev_kfree_skb_any(skb);
31759 return -EIO;
31760 }
31761 - atomic_inc(&vcc->stats->tx);
31762 + atomic_inc_unchecked(&vcc->stats->tx);
31763
31764 return 0;
31765 }
31766 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31767 printk
31768 ("nicstar%d: Can't allocate buffers for aal0.\n",
31769 card->index);
31770 - atomic_add(i, &vcc->stats->rx_drop);
31771 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
31772 break;
31773 }
31774 if (!atm_charge(vcc, sb->truesize)) {
31775 RXPRINTK
31776 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
31777 card->index);
31778 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31779 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31780 dev_kfree_skb_any(sb);
31781 break;
31782 }
31783 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31784 ATM_SKB(sb)->vcc = vcc;
31785 __net_timestamp(sb);
31786 vcc->push(vcc, sb);
31787 - atomic_inc(&vcc->stats->rx);
31788 + atomic_inc_unchecked(&vcc->stats->rx);
31789 cell += ATM_CELL_PAYLOAD;
31790 }
31791
31792 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31793 if (iovb == NULL) {
31794 printk("nicstar%d: Out of iovec buffers.\n",
31795 card->index);
31796 - atomic_inc(&vcc->stats->rx_drop);
31797 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31798 recycle_rx_buf(card, skb);
31799 return;
31800 }
31801 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31802 small or large buffer itself. */
31803 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
31804 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
31805 - atomic_inc(&vcc->stats->rx_err);
31806 + atomic_inc_unchecked(&vcc->stats->rx_err);
31807 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31808 NS_MAX_IOVECS);
31809 NS_PRV_IOVCNT(iovb) = 0;
31810 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31811 ("nicstar%d: Expected a small buffer, and this is not one.\n",
31812 card->index);
31813 which_list(card, skb);
31814 - atomic_inc(&vcc->stats->rx_err);
31815 + atomic_inc_unchecked(&vcc->stats->rx_err);
31816 recycle_rx_buf(card, skb);
31817 vc->rx_iov = NULL;
31818 recycle_iov_buf(card, iovb);
31819 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31820 ("nicstar%d: Expected a large buffer, and this is not one.\n",
31821 card->index);
31822 which_list(card, skb);
31823 - atomic_inc(&vcc->stats->rx_err);
31824 + atomic_inc_unchecked(&vcc->stats->rx_err);
31825 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31826 NS_PRV_IOVCNT(iovb));
31827 vc->rx_iov = NULL;
31828 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31829 printk(" - PDU size mismatch.\n");
31830 else
31831 printk(".\n");
31832 - atomic_inc(&vcc->stats->rx_err);
31833 + atomic_inc_unchecked(&vcc->stats->rx_err);
31834 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31835 NS_PRV_IOVCNT(iovb));
31836 vc->rx_iov = NULL;
31837 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31838 /* skb points to a small buffer */
31839 if (!atm_charge(vcc, skb->truesize)) {
31840 push_rxbufs(card, skb);
31841 - atomic_inc(&vcc->stats->rx_drop);
31842 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31843 } else {
31844 skb_put(skb, len);
31845 dequeue_sm_buf(card, skb);
31846 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31847 ATM_SKB(skb)->vcc = vcc;
31848 __net_timestamp(skb);
31849 vcc->push(vcc, skb);
31850 - atomic_inc(&vcc->stats->rx);
31851 + atomic_inc_unchecked(&vcc->stats->rx);
31852 }
31853 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
31854 struct sk_buff *sb;
31855 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31856 if (len <= NS_SMBUFSIZE) {
31857 if (!atm_charge(vcc, sb->truesize)) {
31858 push_rxbufs(card, sb);
31859 - atomic_inc(&vcc->stats->rx_drop);
31860 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31861 } else {
31862 skb_put(sb, len);
31863 dequeue_sm_buf(card, sb);
31864 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31865 ATM_SKB(sb)->vcc = vcc;
31866 __net_timestamp(sb);
31867 vcc->push(vcc, sb);
31868 - atomic_inc(&vcc->stats->rx);
31869 + atomic_inc_unchecked(&vcc->stats->rx);
31870 }
31871
31872 push_rxbufs(card, skb);
31873 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31874
31875 if (!atm_charge(vcc, skb->truesize)) {
31876 push_rxbufs(card, skb);
31877 - atomic_inc(&vcc->stats->rx_drop);
31878 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31879 } else {
31880 dequeue_lg_buf(card, skb);
31881 #ifdef NS_USE_DESTRUCTORS
31882 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31883 ATM_SKB(skb)->vcc = vcc;
31884 __net_timestamp(skb);
31885 vcc->push(vcc, skb);
31886 - atomic_inc(&vcc->stats->rx);
31887 + atomic_inc_unchecked(&vcc->stats->rx);
31888 }
31889
31890 push_rxbufs(card, sb);
31891 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31892 printk
31893 ("nicstar%d: Out of huge buffers.\n",
31894 card->index);
31895 - atomic_inc(&vcc->stats->rx_drop);
31896 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31897 recycle_iovec_rx_bufs(card,
31898 (struct iovec *)
31899 iovb->data,
31900 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31901 card->hbpool.count++;
31902 } else
31903 dev_kfree_skb_any(hb);
31904 - atomic_inc(&vcc->stats->rx_drop);
31905 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31906 } else {
31907 /* Copy the small buffer to the huge buffer */
31908 sb = (struct sk_buff *)iov->iov_base;
31909 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31910 #endif /* NS_USE_DESTRUCTORS */
31911 __net_timestamp(hb);
31912 vcc->push(vcc, hb);
31913 - atomic_inc(&vcc->stats->rx);
31914 + atomic_inc_unchecked(&vcc->stats->rx);
31915 }
31916 }
31917
31918 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
31919 index 0474a89..06ea4a1 100644
31920 --- a/drivers/atm/solos-pci.c
31921 +++ b/drivers/atm/solos-pci.c
31922 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
31923 }
31924 atm_charge(vcc, skb->truesize);
31925 vcc->push(vcc, skb);
31926 - atomic_inc(&vcc->stats->rx);
31927 + atomic_inc_unchecked(&vcc->stats->rx);
31928 break;
31929
31930 case PKT_STATUS:
31931 @@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31932 vcc = SKB_CB(oldskb)->vcc;
31933
31934 if (vcc) {
31935 - atomic_inc(&vcc->stats->tx);
31936 + atomic_inc_unchecked(&vcc->stats->tx);
31937 solos_pop(vcc, oldskb);
31938 } else {
31939 dev_kfree_skb_irq(oldskb);
31940 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31941 index 0215934..ce9f5b1 100644
31942 --- a/drivers/atm/suni.c
31943 +++ b/drivers/atm/suni.c
31944 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31945
31946
31947 #define ADD_LIMITED(s,v) \
31948 - atomic_add((v),&stats->s); \
31949 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31950 + atomic_add_unchecked((v),&stats->s); \
31951 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31952
31953
31954 static void suni_hz(unsigned long from_timer)
31955 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31956 index 5120a96..e2572bd 100644
31957 --- a/drivers/atm/uPD98402.c
31958 +++ b/drivers/atm/uPD98402.c
31959 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31960 struct sonet_stats tmp;
31961 int error = 0;
31962
31963 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31964 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31965 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31966 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31967 if (zero && !error) {
31968 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31969
31970
31971 #define ADD_LIMITED(s,v) \
31972 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31973 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31974 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31975 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31976 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31977 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31978
31979
31980 static void stat_event(struct atm_dev *dev)
31981 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31982 if (reason & uPD98402_INT_PFM) stat_event(dev);
31983 if (reason & uPD98402_INT_PCO) {
31984 (void) GET(PCOCR); /* clear interrupt cause */
31985 - atomic_add(GET(HECCT),
31986 + atomic_add_unchecked(GET(HECCT),
31987 &PRIV(dev)->sonet_stats.uncorr_hcs);
31988 }
31989 if ((reason & uPD98402_INT_RFO) &&
31990 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31991 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31992 uPD98402_INT_LOS),PIMR); /* enable them */
31993 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31994 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31995 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31996 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31997 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31998 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31999 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32000 return 0;
32001 }
32002
32003 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32004 index 969c3c2..9b72956 100644
32005 --- a/drivers/atm/zatm.c
32006 +++ b/drivers/atm/zatm.c
32007 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32008 }
32009 if (!size) {
32010 dev_kfree_skb_irq(skb);
32011 - if (vcc) atomic_inc(&vcc->stats->rx_err);
32012 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32013 continue;
32014 }
32015 if (!atm_charge(vcc,skb->truesize)) {
32016 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32017 skb->len = size;
32018 ATM_SKB(skb)->vcc = vcc;
32019 vcc->push(vcc,skb);
32020 - atomic_inc(&vcc->stats->rx);
32021 + atomic_inc_unchecked(&vcc->stats->rx);
32022 }
32023 zout(pos & 0xffff,MTA(mbx));
32024 #if 0 /* probably a stupid idea */
32025 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32026 skb_queue_head(&zatm_vcc->backlog,skb);
32027 break;
32028 }
32029 - atomic_inc(&vcc->stats->tx);
32030 + atomic_inc_unchecked(&vcc->stats->tx);
32031 wake_up(&zatm_vcc->tx_wait);
32032 }
32033
32034 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32035 index 17cf7ca..7e553e1 100644
32036 --- a/drivers/base/devtmpfs.c
32037 +++ b/drivers/base/devtmpfs.c
32038 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32039 if (!thread)
32040 return 0;
32041
32042 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32043 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32044 if (err)
32045 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32046 else
32047 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32048 index e6ee5e8..98ad7fc 100644
32049 --- a/drivers/base/power/wakeup.c
32050 +++ b/drivers/base/power/wakeup.c
32051 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32052 * They need to be modified together atomically, so it's better to use one
32053 * atomic variable to hold them both.
32054 */
32055 -static atomic_t combined_event_count = ATOMIC_INIT(0);
32056 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32057
32058 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32059 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32060
32061 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32062 {
32063 - unsigned int comb = atomic_read(&combined_event_count);
32064 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
32065
32066 *cnt = (comb >> IN_PROGRESS_BITS);
32067 *inpr = comb & MAX_IN_PROGRESS;
32068 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32069 ws->start_prevent_time = ws->last_time;
32070
32071 /* Increment the counter of events in progress. */
32072 - cec = atomic_inc_return(&combined_event_count);
32073 + cec = atomic_inc_return_unchecked(&combined_event_count);
32074
32075 trace_wakeup_source_activate(ws->name, cec);
32076 }
32077 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32078 * Increment the counter of registered wakeup events and decrement the
32079 * couter of wakeup events in progress simultaneously.
32080 */
32081 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32082 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32083 trace_wakeup_source_deactivate(ws->name, cec);
32084
32085 split_counters(&cnt, &inpr);
32086 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32087 index ade58bc..867143d 100644
32088 --- a/drivers/block/cciss.c
32089 +++ b/drivers/block/cciss.c
32090 @@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32091 int err;
32092 u32 cp;
32093
32094 + memset(&arg64, 0, sizeof(arg64));
32095 +
32096 err = 0;
32097 err |=
32098 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32099 @@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32100 while (!list_empty(&h->reqQ)) {
32101 c = list_entry(h->reqQ.next, CommandList_struct, list);
32102 /* can't do anything if fifo is full */
32103 - if ((h->access.fifo_full(h))) {
32104 + if ((h->access->fifo_full(h))) {
32105 dev_warn(&h->pdev->dev, "fifo full\n");
32106 break;
32107 }
32108 @@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32109 h->Qdepth--;
32110
32111 /* Tell the controller execute command */
32112 - h->access.submit_command(h, c);
32113 + h->access->submit_command(h, c);
32114
32115 /* Put job onto the completed Q */
32116 addQ(&h->cmpQ, c);
32117 @@ -3441,17 +3443,17 @@ startio:
32118
32119 static inline unsigned long get_next_completion(ctlr_info_t *h)
32120 {
32121 - return h->access.command_completed(h);
32122 + return h->access->command_completed(h);
32123 }
32124
32125 static inline int interrupt_pending(ctlr_info_t *h)
32126 {
32127 - return h->access.intr_pending(h);
32128 + return h->access->intr_pending(h);
32129 }
32130
32131 static inline long interrupt_not_for_us(ctlr_info_t *h)
32132 {
32133 - return ((h->access.intr_pending(h) == 0) ||
32134 + return ((h->access->intr_pending(h) == 0) ||
32135 (h->interrupts_enabled == 0));
32136 }
32137
32138 @@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32139 u32 a;
32140
32141 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32142 - return h->access.command_completed(h);
32143 + return h->access->command_completed(h);
32144
32145 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32146 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32147 @@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32148 trans_support & CFGTBL_Trans_use_short_tags);
32149
32150 /* Change the access methods to the performant access methods */
32151 - h->access = SA5_performant_access;
32152 + h->access = &SA5_performant_access;
32153 h->transMethod = CFGTBL_Trans_Performant;
32154
32155 return;
32156 @@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32157 if (prod_index < 0)
32158 return -ENODEV;
32159 h->product_name = products[prod_index].product_name;
32160 - h->access = *(products[prod_index].access);
32161 + h->access = products[prod_index].access;
32162
32163 if (cciss_board_disabled(h)) {
32164 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32165 @@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32166 }
32167
32168 /* make sure the board interrupts are off */
32169 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32170 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32171 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32172 if (rc)
32173 goto clean2;
32174 @@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32175 * fake ones to scoop up any residual completions.
32176 */
32177 spin_lock_irqsave(&h->lock, flags);
32178 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32179 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32180 spin_unlock_irqrestore(&h->lock, flags);
32181 free_irq(h->intr[h->intr_mode], h);
32182 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32183 @@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32184 dev_info(&h->pdev->dev, "Board READY.\n");
32185 dev_info(&h->pdev->dev,
32186 "Waiting for stale completions to drain.\n");
32187 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32188 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32189 msleep(10000);
32190 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32191 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32192
32193 rc = controller_reset_failed(h->cfgtable);
32194 if (rc)
32195 @@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32196 cciss_scsi_setup(h);
32197
32198 /* Turn the interrupts on so we can service requests */
32199 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32200 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32201
32202 /* Get the firmware version */
32203 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32204 @@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32205 kfree(flush_buf);
32206 if (return_code != IO_OK)
32207 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32208 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32209 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32210 free_irq(h->intr[h->intr_mode], h);
32211 }
32212
32213 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32214 index 7fda30e..eb5dfe0 100644
32215 --- a/drivers/block/cciss.h
32216 +++ b/drivers/block/cciss.h
32217 @@ -101,7 +101,7 @@ struct ctlr_info
32218 /* information about each logical volume */
32219 drive_info_struct *drv[CISS_MAX_LUN];
32220
32221 - struct access_method access;
32222 + struct access_method *access;
32223
32224 /* queue and queue Info */
32225 struct list_head reqQ;
32226 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32227 index 3f08713..56a586a 100644
32228 --- a/drivers/block/cpqarray.c
32229 +++ b/drivers/block/cpqarray.c
32230 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32231 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32232 goto Enomem4;
32233 }
32234 - hba[i]->access.set_intr_mask(hba[i], 0);
32235 + hba[i]->access->set_intr_mask(hba[i], 0);
32236 if (request_irq(hba[i]->intr, do_ida_intr,
32237 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32238 {
32239 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32240 add_timer(&hba[i]->timer);
32241
32242 /* Enable IRQ now that spinlock and rate limit timer are set up */
32243 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32244 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32245
32246 for(j=0; j<NWD; j++) {
32247 struct gendisk *disk = ida_gendisk[i][j];
32248 @@ -694,7 +694,7 @@ DBGINFO(
32249 for(i=0; i<NR_PRODUCTS; i++) {
32250 if (board_id == products[i].board_id) {
32251 c->product_name = products[i].product_name;
32252 - c->access = *(products[i].access);
32253 + c->access = products[i].access;
32254 break;
32255 }
32256 }
32257 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32258 hba[ctlr]->intr = intr;
32259 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32260 hba[ctlr]->product_name = products[j].product_name;
32261 - hba[ctlr]->access = *(products[j].access);
32262 + hba[ctlr]->access = products[j].access;
32263 hba[ctlr]->ctlr = ctlr;
32264 hba[ctlr]->board_id = board_id;
32265 hba[ctlr]->pci_dev = NULL; /* not PCI */
32266 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32267
32268 while((c = h->reqQ) != NULL) {
32269 /* Can't do anything if we're busy */
32270 - if (h->access.fifo_full(h) == 0)
32271 + if (h->access->fifo_full(h) == 0)
32272 return;
32273
32274 /* Get the first entry from the request Q */
32275 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32276 h->Qdepth--;
32277
32278 /* Tell the controller to do our bidding */
32279 - h->access.submit_command(h, c);
32280 + h->access->submit_command(h, c);
32281
32282 /* Get onto the completion Q */
32283 addQ(&h->cmpQ, c);
32284 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32285 unsigned long flags;
32286 __u32 a,a1;
32287
32288 - istat = h->access.intr_pending(h);
32289 + istat = h->access->intr_pending(h);
32290 /* Is this interrupt for us? */
32291 if (istat == 0)
32292 return IRQ_NONE;
32293 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32294 */
32295 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32296 if (istat & FIFO_NOT_EMPTY) {
32297 - while((a = h->access.command_completed(h))) {
32298 + while((a = h->access->command_completed(h))) {
32299 a1 = a; a &= ~3;
32300 if ((c = h->cmpQ) == NULL)
32301 {
32302 @@ -1449,11 +1449,11 @@ static int sendcmd(
32303 /*
32304 * Disable interrupt
32305 */
32306 - info_p->access.set_intr_mask(info_p, 0);
32307 + info_p->access->set_intr_mask(info_p, 0);
32308 /* Make sure there is room in the command FIFO */
32309 /* Actually it should be completely empty at this time. */
32310 for (i = 200000; i > 0; i--) {
32311 - temp = info_p->access.fifo_full(info_p);
32312 + temp = info_p->access->fifo_full(info_p);
32313 if (temp != 0) {
32314 break;
32315 }
32316 @@ -1466,7 +1466,7 @@ DBG(
32317 /*
32318 * Send the cmd
32319 */
32320 - info_p->access.submit_command(info_p, c);
32321 + info_p->access->submit_command(info_p, c);
32322 complete = pollcomplete(ctlr);
32323
32324 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32325 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32326 * we check the new geometry. Then turn interrupts back on when
32327 * we're done.
32328 */
32329 - host->access.set_intr_mask(host, 0);
32330 + host->access->set_intr_mask(host, 0);
32331 getgeometry(ctlr);
32332 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32333 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32334
32335 for(i=0; i<NWD; i++) {
32336 struct gendisk *disk = ida_gendisk[ctlr][i];
32337 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32338 /* Wait (up to 2 seconds) for a command to complete */
32339
32340 for (i = 200000; i > 0; i--) {
32341 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
32342 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
32343 if (done == 0) {
32344 udelay(10); /* a short fixed delay */
32345 } else
32346 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32347 index be73e9d..7fbf140 100644
32348 --- a/drivers/block/cpqarray.h
32349 +++ b/drivers/block/cpqarray.h
32350 @@ -99,7 +99,7 @@ struct ctlr_info {
32351 drv_info_t drv[NWD];
32352 struct proc_dir_entry *proc;
32353
32354 - struct access_method access;
32355 + struct access_method *access;
32356
32357 cmdlist_t *reqQ;
32358 cmdlist_t *cmpQ;
32359 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32360 index 6b51afa..17e1191 100644
32361 --- a/drivers/block/drbd/drbd_int.h
32362 +++ b/drivers/block/drbd/drbd_int.h
32363 @@ -582,7 +582,7 @@ struct drbd_epoch {
32364 struct drbd_tconn *tconn;
32365 struct list_head list;
32366 unsigned int barrier_nr;
32367 - atomic_t epoch_size; /* increased on every request added. */
32368 + atomic_unchecked_t epoch_size; /* increased on every request added. */
32369 atomic_t active; /* increased on every req. added, and dec on every finished. */
32370 unsigned long flags;
32371 };
32372 @@ -1011,7 +1011,7 @@ struct drbd_conf {
32373 int al_tr_cycle;
32374 int al_tr_pos; /* position of the next transaction in the journal */
32375 wait_queue_head_t seq_wait;
32376 - atomic_t packet_seq;
32377 + atomic_unchecked_t packet_seq;
32378 unsigned int peer_seq;
32379 spinlock_t peer_seq_lock;
32380 unsigned int minor;
32381 @@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32382 char __user *uoptval;
32383 int err;
32384
32385 - uoptval = (char __user __force *)optval;
32386 + uoptval = (char __force_user *)optval;
32387
32388 set_fs(KERNEL_DS);
32389 if (level == SOL_SOCKET)
32390 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
32391 index 8c13eeb..217adee 100644
32392 --- a/drivers/block/drbd/drbd_main.c
32393 +++ b/drivers/block/drbd/drbd_main.c
32394 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
32395 p->sector = sector;
32396 p->block_id = block_id;
32397 p->blksize = blksize;
32398 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32399 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32400 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
32401 }
32402
32403 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
32404 return -EIO;
32405 p->sector = cpu_to_be64(req->i.sector);
32406 p->block_id = (unsigned long)req;
32407 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32408 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32409 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
32410 if (mdev->state.conn >= C_SYNC_SOURCE &&
32411 mdev->state.conn <= C_PAUSED_SYNC_T)
32412 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
32413 {
32414 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
32415
32416 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
32417 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
32418 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
32419 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
32420 kfree(tconn->current_epoch);
32421
32422 idr_destroy(&tconn->volumes);
32423 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
32424 index a9eccfc..68e4533 100644
32425 --- a/drivers/block/drbd/drbd_receiver.c
32426 +++ b/drivers/block/drbd/drbd_receiver.c
32427 @@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
32428 {
32429 int err;
32430
32431 - atomic_set(&mdev->packet_seq, 0);
32432 + atomic_set_unchecked(&mdev->packet_seq, 0);
32433 mdev->peer_seq = 0;
32434
32435 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
32436 @@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32437 do {
32438 next_epoch = NULL;
32439
32440 - epoch_size = atomic_read(&epoch->epoch_size);
32441 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
32442
32443 switch (ev & ~EV_CLEANUP) {
32444 case EV_PUT:
32445 @@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32446 rv = FE_DESTROYED;
32447 } else {
32448 epoch->flags = 0;
32449 - atomic_set(&epoch->epoch_size, 0);
32450 + atomic_set_unchecked(&epoch->epoch_size, 0);
32451 /* atomic_set(&epoch->active, 0); is already zero */
32452 if (rv == FE_STILL_LIVE)
32453 rv = FE_RECYCLED;
32454 @@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32455 conn_wait_active_ee_empty(tconn);
32456 drbd_flush(tconn);
32457
32458 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
32459 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32460 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
32461 if (epoch)
32462 break;
32463 @@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32464 }
32465
32466 epoch->flags = 0;
32467 - atomic_set(&epoch->epoch_size, 0);
32468 + atomic_set_unchecked(&epoch->epoch_size, 0);
32469 atomic_set(&epoch->active, 0);
32470
32471 spin_lock(&tconn->epoch_lock);
32472 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
32473 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32474 list_add(&epoch->list, &tconn->current_epoch->list);
32475 tconn->current_epoch = epoch;
32476 tconn->epochs++;
32477 @@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32478
32479 err = wait_for_and_update_peer_seq(mdev, peer_seq);
32480 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
32481 - atomic_inc(&tconn->current_epoch->epoch_size);
32482 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
32483 err2 = drbd_drain_block(mdev, pi->size);
32484 if (!err)
32485 err = err2;
32486 @@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32487
32488 spin_lock(&tconn->epoch_lock);
32489 peer_req->epoch = tconn->current_epoch;
32490 - atomic_inc(&peer_req->epoch->epoch_size);
32491 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
32492 atomic_inc(&peer_req->epoch->active);
32493 spin_unlock(&tconn->epoch_lock);
32494
32495 @@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
32496 if (!list_empty(&tconn->current_epoch->list))
32497 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
32498 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
32499 - atomic_set(&tconn->current_epoch->epoch_size, 0);
32500 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
32501 tconn->send.seen_any_write_yet = false;
32502
32503 conn_info(tconn, "Connection closed\n");
32504 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
32505 index ae12512..37fa397 100644
32506 --- a/drivers/block/loop.c
32507 +++ b/drivers/block/loop.c
32508 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
32509 mm_segment_t old_fs = get_fs();
32510
32511 set_fs(get_ds());
32512 - bw = file->f_op->write(file, buf, len, &pos);
32513 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
32514 set_fs(old_fs);
32515 if (likely(bw == len))
32516 return 0;
32517 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
32518 index d620b44..587561e 100644
32519 --- a/drivers/cdrom/cdrom.c
32520 +++ b/drivers/cdrom/cdrom.c
32521 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
32522 ENSURE(reset, CDC_RESET);
32523 ENSURE(generic_packet, CDC_GENERIC_PACKET);
32524 cdi->mc_flags = 0;
32525 - cdo->n_minors = 0;
32526 cdi->options = CDO_USE_FFLAGS;
32527
32528 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
32529 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
32530 else
32531 cdi->cdda_method = CDDA_OLD;
32532
32533 - if (!cdo->generic_packet)
32534 - cdo->generic_packet = cdrom_dummy_generic_packet;
32535 + if (!cdo->generic_packet) {
32536 + pax_open_kernel();
32537 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
32538 + pax_close_kernel();
32539 + }
32540
32541 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
32542 mutex_lock(&cdrom_mutex);
32543 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
32544 if (cdi->exit)
32545 cdi->exit(cdi);
32546
32547 - cdi->ops->n_minors--;
32548 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
32549 }
32550
32551 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
32552 index d59cdcb..11afddf 100644
32553 --- a/drivers/cdrom/gdrom.c
32554 +++ b/drivers/cdrom/gdrom.c
32555 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
32556 .audio_ioctl = gdrom_audio_ioctl,
32557 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
32558 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
32559 - .n_minors = 1,
32560 };
32561
32562 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
32563 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
32564 index 72bedad..8181ce1 100644
32565 --- a/drivers/char/Kconfig
32566 +++ b/drivers/char/Kconfig
32567 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
32568
32569 config DEVKMEM
32570 bool "/dev/kmem virtual device support"
32571 - default y
32572 + default n
32573 + depends on !GRKERNSEC_KMEM
32574 help
32575 Say Y here if you want to support the /dev/kmem device. The
32576 /dev/kmem device is rarely used, but can be used for certain
32577 @@ -581,6 +582,7 @@ config DEVPORT
32578 bool
32579 depends on !M68K
32580 depends on ISA || PCI
32581 + depends on !GRKERNSEC_KMEM
32582 default y
32583
32584 source "drivers/s390/char/Kconfig"
32585 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
32586 index 2e04433..22afc64 100644
32587 --- a/drivers/char/agp/frontend.c
32588 +++ b/drivers/char/agp/frontend.c
32589 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
32590 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
32591 return -EFAULT;
32592
32593 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
32594 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
32595 return -EFAULT;
32596
32597 client = agp_find_client_by_pid(reserve.pid);
32598 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
32599 index 21cb980..f15107c 100644
32600 --- a/drivers/char/genrtc.c
32601 +++ b/drivers/char/genrtc.c
32602 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
32603 switch (cmd) {
32604
32605 case RTC_PLL_GET:
32606 + memset(&pll, 0, sizeof(pll));
32607 if (get_rtc_pll(&pll))
32608 return -EINVAL;
32609 else
32610 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
32611 index fe6d4be..89f32100 100644
32612 --- a/drivers/char/hpet.c
32613 +++ b/drivers/char/hpet.c
32614 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
32615 }
32616
32617 static int
32618 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
32619 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
32620 struct hpet_info *info)
32621 {
32622 struct hpet_timer __iomem *timer;
32623 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
32624 index 053201b0..8335cce 100644
32625 --- a/drivers/char/ipmi/ipmi_msghandler.c
32626 +++ b/drivers/char/ipmi/ipmi_msghandler.c
32627 @@ -420,7 +420,7 @@ struct ipmi_smi {
32628 struct proc_dir_entry *proc_dir;
32629 char proc_dir_name[10];
32630
32631 - atomic_t stats[IPMI_NUM_STATS];
32632 + atomic_unchecked_t stats[IPMI_NUM_STATS];
32633
32634 /*
32635 * run_to_completion duplicate of smb_info, smi_info
32636 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
32637
32638
32639 #define ipmi_inc_stat(intf, stat) \
32640 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
32641 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
32642 #define ipmi_get_stat(intf, stat) \
32643 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
32644 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
32645
32646 static int is_lan_addr(struct ipmi_addr *addr)
32647 {
32648 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
32649 INIT_LIST_HEAD(&intf->cmd_rcvrs);
32650 init_waitqueue_head(&intf->waitq);
32651 for (i = 0; i < IPMI_NUM_STATS; i++)
32652 - atomic_set(&intf->stats[i], 0);
32653 + atomic_set_unchecked(&intf->stats[i], 0);
32654
32655 intf->proc_dir = NULL;
32656
32657 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
32658 index 1c7fdcd..4899100 100644
32659 --- a/drivers/char/ipmi/ipmi_si_intf.c
32660 +++ b/drivers/char/ipmi/ipmi_si_intf.c
32661 @@ -275,7 +275,7 @@ struct smi_info {
32662 unsigned char slave_addr;
32663
32664 /* Counters and things for the proc filesystem. */
32665 - atomic_t stats[SI_NUM_STATS];
32666 + atomic_unchecked_t stats[SI_NUM_STATS];
32667
32668 struct task_struct *thread;
32669
32670 @@ -284,9 +284,9 @@ struct smi_info {
32671 };
32672
32673 #define smi_inc_stat(smi, stat) \
32674 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
32675 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
32676 #define smi_get_stat(smi, stat) \
32677 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
32678 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
32679
32680 #define SI_MAX_PARMS 4
32681
32682 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
32683 atomic_set(&new_smi->req_events, 0);
32684 new_smi->run_to_completion = 0;
32685 for (i = 0; i < SI_NUM_STATS; i++)
32686 - atomic_set(&new_smi->stats[i], 0);
32687 + atomic_set_unchecked(&new_smi->stats[i], 0);
32688
32689 new_smi->interrupt_disabled = 1;
32690 atomic_set(&new_smi->stop_operation, 0);
32691 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
32692 index c6fa3bc..4ca3e42 100644
32693 --- a/drivers/char/mem.c
32694 +++ b/drivers/char/mem.c
32695 @@ -18,6 +18,7 @@
32696 #include <linux/raw.h>
32697 #include <linux/tty.h>
32698 #include <linux/capability.h>
32699 +#include <linux/security.h>
32700 #include <linux/ptrace.h>
32701 #include <linux/device.h>
32702 #include <linux/highmem.h>
32703 @@ -37,6 +38,10 @@
32704
32705 #define DEVPORT_MINOR 4
32706
32707 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32708 +extern const struct file_operations grsec_fops;
32709 +#endif
32710 +
32711 static inline unsigned long size_inside_page(unsigned long start,
32712 unsigned long size)
32713 {
32714 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32715
32716 while (cursor < to) {
32717 if (!devmem_is_allowed(pfn)) {
32718 +#ifdef CONFIG_GRKERNSEC_KMEM
32719 + gr_handle_mem_readwrite(from, to);
32720 +#else
32721 printk(KERN_INFO
32722 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
32723 current->comm, from, to);
32724 +#endif
32725 return 0;
32726 }
32727 cursor += PAGE_SIZE;
32728 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32729 }
32730 return 1;
32731 }
32732 +#elif defined(CONFIG_GRKERNSEC_KMEM)
32733 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32734 +{
32735 + return 0;
32736 +}
32737 #else
32738 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32739 {
32740 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32741
32742 while (count > 0) {
32743 unsigned long remaining;
32744 + char *temp;
32745
32746 sz = size_inside_page(p, count);
32747
32748 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32749 if (!ptr)
32750 return -EFAULT;
32751
32752 - remaining = copy_to_user(buf, ptr, sz);
32753 +#ifdef CONFIG_PAX_USERCOPY
32754 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32755 + if (!temp) {
32756 + unxlate_dev_mem_ptr(p, ptr);
32757 + return -ENOMEM;
32758 + }
32759 + memcpy(temp, ptr, sz);
32760 +#else
32761 + temp = ptr;
32762 +#endif
32763 +
32764 + remaining = copy_to_user(buf, temp, sz);
32765 +
32766 +#ifdef CONFIG_PAX_USERCOPY
32767 + kfree(temp);
32768 +#endif
32769 +
32770 unxlate_dev_mem_ptr(p, ptr);
32771 if (remaining)
32772 return -EFAULT;
32773 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32774 size_t count, loff_t *ppos)
32775 {
32776 unsigned long p = *ppos;
32777 - ssize_t low_count, read, sz;
32778 + ssize_t low_count, read, sz, err = 0;
32779 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
32780 - int err = 0;
32781
32782 read = 0;
32783 if (p < (unsigned long) high_memory) {
32784 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32785 }
32786 #endif
32787 while (low_count > 0) {
32788 + char *temp;
32789 +
32790 sz = size_inside_page(p, low_count);
32791
32792 /*
32793 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32794 */
32795 kbuf = xlate_dev_kmem_ptr((char *)p);
32796
32797 - if (copy_to_user(buf, kbuf, sz))
32798 +#ifdef CONFIG_PAX_USERCOPY
32799 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32800 + if (!temp)
32801 + return -ENOMEM;
32802 + memcpy(temp, kbuf, sz);
32803 +#else
32804 + temp = kbuf;
32805 +#endif
32806 +
32807 + err = copy_to_user(buf, temp, sz);
32808 +
32809 +#ifdef CONFIG_PAX_USERCOPY
32810 + kfree(temp);
32811 +#endif
32812 +
32813 + if (err)
32814 return -EFAULT;
32815 buf += sz;
32816 p += sz;
32817 @@ -833,6 +880,9 @@ static const struct memdev {
32818 #ifdef CONFIG_CRASH_DUMP
32819 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32820 #endif
32821 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32822 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32823 +#endif
32824 };
32825
32826 static int memory_open(struct inode *inode, struct file *filp)
32827 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32828 index 9df78e2..01ba9ae 100644
32829 --- a/drivers/char/nvram.c
32830 +++ b/drivers/char/nvram.c
32831 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32832
32833 spin_unlock_irq(&rtc_lock);
32834
32835 - if (copy_to_user(buf, contents, tmp - contents))
32836 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32837 return -EFAULT;
32838
32839 *ppos = i;
32840 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32841 index b66eaa0..2619d1b 100644
32842 --- a/drivers/char/pcmcia/synclink_cs.c
32843 +++ b/drivers/char/pcmcia/synclink_cs.c
32844 @@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32845
32846 if (debug_level >= DEBUG_LEVEL_INFO)
32847 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32848 - __FILE__,__LINE__, info->device_name, port->count);
32849 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32850
32851 - WARN_ON(!port->count);
32852 + WARN_ON(!atomic_read(&port->count));
32853
32854 if (tty_port_close_start(port, tty, filp) == 0)
32855 goto cleanup;
32856 @@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32857 cleanup:
32858 if (debug_level >= DEBUG_LEVEL_INFO)
32859 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32860 - tty->driver->name, port->count);
32861 + tty->driver->name, atomic_read(&port->count));
32862 }
32863
32864 /* Wait until the transmitter is empty.
32865 @@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32866
32867 if (debug_level >= DEBUG_LEVEL_INFO)
32868 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32869 - __FILE__,__LINE__,tty->driver->name, port->count);
32870 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32871
32872 /* If port is closing, signal caller to try again */
32873 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32874 @@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32875 goto cleanup;
32876 }
32877 spin_lock(&port->lock);
32878 - port->count++;
32879 + atomic_inc(&port->count);
32880 spin_unlock(&port->lock);
32881 spin_unlock_irqrestore(&info->netlock, flags);
32882
32883 - if (port->count == 1) {
32884 + if (atomic_read(&port->count) == 1) {
32885 /* 1st open on this device, init hardware */
32886 retval = startup(info, tty);
32887 if (retval < 0)
32888 @@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32889 unsigned short new_crctype;
32890
32891 /* return error if TTY interface open */
32892 - if (info->port.count)
32893 + if (atomic_read(&info->port.count))
32894 return -EBUSY;
32895
32896 switch (encoding)
32897 @@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
32898
32899 /* arbitrate between network and tty opens */
32900 spin_lock_irqsave(&info->netlock, flags);
32901 - if (info->port.count != 0 || info->netcount != 0) {
32902 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32903 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32904 spin_unlock_irqrestore(&info->netlock, flags);
32905 return -EBUSY;
32906 @@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32907 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32908
32909 /* return error if TTY interface open */
32910 - if (info->port.count)
32911 + if (atomic_read(&info->port.count))
32912 return -EBUSY;
32913
32914 if (cmd != SIOCWANDEV)
32915 diff --git a/drivers/char/random.c b/drivers/char/random.c
32916 index 85e81ec..bce8b97 100644
32917 --- a/drivers/char/random.c
32918 +++ b/drivers/char/random.c
32919 @@ -272,8 +272,13 @@
32920 /*
32921 * Configuration information
32922 */
32923 +#ifdef CONFIG_GRKERNSEC_RANDNET
32924 +#define INPUT_POOL_WORDS 512
32925 +#define OUTPUT_POOL_WORDS 128
32926 +#else
32927 #define INPUT_POOL_WORDS 128
32928 #define OUTPUT_POOL_WORDS 32
32929 +#endif
32930 #define SEC_XFER_SIZE 512
32931 #define EXTRACT_SIZE 10
32932
32933 @@ -313,10 +318,17 @@ static struct poolinfo {
32934 int poolwords;
32935 int tap1, tap2, tap3, tap4, tap5;
32936 } poolinfo_table[] = {
32937 +#ifdef CONFIG_GRKERNSEC_RANDNET
32938 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32939 + { 512, 411, 308, 208, 104, 1 },
32940 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32941 + { 128, 103, 76, 51, 25, 1 },
32942 +#else
32943 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32944 { 128, 103, 76, 51, 25, 1 },
32945 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32946 { 32, 26, 20, 14, 7, 1 },
32947 +#endif
32948 #if 0
32949 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32950 { 2048, 1638, 1231, 819, 411, 1 },
32951 @@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32952 input_rotate += i ? 7 : 14;
32953 }
32954
32955 - ACCESS_ONCE(r->input_rotate) = input_rotate;
32956 - ACCESS_ONCE(r->add_ptr) = i;
32957 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32958 + ACCESS_ONCE_RW(r->add_ptr) = i;
32959 smp_wmb();
32960
32961 if (out)
32962 @@ -1020,7 +1032,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32963
32964 extract_buf(r, tmp);
32965 i = min_t(int, nbytes, EXTRACT_SIZE);
32966 - if (copy_to_user(buf, tmp, i)) {
32967 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32968 ret = -EFAULT;
32969 break;
32970 }
32971 @@ -1356,7 +1368,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32972 #include <linux/sysctl.h>
32973
32974 static int min_read_thresh = 8, min_write_thresh;
32975 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
32976 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32977 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32978 static char sysctl_bootid[16];
32979
32980 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32981 index d780295..b29f3a8 100644
32982 --- a/drivers/char/sonypi.c
32983 +++ b/drivers/char/sonypi.c
32984 @@ -54,6 +54,7 @@
32985
32986 #include <asm/uaccess.h>
32987 #include <asm/io.h>
32988 +#include <asm/local.h>
32989
32990 #include <linux/sonypi.h>
32991
32992 @@ -490,7 +491,7 @@ static struct sonypi_device {
32993 spinlock_t fifo_lock;
32994 wait_queue_head_t fifo_proc_list;
32995 struct fasync_struct *fifo_async;
32996 - int open_count;
32997 + local_t open_count;
32998 int model;
32999 struct input_dev *input_jog_dev;
33000 struct input_dev *input_key_dev;
33001 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33002 static int sonypi_misc_release(struct inode *inode, struct file *file)
33003 {
33004 mutex_lock(&sonypi_device.lock);
33005 - sonypi_device.open_count--;
33006 + local_dec(&sonypi_device.open_count);
33007 mutex_unlock(&sonypi_device.lock);
33008 return 0;
33009 }
33010 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33011 {
33012 mutex_lock(&sonypi_device.lock);
33013 /* Flush input queue on first open */
33014 - if (!sonypi_device.open_count)
33015 + if (!local_read(&sonypi_device.open_count))
33016 kfifo_reset(&sonypi_device.fifo);
33017 - sonypi_device.open_count++;
33018 + local_inc(&sonypi_device.open_count);
33019 mutex_unlock(&sonypi_device.lock);
33020
33021 return 0;
33022 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33023 index 93211df..c7805f7 100644
33024 --- a/drivers/char/tpm/tpm.c
33025 +++ b/drivers/char/tpm/tpm.c
33026 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33027 chip->vendor.req_complete_val)
33028 goto out_recv;
33029
33030 - if ((status == chip->vendor.req_canceled)) {
33031 + if (status == chip->vendor.req_canceled) {
33032 dev_err(chip->dev, "Operation Canceled\n");
33033 rc = -ECANCELED;
33034 goto out;
33035 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33036 index 56051d0..11cf3b7 100644
33037 --- a/drivers/char/tpm/tpm_acpi.c
33038 +++ b/drivers/char/tpm/tpm_acpi.c
33039 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33040 virt = acpi_os_map_memory(start, len);
33041 if (!virt) {
33042 kfree(log->bios_event_log);
33043 + log->bios_event_log = NULL;
33044 printk("%s: ERROR - Unable to map memory\n", __func__);
33045 return -EIO;
33046 }
33047
33048 - memcpy_fromio(log->bios_event_log, virt, len);
33049 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33050
33051 acpi_os_unmap_memory(virt, len);
33052 return 0;
33053 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33054 index 84ddc55..1d32f1e 100644
33055 --- a/drivers/char/tpm/tpm_eventlog.c
33056 +++ b/drivers/char/tpm/tpm_eventlog.c
33057 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33058 event = addr;
33059
33060 if ((event->event_type == 0 && event->event_size == 0) ||
33061 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33062 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33063 return NULL;
33064
33065 return addr;
33066 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33067 return NULL;
33068
33069 if ((event->event_type == 0 && event->event_size == 0) ||
33070 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33071 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33072 return NULL;
33073
33074 (*pos)++;
33075 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33076 int i;
33077
33078 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33079 - seq_putc(m, data[i]);
33080 + if (!seq_putc(m, data[i]))
33081 + return -EFAULT;
33082
33083 return 0;
33084 }
33085 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33086 index ee4dbea..69c817b 100644
33087 --- a/drivers/char/virtio_console.c
33088 +++ b/drivers/char/virtio_console.c
33089 @@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33090 if (to_user) {
33091 ssize_t ret;
33092
33093 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33094 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33095 if (ret)
33096 return -EFAULT;
33097 } else {
33098 @@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33099 if (!port_has_data(port) && !port->host_connected)
33100 return 0;
33101
33102 - return fill_readbuf(port, ubuf, count, true);
33103 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33104 }
33105
33106 static int wait_port_writable(struct port *port, bool nonblock)
33107 diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33108 index 8ae1a61..9c00613 100644
33109 --- a/drivers/clocksource/arm_generic.c
33110 +++ b/drivers/clocksource/arm_generic.c
33111 @@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33112 return NOTIFY_OK;
33113 }
33114
33115 -static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33116 +static struct notifier_block arch_timer_cpu_nb = {
33117 .notifier_call = arch_timer_cpu_notify,
33118 };
33119
33120 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33121 index 1f93dbd..edf95ff 100644
33122 --- a/drivers/cpufreq/cpufreq.c
33123 +++ b/drivers/cpufreq/cpufreq.c
33124 @@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33125 return NOTIFY_OK;
33126 }
33127
33128 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
33129 +static struct notifier_block cpufreq_cpu_notifier = {
33130 .notifier_call = cpufreq_cpu_callback,
33131 };
33132
33133 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33134 index 9d7732b..0b1a793 100644
33135 --- a/drivers/cpufreq/cpufreq_stats.c
33136 +++ b/drivers/cpufreq/cpufreq_stats.c
33137 @@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33138 }
33139
33140 /* priority=1 so this will get called before cpufreq_remove_dev */
33141 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33142 +static struct notifier_block cpufreq_stat_cpu_notifier = {
33143 .notifier_call = cpufreq_stat_cpu_callback,
33144 .priority = 1,
33145 };
33146 diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
33147 index 3315e4b..fc38316 100644
33148 --- a/drivers/dma/sh/shdma.c
33149 +++ b/drivers/dma/sh/shdma.c
33150 @@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
33151 return ret;
33152 }
33153
33154 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
33155 +static struct notifier_block sh_dmae_nmi_notifier = {
33156 .notifier_call = sh_dmae_nmi_handler,
33157
33158 /* Run before NMI debug handler and KGDB */
33159 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
33160 index 0056c4d..725934f 100644
33161 --- a/drivers/edac/edac_pci_sysfs.c
33162 +++ b/drivers/edac/edac_pci_sysfs.c
33163 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
33164 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
33165 static int edac_pci_poll_msec = 1000; /* one second workq period */
33166
33167 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
33168 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
33169 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
33170 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
33171
33172 static struct kobject *edac_pci_top_main_kobj;
33173 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
33174 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33175 edac_printk(KERN_CRIT, EDAC_PCI,
33176 "Signaled System Error on %s\n",
33177 pci_name(dev));
33178 - atomic_inc(&pci_nonparity_count);
33179 + atomic_inc_unchecked(&pci_nonparity_count);
33180 }
33181
33182 if (status & (PCI_STATUS_PARITY)) {
33183 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33184 "Master Data Parity Error on %s\n",
33185 pci_name(dev));
33186
33187 - atomic_inc(&pci_parity_count);
33188 + atomic_inc_unchecked(&pci_parity_count);
33189 }
33190
33191 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33192 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33193 "Detected Parity Error on %s\n",
33194 pci_name(dev));
33195
33196 - atomic_inc(&pci_parity_count);
33197 + atomic_inc_unchecked(&pci_parity_count);
33198 }
33199 }
33200
33201 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33202 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
33203 "Signaled System Error on %s\n",
33204 pci_name(dev));
33205 - atomic_inc(&pci_nonparity_count);
33206 + atomic_inc_unchecked(&pci_nonparity_count);
33207 }
33208
33209 if (status & (PCI_STATUS_PARITY)) {
33210 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33211 "Master Data Parity Error on "
33212 "%s\n", pci_name(dev));
33213
33214 - atomic_inc(&pci_parity_count);
33215 + atomic_inc_unchecked(&pci_parity_count);
33216 }
33217
33218 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33219 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33220 "Detected Parity Error on %s\n",
33221 pci_name(dev));
33222
33223 - atomic_inc(&pci_parity_count);
33224 + atomic_inc_unchecked(&pci_parity_count);
33225 }
33226 }
33227 }
33228 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
33229 if (!check_pci_errors)
33230 return;
33231
33232 - before_count = atomic_read(&pci_parity_count);
33233 + before_count = atomic_read_unchecked(&pci_parity_count);
33234
33235 /* scan all PCI devices looking for a Parity Error on devices and
33236 * bridges.
33237 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
33238 /* Only if operator has selected panic on PCI Error */
33239 if (edac_pci_get_panic_on_pe()) {
33240 /* If the count is different 'after' from 'before' */
33241 - if (before_count != atomic_read(&pci_parity_count))
33242 + if (before_count != atomic_read_unchecked(&pci_parity_count))
33243 panic("EDAC: PCI Parity Error");
33244 }
33245 }
33246 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
33247 index 6796799..99e8377 100644
33248 --- a/drivers/edac/mce_amd.h
33249 +++ b/drivers/edac/mce_amd.h
33250 @@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
33251 struct amd_decoder_ops {
33252 bool (*mc0_mce)(u16, u8);
33253 bool (*mc1_mce)(u16, u8);
33254 -};
33255 +} __no_const;
33256
33257 void amd_report_gart_errors(bool);
33258 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
33259 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
33260 index 57ea7f4..789e3c3 100644
33261 --- a/drivers/firewire/core-card.c
33262 +++ b/drivers/firewire/core-card.c
33263 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
33264
33265 void fw_core_remove_card(struct fw_card *card)
33266 {
33267 - struct fw_card_driver dummy_driver = dummy_driver_template;
33268 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
33269
33270 card->driver->update_phy_reg(card, 4,
33271 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
33272 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
33273 index f8d2287..5aaf4db 100644
33274 --- a/drivers/firewire/core-cdev.c
33275 +++ b/drivers/firewire/core-cdev.c
33276 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
33277 int ret;
33278
33279 if ((request->channels == 0 && request->bandwidth == 0) ||
33280 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
33281 - request->bandwidth < 0)
33282 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
33283 return -EINVAL;
33284
33285 r = kmalloc(sizeof(*r), GFP_KERNEL);
33286 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
33287 index 28a94c7..58da63a 100644
33288 --- a/drivers/firewire/core-transaction.c
33289 +++ b/drivers/firewire/core-transaction.c
33290 @@ -38,6 +38,7 @@
33291 #include <linux/timer.h>
33292 #include <linux/types.h>
33293 #include <linux/workqueue.h>
33294 +#include <linux/sched.h>
33295
33296 #include <asm/byteorder.h>
33297
33298 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
33299 index 515a42c..5ecf3ba 100644
33300 --- a/drivers/firewire/core.h
33301 +++ b/drivers/firewire/core.h
33302 @@ -111,6 +111,7 @@ struct fw_card_driver {
33303
33304 int (*stop_iso)(struct fw_iso_context *ctx);
33305 };
33306 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
33307
33308 void fw_card_initialize(struct fw_card *card,
33309 const struct fw_card_driver *driver, struct device *device);
33310 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
33311 index 982f1f5..d21e5da 100644
33312 --- a/drivers/firmware/dmi_scan.c
33313 +++ b/drivers/firmware/dmi_scan.c
33314 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
33315 }
33316 }
33317 else {
33318 - /*
33319 - * no iounmap() for that ioremap(); it would be a no-op, but
33320 - * it's so early in setup that sucker gets confused into doing
33321 - * what it shouldn't if we actually call it.
33322 - */
33323 p = dmi_ioremap(0xF0000, 0x10000);
33324 if (p == NULL)
33325 goto error;
33326 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
33327 if (buf == NULL)
33328 return -1;
33329
33330 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
33331 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
33332
33333 iounmap(buf);
33334 return 0;
33335 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
33336 index f5596db..9355ce6 100644
33337 --- a/drivers/firmware/efivars.c
33338 +++ b/drivers/firmware/efivars.c
33339 @@ -132,7 +132,7 @@ struct efivar_attribute {
33340 };
33341
33342 static struct efivars __efivars;
33343 -static struct efivar_operations ops;
33344 +static efivar_operations_no_const ops __read_only;
33345
33346 #define PSTORE_EFI_ATTRIBUTES \
33347 (EFI_VARIABLE_NON_VOLATILE | \
33348 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
33349 index 9902732..64b62dd 100644
33350 --- a/drivers/gpio/gpio-vr41xx.c
33351 +++ b/drivers/gpio/gpio-vr41xx.c
33352 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
33353 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
33354 maskl, pendl, maskh, pendh);
33355
33356 - atomic_inc(&irq_err_count);
33357 + atomic_inc_unchecked(&irq_err_count);
33358
33359 return -EINVAL;
33360 }
33361 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
33362 index 7b2d378..cc947ea 100644
33363 --- a/drivers/gpu/drm/drm_crtc_helper.c
33364 +++ b/drivers/gpu/drm/drm_crtc_helper.c
33365 @@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
33366 struct drm_crtc *tmp;
33367 int crtc_mask = 1;
33368
33369 - WARN(!crtc, "checking null crtc?\n");
33370 + BUG_ON(!crtc);
33371
33372 dev = crtc->dev;
33373
33374 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
33375 index be174ca..0bcbb71 100644
33376 --- a/drivers/gpu/drm/drm_drv.c
33377 +++ b/drivers/gpu/drm/drm_drv.c
33378 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
33379 /**
33380 * Copy and IOCTL return string to user space
33381 */
33382 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
33383 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
33384 {
33385 int len;
33386
33387 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
33388 return -ENODEV;
33389
33390 atomic_inc(&dev->ioctl_count);
33391 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
33392 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
33393 ++file_priv->ioctl_count;
33394
33395 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
33396 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
33397 index 133b413..fd68225 100644
33398 --- a/drivers/gpu/drm/drm_fops.c
33399 +++ b/drivers/gpu/drm/drm_fops.c
33400 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
33401 }
33402
33403 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
33404 - atomic_set(&dev->counts[i], 0);
33405 + atomic_set_unchecked(&dev->counts[i], 0);
33406
33407 dev->sigdata.lock = NULL;
33408
33409 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
33410 if (drm_device_is_unplugged(dev))
33411 return -ENODEV;
33412
33413 - if (!dev->open_count++)
33414 + if (local_inc_return(&dev->open_count) == 1)
33415 need_setup = 1;
33416 mutex_lock(&dev->struct_mutex);
33417 old_mapping = dev->dev_mapping;
33418 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
33419 retcode = drm_open_helper(inode, filp, dev);
33420 if (retcode)
33421 goto err_undo;
33422 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
33423 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
33424 if (need_setup) {
33425 retcode = drm_setup(dev);
33426 if (retcode)
33427 @@ -164,7 +164,7 @@ err_undo:
33428 iput(container_of(dev->dev_mapping, struct inode, i_data));
33429 dev->dev_mapping = old_mapping;
33430 mutex_unlock(&dev->struct_mutex);
33431 - dev->open_count--;
33432 + local_dec(&dev->open_count);
33433 return retcode;
33434 }
33435 EXPORT_SYMBOL(drm_open);
33436 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
33437
33438 mutex_lock(&drm_global_mutex);
33439
33440 - DRM_DEBUG("open_count = %d\n", dev->open_count);
33441 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
33442
33443 if (dev->driver->preclose)
33444 dev->driver->preclose(dev, file_priv);
33445 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
33446 * Begin inline drm_release
33447 */
33448
33449 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
33450 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
33451 task_pid_nr(current),
33452 (long)old_encode_dev(file_priv->minor->device),
33453 - dev->open_count);
33454 + local_read(&dev->open_count));
33455
33456 /* Release any auth tokens that might point to this file_priv,
33457 (do that under the drm_global_mutex) */
33458 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
33459 * End inline drm_release
33460 */
33461
33462 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
33463 - if (!--dev->open_count) {
33464 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
33465 + if (local_dec_and_test(&dev->open_count)) {
33466 if (atomic_read(&dev->ioctl_count)) {
33467 DRM_ERROR("Device busy: %d\n",
33468 atomic_read(&dev->ioctl_count));
33469 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
33470 index f731116..629842c 100644
33471 --- a/drivers/gpu/drm/drm_global.c
33472 +++ b/drivers/gpu/drm/drm_global.c
33473 @@ -36,7 +36,7 @@
33474 struct drm_global_item {
33475 struct mutex mutex;
33476 void *object;
33477 - int refcount;
33478 + atomic_t refcount;
33479 };
33480
33481 static struct drm_global_item glob[DRM_GLOBAL_NUM];
33482 @@ -49,7 +49,7 @@ void drm_global_init(void)
33483 struct drm_global_item *item = &glob[i];
33484 mutex_init(&item->mutex);
33485 item->object = NULL;
33486 - item->refcount = 0;
33487 + atomic_set(&item->refcount, 0);
33488 }
33489 }
33490
33491 @@ -59,7 +59,7 @@ void drm_global_release(void)
33492 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
33493 struct drm_global_item *item = &glob[i];
33494 BUG_ON(item->object != NULL);
33495 - BUG_ON(item->refcount != 0);
33496 + BUG_ON(atomic_read(&item->refcount) != 0);
33497 }
33498 }
33499
33500 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33501 void *object;
33502
33503 mutex_lock(&item->mutex);
33504 - if (item->refcount == 0) {
33505 + if (atomic_read(&item->refcount) == 0) {
33506 item->object = kzalloc(ref->size, GFP_KERNEL);
33507 if (unlikely(item->object == NULL)) {
33508 ret = -ENOMEM;
33509 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33510 goto out_err;
33511
33512 }
33513 - ++item->refcount;
33514 + atomic_inc(&item->refcount);
33515 ref->object = item->object;
33516 object = item->object;
33517 mutex_unlock(&item->mutex);
33518 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
33519 struct drm_global_item *item = &glob[ref->global_type];
33520
33521 mutex_lock(&item->mutex);
33522 - BUG_ON(item->refcount == 0);
33523 + BUG_ON(atomic_read(&item->refcount) == 0);
33524 BUG_ON(ref->object != item->object);
33525 - if (--item->refcount == 0) {
33526 + if (atomic_dec_and_test(&item->refcount)) {
33527 ref->release(ref);
33528 item->object = NULL;
33529 }
33530 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
33531 index d4b20ce..77a8d41 100644
33532 --- a/drivers/gpu/drm/drm_info.c
33533 +++ b/drivers/gpu/drm/drm_info.c
33534 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
33535 struct drm_local_map *map;
33536 struct drm_map_list *r_list;
33537
33538 - /* Hardcoded from _DRM_FRAME_BUFFER,
33539 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
33540 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
33541 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
33542 + static const char * const types[] = {
33543 + [_DRM_FRAME_BUFFER] = "FB",
33544 + [_DRM_REGISTERS] = "REG",
33545 + [_DRM_SHM] = "SHM",
33546 + [_DRM_AGP] = "AGP",
33547 + [_DRM_SCATTER_GATHER] = "SG",
33548 + [_DRM_CONSISTENT] = "PCI",
33549 + [_DRM_GEM] = "GEM" };
33550 const char *type;
33551 int i;
33552
33553 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
33554 map = r_list->map;
33555 if (!map)
33556 continue;
33557 - if (map->type < 0 || map->type > 5)
33558 + if (map->type >= ARRAY_SIZE(types))
33559 type = "??";
33560 else
33561 type = types[map->type];
33562 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
33563 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
33564 vma->vm_flags & VM_LOCKED ? 'l' : '-',
33565 vma->vm_flags & VM_IO ? 'i' : '-',
33566 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33567 + 0);
33568 +#else
33569 vma->vm_pgoff);
33570 +#endif
33571
33572 #if defined(__i386__)
33573 pgprot = pgprot_val(vma->vm_page_prot);
33574 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
33575 index 2f4c434..764794b 100644
33576 --- a/drivers/gpu/drm/drm_ioc32.c
33577 +++ b/drivers/gpu/drm/drm_ioc32.c
33578 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
33579 request = compat_alloc_user_space(nbytes);
33580 if (!access_ok(VERIFY_WRITE, request, nbytes))
33581 return -EFAULT;
33582 - list = (struct drm_buf_desc *) (request + 1);
33583 + list = (struct drm_buf_desc __user *) (request + 1);
33584
33585 if (__put_user(count, &request->count)
33586 || __put_user(list, &request->list))
33587 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
33588 request = compat_alloc_user_space(nbytes);
33589 if (!access_ok(VERIFY_WRITE, request, nbytes))
33590 return -EFAULT;
33591 - list = (struct drm_buf_pub *) (request + 1);
33592 + list = (struct drm_buf_pub __user *) (request + 1);
33593
33594 if (__put_user(count, &request->count)
33595 || __put_user(list, &request->list))
33596 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
33597 index e77bd8b..1571b85 100644
33598 --- a/drivers/gpu/drm/drm_ioctl.c
33599 +++ b/drivers/gpu/drm/drm_ioctl.c
33600 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
33601 stats->data[i].value =
33602 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
33603 else
33604 - stats->data[i].value = atomic_read(&dev->counts[i]);
33605 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
33606 stats->data[i].type = dev->types[i];
33607 }
33608
33609 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
33610 index d752c96..fe08455 100644
33611 --- a/drivers/gpu/drm/drm_lock.c
33612 +++ b/drivers/gpu/drm/drm_lock.c
33613 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33614 if (drm_lock_take(&master->lock, lock->context)) {
33615 master->lock.file_priv = file_priv;
33616 master->lock.lock_time = jiffies;
33617 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
33618 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
33619 break; /* Got lock */
33620 }
33621
33622 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33623 return -EINVAL;
33624 }
33625
33626 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
33627 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
33628
33629 if (drm_lock_free(&master->lock, lock->context)) {
33630 /* FIXME: Should really bail out here. */
33631 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
33632 index 200e104..59facda 100644
33633 --- a/drivers/gpu/drm/drm_stub.c
33634 +++ b/drivers/gpu/drm/drm_stub.c
33635 @@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
33636
33637 drm_device_set_unplugged(dev);
33638
33639 - if (dev->open_count == 0) {
33640 + if (local_read(&dev->open_count) == 0) {
33641 drm_put_dev(dev);
33642 }
33643 mutex_unlock(&drm_global_mutex);
33644 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
33645 index 004ecdf..db1f6e0 100644
33646 --- a/drivers/gpu/drm/i810/i810_dma.c
33647 +++ b/drivers/gpu/drm/i810/i810_dma.c
33648 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
33649 dma->buflist[vertex->idx],
33650 vertex->discard, vertex->used);
33651
33652 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33653 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33654 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33655 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33656 sarea_priv->last_enqueue = dev_priv->counter - 1;
33657 sarea_priv->last_dispatch = (int)hw_status[5];
33658
33659 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
33660 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
33661 mc->last_render);
33662
33663 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33664 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33665 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33666 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33667 sarea_priv->last_enqueue = dev_priv->counter - 1;
33668 sarea_priv->last_dispatch = (int)hw_status[5];
33669
33670 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
33671 index 6e0acad..93c8289 100644
33672 --- a/drivers/gpu/drm/i810/i810_drv.h
33673 +++ b/drivers/gpu/drm/i810/i810_drv.h
33674 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
33675 int page_flipping;
33676
33677 wait_queue_head_t irq_queue;
33678 - atomic_t irq_received;
33679 - atomic_t irq_emitted;
33680 + atomic_unchecked_t irq_received;
33681 + atomic_unchecked_t irq_emitted;
33682
33683 int front_offset;
33684 } drm_i810_private_t;
33685 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
33686 index 9d4a2c2..32a119f 100644
33687 --- a/drivers/gpu/drm/i915/i915_debugfs.c
33688 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
33689 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33690 I915_READ(GTIMR));
33691 }
33692 seq_printf(m, "Interrupts received: %d\n",
33693 - atomic_read(&dev_priv->irq_received));
33694 + atomic_read_unchecked(&dev_priv->irq_received));
33695 for_each_ring(ring, dev_priv, i) {
33696 if (IS_GEN6(dev) || IS_GEN7(dev)) {
33697 seq_printf(m,
33698 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
33699 index 99daa89..84ebd44 100644
33700 --- a/drivers/gpu/drm/i915/i915_dma.c
33701 +++ b/drivers/gpu/drm/i915/i915_dma.c
33702 @@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
33703 bool can_switch;
33704
33705 spin_lock(&dev->count_lock);
33706 - can_switch = (dev->open_count == 0);
33707 + can_switch = (local_read(&dev->open_count) == 0);
33708 spin_unlock(&dev->count_lock);
33709 return can_switch;
33710 }
33711 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33712 index 12ab3bd..b3bed3b 100644
33713 --- a/drivers/gpu/drm/i915/i915_drv.h
33714 +++ b/drivers/gpu/drm/i915/i915_drv.h
33715 @@ -656,7 +656,7 @@ typedef struct drm_i915_private {
33716 drm_dma_handle_t *status_page_dmah;
33717 struct resource mch_res;
33718
33719 - atomic_t irq_received;
33720 + atomic_unchecked_t irq_received;
33721
33722 /* protects the irq masks */
33723 spinlock_t irq_lock;
33724 @@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
33725 * will be page flipped away on the next vblank. When it
33726 * reaches 0, dev_priv->pending_flip_queue will be woken up.
33727 */
33728 - atomic_t pending_flip;
33729 + atomic_unchecked_t pending_flip;
33730 };
33731 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
33732
33733 @@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
33734 struct drm_i915_private *dev_priv, unsigned port);
33735 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
33736 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
33737 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33738 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33739 {
33740 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
33741 }
33742 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33743 index 26d08bb..fccb984 100644
33744 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33745 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33746 @@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
33747 i915_gem_clflush_object(obj);
33748
33749 if (obj->base.pending_write_domain)
33750 - flips |= atomic_read(&obj->pending_flip);
33751 + flips |= atomic_read_unchecked(&obj->pending_flip);
33752
33753 flush_domains |= obj->base.write_domain;
33754 }
33755 @@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
33756
33757 static int
33758 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
33759 - int count)
33760 + unsigned int count)
33761 {
33762 - int i;
33763 + unsigned int i;
33764
33765 for (i = 0; i < count; i++) {
33766 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
33767 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33768 index fe84338..a863190 100644
33769 --- a/drivers/gpu/drm/i915/i915_irq.c
33770 +++ b/drivers/gpu/drm/i915/i915_irq.c
33771 @@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
33772 u32 pipe_stats[I915_MAX_PIPES];
33773 bool blc_event;
33774
33775 - atomic_inc(&dev_priv->irq_received);
33776 + atomic_inc_unchecked(&dev_priv->irq_received);
33777
33778 while (true) {
33779 iir = I915_READ(VLV_IIR);
33780 @@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
33781 irqreturn_t ret = IRQ_NONE;
33782 int i;
33783
33784 - atomic_inc(&dev_priv->irq_received);
33785 + atomic_inc_unchecked(&dev_priv->irq_received);
33786
33787 /* disable master interrupt before clearing iir */
33788 de_ier = I915_READ(DEIER);
33789 @@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
33790 int ret = IRQ_NONE;
33791 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33792
33793 - atomic_inc(&dev_priv->irq_received);
33794 + atomic_inc_unchecked(&dev_priv->irq_received);
33795
33796 /* disable master interrupt before clearing iir */
33797 de_ier = I915_READ(DEIER);
33798 @@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33799 {
33800 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33801
33802 - atomic_set(&dev_priv->irq_received, 0);
33803 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33804
33805 I915_WRITE(HWSTAM, 0xeffe);
33806
33807 @@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33808 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33809 int pipe;
33810
33811 - atomic_set(&dev_priv->irq_received, 0);
33812 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33813
33814 /* VLV magic */
33815 I915_WRITE(VLV_IMR, 0);
33816 @@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33817 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33818 int pipe;
33819
33820 - atomic_set(&dev_priv->irq_received, 0);
33821 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33822
33823 for_each_pipe(pipe)
33824 I915_WRITE(PIPESTAT(pipe), 0);
33825 @@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
33826 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33827 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33828
33829 - atomic_inc(&dev_priv->irq_received);
33830 + atomic_inc_unchecked(&dev_priv->irq_received);
33831
33832 iir = I915_READ16(IIR);
33833 if (iir == 0)
33834 @@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33835 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33836 int pipe;
33837
33838 - atomic_set(&dev_priv->irq_received, 0);
33839 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33840
33841 if (I915_HAS_HOTPLUG(dev)) {
33842 I915_WRITE(PORT_HOTPLUG_EN, 0);
33843 @@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
33844 };
33845 int pipe, ret = IRQ_NONE;
33846
33847 - atomic_inc(&dev_priv->irq_received);
33848 + atomic_inc_unchecked(&dev_priv->irq_received);
33849
33850 iir = I915_READ(IIR);
33851 do {
33852 @@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33853 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33854 int pipe;
33855
33856 - atomic_set(&dev_priv->irq_received, 0);
33857 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33858
33859 I915_WRITE(PORT_HOTPLUG_EN, 0);
33860 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33861 @@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
33862 int irq_received;
33863 int ret = IRQ_NONE, pipe;
33864
33865 - atomic_inc(&dev_priv->irq_received);
33866 + atomic_inc_unchecked(&dev_priv->irq_received);
33867
33868 iir = I915_READ(IIR);
33869
33870 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33871 index da1ad9c..10d368b 100644
33872 --- a/drivers/gpu/drm/i915/intel_display.c
33873 +++ b/drivers/gpu/drm/i915/intel_display.c
33874 @@ -2244,7 +2244,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33875
33876 wait_event(dev_priv->pending_flip_queue,
33877 atomic_read(&dev_priv->mm.wedged) ||
33878 - atomic_read(&obj->pending_flip) == 0);
33879 + atomic_read_unchecked(&obj->pending_flip) == 0);
33880
33881 /* Big Hammer, we also need to ensure that any pending
33882 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33883 @@ -7109,8 +7109,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33884
33885 obj = work->old_fb_obj;
33886
33887 - atomic_clear_mask(1 << intel_crtc->plane,
33888 - &obj->pending_flip.counter);
33889 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33890 wake_up(&dev_priv->pending_flip_queue);
33891
33892 queue_work(dev_priv->wq, &work->work);
33893 @@ -7477,7 +7476,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33894 /* Block clients from rendering to the new back buffer until
33895 * the flip occurs and the object is no longer visible.
33896 */
33897 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33898 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33899 atomic_inc(&intel_crtc->unpin_work_count);
33900
33901 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33902 @@ -7494,7 +7493,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33903
33904 cleanup_pending:
33905 atomic_dec(&intel_crtc->unpin_work_count);
33906 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33907 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33908 drm_gem_object_unreference(&work->old_fb_obj->base);
33909 drm_gem_object_unreference(&obj->base);
33910 mutex_unlock(&dev->struct_mutex);
33911 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33912 index 54558a0..2d97005 100644
33913 --- a/drivers/gpu/drm/mga/mga_drv.h
33914 +++ b/drivers/gpu/drm/mga/mga_drv.h
33915 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33916 u32 clear_cmd;
33917 u32 maccess;
33918
33919 - atomic_t vbl_received; /**< Number of vblanks received. */
33920 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33921 wait_queue_head_t fence_queue;
33922 - atomic_t last_fence_retired;
33923 + atomic_unchecked_t last_fence_retired;
33924 u32 next_fence_to_post;
33925
33926 unsigned int fb_cpp;
33927 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33928 index 598c281..60d590e 100644
33929 --- a/drivers/gpu/drm/mga/mga_irq.c
33930 +++ b/drivers/gpu/drm/mga/mga_irq.c
33931 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33932 if (crtc != 0)
33933 return 0;
33934
33935 - return atomic_read(&dev_priv->vbl_received);
33936 + return atomic_read_unchecked(&dev_priv->vbl_received);
33937 }
33938
33939
33940 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33941 /* VBLANK interrupt */
33942 if (status & MGA_VLINEPEN) {
33943 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33944 - atomic_inc(&dev_priv->vbl_received);
33945 + atomic_inc_unchecked(&dev_priv->vbl_received);
33946 drm_handle_vblank(dev, 0);
33947 handled = 1;
33948 }
33949 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33950 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33951 MGA_WRITE(MGA_PRIMEND, prim_end);
33952
33953 - atomic_inc(&dev_priv->last_fence_retired);
33954 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
33955 DRM_WAKEUP(&dev_priv->fence_queue);
33956 handled = 1;
33957 }
33958 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33959 * using fences.
33960 */
33961 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33962 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33963 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33964 - *sequence) <= (1 << 23)));
33965
33966 *sequence = cur_fence;
33967 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33968 index 865eddf..62c4cc3 100644
33969 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33970 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33971 @@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33972 struct bit_table {
33973 const char id;
33974 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33975 -};
33976 +} __no_const;
33977
33978 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33979
33980 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33981 index aa89eb9..d45d38b 100644
33982 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33983 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33984 @@ -80,7 +80,7 @@ struct nouveau_drm {
33985 struct drm_global_reference mem_global_ref;
33986 struct ttm_bo_global_ref bo_global_ref;
33987 struct ttm_bo_device bdev;
33988 - atomic_t validate_sequence;
33989 + atomic_unchecked_t validate_sequence;
33990 int (*move)(struct nouveau_channel *,
33991 struct ttm_buffer_object *,
33992 struct ttm_mem_reg *, struct ttm_mem_reg *);
33993 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33994 index cdb83ac..27f0a16 100644
33995 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33996 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33997 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33998 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33999 struct nouveau_channel *);
34000 u32 (*read)(struct nouveau_channel *);
34001 -};
34002 +} __no_const;
34003
34004 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
34005
34006 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
34007 index 8bf695c..9fbc90a 100644
34008 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
34009 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
34010 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
34011 int trycnt = 0;
34012 int ret, i;
34013
34014 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
34015 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
34016 retry:
34017 if (++trycnt > 100000) {
34018 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
34019 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
34020 index 25d3495..d81aaf6 100644
34021 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
34022 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
34023 @@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
34024 bool can_switch;
34025
34026 spin_lock(&dev->count_lock);
34027 - can_switch = (dev->open_count == 0);
34028 + can_switch = (local_read(&dev->open_count) == 0);
34029 spin_unlock(&dev->count_lock);
34030 return can_switch;
34031 }
34032 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
34033 index d4660cf..70dbe65 100644
34034 --- a/drivers/gpu/drm/r128/r128_cce.c
34035 +++ b/drivers/gpu/drm/r128/r128_cce.c
34036 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
34037
34038 /* GH: Simple idle check.
34039 */
34040 - atomic_set(&dev_priv->idle_count, 0);
34041 + atomic_set_unchecked(&dev_priv->idle_count, 0);
34042
34043 /* We don't support anything other than bus-mastering ring mode,
34044 * but the ring can be in either AGP or PCI space for the ring
34045 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
34046 index 930c71b..499aded 100644
34047 --- a/drivers/gpu/drm/r128/r128_drv.h
34048 +++ b/drivers/gpu/drm/r128/r128_drv.h
34049 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
34050 int is_pci;
34051 unsigned long cce_buffers_offset;
34052
34053 - atomic_t idle_count;
34054 + atomic_unchecked_t idle_count;
34055
34056 int page_flipping;
34057 int current_page;
34058 u32 crtc_offset;
34059 u32 crtc_offset_cntl;
34060
34061 - atomic_t vbl_received;
34062 + atomic_unchecked_t vbl_received;
34063
34064 u32 color_fmt;
34065 unsigned int front_offset;
34066 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
34067 index 2ea4f09..d391371 100644
34068 --- a/drivers/gpu/drm/r128/r128_irq.c
34069 +++ b/drivers/gpu/drm/r128/r128_irq.c
34070 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
34071 if (crtc != 0)
34072 return 0;
34073
34074 - return atomic_read(&dev_priv->vbl_received);
34075 + return atomic_read_unchecked(&dev_priv->vbl_received);
34076 }
34077
34078 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34079 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34080 /* VBLANK interrupt */
34081 if (status & R128_CRTC_VBLANK_INT) {
34082 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
34083 - atomic_inc(&dev_priv->vbl_received);
34084 + atomic_inc_unchecked(&dev_priv->vbl_received);
34085 drm_handle_vblank(dev, 0);
34086 return IRQ_HANDLED;
34087 }
34088 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
34089 index 19bb7e6..de7e2a2 100644
34090 --- a/drivers/gpu/drm/r128/r128_state.c
34091 +++ b/drivers/gpu/drm/r128/r128_state.c
34092 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
34093
34094 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
34095 {
34096 - if (atomic_read(&dev_priv->idle_count) == 0)
34097 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
34098 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
34099 else
34100 - atomic_set(&dev_priv->idle_count, 0);
34101 + atomic_set_unchecked(&dev_priv->idle_count, 0);
34102 }
34103
34104 #endif
34105 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
34106 index 5a82b6b..9e69c73 100644
34107 --- a/drivers/gpu/drm/radeon/mkregtable.c
34108 +++ b/drivers/gpu/drm/radeon/mkregtable.c
34109 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
34110 regex_t mask_rex;
34111 regmatch_t match[4];
34112 char buf[1024];
34113 - size_t end;
34114 + long end;
34115 int len;
34116 int done = 0;
34117 int r;
34118 unsigned o;
34119 struct offset *offset;
34120 char last_reg_s[10];
34121 - int last_reg;
34122 + unsigned long last_reg;
34123
34124 if (regcomp
34125 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
34126 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
34127 index 0d6562b..a154330 100644
34128 --- a/drivers/gpu/drm/radeon/radeon_device.c
34129 +++ b/drivers/gpu/drm/radeon/radeon_device.c
34130 @@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
34131 bool can_switch;
34132
34133 spin_lock(&dev->count_lock);
34134 - can_switch = (dev->open_count == 0);
34135 + can_switch = (local_read(&dev->open_count) == 0);
34136 spin_unlock(&dev->count_lock);
34137 return can_switch;
34138 }
34139 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
34140 index e7fdf16..f4f6490 100644
34141 --- a/drivers/gpu/drm/radeon/radeon_drv.h
34142 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
34143 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
34144
34145 /* SW interrupt */
34146 wait_queue_head_t swi_queue;
34147 - atomic_t swi_emitted;
34148 + atomic_unchecked_t swi_emitted;
34149 int vblank_crtc;
34150 uint32_t irq_enable_reg;
34151 uint32_t r500_disp_irq_reg;
34152 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
34153 index c180df8..cd80dd2d 100644
34154 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
34155 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
34156 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
34157 request = compat_alloc_user_space(sizeof(*request));
34158 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
34159 || __put_user(req32.param, &request->param)
34160 - || __put_user((void __user *)(unsigned long)req32.value,
34161 + || __put_user((unsigned long)req32.value,
34162 &request->value))
34163 return -EFAULT;
34164
34165 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
34166 index e771033..a0bc6b3 100644
34167 --- a/drivers/gpu/drm/radeon/radeon_irq.c
34168 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
34169 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
34170 unsigned int ret;
34171 RING_LOCALS;
34172
34173 - atomic_inc(&dev_priv->swi_emitted);
34174 - ret = atomic_read(&dev_priv->swi_emitted);
34175 + atomic_inc_unchecked(&dev_priv->swi_emitted);
34176 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
34177
34178 BEGIN_RING(4);
34179 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
34180 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
34181 drm_radeon_private_t *dev_priv =
34182 (drm_radeon_private_t *) dev->dev_private;
34183
34184 - atomic_set(&dev_priv->swi_emitted, 0);
34185 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
34186 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
34187
34188 dev->max_vblank_count = 0x001fffff;
34189 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
34190 index 8e9057b..af6dacb 100644
34191 --- a/drivers/gpu/drm/radeon/radeon_state.c
34192 +++ b/drivers/gpu/drm/radeon/radeon_state.c
34193 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
34194 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
34195 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
34196
34197 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34198 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34199 sarea_priv->nbox * sizeof(depth_boxes[0])))
34200 return -EFAULT;
34201
34202 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
34203 {
34204 drm_radeon_private_t *dev_priv = dev->dev_private;
34205 drm_radeon_getparam_t *param = data;
34206 - int value;
34207 + int value = 0;
34208
34209 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
34210
34211 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
34212 index 93f760e..33d9839 100644
34213 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
34214 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
34215 @@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
34216 man->size = size >> PAGE_SHIFT;
34217 }
34218
34219 -static struct vm_operations_struct radeon_ttm_vm_ops;
34220 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
34221 static const struct vm_operations_struct *ttm_vm_ops = NULL;
34222
34223 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
34224 @@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
34225 }
34226 if (unlikely(ttm_vm_ops == NULL)) {
34227 ttm_vm_ops = vma->vm_ops;
34228 + pax_open_kernel();
34229 radeon_ttm_vm_ops = *ttm_vm_ops;
34230 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
34231 + pax_close_kernel();
34232 }
34233 vma->vm_ops = &radeon_ttm_vm_ops;
34234 return 0;
34235 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
34236 index 5706d2a..17aedaa 100644
34237 --- a/drivers/gpu/drm/radeon/rs690.c
34238 +++ b/drivers/gpu/drm/radeon/rs690.c
34239 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
34240 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
34241 rdev->pm.sideport_bandwidth.full)
34242 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
34243 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
34244 + read_delay_latency.full = dfixed_const(800 * 1000);
34245 read_delay_latency.full = dfixed_div(read_delay_latency,
34246 rdev->pm.igp_sideport_mclk);
34247 + a.full = dfixed_const(370);
34248 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
34249 } else {
34250 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
34251 rdev->pm.k8_bandwidth.full)
34252 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34253 index bd2a3b4..122d9ad 100644
34254 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
34255 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34256 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
34257 static int ttm_pool_mm_shrink(struct shrinker *shrink,
34258 struct shrink_control *sc)
34259 {
34260 - static atomic_t start_pool = ATOMIC_INIT(0);
34261 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
34262 unsigned i;
34263 - unsigned pool_offset = atomic_add_return(1, &start_pool);
34264 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
34265 struct ttm_page_pool *pool;
34266 int shrink_pages = sc->nr_to_scan;
34267
34268 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
34269 index 893a650..6190d3b 100644
34270 --- a/drivers/gpu/drm/via/via_drv.h
34271 +++ b/drivers/gpu/drm/via/via_drv.h
34272 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
34273 typedef uint32_t maskarray_t[5];
34274
34275 typedef struct drm_via_irq {
34276 - atomic_t irq_received;
34277 + atomic_unchecked_t irq_received;
34278 uint32_t pending_mask;
34279 uint32_t enable_mask;
34280 wait_queue_head_t irq_queue;
34281 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
34282 struct timeval last_vblank;
34283 int last_vblank_valid;
34284 unsigned usec_per_vblank;
34285 - atomic_t vbl_received;
34286 + atomic_unchecked_t vbl_received;
34287 drm_via_state_t hc_state;
34288 char pci_buf[VIA_PCI_BUF_SIZE];
34289 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
34290 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
34291 index ac98964..5dbf512 100644
34292 --- a/drivers/gpu/drm/via/via_irq.c
34293 +++ b/drivers/gpu/drm/via/via_irq.c
34294 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
34295 if (crtc != 0)
34296 return 0;
34297
34298 - return atomic_read(&dev_priv->vbl_received);
34299 + return atomic_read_unchecked(&dev_priv->vbl_received);
34300 }
34301
34302 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34303 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34304
34305 status = VIA_READ(VIA_REG_INTERRUPT);
34306 if (status & VIA_IRQ_VBLANK_PENDING) {
34307 - atomic_inc(&dev_priv->vbl_received);
34308 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
34309 + atomic_inc_unchecked(&dev_priv->vbl_received);
34310 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
34311 do_gettimeofday(&cur_vblank);
34312 if (dev_priv->last_vblank_valid) {
34313 dev_priv->usec_per_vblank =
34314 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34315 dev_priv->last_vblank = cur_vblank;
34316 dev_priv->last_vblank_valid = 1;
34317 }
34318 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
34319 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
34320 DRM_DEBUG("US per vblank is: %u\n",
34321 dev_priv->usec_per_vblank);
34322 }
34323 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34324
34325 for (i = 0; i < dev_priv->num_irqs; ++i) {
34326 if (status & cur_irq->pending_mask) {
34327 - atomic_inc(&cur_irq->irq_received);
34328 + atomic_inc_unchecked(&cur_irq->irq_received);
34329 DRM_WAKEUP(&cur_irq->irq_queue);
34330 handled = 1;
34331 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
34332 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
34333 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34334 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
34335 masks[irq][4]));
34336 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
34337 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
34338 } else {
34339 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34340 (((cur_irq_sequence =
34341 - atomic_read(&cur_irq->irq_received)) -
34342 + atomic_read_unchecked(&cur_irq->irq_received)) -
34343 *sequence) <= (1 << 23)));
34344 }
34345 *sequence = cur_irq_sequence;
34346 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
34347 }
34348
34349 for (i = 0; i < dev_priv->num_irqs; ++i) {
34350 - atomic_set(&cur_irq->irq_received, 0);
34351 + atomic_set_unchecked(&cur_irq->irq_received, 0);
34352 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
34353 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
34354 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
34355 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
34356 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
34357 case VIA_IRQ_RELATIVE:
34358 irqwait->request.sequence +=
34359 - atomic_read(&cur_irq->irq_received);
34360 + atomic_read_unchecked(&cur_irq->irq_received);
34361 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
34362 case VIA_IRQ_ABSOLUTE:
34363 break;
34364 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34365 index 13aeda7..4a952d1 100644
34366 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34367 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34368 @@ -290,7 +290,7 @@ struct vmw_private {
34369 * Fencing and IRQs.
34370 */
34371
34372 - atomic_t marker_seq;
34373 + atomic_unchecked_t marker_seq;
34374 wait_queue_head_t fence_queue;
34375 wait_queue_head_t fifo_queue;
34376 int fence_queue_waiters; /* Protected by hw_mutex */
34377 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34378 index 3eb1486..0a47ee9 100644
34379 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34380 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34381 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
34382 (unsigned int) min,
34383 (unsigned int) fifo->capabilities);
34384
34385 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34386 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34387 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
34388 vmw_marker_queue_init(&fifo->marker_queue);
34389 return vmw_fifo_send_fence(dev_priv, &dummy);
34390 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
34391 if (reserveable)
34392 iowrite32(bytes, fifo_mem +
34393 SVGA_FIFO_RESERVED);
34394 - return fifo_mem + (next_cmd >> 2);
34395 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
34396 } else {
34397 need_bounce = true;
34398 }
34399 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34400
34401 fm = vmw_fifo_reserve(dev_priv, bytes);
34402 if (unlikely(fm == NULL)) {
34403 - *seqno = atomic_read(&dev_priv->marker_seq);
34404 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34405 ret = -ENOMEM;
34406 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
34407 false, 3*HZ);
34408 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34409 }
34410
34411 do {
34412 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
34413 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
34414 } while (*seqno == 0);
34415
34416 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
34417 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34418 index 4640adb..e1384ed 100644
34419 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34420 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34421 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
34422 * emitted. Then the fence is stale and signaled.
34423 */
34424
34425 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
34426 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
34427 > VMW_FENCE_WRAP);
34428
34429 return ret;
34430 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
34431
34432 if (fifo_idle)
34433 down_read(&fifo_state->rwsem);
34434 - signal_seq = atomic_read(&dev_priv->marker_seq);
34435 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
34436 ret = 0;
34437
34438 for (;;) {
34439 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34440 index 8a8725c..afed796 100644
34441 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34442 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34443 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
34444 while (!vmw_lag_lt(queue, us)) {
34445 spin_lock(&queue->lock);
34446 if (list_empty(&queue->head))
34447 - seqno = atomic_read(&dev_priv->marker_seq);
34448 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34449 else {
34450 marker = list_first_entry(&queue->head,
34451 struct vmw_marker, head);
34452 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
34453 index eb2ee11..6cc50ab 100644
34454 --- a/drivers/hid/hid-core.c
34455 +++ b/drivers/hid/hid-core.c
34456 @@ -2240,7 +2240,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
34457
34458 int hid_add_device(struct hid_device *hdev)
34459 {
34460 - static atomic_t id = ATOMIC_INIT(0);
34461 + static atomic_unchecked_t id = ATOMIC_INIT(0);
34462 int ret;
34463
34464 if (WARN_ON(hdev->status & HID_STAT_ADDED))
34465 @@ -2274,7 +2274,7 @@ int hid_add_device(struct hid_device *hdev)
34466 /* XXX hack, any other cleaner solution after the driver core
34467 * is converted to allow more than 20 bytes as the device name? */
34468 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
34469 - hdev->vendor, hdev->product, atomic_inc_return(&id));
34470 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
34471
34472 hid_debug_register(hdev, dev_name(&hdev->dev));
34473 ret = device_add(&hdev->dev);
34474 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
34475 index eec3291..8ed706b 100644
34476 --- a/drivers/hid/hid-wiimote-debug.c
34477 +++ b/drivers/hid/hid-wiimote-debug.c
34478 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
34479 else if (size == 0)
34480 return -EIO;
34481
34482 - if (copy_to_user(u, buf, size))
34483 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
34484 return -EFAULT;
34485
34486 *off += size;
34487 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
34488 index 773a2f2..7ce08bc 100644
34489 --- a/drivers/hv/channel.c
34490 +++ b/drivers/hv/channel.c
34491 @@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
34492 int ret = 0;
34493 int t;
34494
34495 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
34496 - atomic_inc(&vmbus_connection.next_gpadl_handle);
34497 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
34498 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
34499
34500 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
34501 if (ret)
34502 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
34503 index 3648f8f..30ef30d 100644
34504 --- a/drivers/hv/hv.c
34505 +++ b/drivers/hv/hv.c
34506 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
34507 u64 output_address = (output) ? virt_to_phys(output) : 0;
34508 u32 output_address_hi = output_address >> 32;
34509 u32 output_address_lo = output_address & 0xFFFFFFFF;
34510 - void *hypercall_page = hv_context.hypercall_page;
34511 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
34512
34513 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
34514 "=a"(hv_status_lo) : "d" (control_hi),
34515 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
34516 index d8d1fad..b91caf7 100644
34517 --- a/drivers/hv/hyperv_vmbus.h
34518 +++ b/drivers/hv/hyperv_vmbus.h
34519 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
34520 struct vmbus_connection {
34521 enum vmbus_connect_state conn_state;
34522
34523 - atomic_t next_gpadl_handle;
34524 + atomic_unchecked_t next_gpadl_handle;
34525
34526 /*
34527 * Represents channel interrupts. Each bit position represents a
34528 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
34529 index 8e1a9ec..4687821 100644
34530 --- a/drivers/hv/vmbus_drv.c
34531 +++ b/drivers/hv/vmbus_drv.c
34532 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
34533 {
34534 int ret = 0;
34535
34536 - static atomic_t device_num = ATOMIC_INIT(0);
34537 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
34538
34539 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
34540 - atomic_inc_return(&device_num));
34541 + atomic_inc_return_unchecked(&device_num));
34542
34543 child_device_obj->device.bus = &hv_bus;
34544 child_device_obj->device.parent = &hv_acpi_dev->dev;
34545 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
34546 index d64923d..72591e8 100644
34547 --- a/drivers/hwmon/coretemp.c
34548 +++ b/drivers/hwmon/coretemp.c
34549 @@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
34550 return NOTIFY_OK;
34551 }
34552
34553 -static struct notifier_block coretemp_cpu_notifier __refdata = {
34554 +static struct notifier_block coretemp_cpu_notifier = {
34555 .notifier_call = coretemp_cpu_callback,
34556 };
34557
34558 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
34559 index 1c85d39..55ed3cf 100644
34560 --- a/drivers/hwmon/sht15.c
34561 +++ b/drivers/hwmon/sht15.c
34562 @@ -169,7 +169,7 @@ struct sht15_data {
34563 int supply_uV;
34564 bool supply_uV_valid;
34565 struct work_struct update_supply_work;
34566 - atomic_t interrupt_handled;
34567 + atomic_unchecked_t interrupt_handled;
34568 };
34569
34570 /**
34571 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
34572 return ret;
34573
34574 gpio_direction_input(data->pdata->gpio_data);
34575 - atomic_set(&data->interrupt_handled, 0);
34576 + atomic_set_unchecked(&data->interrupt_handled, 0);
34577
34578 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34579 if (gpio_get_value(data->pdata->gpio_data) == 0) {
34580 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
34581 /* Only relevant if the interrupt hasn't occurred. */
34582 - if (!atomic_read(&data->interrupt_handled))
34583 + if (!atomic_read_unchecked(&data->interrupt_handled))
34584 schedule_work(&data->read_work);
34585 }
34586 ret = wait_event_timeout(data->wait_queue,
34587 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
34588
34589 /* First disable the interrupt */
34590 disable_irq_nosync(irq);
34591 - atomic_inc(&data->interrupt_handled);
34592 + atomic_inc_unchecked(&data->interrupt_handled);
34593 /* Then schedule a reading work struct */
34594 if (data->state != SHT15_READING_NOTHING)
34595 schedule_work(&data->read_work);
34596 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
34597 * If not, then start the interrupt again - care here as could
34598 * have gone low in meantime so verify it hasn't!
34599 */
34600 - atomic_set(&data->interrupt_handled, 0);
34601 + atomic_set_unchecked(&data->interrupt_handled, 0);
34602 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34603 /* If still not occurred or another handler was scheduled */
34604 if (gpio_get_value(data->pdata->gpio_data)
34605 - || atomic_read(&data->interrupt_handled))
34606 + || atomic_read_unchecked(&data->interrupt_handled))
34607 return;
34608 }
34609
34610 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
34611 index 76f157b..9c0db1b 100644
34612 --- a/drivers/hwmon/via-cputemp.c
34613 +++ b/drivers/hwmon/via-cputemp.c
34614 @@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
34615 return NOTIFY_OK;
34616 }
34617
34618 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
34619 +static struct notifier_block via_cputemp_cpu_notifier = {
34620 .notifier_call = via_cputemp_cpu_callback,
34621 };
34622
34623 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
34624 index 378fcb5..5e91fa8 100644
34625 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
34626 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
34627 @@ -43,7 +43,7 @@
34628 extern struct i2c_adapter amd756_smbus;
34629
34630 static struct i2c_adapter *s4882_adapter;
34631 -static struct i2c_algorithm *s4882_algo;
34632 +static i2c_algorithm_no_const *s4882_algo;
34633
34634 /* Wrapper access functions for multiplexed SMBus */
34635 static DEFINE_MUTEX(amd756_lock);
34636 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
34637 index 29015eb..af2d8e9 100644
34638 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
34639 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
34640 @@ -41,7 +41,7 @@
34641 extern struct i2c_adapter *nforce2_smbus;
34642
34643 static struct i2c_adapter *s4985_adapter;
34644 -static struct i2c_algorithm *s4985_algo;
34645 +static i2c_algorithm_no_const *s4985_algo;
34646
34647 /* Wrapper access functions for multiplexed SMBus */
34648 static DEFINE_MUTEX(nforce2_lock);
34649 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34650 index 8126824..55a2798 100644
34651 --- a/drivers/ide/ide-cd.c
34652 +++ b/drivers/ide/ide-cd.c
34653 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34654 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34655 if ((unsigned long)buf & alignment
34656 || blk_rq_bytes(rq) & q->dma_pad_mask
34657 - || object_is_on_stack(buf))
34658 + || object_starts_on_stack(buf))
34659 drive->dma = 0;
34660 }
34661 }
34662 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34663 index 394fea2..c833880 100644
34664 --- a/drivers/infiniband/core/cm.c
34665 +++ b/drivers/infiniband/core/cm.c
34666 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34667
34668 struct cm_counter_group {
34669 struct kobject obj;
34670 - atomic_long_t counter[CM_ATTR_COUNT];
34671 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34672 };
34673
34674 struct cm_counter_attribute {
34675 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34676 struct ib_mad_send_buf *msg = NULL;
34677 int ret;
34678
34679 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34680 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34681 counter[CM_REQ_COUNTER]);
34682
34683 /* Quick state check to discard duplicate REQs. */
34684 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34685 if (!cm_id_priv)
34686 return;
34687
34688 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34689 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34690 counter[CM_REP_COUNTER]);
34691 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34692 if (ret)
34693 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
34694 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34695 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34696 spin_unlock_irq(&cm_id_priv->lock);
34697 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34698 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34699 counter[CM_RTU_COUNTER]);
34700 goto out;
34701 }
34702 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
34703 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34704 dreq_msg->local_comm_id);
34705 if (!cm_id_priv) {
34706 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34707 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34708 counter[CM_DREQ_COUNTER]);
34709 cm_issue_drep(work->port, work->mad_recv_wc);
34710 return -EINVAL;
34711 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
34712 case IB_CM_MRA_REP_RCVD:
34713 break;
34714 case IB_CM_TIMEWAIT:
34715 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34716 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34717 counter[CM_DREQ_COUNTER]);
34718 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34719 goto unlock;
34720 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
34721 cm_free_msg(msg);
34722 goto deref;
34723 case IB_CM_DREQ_RCVD:
34724 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34725 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34726 counter[CM_DREQ_COUNTER]);
34727 goto unlock;
34728 default:
34729 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
34730 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34731 cm_id_priv->msg, timeout)) {
34732 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34733 - atomic_long_inc(&work->port->
34734 + atomic_long_inc_unchecked(&work->port->
34735 counter_group[CM_RECV_DUPLICATES].
34736 counter[CM_MRA_COUNTER]);
34737 goto out;
34738 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
34739 break;
34740 case IB_CM_MRA_REQ_RCVD:
34741 case IB_CM_MRA_REP_RCVD:
34742 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34743 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34744 counter[CM_MRA_COUNTER]);
34745 /* fall through */
34746 default:
34747 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
34748 case IB_CM_LAP_IDLE:
34749 break;
34750 case IB_CM_MRA_LAP_SENT:
34751 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34752 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34753 counter[CM_LAP_COUNTER]);
34754 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34755 goto unlock;
34756 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
34757 cm_free_msg(msg);
34758 goto deref;
34759 case IB_CM_LAP_RCVD:
34760 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34761 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34762 counter[CM_LAP_COUNTER]);
34763 goto unlock;
34764 default:
34765 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34766 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34767 if (cur_cm_id_priv) {
34768 spin_unlock_irq(&cm.lock);
34769 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34770 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34771 counter[CM_SIDR_REQ_COUNTER]);
34772 goto out; /* Duplicate message. */
34773 }
34774 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34775 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34776 msg->retries = 1;
34777
34778 - atomic_long_add(1 + msg->retries,
34779 + atomic_long_add_unchecked(1 + msg->retries,
34780 &port->counter_group[CM_XMIT].counter[attr_index]);
34781 if (msg->retries)
34782 - atomic_long_add(msg->retries,
34783 + atomic_long_add_unchecked(msg->retries,
34784 &port->counter_group[CM_XMIT_RETRIES].
34785 counter[attr_index]);
34786
34787 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34788 }
34789
34790 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34791 - atomic_long_inc(&port->counter_group[CM_RECV].
34792 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34793 counter[attr_id - CM_ATTR_ID_OFFSET]);
34794
34795 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34796 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34797 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34798
34799 return sprintf(buf, "%ld\n",
34800 - atomic_long_read(&group->counter[cm_attr->index]));
34801 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34802 }
34803
34804 static const struct sysfs_ops cm_counter_ops = {
34805 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34806 index 176c8f9..2627b62 100644
34807 --- a/drivers/infiniband/core/fmr_pool.c
34808 +++ b/drivers/infiniband/core/fmr_pool.c
34809 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
34810
34811 struct task_struct *thread;
34812
34813 - atomic_t req_ser;
34814 - atomic_t flush_ser;
34815 + atomic_unchecked_t req_ser;
34816 + atomic_unchecked_t flush_ser;
34817
34818 wait_queue_head_t force_wait;
34819 };
34820 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34821 struct ib_fmr_pool *pool = pool_ptr;
34822
34823 do {
34824 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34825 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34826 ib_fmr_batch_release(pool);
34827
34828 - atomic_inc(&pool->flush_ser);
34829 + atomic_inc_unchecked(&pool->flush_ser);
34830 wake_up_interruptible(&pool->force_wait);
34831
34832 if (pool->flush_function)
34833 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34834 }
34835
34836 set_current_state(TASK_INTERRUPTIBLE);
34837 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34838 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34839 !kthread_should_stop())
34840 schedule();
34841 __set_current_state(TASK_RUNNING);
34842 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34843 pool->dirty_watermark = params->dirty_watermark;
34844 pool->dirty_len = 0;
34845 spin_lock_init(&pool->pool_lock);
34846 - atomic_set(&pool->req_ser, 0);
34847 - atomic_set(&pool->flush_ser, 0);
34848 + atomic_set_unchecked(&pool->req_ser, 0);
34849 + atomic_set_unchecked(&pool->flush_ser, 0);
34850 init_waitqueue_head(&pool->force_wait);
34851
34852 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34853 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34854 }
34855 spin_unlock_irq(&pool->pool_lock);
34856
34857 - serial = atomic_inc_return(&pool->req_ser);
34858 + serial = atomic_inc_return_unchecked(&pool->req_ser);
34859 wake_up_process(pool->thread);
34860
34861 if (wait_event_interruptible(pool->force_wait,
34862 - atomic_read(&pool->flush_ser) - serial >= 0))
34863 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34864 return -EINTR;
34865
34866 return 0;
34867 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34868 } else {
34869 list_add_tail(&fmr->list, &pool->dirty_list);
34870 if (++pool->dirty_len >= pool->dirty_watermark) {
34871 - atomic_inc(&pool->req_ser);
34872 + atomic_inc_unchecked(&pool->req_ser);
34873 wake_up_process(pool->thread);
34874 }
34875 }
34876 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34877 index afd8179..598063f 100644
34878 --- a/drivers/infiniband/hw/cxgb4/mem.c
34879 +++ b/drivers/infiniband/hw/cxgb4/mem.c
34880 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34881 int err;
34882 struct fw_ri_tpte tpt;
34883 u32 stag_idx;
34884 - static atomic_t key;
34885 + static atomic_unchecked_t key;
34886
34887 if (c4iw_fatal_error(rdev))
34888 return -EIO;
34889 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34890 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34891 rdev->stats.stag.max = rdev->stats.stag.cur;
34892 mutex_unlock(&rdev->stats.lock);
34893 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34894 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34895 }
34896 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34897 __func__, stag_state, type, pdid, stag_idx);
34898 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34899 index 79b3dbc..96e5fcc 100644
34900 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
34901 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34902 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34903 struct ib_atomic_eth *ateth;
34904 struct ipath_ack_entry *e;
34905 u64 vaddr;
34906 - atomic64_t *maddr;
34907 + atomic64_unchecked_t *maddr;
34908 u64 sdata;
34909 u32 rkey;
34910 u8 next;
34911 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34912 IB_ACCESS_REMOTE_ATOMIC)))
34913 goto nack_acc_unlck;
34914 /* Perform atomic OP and save result. */
34915 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34916 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34917 sdata = be64_to_cpu(ateth->swap_data);
34918 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34919 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34920 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34921 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34922 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34923 be64_to_cpu(ateth->compare_data),
34924 sdata);
34925 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34926 index 1f95bba..9530f87 100644
34927 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34928 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34929 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34930 unsigned long flags;
34931 struct ib_wc wc;
34932 u64 sdata;
34933 - atomic64_t *maddr;
34934 + atomic64_unchecked_t *maddr;
34935 enum ib_wc_status send_status;
34936
34937 /*
34938 @@ -382,11 +382,11 @@ again:
34939 IB_ACCESS_REMOTE_ATOMIC)))
34940 goto acc_err;
34941 /* Perform atomic OP and save result. */
34942 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34943 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34944 sdata = wqe->wr.wr.atomic.compare_add;
34945 *(u64 *) sqp->s_sge.sge.vaddr =
34946 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34947 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34948 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34949 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34950 sdata, wqe->wr.wr.atomic.swap);
34951 goto send_comp;
34952 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34953 index 5b152a3..c1f3e83 100644
34954 --- a/drivers/infiniband/hw/nes/nes.c
34955 +++ b/drivers/infiniband/hw/nes/nes.c
34956 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34957 LIST_HEAD(nes_adapter_list);
34958 static LIST_HEAD(nes_dev_list);
34959
34960 -atomic_t qps_destroyed;
34961 +atomic_unchecked_t qps_destroyed;
34962
34963 static unsigned int ee_flsh_adapter;
34964 static unsigned int sysfs_nonidx_addr;
34965 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34966 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34967 struct nes_adapter *nesadapter = nesdev->nesadapter;
34968
34969 - atomic_inc(&qps_destroyed);
34970 + atomic_inc_unchecked(&qps_destroyed);
34971
34972 /* Free the control structures */
34973
34974 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34975 index 33cc589..3bd6538 100644
34976 --- a/drivers/infiniband/hw/nes/nes.h
34977 +++ b/drivers/infiniband/hw/nes/nes.h
34978 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34979 extern unsigned int wqm_quanta;
34980 extern struct list_head nes_adapter_list;
34981
34982 -extern atomic_t cm_connects;
34983 -extern atomic_t cm_accepts;
34984 -extern atomic_t cm_disconnects;
34985 -extern atomic_t cm_closes;
34986 -extern atomic_t cm_connecteds;
34987 -extern atomic_t cm_connect_reqs;
34988 -extern atomic_t cm_rejects;
34989 -extern atomic_t mod_qp_timouts;
34990 -extern atomic_t qps_created;
34991 -extern atomic_t qps_destroyed;
34992 -extern atomic_t sw_qps_destroyed;
34993 +extern atomic_unchecked_t cm_connects;
34994 +extern atomic_unchecked_t cm_accepts;
34995 +extern atomic_unchecked_t cm_disconnects;
34996 +extern atomic_unchecked_t cm_closes;
34997 +extern atomic_unchecked_t cm_connecteds;
34998 +extern atomic_unchecked_t cm_connect_reqs;
34999 +extern atomic_unchecked_t cm_rejects;
35000 +extern atomic_unchecked_t mod_qp_timouts;
35001 +extern atomic_unchecked_t qps_created;
35002 +extern atomic_unchecked_t qps_destroyed;
35003 +extern atomic_unchecked_t sw_qps_destroyed;
35004 extern u32 mh_detected;
35005 extern u32 mh_pauses_sent;
35006 extern u32 cm_packets_sent;
35007 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
35008 extern u32 cm_packets_received;
35009 extern u32 cm_packets_dropped;
35010 extern u32 cm_packets_retrans;
35011 -extern atomic_t cm_listens_created;
35012 -extern atomic_t cm_listens_destroyed;
35013 +extern atomic_unchecked_t cm_listens_created;
35014 +extern atomic_unchecked_t cm_listens_destroyed;
35015 extern u32 cm_backlog_drops;
35016 -extern atomic_t cm_loopbacks;
35017 -extern atomic_t cm_nodes_created;
35018 -extern atomic_t cm_nodes_destroyed;
35019 -extern atomic_t cm_accel_dropped_pkts;
35020 -extern atomic_t cm_resets_recvd;
35021 -extern atomic_t pau_qps_created;
35022 -extern atomic_t pau_qps_destroyed;
35023 +extern atomic_unchecked_t cm_loopbacks;
35024 +extern atomic_unchecked_t cm_nodes_created;
35025 +extern atomic_unchecked_t cm_nodes_destroyed;
35026 +extern atomic_unchecked_t cm_accel_dropped_pkts;
35027 +extern atomic_unchecked_t cm_resets_recvd;
35028 +extern atomic_unchecked_t pau_qps_created;
35029 +extern atomic_unchecked_t pau_qps_destroyed;
35030
35031 extern u32 int_mod_timer_init;
35032 extern u32 int_mod_cq_depth_256;
35033 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
35034 index 22ea67e..dcbe3bc 100644
35035 --- a/drivers/infiniband/hw/nes/nes_cm.c
35036 +++ b/drivers/infiniband/hw/nes/nes_cm.c
35037 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
35038 u32 cm_packets_retrans;
35039 u32 cm_packets_created;
35040 u32 cm_packets_received;
35041 -atomic_t cm_listens_created;
35042 -atomic_t cm_listens_destroyed;
35043 +atomic_unchecked_t cm_listens_created;
35044 +atomic_unchecked_t cm_listens_destroyed;
35045 u32 cm_backlog_drops;
35046 -atomic_t cm_loopbacks;
35047 -atomic_t cm_nodes_created;
35048 -atomic_t cm_nodes_destroyed;
35049 -atomic_t cm_accel_dropped_pkts;
35050 -atomic_t cm_resets_recvd;
35051 +atomic_unchecked_t cm_loopbacks;
35052 +atomic_unchecked_t cm_nodes_created;
35053 +atomic_unchecked_t cm_nodes_destroyed;
35054 +atomic_unchecked_t cm_accel_dropped_pkts;
35055 +atomic_unchecked_t cm_resets_recvd;
35056
35057 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
35058 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
35059 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
35060
35061 static struct nes_cm_core *g_cm_core;
35062
35063 -atomic_t cm_connects;
35064 -atomic_t cm_accepts;
35065 -atomic_t cm_disconnects;
35066 -atomic_t cm_closes;
35067 -atomic_t cm_connecteds;
35068 -atomic_t cm_connect_reqs;
35069 -atomic_t cm_rejects;
35070 +atomic_unchecked_t cm_connects;
35071 +atomic_unchecked_t cm_accepts;
35072 +atomic_unchecked_t cm_disconnects;
35073 +atomic_unchecked_t cm_closes;
35074 +atomic_unchecked_t cm_connecteds;
35075 +atomic_unchecked_t cm_connect_reqs;
35076 +atomic_unchecked_t cm_rejects;
35077
35078 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
35079 {
35080 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
35081 kfree(listener);
35082 listener = NULL;
35083 ret = 0;
35084 - atomic_inc(&cm_listens_destroyed);
35085 + atomic_inc_unchecked(&cm_listens_destroyed);
35086 } else {
35087 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
35088 }
35089 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
35090 cm_node->rem_mac);
35091
35092 add_hte_node(cm_core, cm_node);
35093 - atomic_inc(&cm_nodes_created);
35094 + atomic_inc_unchecked(&cm_nodes_created);
35095
35096 return cm_node;
35097 }
35098 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
35099 }
35100
35101 atomic_dec(&cm_core->node_cnt);
35102 - atomic_inc(&cm_nodes_destroyed);
35103 + atomic_inc_unchecked(&cm_nodes_destroyed);
35104 nesqp = cm_node->nesqp;
35105 if (nesqp) {
35106 nesqp->cm_node = NULL;
35107 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
35108
35109 static void drop_packet(struct sk_buff *skb)
35110 {
35111 - atomic_inc(&cm_accel_dropped_pkts);
35112 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
35113 dev_kfree_skb_any(skb);
35114 }
35115
35116 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
35117 {
35118
35119 int reset = 0; /* whether to send reset in case of err.. */
35120 - atomic_inc(&cm_resets_recvd);
35121 + atomic_inc_unchecked(&cm_resets_recvd);
35122 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35123 " refcnt=%d\n", cm_node, cm_node->state,
35124 atomic_read(&cm_node->ref_count));
35125 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35126 rem_ref_cm_node(cm_node->cm_core, cm_node);
35127 return NULL;
35128 }
35129 - atomic_inc(&cm_loopbacks);
35130 + atomic_inc_unchecked(&cm_loopbacks);
35131 loopbackremotenode->loopbackpartner = cm_node;
35132 loopbackremotenode->tcp_cntxt.rcv_wscale =
35133 NES_CM_DEFAULT_RCV_WND_SCALE;
35134 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35135 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
35136 else {
35137 rem_ref_cm_node(cm_core, cm_node);
35138 - atomic_inc(&cm_accel_dropped_pkts);
35139 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
35140 dev_kfree_skb_any(skb);
35141 }
35142 break;
35143 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35144
35145 if ((cm_id) && (cm_id->event_handler)) {
35146 if (issue_disconn) {
35147 - atomic_inc(&cm_disconnects);
35148 + atomic_inc_unchecked(&cm_disconnects);
35149 cm_event.event = IW_CM_EVENT_DISCONNECT;
35150 cm_event.status = disconn_status;
35151 cm_event.local_addr = cm_id->local_addr;
35152 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35153 }
35154
35155 if (issue_close) {
35156 - atomic_inc(&cm_closes);
35157 + atomic_inc_unchecked(&cm_closes);
35158 nes_disconnect(nesqp, 1);
35159
35160 cm_id->provider_data = nesqp;
35161 @@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35162
35163 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35164 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35165 - atomic_inc(&cm_accepts);
35166 + atomic_inc_unchecked(&cm_accepts);
35167
35168 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35169 netdev_refcnt_read(nesvnic->netdev));
35170 @@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35171 struct nes_cm_core *cm_core;
35172 u8 *start_buff;
35173
35174 - atomic_inc(&cm_rejects);
35175 + atomic_inc_unchecked(&cm_rejects);
35176 cm_node = (struct nes_cm_node *)cm_id->provider_data;
35177 loopback = cm_node->loopbackpartner;
35178 cm_core = cm_node->cm_core;
35179 @@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35180 ntohl(cm_id->local_addr.sin_addr.s_addr),
35181 ntohs(cm_id->local_addr.sin_port));
35182
35183 - atomic_inc(&cm_connects);
35184 + atomic_inc_unchecked(&cm_connects);
35185 nesqp->active_conn = 1;
35186
35187 /* cache the cm_id in the qp */
35188 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
35189 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
35190 return err;
35191 }
35192 - atomic_inc(&cm_listens_created);
35193 + atomic_inc_unchecked(&cm_listens_created);
35194 }
35195
35196 cm_id->add_ref(cm_id);
35197 @@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35198
35199 if (nesqp->destroyed)
35200 return;
35201 - atomic_inc(&cm_connecteds);
35202 + atomic_inc_unchecked(&cm_connecteds);
35203 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35204 " local port 0x%04X. jiffies = %lu.\n",
35205 nesqp->hwqp.qp_id,
35206 @@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35207
35208 cm_id->add_ref(cm_id);
35209 ret = cm_id->event_handler(cm_id, &cm_event);
35210 - atomic_inc(&cm_closes);
35211 + atomic_inc_unchecked(&cm_closes);
35212 cm_event.event = IW_CM_EVENT_CLOSE;
35213 cm_event.status = 0;
35214 cm_event.provider_data = cm_id->provider_data;
35215 @@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35216 return;
35217 cm_id = cm_node->cm_id;
35218
35219 - atomic_inc(&cm_connect_reqs);
35220 + atomic_inc_unchecked(&cm_connect_reqs);
35221 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35222 cm_node, cm_id, jiffies);
35223
35224 @@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35225 return;
35226 cm_id = cm_node->cm_id;
35227
35228 - atomic_inc(&cm_connect_reqs);
35229 + atomic_inc_unchecked(&cm_connect_reqs);
35230 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35231 cm_node, cm_id, jiffies);
35232
35233 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
35234 index 4166452..fc952c3 100644
35235 --- a/drivers/infiniband/hw/nes/nes_mgt.c
35236 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
35237 @@ -40,8 +40,8 @@
35238 #include "nes.h"
35239 #include "nes_mgt.h"
35240
35241 -atomic_t pau_qps_created;
35242 -atomic_t pau_qps_destroyed;
35243 +atomic_unchecked_t pau_qps_created;
35244 +atomic_unchecked_t pau_qps_destroyed;
35245
35246 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
35247 {
35248 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
35249 {
35250 struct sk_buff *skb;
35251 unsigned long flags;
35252 - atomic_inc(&pau_qps_destroyed);
35253 + atomic_inc_unchecked(&pau_qps_destroyed);
35254
35255 /* Free packets that have not yet been forwarded */
35256 /* Lock is acquired by skb_dequeue when removing the skb */
35257 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
35258 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
35259 skb_queue_head_init(&nesqp->pau_list);
35260 spin_lock_init(&nesqp->pau_lock);
35261 - atomic_inc(&pau_qps_created);
35262 + atomic_inc_unchecked(&pau_qps_created);
35263 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
35264 }
35265
35266 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35267 index 9542e16..a008c40 100644
35268 --- a/drivers/infiniband/hw/nes/nes_nic.c
35269 +++ b/drivers/infiniband/hw/nes/nes_nic.c
35270 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35271 target_stat_values[++index] = mh_detected;
35272 target_stat_values[++index] = mh_pauses_sent;
35273 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35274 - target_stat_values[++index] = atomic_read(&cm_connects);
35275 - target_stat_values[++index] = atomic_read(&cm_accepts);
35276 - target_stat_values[++index] = atomic_read(&cm_disconnects);
35277 - target_stat_values[++index] = atomic_read(&cm_connecteds);
35278 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35279 - target_stat_values[++index] = atomic_read(&cm_rejects);
35280 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35281 - target_stat_values[++index] = atomic_read(&qps_created);
35282 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35283 - target_stat_values[++index] = atomic_read(&qps_destroyed);
35284 - target_stat_values[++index] = atomic_read(&cm_closes);
35285 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35286 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35287 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35288 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35289 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35290 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35291 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35292 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35293 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35294 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35295 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35296 target_stat_values[++index] = cm_packets_sent;
35297 target_stat_values[++index] = cm_packets_bounced;
35298 target_stat_values[++index] = cm_packets_created;
35299 target_stat_values[++index] = cm_packets_received;
35300 target_stat_values[++index] = cm_packets_dropped;
35301 target_stat_values[++index] = cm_packets_retrans;
35302 - target_stat_values[++index] = atomic_read(&cm_listens_created);
35303 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
35304 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
35305 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
35306 target_stat_values[++index] = cm_backlog_drops;
35307 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
35308 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
35309 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35310 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35311 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35312 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35313 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35314 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35315 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35316 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35317 target_stat_values[++index] = nesadapter->free_4kpbl;
35318 target_stat_values[++index] = nesadapter->free_256pbl;
35319 target_stat_values[++index] = int_mod_timer_init;
35320 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
35321 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
35322 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
35323 - target_stat_values[++index] = atomic_read(&pau_qps_created);
35324 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
35325 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
35326 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
35327 }
35328
35329 /**
35330 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35331 index 07e4fba..685f041 100644
35332 --- a/drivers/infiniband/hw/nes/nes_verbs.c
35333 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
35334 @@ -46,9 +46,9 @@
35335
35336 #include <rdma/ib_umem.h>
35337
35338 -atomic_t mod_qp_timouts;
35339 -atomic_t qps_created;
35340 -atomic_t sw_qps_destroyed;
35341 +atomic_unchecked_t mod_qp_timouts;
35342 +atomic_unchecked_t qps_created;
35343 +atomic_unchecked_t sw_qps_destroyed;
35344
35345 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35346
35347 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35348 if (init_attr->create_flags)
35349 return ERR_PTR(-EINVAL);
35350
35351 - atomic_inc(&qps_created);
35352 + atomic_inc_unchecked(&qps_created);
35353 switch (init_attr->qp_type) {
35354 case IB_QPT_RC:
35355 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35356 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35357 struct iw_cm_event cm_event;
35358 int ret = 0;
35359
35360 - atomic_inc(&sw_qps_destroyed);
35361 + atomic_inc_unchecked(&sw_qps_destroyed);
35362 nesqp->destroyed = 1;
35363
35364 /* Blow away the connection if it exists. */
35365 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
35366 index 4d11575..3e890e5 100644
35367 --- a/drivers/infiniband/hw/qib/qib.h
35368 +++ b/drivers/infiniband/hw/qib/qib.h
35369 @@ -51,6 +51,7 @@
35370 #include <linux/completion.h>
35371 #include <linux/kref.h>
35372 #include <linux/sched.h>
35373 +#include <linux/slab.h>
35374
35375 #include "qib_common.h"
35376 #include "qib_verbs.h"
35377 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35378 index da739d9..da1c7f4 100644
35379 --- a/drivers/input/gameport/gameport.c
35380 +++ b/drivers/input/gameport/gameport.c
35381 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
35382 */
35383 static void gameport_init_port(struct gameport *gameport)
35384 {
35385 - static atomic_t gameport_no = ATOMIC_INIT(0);
35386 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35387
35388 __module_get(THIS_MODULE);
35389
35390 mutex_init(&gameport->drv_mutex);
35391 device_initialize(&gameport->dev);
35392 dev_set_name(&gameport->dev, "gameport%lu",
35393 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
35394 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35395 gameport->dev.bus = &gameport_bus;
35396 gameport->dev.release = gameport_release_port;
35397 if (gameport->parent)
35398 diff --git a/drivers/input/input.c b/drivers/input/input.c
35399 index c044699..174d71a 100644
35400 --- a/drivers/input/input.c
35401 +++ b/drivers/input/input.c
35402 @@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
35403 */
35404 int input_register_device(struct input_dev *dev)
35405 {
35406 - static atomic_t input_no = ATOMIC_INIT(0);
35407 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35408 struct input_devres *devres = NULL;
35409 struct input_handler *handler;
35410 unsigned int packet_size;
35411 @@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
35412 dev->setkeycode = input_default_setkeycode;
35413
35414 dev_set_name(&dev->dev, "input%ld",
35415 - (unsigned long) atomic_inc_return(&input_no) - 1);
35416 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35417
35418 error = device_add(&dev->dev);
35419 if (error)
35420 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35421 index 04c69af..5f92d00 100644
35422 --- a/drivers/input/joystick/sidewinder.c
35423 +++ b/drivers/input/joystick/sidewinder.c
35424 @@ -30,6 +30,7 @@
35425 #include <linux/kernel.h>
35426 #include <linux/module.h>
35427 #include <linux/slab.h>
35428 +#include <linux/sched.h>
35429 #include <linux/init.h>
35430 #include <linux/input.h>
35431 #include <linux/gameport.h>
35432 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35433 index d6cbfe9..6225402 100644
35434 --- a/drivers/input/joystick/xpad.c
35435 +++ b/drivers/input/joystick/xpad.c
35436 @@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35437
35438 static int xpad_led_probe(struct usb_xpad *xpad)
35439 {
35440 - static atomic_t led_seq = ATOMIC_INIT(0);
35441 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35442 long led_no;
35443 struct xpad_led *led;
35444 struct led_classdev *led_cdev;
35445 @@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35446 if (!led)
35447 return -ENOMEM;
35448
35449 - led_no = (long)atomic_inc_return(&led_seq) - 1;
35450 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35451
35452 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35453 led->xpad = xpad;
35454 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
35455 index 4c842c3..590b0bf 100644
35456 --- a/drivers/input/mousedev.c
35457 +++ b/drivers/input/mousedev.c
35458 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
35459
35460 spin_unlock_irq(&client->packet_lock);
35461
35462 - if (copy_to_user(buffer, data, count))
35463 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
35464 return -EFAULT;
35465
35466 return count;
35467 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35468 index 25fc597..558bf3b 100644
35469 --- a/drivers/input/serio/serio.c
35470 +++ b/drivers/input/serio/serio.c
35471 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
35472 */
35473 static void serio_init_port(struct serio *serio)
35474 {
35475 - static atomic_t serio_no = ATOMIC_INIT(0);
35476 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35477
35478 __module_get(THIS_MODULE);
35479
35480 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
35481 mutex_init(&serio->drv_mutex);
35482 device_initialize(&serio->dev);
35483 dev_set_name(&serio->dev, "serio%ld",
35484 - (long)atomic_inc_return(&serio_no) - 1);
35485 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
35486 serio->dev.bus = &serio_bus;
35487 serio->dev.release = serio_release_port;
35488 serio->dev.groups = serio_device_attr_groups;
35489 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
35490 index 89562a8..218999b 100644
35491 --- a/drivers/isdn/capi/capi.c
35492 +++ b/drivers/isdn/capi/capi.c
35493 @@ -81,8 +81,8 @@ struct capiminor {
35494
35495 struct capi20_appl *ap;
35496 u32 ncci;
35497 - atomic_t datahandle;
35498 - atomic_t msgid;
35499 + atomic_unchecked_t datahandle;
35500 + atomic_unchecked_t msgid;
35501
35502 struct tty_port port;
35503 int ttyinstop;
35504 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
35505 capimsg_setu16(s, 2, mp->ap->applid);
35506 capimsg_setu8 (s, 4, CAPI_DATA_B3);
35507 capimsg_setu8 (s, 5, CAPI_RESP);
35508 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
35509 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
35510 capimsg_setu32(s, 8, mp->ncci);
35511 capimsg_setu16(s, 12, datahandle);
35512 }
35513 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
35514 mp->outbytes -= len;
35515 spin_unlock_bh(&mp->outlock);
35516
35517 - datahandle = atomic_inc_return(&mp->datahandle);
35518 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
35519 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
35520 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35521 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35522 capimsg_setu16(skb->data, 2, mp->ap->applid);
35523 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
35524 capimsg_setu8 (skb->data, 5, CAPI_REQ);
35525 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
35526 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
35527 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
35528 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
35529 capimsg_setu16(skb->data, 16, len); /* Data length */
35530 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35531 index 67abf3f..076b3a6 100644
35532 --- a/drivers/isdn/gigaset/interface.c
35533 +++ b/drivers/isdn/gigaset/interface.c
35534 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35535 }
35536 tty->driver_data = cs;
35537
35538 - ++cs->port.count;
35539 + atomic_inc(&cs->port.count);
35540
35541 - if (cs->port.count == 1) {
35542 + if (atomic_read(&cs->port.count) == 1) {
35543 tty_port_tty_set(&cs->port, tty);
35544 tty->low_latency = 1;
35545 }
35546 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35547
35548 if (!cs->connected)
35549 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35550 - else if (!cs->port.count)
35551 + else if (!atomic_read(&cs->port.count))
35552 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35553 - else if (!--cs->port.count)
35554 + else if (!atomic_dec_return(&cs->port.count))
35555 tty_port_tty_set(&cs->port, NULL);
35556
35557 mutex_unlock(&cs->mutex);
35558 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35559 index 821f7ac..28d4030 100644
35560 --- a/drivers/isdn/hardware/avm/b1.c
35561 +++ b/drivers/isdn/hardware/avm/b1.c
35562 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
35563 }
35564 if (left) {
35565 if (t4file->user) {
35566 - if (copy_from_user(buf, dp, left))
35567 + if (left > sizeof buf || copy_from_user(buf, dp, left))
35568 return -EFAULT;
35569 } else {
35570 memcpy(buf, dp, left);
35571 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
35572 }
35573 if (left) {
35574 if (config->user) {
35575 - if (copy_from_user(buf, dp, left))
35576 + if (left > sizeof buf || copy_from_user(buf, dp, left))
35577 return -EFAULT;
35578 } else {
35579 memcpy(buf, dp, left);
35580 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
35581 index e09dc8a..15e2efb 100644
35582 --- a/drivers/isdn/i4l/isdn_tty.c
35583 +++ b/drivers/isdn/i4l/isdn_tty.c
35584 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
35585
35586 #ifdef ISDN_DEBUG_MODEM_OPEN
35587 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
35588 - port->count);
35589 + atomic_read(&port->count));
35590 #endif
35591 - port->count++;
35592 + atomic_inc(&port->count);
35593 port->tty = tty;
35594 /*
35595 * Start up serial port
35596 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35597 #endif
35598 return;
35599 }
35600 - if ((tty->count == 1) && (port->count != 1)) {
35601 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
35602 /*
35603 * Uh, oh. tty->count is 1, which means that the tty
35604 * structure will be freed. Info->count should always
35605 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35606 * serial port won't be shutdown.
35607 */
35608 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
35609 - "info->count is %d\n", port->count);
35610 - port->count = 1;
35611 + "info->count is %d\n", atomic_read(&port->count));
35612 + atomic_set(&port->count, 1);
35613 }
35614 - if (--port->count < 0) {
35615 + if (atomic_dec_return(&port->count) < 0) {
35616 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
35617 - info->line, port->count);
35618 - port->count = 0;
35619 + info->line, atomic_read(&port->count));
35620 + atomic_set(&port->count, 0);
35621 }
35622 - if (port->count) {
35623 + if (atomic_read(&port->count)) {
35624 #ifdef ISDN_DEBUG_MODEM_OPEN
35625 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
35626 #endif
35627 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
35628 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
35629 return;
35630 isdn_tty_shutdown(info);
35631 - port->count = 0;
35632 + atomic_set(&port->count, 0);
35633 port->flags &= ~ASYNC_NORMAL_ACTIVE;
35634 port->tty = NULL;
35635 wake_up_interruptible(&port->open_wait);
35636 @@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
35637 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
35638 modem_info *info = &dev->mdm.info[i];
35639
35640 - if (info->port.count == 0)
35641 + if (atomic_read(&info->port.count) == 0)
35642 continue;
35643 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
35644 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
35645 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35646 index e74df7c..03a03ba 100644
35647 --- a/drivers/isdn/icn/icn.c
35648 +++ b/drivers/isdn/icn/icn.c
35649 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
35650 if (count > len)
35651 count = len;
35652 if (user) {
35653 - if (copy_from_user(msg, buf, count))
35654 + if (count > sizeof msg || copy_from_user(msg, buf, count))
35655 return -EFAULT;
35656 } else
35657 memcpy(msg, buf, count);
35658 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35659 index a5ebc00..982886f 100644
35660 --- a/drivers/lguest/core.c
35661 +++ b/drivers/lguest/core.c
35662 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
35663 * it's worked so far. The end address needs +1 because __get_vm_area
35664 * allocates an extra guard page, so we need space for that.
35665 */
35666 +
35667 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35668 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35669 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35670 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35671 +#else
35672 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35673 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35674 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35675 +#endif
35676 +
35677 if (!switcher_vma) {
35678 err = -ENOMEM;
35679 printk("lguest: could not map switcher pages high\n");
35680 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
35681 * Now the Switcher is mapped at the right address, we can't fail!
35682 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
35683 */
35684 - memcpy(switcher_vma->addr, start_switcher_text,
35685 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35686 end_switcher_text - start_switcher_text);
35687
35688 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35689 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35690 index 4af12e1..0e89afe 100644
35691 --- a/drivers/lguest/x86/core.c
35692 +++ b/drivers/lguest/x86/core.c
35693 @@ -59,7 +59,7 @@ static struct {
35694 /* Offset from where switcher.S was compiled to where we've copied it */
35695 static unsigned long switcher_offset(void)
35696 {
35697 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35698 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35699 }
35700
35701 /* This cpu's struct lguest_pages. */
35702 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35703 * These copies are pretty cheap, so we do them unconditionally: */
35704 /* Save the current Host top-level page directory.
35705 */
35706 +
35707 +#ifdef CONFIG_PAX_PER_CPU_PGD
35708 + pages->state.host_cr3 = read_cr3();
35709 +#else
35710 pages->state.host_cr3 = __pa(current->mm->pgd);
35711 +#endif
35712 +
35713 /*
35714 * Set up the Guest's page tables to see this CPU's pages (and no
35715 * other CPU's pages).
35716 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
35717 * compiled-in switcher code and the high-mapped copy we just made.
35718 */
35719 for (i = 0; i < IDT_ENTRIES; i++)
35720 - default_idt_entries[i] += switcher_offset();
35721 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35722
35723 /*
35724 * Set up the Switcher's per-cpu areas.
35725 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
35726 * it will be undisturbed when we switch. To change %cs and jump we
35727 * need this structure to feed to Intel's "lcall" instruction.
35728 */
35729 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35730 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35731 lguest_entry.segment = LGUEST_CS;
35732
35733 /*
35734 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35735 index 40634b0..4f5855e 100644
35736 --- a/drivers/lguest/x86/switcher_32.S
35737 +++ b/drivers/lguest/x86/switcher_32.S
35738 @@ -87,6 +87,7 @@
35739 #include <asm/page.h>
35740 #include <asm/segment.h>
35741 #include <asm/lguest.h>
35742 +#include <asm/processor-flags.h>
35743
35744 // We mark the start of the code to copy
35745 // It's placed in .text tho it's never run here
35746 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35747 // Changes type when we load it: damn Intel!
35748 // For after we switch over our page tables
35749 // That entry will be read-only: we'd crash.
35750 +
35751 +#ifdef CONFIG_PAX_KERNEXEC
35752 + mov %cr0, %edx
35753 + xor $X86_CR0_WP, %edx
35754 + mov %edx, %cr0
35755 +#endif
35756 +
35757 movl $(GDT_ENTRY_TSS*8), %edx
35758 ltr %dx
35759
35760 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35761 // Let's clear it again for our return.
35762 // The GDT descriptor of the Host
35763 // Points to the table after two "size" bytes
35764 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35765 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35766 // Clear "used" from type field (byte 5, bit 2)
35767 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35768 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35769 +
35770 +#ifdef CONFIG_PAX_KERNEXEC
35771 + mov %cr0, %eax
35772 + xor $X86_CR0_WP, %eax
35773 + mov %eax, %cr0
35774 +#endif
35775
35776 // Once our page table's switched, the Guest is live!
35777 // The Host fades as we run this final step.
35778 @@ -295,13 +309,12 @@ deliver_to_host:
35779 // I consulted gcc, and it gave
35780 // These instructions, which I gladly credit:
35781 leal (%edx,%ebx,8), %eax
35782 - movzwl (%eax),%edx
35783 - movl 4(%eax), %eax
35784 - xorw %ax, %ax
35785 - orl %eax, %edx
35786 + movl 4(%eax), %edx
35787 + movw (%eax), %dx
35788 // Now the address of the handler's in %edx
35789 // We call it now: its "iret" drops us home.
35790 - jmp *%edx
35791 + ljmp $__KERNEL_CS, $1f
35792 +1: jmp *%edx
35793
35794 // Every interrupt can come to us here
35795 // But we must truly tell each apart.
35796 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35797 index 7155945..4bcc562 100644
35798 --- a/drivers/md/bitmap.c
35799 +++ b/drivers/md/bitmap.c
35800 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35801 chunk_kb ? "KB" : "B");
35802 if (bitmap->storage.file) {
35803 seq_printf(seq, ", file: ");
35804 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35805 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35806 }
35807
35808 seq_printf(seq, "\n");
35809 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35810 index 0666b5d..ed82cb4 100644
35811 --- a/drivers/md/dm-ioctl.c
35812 +++ b/drivers/md/dm-ioctl.c
35813 @@ -1628,7 +1628,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35814 cmd == DM_LIST_VERSIONS_CMD)
35815 return 0;
35816
35817 - if ((cmd == DM_DEV_CREATE_CMD)) {
35818 + if (cmd == DM_DEV_CREATE_CMD) {
35819 if (!*param->name) {
35820 DMWARN("name not supplied when creating device");
35821 return -EINVAL;
35822 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35823 index fa51918..c26253c 100644
35824 --- a/drivers/md/dm-raid1.c
35825 +++ b/drivers/md/dm-raid1.c
35826 @@ -40,7 +40,7 @@ enum dm_raid1_error {
35827
35828 struct mirror {
35829 struct mirror_set *ms;
35830 - atomic_t error_count;
35831 + atomic_unchecked_t error_count;
35832 unsigned long error_type;
35833 struct dm_dev *dev;
35834 sector_t offset;
35835 @@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35836 struct mirror *m;
35837
35838 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35839 - if (!atomic_read(&m->error_count))
35840 + if (!atomic_read_unchecked(&m->error_count))
35841 return m;
35842
35843 return NULL;
35844 @@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35845 * simple way to tell if a device has encountered
35846 * errors.
35847 */
35848 - atomic_inc(&m->error_count);
35849 + atomic_inc_unchecked(&m->error_count);
35850
35851 if (test_and_set_bit(error_type, &m->error_type))
35852 return;
35853 @@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35854 struct mirror *m = get_default_mirror(ms);
35855
35856 do {
35857 - if (likely(!atomic_read(&m->error_count)))
35858 + if (likely(!atomic_read_unchecked(&m->error_count)))
35859 return m;
35860
35861 if (m-- == ms->mirror)
35862 @@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
35863 {
35864 struct mirror *default_mirror = get_default_mirror(m->ms);
35865
35866 - return !atomic_read(&default_mirror->error_count);
35867 + return !atomic_read_unchecked(&default_mirror->error_count);
35868 }
35869
35870 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35871 @@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35872 */
35873 if (likely(region_in_sync(ms, region, 1)))
35874 m = choose_mirror(ms, bio->bi_sector);
35875 - else if (m && atomic_read(&m->error_count))
35876 + else if (m && atomic_read_unchecked(&m->error_count))
35877 m = NULL;
35878
35879 if (likely(m))
35880 @@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35881 }
35882
35883 ms->mirror[mirror].ms = ms;
35884 - atomic_set(&(ms->mirror[mirror].error_count), 0);
35885 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35886 ms->mirror[mirror].error_type = 0;
35887 ms->mirror[mirror].offset = offset;
35888
35889 @@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
35890 */
35891 static char device_status_char(struct mirror *m)
35892 {
35893 - if (!atomic_read(&(m->error_count)))
35894 + if (!atomic_read_unchecked(&(m->error_count)))
35895 return 'A';
35896
35897 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35898 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35899 index c89cde8..9d184cf 100644
35900 --- a/drivers/md/dm-stripe.c
35901 +++ b/drivers/md/dm-stripe.c
35902 @@ -20,7 +20,7 @@ struct stripe {
35903 struct dm_dev *dev;
35904 sector_t physical_start;
35905
35906 - atomic_t error_count;
35907 + atomic_unchecked_t error_count;
35908 };
35909
35910 struct stripe_c {
35911 @@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35912 kfree(sc);
35913 return r;
35914 }
35915 - atomic_set(&(sc->stripe[i].error_count), 0);
35916 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35917 }
35918
35919 ti->private = sc;
35920 @@ -325,7 +325,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35921 DMEMIT("%d ", sc->stripes);
35922 for (i = 0; i < sc->stripes; i++) {
35923 DMEMIT("%s ", sc->stripe[i].dev->name);
35924 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35925 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35926 'D' : 'A';
35927 }
35928 buffer[i] = '\0';
35929 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
35930 */
35931 for (i = 0; i < sc->stripes; i++)
35932 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35933 - atomic_inc(&(sc->stripe[i].error_count));
35934 - if (atomic_read(&(sc->stripe[i].error_count)) <
35935 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
35936 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35937 DM_IO_ERROR_THRESHOLD)
35938 schedule_work(&sc->trigger_event);
35939 }
35940 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35941 index daf25d0..d74f49f 100644
35942 --- a/drivers/md/dm-table.c
35943 +++ b/drivers/md/dm-table.c
35944 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35945 if (!dev_size)
35946 return 0;
35947
35948 - if ((start >= dev_size) || (start + len > dev_size)) {
35949 + if ((start >= dev_size) || (len > dev_size - start)) {
35950 DMWARN("%s: %s too small for target: "
35951 "start=%llu, len=%llu, dev_size=%llu",
35952 dm_device_name(ti->table->md), bdevname(bdev, b),
35953 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35954 index 4d6e853..a234157 100644
35955 --- a/drivers/md/dm-thin-metadata.c
35956 +++ b/drivers/md/dm-thin-metadata.c
35957 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35958 {
35959 pmd->info.tm = pmd->tm;
35960 pmd->info.levels = 2;
35961 - pmd->info.value_type.context = pmd->data_sm;
35962 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35963 pmd->info.value_type.size = sizeof(__le64);
35964 pmd->info.value_type.inc = data_block_inc;
35965 pmd->info.value_type.dec = data_block_dec;
35966 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35967
35968 pmd->bl_info.tm = pmd->tm;
35969 pmd->bl_info.levels = 1;
35970 - pmd->bl_info.value_type.context = pmd->data_sm;
35971 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35972 pmd->bl_info.value_type.size = sizeof(__le64);
35973 pmd->bl_info.value_type.inc = data_block_inc;
35974 pmd->bl_info.value_type.dec = data_block_dec;
35975 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35976 index 314a0e2..1376406 100644
35977 --- a/drivers/md/dm.c
35978 +++ b/drivers/md/dm.c
35979 @@ -170,9 +170,9 @@ struct mapped_device {
35980 /*
35981 * Event handling.
35982 */
35983 - atomic_t event_nr;
35984 + atomic_unchecked_t event_nr;
35985 wait_queue_head_t eventq;
35986 - atomic_t uevent_seq;
35987 + atomic_unchecked_t uevent_seq;
35988 struct list_head uevent_list;
35989 spinlock_t uevent_lock; /* Protect access to uevent_list */
35990
35991 @@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
35992 rwlock_init(&md->map_lock);
35993 atomic_set(&md->holders, 1);
35994 atomic_set(&md->open_count, 0);
35995 - atomic_set(&md->event_nr, 0);
35996 - atomic_set(&md->uevent_seq, 0);
35997 + atomic_set_unchecked(&md->event_nr, 0);
35998 + atomic_set_unchecked(&md->uevent_seq, 0);
35999 INIT_LIST_HEAD(&md->uevent_list);
36000 spin_lock_init(&md->uevent_lock);
36001
36002 @@ -2014,7 +2014,7 @@ static void event_callback(void *context)
36003
36004 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36005
36006 - atomic_inc(&md->event_nr);
36007 + atomic_inc_unchecked(&md->event_nr);
36008 wake_up(&md->eventq);
36009 }
36010
36011 @@ -2669,18 +2669,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36012
36013 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36014 {
36015 - return atomic_add_return(1, &md->uevent_seq);
36016 + return atomic_add_return_unchecked(1, &md->uevent_seq);
36017 }
36018
36019 uint32_t dm_get_event_nr(struct mapped_device *md)
36020 {
36021 - return atomic_read(&md->event_nr);
36022 + return atomic_read_unchecked(&md->event_nr);
36023 }
36024
36025 int dm_wait_event(struct mapped_device *md, int event_nr)
36026 {
36027 return wait_event_interruptible(md->eventq,
36028 - (event_nr != atomic_read(&md->event_nr)));
36029 + (event_nr != atomic_read_unchecked(&md->event_nr)));
36030 }
36031
36032 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36033 diff --git a/drivers/md/md.c b/drivers/md/md.c
36034 index 3db3d1b..9487468 100644
36035 --- a/drivers/md/md.c
36036 +++ b/drivers/md/md.c
36037 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
36038 * start build, activate spare
36039 */
36040 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36041 -static atomic_t md_event_count;
36042 +static atomic_unchecked_t md_event_count;
36043 void md_new_event(struct mddev *mddev)
36044 {
36045 - atomic_inc(&md_event_count);
36046 + atomic_inc_unchecked(&md_event_count);
36047 wake_up(&md_event_waiters);
36048 }
36049 EXPORT_SYMBOL_GPL(md_new_event);
36050 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36051 */
36052 static void md_new_event_inintr(struct mddev *mddev)
36053 {
36054 - atomic_inc(&md_event_count);
36055 + atomic_inc_unchecked(&md_event_count);
36056 wake_up(&md_event_waiters);
36057 }
36058
36059 @@ -1503,7 +1503,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
36060 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
36061 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
36062 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
36063 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36064 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36065
36066 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36067 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36068 @@ -1747,7 +1747,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
36069 else
36070 sb->resync_offset = cpu_to_le64(0);
36071
36072 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36073 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36074
36075 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36076 sb->size = cpu_to_le64(mddev->dev_sectors);
36077 @@ -2747,7 +2747,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36078 static ssize_t
36079 errors_show(struct md_rdev *rdev, char *page)
36080 {
36081 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36082 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36083 }
36084
36085 static ssize_t
36086 @@ -2756,7 +2756,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
36087 char *e;
36088 unsigned long n = simple_strtoul(buf, &e, 10);
36089 if (*buf && (*e == 0 || *e == '\n')) {
36090 - atomic_set(&rdev->corrected_errors, n);
36091 + atomic_set_unchecked(&rdev->corrected_errors, n);
36092 return len;
36093 }
36094 return -EINVAL;
36095 @@ -3203,8 +3203,8 @@ int md_rdev_init(struct md_rdev *rdev)
36096 rdev->sb_loaded = 0;
36097 rdev->bb_page = NULL;
36098 atomic_set(&rdev->nr_pending, 0);
36099 - atomic_set(&rdev->read_errors, 0);
36100 - atomic_set(&rdev->corrected_errors, 0);
36101 + atomic_set_unchecked(&rdev->read_errors, 0);
36102 + atomic_set_unchecked(&rdev->corrected_errors, 0);
36103
36104 INIT_LIST_HEAD(&rdev->same_set);
36105 init_waitqueue_head(&rdev->blocked_wait);
36106 @@ -6980,7 +6980,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36107
36108 spin_unlock(&pers_lock);
36109 seq_printf(seq, "\n");
36110 - seq->poll_event = atomic_read(&md_event_count);
36111 + seq->poll_event = atomic_read_unchecked(&md_event_count);
36112 return 0;
36113 }
36114 if (v == (void*)2) {
36115 @@ -7083,7 +7083,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36116 return error;
36117
36118 seq = file->private_data;
36119 - seq->poll_event = atomic_read(&md_event_count);
36120 + seq->poll_event = atomic_read_unchecked(&md_event_count);
36121 return error;
36122 }
36123
36124 @@ -7097,7 +7097,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36125 /* always allow read */
36126 mask = POLLIN | POLLRDNORM;
36127
36128 - if (seq->poll_event != atomic_read(&md_event_count))
36129 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
36130 mask |= POLLERR | POLLPRI;
36131 return mask;
36132 }
36133 @@ -7141,7 +7141,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
36134 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36135 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36136 (int)part_stat_read(&disk->part0, sectors[1]) -
36137 - atomic_read(&disk->sync_io);
36138 + atomic_read_unchecked(&disk->sync_io);
36139 /* sync IO will cause sync_io to increase before the disk_stats
36140 * as sync_io is counted when a request starts, and
36141 * disk_stats is counted when it completes.
36142 diff --git a/drivers/md/md.h b/drivers/md/md.h
36143 index eca59c3..7c42285 100644
36144 --- a/drivers/md/md.h
36145 +++ b/drivers/md/md.h
36146 @@ -94,13 +94,13 @@ struct md_rdev {
36147 * only maintained for arrays that
36148 * support hot removal
36149 */
36150 - atomic_t read_errors; /* number of consecutive read errors that
36151 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
36152 * we have tried to ignore.
36153 */
36154 struct timespec last_read_error; /* monotonic time since our
36155 * last read error
36156 */
36157 - atomic_t corrected_errors; /* number of corrected read errors,
36158 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36159 * for reporting to userspace and storing
36160 * in superblock.
36161 */
36162 @@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
36163
36164 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36165 {
36166 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36167 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36168 }
36169
36170 struct md_personality
36171 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
36172 index 1cbfc6b..56e1dbb 100644
36173 --- a/drivers/md/persistent-data/dm-space-map.h
36174 +++ b/drivers/md/persistent-data/dm-space-map.h
36175 @@ -60,6 +60,7 @@ struct dm_space_map {
36176 int (*root_size)(struct dm_space_map *sm, size_t *result);
36177 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
36178 };
36179 +typedef struct dm_space_map __no_const dm_space_map_no_const;
36180
36181 /*----------------------------------------------------------------*/
36182
36183 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36184 index d5bddfc..b079b4b 100644
36185 --- a/drivers/md/raid1.c
36186 +++ b/drivers/md/raid1.c
36187 @@ -1818,7 +1818,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
36188 if (r1_sync_page_io(rdev, sect, s,
36189 bio->bi_io_vec[idx].bv_page,
36190 READ) != 0)
36191 - atomic_add(s, &rdev->corrected_errors);
36192 + atomic_add_unchecked(s, &rdev->corrected_errors);
36193 }
36194 sectors -= s;
36195 sect += s;
36196 @@ -2040,7 +2040,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
36197 test_bit(In_sync, &rdev->flags)) {
36198 if (r1_sync_page_io(rdev, sect, s,
36199 conf->tmppage, READ)) {
36200 - atomic_add(s, &rdev->corrected_errors);
36201 + atomic_add_unchecked(s, &rdev->corrected_errors);
36202 printk(KERN_INFO
36203 "md/raid1:%s: read error corrected "
36204 "(%d sectors at %llu on %s)\n",
36205 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36206 index 64d4824..8b9ea57 100644
36207 --- a/drivers/md/raid10.c
36208 +++ b/drivers/md/raid10.c
36209 @@ -1877,7 +1877,7 @@ static void end_sync_read(struct bio *bio, int error)
36210 /* The write handler will notice the lack of
36211 * R10BIO_Uptodate and record any errors etc
36212 */
36213 - atomic_add(r10_bio->sectors,
36214 + atomic_add_unchecked(r10_bio->sectors,
36215 &conf->mirrors[d].rdev->corrected_errors);
36216
36217 /* for reconstruct, we always reschedule after a read.
36218 @@ -2226,7 +2226,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36219 {
36220 struct timespec cur_time_mon;
36221 unsigned long hours_since_last;
36222 - unsigned int read_errors = atomic_read(&rdev->read_errors);
36223 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
36224
36225 ktime_get_ts(&cur_time_mon);
36226
36227 @@ -2248,9 +2248,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36228 * overflowing the shift of read_errors by hours_since_last.
36229 */
36230 if (hours_since_last >= 8 * sizeof(read_errors))
36231 - atomic_set(&rdev->read_errors, 0);
36232 + atomic_set_unchecked(&rdev->read_errors, 0);
36233 else
36234 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
36235 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
36236 }
36237
36238 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
36239 @@ -2304,8 +2304,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36240 return;
36241
36242 check_decay_read_errors(mddev, rdev);
36243 - atomic_inc(&rdev->read_errors);
36244 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
36245 + atomic_inc_unchecked(&rdev->read_errors);
36246 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
36247 char b[BDEVNAME_SIZE];
36248 bdevname(rdev->bdev, b);
36249
36250 @@ -2313,7 +2313,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36251 "md/raid10:%s: %s: Raid device exceeded "
36252 "read_error threshold [cur %d:max %d]\n",
36253 mdname(mddev), b,
36254 - atomic_read(&rdev->read_errors), max_read_errors);
36255 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
36256 printk(KERN_NOTICE
36257 "md/raid10:%s: %s: Failing raid device\n",
36258 mdname(mddev), b);
36259 @@ -2468,7 +2468,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36260 sect +
36261 choose_data_offset(r10_bio, rdev)),
36262 bdevname(rdev->bdev, b));
36263 - atomic_add(s, &rdev->corrected_errors);
36264 + atomic_add_unchecked(s, &rdev->corrected_errors);
36265 }
36266
36267 rdev_dec_pending(rdev, mddev);
36268 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36269 index 19d77a0..56051b92 100644
36270 --- a/drivers/md/raid5.c
36271 +++ b/drivers/md/raid5.c
36272 @@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
36273 mdname(conf->mddev), STRIPE_SECTORS,
36274 (unsigned long long)s,
36275 bdevname(rdev->bdev, b));
36276 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
36277 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
36278 clear_bit(R5_ReadError, &sh->dev[i].flags);
36279 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36280 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
36281 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
36282
36283 - if (atomic_read(&rdev->read_errors))
36284 - atomic_set(&rdev->read_errors, 0);
36285 + if (atomic_read_unchecked(&rdev->read_errors))
36286 + atomic_set_unchecked(&rdev->read_errors, 0);
36287 } else {
36288 const char *bdn = bdevname(rdev->bdev, b);
36289 int retry = 0;
36290 int set_bad = 0;
36291
36292 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36293 - atomic_inc(&rdev->read_errors);
36294 + atomic_inc_unchecked(&rdev->read_errors);
36295 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
36296 printk_ratelimited(
36297 KERN_WARNING
36298 @@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36299 mdname(conf->mddev),
36300 (unsigned long long)s,
36301 bdn);
36302 - } else if (atomic_read(&rdev->read_errors)
36303 + } else if (atomic_read_unchecked(&rdev->read_errors)
36304 > conf->max_nr_stripes)
36305 printk(KERN_WARNING
36306 "md/raid:%s: Too many read errors, failing device %s.\n",
36307 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
36308 index d33101a..6b13069 100644
36309 --- a/drivers/media/dvb-core/dvbdev.c
36310 +++ b/drivers/media/dvb-core/dvbdev.c
36311 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36312 const struct dvb_device *template, void *priv, int type)
36313 {
36314 struct dvb_device *dvbdev;
36315 - struct file_operations *dvbdevfops;
36316 + file_operations_no_const *dvbdevfops;
36317 struct device *clsdev;
36318 int minor;
36319 int id;
36320 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
36321 index 404f63a..4796533 100644
36322 --- a/drivers/media/dvb-frontends/dib3000.h
36323 +++ b/drivers/media/dvb-frontends/dib3000.h
36324 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36325 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36326 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36327 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36328 -};
36329 +} __no_const;
36330
36331 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36332 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36333 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
36334 index 35cc526..9d90d83 100644
36335 --- a/drivers/media/platform/omap/omap_vout.c
36336 +++ b/drivers/media/platform/omap/omap_vout.c
36337 @@ -63,7 +63,6 @@ enum omap_vout_channels {
36338 OMAP_VIDEO2,
36339 };
36340
36341 -static struct videobuf_queue_ops video_vbq_ops;
36342 /* Variables configurable through module params*/
36343 static u32 video1_numbuffers = 3;
36344 static u32 video2_numbuffers = 3;
36345 @@ -1010,6 +1009,12 @@ static int omap_vout_open(struct file *file)
36346 {
36347 struct videobuf_queue *q;
36348 struct omap_vout_device *vout = NULL;
36349 + static struct videobuf_queue_ops video_vbq_ops = {
36350 + .buf_setup = omap_vout_buffer_setup,
36351 + .buf_prepare = omap_vout_buffer_prepare,
36352 + .buf_release = omap_vout_buffer_release,
36353 + .buf_queue = omap_vout_buffer_queue,
36354 + };
36355
36356 vout = video_drvdata(file);
36357 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
36358 @@ -1027,10 +1032,6 @@ static int omap_vout_open(struct file *file)
36359 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
36360
36361 q = &vout->vbq;
36362 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
36363 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
36364 - video_vbq_ops.buf_release = omap_vout_buffer_release;
36365 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
36366 spin_lock_init(&vout->vbq_lock);
36367
36368 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
36369 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
36370 index b671e20..34088b7 100644
36371 --- a/drivers/media/platform/s5p-tv/mixer.h
36372 +++ b/drivers/media/platform/s5p-tv/mixer.h
36373 @@ -155,7 +155,7 @@ struct mxr_layer {
36374 /** layer index (unique identifier) */
36375 int idx;
36376 /** callbacks for layer methods */
36377 - struct mxr_layer_ops ops;
36378 + struct mxr_layer_ops *ops;
36379 /** format array */
36380 const struct mxr_format **fmt_array;
36381 /** size of format array */
36382 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36383 index b93a21f..2535195 100644
36384 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36385 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36386 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
36387 {
36388 struct mxr_layer *layer;
36389 int ret;
36390 - struct mxr_layer_ops ops = {
36391 + static struct mxr_layer_ops ops = {
36392 .release = mxr_graph_layer_release,
36393 .buffer_set = mxr_graph_buffer_set,
36394 .stream_set = mxr_graph_stream_set,
36395 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
36396 index 3b1670a..595c939 100644
36397 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
36398 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
36399 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
36400 layer->update_buf = next;
36401 }
36402
36403 - layer->ops.buffer_set(layer, layer->update_buf);
36404 + layer->ops->buffer_set(layer, layer->update_buf);
36405
36406 if (done && done != layer->shadow_buf)
36407 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
36408 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
36409 index 1f3b743..e839271 100644
36410 --- a/drivers/media/platform/s5p-tv/mixer_video.c
36411 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
36412 @@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
36413 layer->geo.src.height = layer->geo.src.full_height;
36414
36415 mxr_geometry_dump(mdev, &layer->geo);
36416 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36417 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36418 mxr_geometry_dump(mdev, &layer->geo);
36419 }
36420
36421 @@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
36422 layer->geo.dst.full_width = mbus_fmt.width;
36423 layer->geo.dst.full_height = mbus_fmt.height;
36424 layer->geo.dst.field = mbus_fmt.field;
36425 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36426 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36427
36428 mxr_geometry_dump(mdev, &layer->geo);
36429 }
36430 @@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
36431 /* set source size to highest accepted value */
36432 geo->src.full_width = max(geo->dst.full_width, pix->width);
36433 geo->src.full_height = max(geo->dst.full_height, pix->height);
36434 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36435 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36436 mxr_geometry_dump(mdev, &layer->geo);
36437 /* set cropping to total visible screen */
36438 geo->src.width = pix->width;
36439 @@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
36440 geo->src.x_offset = 0;
36441 geo->src.y_offset = 0;
36442 /* assure consistency of geometry */
36443 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36444 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36445 mxr_geometry_dump(mdev, &layer->geo);
36446 /* set full size to lowest possible value */
36447 geo->src.full_width = 0;
36448 geo->src.full_height = 0;
36449 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36450 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36451 mxr_geometry_dump(mdev, &layer->geo);
36452
36453 /* returning results */
36454 @@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
36455 target->width = s->r.width;
36456 target->height = s->r.height;
36457
36458 - layer->ops.fix_geometry(layer, stage, s->flags);
36459 + layer->ops->fix_geometry(layer, stage, s->flags);
36460
36461 /* retrieve update selection rectangle */
36462 res.left = target->x_offset;
36463 @@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
36464 mxr_output_get(mdev);
36465
36466 mxr_layer_update_output(layer);
36467 - layer->ops.format_set(layer);
36468 + layer->ops->format_set(layer);
36469 /* enabling layer in hardware */
36470 spin_lock_irqsave(&layer->enq_slock, flags);
36471 layer->state = MXR_LAYER_STREAMING;
36472 spin_unlock_irqrestore(&layer->enq_slock, flags);
36473
36474 - layer->ops.stream_set(layer, MXR_ENABLE);
36475 + layer->ops->stream_set(layer, MXR_ENABLE);
36476 mxr_streamer_get(mdev);
36477
36478 return 0;
36479 @@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
36480 spin_unlock_irqrestore(&layer->enq_slock, flags);
36481
36482 /* disabling layer in hardware */
36483 - layer->ops.stream_set(layer, MXR_DISABLE);
36484 + layer->ops->stream_set(layer, MXR_DISABLE);
36485 /* remove one streamer */
36486 mxr_streamer_put(mdev);
36487 /* allow changes in output configuration */
36488 @@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
36489
36490 void mxr_layer_release(struct mxr_layer *layer)
36491 {
36492 - if (layer->ops.release)
36493 - layer->ops.release(layer);
36494 + if (layer->ops->release)
36495 + layer->ops->release(layer);
36496 }
36497
36498 void mxr_base_layer_release(struct mxr_layer *layer)
36499 @@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
36500
36501 layer->mdev = mdev;
36502 layer->idx = idx;
36503 - layer->ops = *ops;
36504 + layer->ops = ops;
36505
36506 spin_lock_init(&layer->enq_slock);
36507 INIT_LIST_HEAD(&layer->enq_list);
36508 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36509 index 3d13a63..da31bf1 100644
36510 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36511 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36512 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
36513 {
36514 struct mxr_layer *layer;
36515 int ret;
36516 - struct mxr_layer_ops ops = {
36517 + static struct mxr_layer_ops ops = {
36518 .release = mxr_vp_layer_release,
36519 .buffer_set = mxr_vp_buffer_set,
36520 .stream_set = mxr_vp_stream_set,
36521 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36522 index 643d80a..56bb96b 100644
36523 --- a/drivers/media/radio/radio-cadet.c
36524 +++ b/drivers/media/radio/radio-cadet.c
36525 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36526 unsigned char readbuf[RDS_BUFFER];
36527 int i = 0;
36528
36529 + if (count > RDS_BUFFER)
36530 + return -EFAULT;
36531 mutex_lock(&dev->lock);
36532 if (dev->rdsstat == 0)
36533 cadet_start_rds(dev);
36534 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36535 while (i < count && dev->rdsin != dev->rdsout)
36536 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36537
36538 - if (i && copy_to_user(data, readbuf, i))
36539 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
36540 i = -EFAULT;
36541 unlock:
36542 mutex_unlock(&dev->lock);
36543 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
36544 index 3940bb0..fb3952a 100644
36545 --- a/drivers/media/usb/dvb-usb/cxusb.c
36546 +++ b/drivers/media/usb/dvb-usb/cxusb.c
36547 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36548
36549 struct dib0700_adapter_state {
36550 int (*set_param_save) (struct dvb_frontend *);
36551 -};
36552 +} __no_const;
36553
36554 static int dib7070_set_param_override(struct dvb_frontend *fe)
36555 {
36556 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
36557 index 9382895..ac8093c 100644
36558 --- a/drivers/media/usb/dvb-usb/dw2102.c
36559 +++ b/drivers/media/usb/dvb-usb/dw2102.c
36560 @@ -95,7 +95,7 @@ struct su3000_state {
36561
36562 struct s6x0_state {
36563 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
36564 -};
36565 +} __no_const;
36566
36567 /* debug */
36568 static int dvb_usb_dw2102_debug;
36569 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36570 index fb69baa..cf7ad22 100644
36571 --- a/drivers/message/fusion/mptbase.c
36572 +++ b/drivers/message/fusion/mptbase.c
36573 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
36574 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36575 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36576
36577 +#ifdef CONFIG_GRKERNSEC_HIDESYM
36578 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
36579 +#else
36580 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36581 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36582 +#endif
36583 +
36584 /*
36585 * Rounding UP to nearest 4-kB boundary here...
36586 */
36587 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36588 index fa43c39..daeb158 100644
36589 --- a/drivers/message/fusion/mptsas.c
36590 +++ b/drivers/message/fusion/mptsas.c
36591 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36592 return 0;
36593 }
36594
36595 +static inline void
36596 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36597 +{
36598 + if (phy_info->port_details) {
36599 + phy_info->port_details->rphy = rphy;
36600 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36601 + ioc->name, rphy));
36602 + }
36603 +
36604 + if (rphy) {
36605 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36606 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36607 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36608 + ioc->name, rphy, rphy->dev.release));
36609 + }
36610 +}
36611 +
36612 /* no mutex */
36613 static void
36614 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36615 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36616 return NULL;
36617 }
36618
36619 -static inline void
36620 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36621 -{
36622 - if (phy_info->port_details) {
36623 - phy_info->port_details->rphy = rphy;
36624 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36625 - ioc->name, rphy));
36626 - }
36627 -
36628 - if (rphy) {
36629 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36630 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36631 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36632 - ioc->name, rphy, rphy->dev.release));
36633 - }
36634 -}
36635 -
36636 static inline struct sas_port *
36637 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36638 {
36639 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36640 index 164afa7..b6b2e74 100644
36641 --- a/drivers/message/fusion/mptscsih.c
36642 +++ b/drivers/message/fusion/mptscsih.c
36643 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36644
36645 h = shost_priv(SChost);
36646
36647 - if (h) {
36648 - if (h->info_kbuf == NULL)
36649 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36650 - return h->info_kbuf;
36651 - h->info_kbuf[0] = '\0';
36652 + if (!h)
36653 + return NULL;
36654
36655 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36656 - h->info_kbuf[size-1] = '\0';
36657 - }
36658 + if (h->info_kbuf == NULL)
36659 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36660 + return h->info_kbuf;
36661 + h->info_kbuf[0] = '\0';
36662 +
36663 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36664 + h->info_kbuf[size-1] = '\0';
36665
36666 return h->info_kbuf;
36667 }
36668 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36669 index 8001aa6..b137580 100644
36670 --- a/drivers/message/i2o/i2o_proc.c
36671 +++ b/drivers/message/i2o/i2o_proc.c
36672 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36673 "Array Controller Device"
36674 };
36675
36676 -static char *chtostr(char *tmp, u8 *chars, int n)
36677 -{
36678 - tmp[0] = 0;
36679 - return strncat(tmp, (char *)chars, n);
36680 -}
36681 -
36682 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36683 char *group)
36684 {
36685 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36686 } *result;
36687
36688 i2o_exec_execute_ddm_table ddm_table;
36689 - char tmp[28 + 1];
36690
36691 result = kmalloc(sizeof(*result), GFP_KERNEL);
36692 if (!result)
36693 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36694
36695 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36696 seq_printf(seq, "%-#8x", ddm_table.module_id);
36697 - seq_printf(seq, "%-29s",
36698 - chtostr(tmp, ddm_table.module_name_version, 28));
36699 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36700 seq_printf(seq, "%9d ", ddm_table.data_size);
36701 seq_printf(seq, "%8d", ddm_table.code_size);
36702
36703 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36704
36705 i2o_driver_result_table *result;
36706 i2o_driver_store_table *dst;
36707 - char tmp[28 + 1];
36708
36709 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36710 if (result == NULL)
36711 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36712
36713 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36714 seq_printf(seq, "%-#8x", dst->module_id);
36715 - seq_printf(seq, "%-29s",
36716 - chtostr(tmp, dst->module_name_version, 28));
36717 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36718 + seq_printf(seq, "%-.28s", dst->module_name_version);
36719 + seq_printf(seq, "%-.8s", dst->date);
36720 seq_printf(seq, "%8d ", dst->module_size);
36721 seq_printf(seq, "%8d ", dst->mpb_size);
36722 seq_printf(seq, "0x%04x", dst->module_flags);
36723 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36724 // == (allow) 512d bytes (max)
36725 static u16 *work16 = (u16 *) work32;
36726 int token;
36727 - char tmp[16 + 1];
36728
36729 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36730
36731 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36732 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36733 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36734 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36735 - seq_printf(seq, "Vendor info : %s\n",
36736 - chtostr(tmp, (u8 *) (work32 + 2), 16));
36737 - seq_printf(seq, "Product info : %s\n",
36738 - chtostr(tmp, (u8 *) (work32 + 6), 16));
36739 - seq_printf(seq, "Description : %s\n",
36740 - chtostr(tmp, (u8 *) (work32 + 10), 16));
36741 - seq_printf(seq, "Product rev. : %s\n",
36742 - chtostr(tmp, (u8 *) (work32 + 14), 8));
36743 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36744 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36745 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36746 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36747
36748 seq_printf(seq, "Serial number : ");
36749 print_serial_number(seq, (u8 *) (work32 + 16),
36750 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36751 u8 pad[256]; // allow up to 256 byte (max) serial number
36752 } result;
36753
36754 - char tmp[24 + 1];
36755 -
36756 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36757
36758 if (token < 0) {
36759 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36760 }
36761
36762 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36763 - seq_printf(seq, "Module name : %s\n",
36764 - chtostr(tmp, result.module_name, 24));
36765 - seq_printf(seq, "Module revision : %s\n",
36766 - chtostr(tmp, result.module_rev, 8));
36767 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
36768 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36769
36770 seq_printf(seq, "Serial number : ");
36771 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36772 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36773 u8 instance_number[4];
36774 } result;
36775
36776 - char tmp[64 + 1];
36777 -
36778 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36779
36780 if (token < 0) {
36781 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36782 return 0;
36783 }
36784
36785 - seq_printf(seq, "Device name : %s\n",
36786 - chtostr(tmp, result.device_name, 64));
36787 - seq_printf(seq, "Service name : %s\n",
36788 - chtostr(tmp, result.service_name, 64));
36789 - seq_printf(seq, "Physical name : %s\n",
36790 - chtostr(tmp, result.physical_location, 64));
36791 - seq_printf(seq, "Instance number : %s\n",
36792 - chtostr(tmp, result.instance_number, 4));
36793 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
36794 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
36795 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36796 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36797
36798 return 0;
36799 }
36800 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36801 index a8c08f3..155fe3d 100644
36802 --- a/drivers/message/i2o/iop.c
36803 +++ b/drivers/message/i2o/iop.c
36804 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36805
36806 spin_lock_irqsave(&c->context_list_lock, flags);
36807
36808 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36809 - atomic_inc(&c->context_list_counter);
36810 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36811 + atomic_inc_unchecked(&c->context_list_counter);
36812
36813 - entry->context = atomic_read(&c->context_list_counter);
36814 + entry->context = atomic_read_unchecked(&c->context_list_counter);
36815
36816 list_add(&entry->list, &c->context_list);
36817
36818 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36819
36820 #if BITS_PER_LONG == 64
36821 spin_lock_init(&c->context_list_lock);
36822 - atomic_set(&c->context_list_counter, 0);
36823 + atomic_set_unchecked(&c->context_list_counter, 0);
36824 INIT_LIST_HEAD(&c->context_list);
36825 #endif
36826
36827 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36828 index 45ece11..8efa218 100644
36829 --- a/drivers/mfd/janz-cmodio.c
36830 +++ b/drivers/mfd/janz-cmodio.c
36831 @@ -13,6 +13,7 @@
36832
36833 #include <linux/kernel.h>
36834 #include <linux/module.h>
36835 +#include <linux/slab.h>
36836 #include <linux/init.h>
36837 #include <linux/pci.h>
36838 #include <linux/interrupt.h>
36839 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36840 index 3aa9a96..59cf685 100644
36841 --- a/drivers/misc/kgdbts.c
36842 +++ b/drivers/misc/kgdbts.c
36843 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36844 char before[BREAK_INSTR_SIZE];
36845 char after[BREAK_INSTR_SIZE];
36846
36847 - probe_kernel_read(before, (char *)kgdbts_break_test,
36848 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36849 BREAK_INSTR_SIZE);
36850 init_simple_test();
36851 ts.tst = plant_and_detach_test;
36852 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36853 /* Activate test with initial breakpoint */
36854 if (!is_early)
36855 kgdb_breakpoint();
36856 - probe_kernel_read(after, (char *)kgdbts_break_test,
36857 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36858 BREAK_INSTR_SIZE);
36859 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36860 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36861 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36862 index 4a87e5c..76bdf5c 100644
36863 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
36864 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36865 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36866 * the lid is closed. This leads to interrupts as soon as a little move
36867 * is done.
36868 */
36869 - atomic_inc(&lis3->count);
36870 + atomic_inc_unchecked(&lis3->count);
36871
36872 wake_up_interruptible(&lis3->misc_wait);
36873 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36874 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36875 if (lis3->pm_dev)
36876 pm_runtime_get_sync(lis3->pm_dev);
36877
36878 - atomic_set(&lis3->count, 0);
36879 + atomic_set_unchecked(&lis3->count, 0);
36880 return 0;
36881 }
36882
36883 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36884 add_wait_queue(&lis3->misc_wait, &wait);
36885 while (true) {
36886 set_current_state(TASK_INTERRUPTIBLE);
36887 - data = atomic_xchg(&lis3->count, 0);
36888 + data = atomic_xchg_unchecked(&lis3->count, 0);
36889 if (data)
36890 break;
36891
36892 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36893 struct lis3lv02d, miscdev);
36894
36895 poll_wait(file, &lis3->misc_wait, wait);
36896 - if (atomic_read(&lis3->count))
36897 + if (atomic_read_unchecked(&lis3->count))
36898 return POLLIN | POLLRDNORM;
36899 return 0;
36900 }
36901 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36902 index c439c82..1f20f57 100644
36903 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
36904 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36905 @@ -297,7 +297,7 @@ struct lis3lv02d {
36906 struct input_polled_dev *idev; /* input device */
36907 struct platform_device *pdev; /* platform device */
36908 struct regulator_bulk_data regulators[2];
36909 - atomic_t count; /* interrupt count after last read */
36910 + atomic_unchecked_t count; /* interrupt count after last read */
36911 union axis_conversion ac; /* hw -> logical axis */
36912 int mapped_btns[3];
36913
36914 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36915 index 2f30bad..c4c13d0 100644
36916 --- a/drivers/misc/sgi-gru/gruhandles.c
36917 +++ b/drivers/misc/sgi-gru/gruhandles.c
36918 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36919 unsigned long nsec;
36920
36921 nsec = CLKS2NSEC(clks);
36922 - atomic_long_inc(&mcs_op_statistics[op].count);
36923 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
36924 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36925 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36926 if (mcs_op_statistics[op].max < nsec)
36927 mcs_op_statistics[op].max = nsec;
36928 }
36929 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36930 index 950dbe9..eeef0f8 100644
36931 --- a/drivers/misc/sgi-gru/gruprocfs.c
36932 +++ b/drivers/misc/sgi-gru/gruprocfs.c
36933 @@ -32,9 +32,9 @@
36934
36935 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36936
36937 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36938 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36939 {
36940 - unsigned long val = atomic_long_read(v);
36941 + unsigned long val = atomic_long_read_unchecked(v);
36942
36943 seq_printf(s, "%16lu %s\n", val, id);
36944 }
36945 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36946
36947 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36948 for (op = 0; op < mcsop_last; op++) {
36949 - count = atomic_long_read(&mcs_op_statistics[op].count);
36950 - total = atomic_long_read(&mcs_op_statistics[op].total);
36951 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36952 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36953 max = mcs_op_statistics[op].max;
36954 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36955 count ? total / count : 0, max);
36956 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36957 index 5c3ce24..4915ccb 100644
36958 --- a/drivers/misc/sgi-gru/grutables.h
36959 +++ b/drivers/misc/sgi-gru/grutables.h
36960 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36961 * GRU statistics.
36962 */
36963 struct gru_stats_s {
36964 - atomic_long_t vdata_alloc;
36965 - atomic_long_t vdata_free;
36966 - atomic_long_t gts_alloc;
36967 - atomic_long_t gts_free;
36968 - atomic_long_t gms_alloc;
36969 - atomic_long_t gms_free;
36970 - atomic_long_t gts_double_allocate;
36971 - atomic_long_t assign_context;
36972 - atomic_long_t assign_context_failed;
36973 - atomic_long_t free_context;
36974 - atomic_long_t load_user_context;
36975 - atomic_long_t load_kernel_context;
36976 - atomic_long_t lock_kernel_context;
36977 - atomic_long_t unlock_kernel_context;
36978 - atomic_long_t steal_user_context;
36979 - atomic_long_t steal_kernel_context;
36980 - atomic_long_t steal_context_failed;
36981 - atomic_long_t nopfn;
36982 - atomic_long_t asid_new;
36983 - atomic_long_t asid_next;
36984 - atomic_long_t asid_wrap;
36985 - atomic_long_t asid_reuse;
36986 - atomic_long_t intr;
36987 - atomic_long_t intr_cbr;
36988 - atomic_long_t intr_tfh;
36989 - atomic_long_t intr_spurious;
36990 - atomic_long_t intr_mm_lock_failed;
36991 - atomic_long_t call_os;
36992 - atomic_long_t call_os_wait_queue;
36993 - atomic_long_t user_flush_tlb;
36994 - atomic_long_t user_unload_context;
36995 - atomic_long_t user_exception;
36996 - atomic_long_t set_context_option;
36997 - atomic_long_t check_context_retarget_intr;
36998 - atomic_long_t check_context_unload;
36999 - atomic_long_t tlb_dropin;
37000 - atomic_long_t tlb_preload_page;
37001 - atomic_long_t tlb_dropin_fail_no_asid;
37002 - atomic_long_t tlb_dropin_fail_upm;
37003 - atomic_long_t tlb_dropin_fail_invalid;
37004 - atomic_long_t tlb_dropin_fail_range_active;
37005 - atomic_long_t tlb_dropin_fail_idle;
37006 - atomic_long_t tlb_dropin_fail_fmm;
37007 - atomic_long_t tlb_dropin_fail_no_exception;
37008 - atomic_long_t tfh_stale_on_fault;
37009 - atomic_long_t mmu_invalidate_range;
37010 - atomic_long_t mmu_invalidate_page;
37011 - atomic_long_t flush_tlb;
37012 - atomic_long_t flush_tlb_gru;
37013 - atomic_long_t flush_tlb_gru_tgh;
37014 - atomic_long_t flush_tlb_gru_zero_asid;
37015 + atomic_long_unchecked_t vdata_alloc;
37016 + atomic_long_unchecked_t vdata_free;
37017 + atomic_long_unchecked_t gts_alloc;
37018 + atomic_long_unchecked_t gts_free;
37019 + atomic_long_unchecked_t gms_alloc;
37020 + atomic_long_unchecked_t gms_free;
37021 + atomic_long_unchecked_t gts_double_allocate;
37022 + atomic_long_unchecked_t assign_context;
37023 + atomic_long_unchecked_t assign_context_failed;
37024 + atomic_long_unchecked_t free_context;
37025 + atomic_long_unchecked_t load_user_context;
37026 + atomic_long_unchecked_t load_kernel_context;
37027 + atomic_long_unchecked_t lock_kernel_context;
37028 + atomic_long_unchecked_t unlock_kernel_context;
37029 + atomic_long_unchecked_t steal_user_context;
37030 + atomic_long_unchecked_t steal_kernel_context;
37031 + atomic_long_unchecked_t steal_context_failed;
37032 + atomic_long_unchecked_t nopfn;
37033 + atomic_long_unchecked_t asid_new;
37034 + atomic_long_unchecked_t asid_next;
37035 + atomic_long_unchecked_t asid_wrap;
37036 + atomic_long_unchecked_t asid_reuse;
37037 + atomic_long_unchecked_t intr;
37038 + atomic_long_unchecked_t intr_cbr;
37039 + atomic_long_unchecked_t intr_tfh;
37040 + atomic_long_unchecked_t intr_spurious;
37041 + atomic_long_unchecked_t intr_mm_lock_failed;
37042 + atomic_long_unchecked_t call_os;
37043 + atomic_long_unchecked_t call_os_wait_queue;
37044 + atomic_long_unchecked_t user_flush_tlb;
37045 + atomic_long_unchecked_t user_unload_context;
37046 + atomic_long_unchecked_t user_exception;
37047 + atomic_long_unchecked_t set_context_option;
37048 + atomic_long_unchecked_t check_context_retarget_intr;
37049 + atomic_long_unchecked_t check_context_unload;
37050 + atomic_long_unchecked_t tlb_dropin;
37051 + atomic_long_unchecked_t tlb_preload_page;
37052 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37053 + atomic_long_unchecked_t tlb_dropin_fail_upm;
37054 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
37055 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
37056 + atomic_long_unchecked_t tlb_dropin_fail_idle;
37057 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
37058 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37059 + atomic_long_unchecked_t tfh_stale_on_fault;
37060 + atomic_long_unchecked_t mmu_invalidate_range;
37061 + atomic_long_unchecked_t mmu_invalidate_page;
37062 + atomic_long_unchecked_t flush_tlb;
37063 + atomic_long_unchecked_t flush_tlb_gru;
37064 + atomic_long_unchecked_t flush_tlb_gru_tgh;
37065 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37066
37067 - atomic_long_t copy_gpa;
37068 - atomic_long_t read_gpa;
37069 + atomic_long_unchecked_t copy_gpa;
37070 + atomic_long_unchecked_t read_gpa;
37071
37072 - atomic_long_t mesq_receive;
37073 - atomic_long_t mesq_receive_none;
37074 - atomic_long_t mesq_send;
37075 - atomic_long_t mesq_send_failed;
37076 - atomic_long_t mesq_noop;
37077 - atomic_long_t mesq_send_unexpected_error;
37078 - atomic_long_t mesq_send_lb_overflow;
37079 - atomic_long_t mesq_send_qlimit_reached;
37080 - atomic_long_t mesq_send_amo_nacked;
37081 - atomic_long_t mesq_send_put_nacked;
37082 - atomic_long_t mesq_page_overflow;
37083 - atomic_long_t mesq_qf_locked;
37084 - atomic_long_t mesq_qf_noop_not_full;
37085 - atomic_long_t mesq_qf_switch_head_failed;
37086 - atomic_long_t mesq_qf_unexpected_error;
37087 - atomic_long_t mesq_noop_unexpected_error;
37088 - atomic_long_t mesq_noop_lb_overflow;
37089 - atomic_long_t mesq_noop_qlimit_reached;
37090 - atomic_long_t mesq_noop_amo_nacked;
37091 - atomic_long_t mesq_noop_put_nacked;
37092 - atomic_long_t mesq_noop_page_overflow;
37093 + atomic_long_unchecked_t mesq_receive;
37094 + atomic_long_unchecked_t mesq_receive_none;
37095 + atomic_long_unchecked_t mesq_send;
37096 + atomic_long_unchecked_t mesq_send_failed;
37097 + atomic_long_unchecked_t mesq_noop;
37098 + atomic_long_unchecked_t mesq_send_unexpected_error;
37099 + atomic_long_unchecked_t mesq_send_lb_overflow;
37100 + atomic_long_unchecked_t mesq_send_qlimit_reached;
37101 + atomic_long_unchecked_t mesq_send_amo_nacked;
37102 + atomic_long_unchecked_t mesq_send_put_nacked;
37103 + atomic_long_unchecked_t mesq_page_overflow;
37104 + atomic_long_unchecked_t mesq_qf_locked;
37105 + atomic_long_unchecked_t mesq_qf_noop_not_full;
37106 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
37107 + atomic_long_unchecked_t mesq_qf_unexpected_error;
37108 + atomic_long_unchecked_t mesq_noop_unexpected_error;
37109 + atomic_long_unchecked_t mesq_noop_lb_overflow;
37110 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
37111 + atomic_long_unchecked_t mesq_noop_amo_nacked;
37112 + atomic_long_unchecked_t mesq_noop_put_nacked;
37113 + atomic_long_unchecked_t mesq_noop_page_overflow;
37114
37115 };
37116
37117 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37118 tghop_invalidate, mcsop_last};
37119
37120 struct mcs_op_statistic {
37121 - atomic_long_t count;
37122 - atomic_long_t total;
37123 + atomic_long_unchecked_t count;
37124 + atomic_long_unchecked_t total;
37125 unsigned long max;
37126 };
37127
37128 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37129
37130 #define STAT(id) do { \
37131 if (gru_options & OPT_STATS) \
37132 - atomic_long_inc(&gru_stats.id); \
37133 + atomic_long_inc_unchecked(&gru_stats.id); \
37134 } while (0)
37135
37136 #ifdef CONFIG_SGI_GRU_DEBUG
37137 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37138 index c862cd4..0d176fe 100644
37139 --- a/drivers/misc/sgi-xp/xp.h
37140 +++ b/drivers/misc/sgi-xp/xp.h
37141 @@ -288,7 +288,7 @@ struct xpc_interface {
37142 xpc_notify_func, void *);
37143 void (*received) (short, int, void *);
37144 enum xp_retval (*partid_to_nasids) (short, void *);
37145 -};
37146 +} __no_const;
37147
37148 extern struct xpc_interface xpc_interface;
37149
37150 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37151 index b94d5f7..7f494c5 100644
37152 --- a/drivers/misc/sgi-xp/xpc.h
37153 +++ b/drivers/misc/sgi-xp/xpc.h
37154 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
37155 void (*received_payload) (struct xpc_channel *, void *);
37156 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37157 };
37158 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37159
37160 /* struct xpc_partition act_state values (for XPC HB) */
37161
37162 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37163 /* found in xpc_main.c */
37164 extern struct device *xpc_part;
37165 extern struct device *xpc_chan;
37166 -extern struct xpc_arch_operations xpc_arch_ops;
37167 +extern xpc_arch_operations_no_const xpc_arch_ops;
37168 extern int xpc_disengage_timelimit;
37169 extern int xpc_disengage_timedout;
37170 extern int xpc_activate_IRQ_rcvd;
37171 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37172 index d971817..33bdca5 100644
37173 --- a/drivers/misc/sgi-xp/xpc_main.c
37174 +++ b/drivers/misc/sgi-xp/xpc_main.c
37175 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
37176 .notifier_call = xpc_system_die,
37177 };
37178
37179 -struct xpc_arch_operations xpc_arch_ops;
37180 +xpc_arch_operations_no_const xpc_arch_ops;
37181
37182 /*
37183 * Timer function to enforce the timelimit on the partition disengage.
37184 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
37185
37186 if (((die_args->trapnr == X86_TRAP_MF) ||
37187 (die_args->trapnr == X86_TRAP_XF)) &&
37188 - !user_mode_vm(die_args->regs))
37189 + !user_mode(die_args->regs))
37190 xpc_die_deactivate();
37191
37192 break;
37193 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
37194 index 6d8f701..35b6369 100644
37195 --- a/drivers/mmc/core/mmc_ops.c
37196 +++ b/drivers/mmc/core/mmc_ops.c
37197 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
37198 void *data_buf;
37199 int is_on_stack;
37200
37201 - is_on_stack = object_is_on_stack(buf);
37202 + is_on_stack = object_starts_on_stack(buf);
37203 if (is_on_stack) {
37204 /*
37205 * dma onto stack is unsafe/nonportable, but callers to this
37206 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
37207 index 53b8fd9..615b462 100644
37208 --- a/drivers/mmc/host/dw_mmc.h
37209 +++ b/drivers/mmc/host/dw_mmc.h
37210 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
37211 int (*parse_dt)(struct dw_mci *host);
37212 int (*setup_bus)(struct dw_mci *host,
37213 struct device_node *slot_np, u8 bus_width);
37214 -};
37215 +} __do_const;
37216 #endif /* _DW_MMC_H_ */
37217 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
37218 index 82a8de1..3c56ccb 100644
37219 --- a/drivers/mmc/host/sdhci-s3c.c
37220 +++ b/drivers/mmc/host/sdhci-s3c.c
37221 @@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
37222 * we can use overriding functions instead of default.
37223 */
37224 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
37225 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37226 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37227 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37228 + pax_open_kernel();
37229 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37230 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37231 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37232 + pax_close_kernel();
37233 }
37234
37235 /* It supports additional host capabilities if needed */
37236 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37237 index a4eb8b5..8c0628f 100644
37238 --- a/drivers/mtd/devices/doc2000.c
37239 +++ b/drivers/mtd/devices/doc2000.c
37240 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37241
37242 /* The ECC will not be calculated correctly if less than 512 is written */
37243 /* DBB-
37244 - if (len != 0x200 && eccbuf)
37245 + if (len != 0x200)
37246 printk(KERN_WARNING
37247 "ECC needs a full sector write (adr: %lx size %lx)\n",
37248 (long) to, (long) len);
37249 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
37250 index 0c8bb6b..6f35deb 100644
37251 --- a/drivers/mtd/nand/denali.c
37252 +++ b/drivers/mtd/nand/denali.c
37253 @@ -24,6 +24,7 @@
37254 #include <linux/slab.h>
37255 #include <linux/mtd/mtd.h>
37256 #include <linux/module.h>
37257 +#include <linux/slab.h>
37258
37259 #include "denali.h"
37260
37261 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37262 index 51b9d6a..52af9a7 100644
37263 --- a/drivers/mtd/nftlmount.c
37264 +++ b/drivers/mtd/nftlmount.c
37265 @@ -24,6 +24,7 @@
37266 #include <asm/errno.h>
37267 #include <linux/delay.h>
37268 #include <linux/slab.h>
37269 +#include <linux/sched.h>
37270 #include <linux/mtd/mtd.h>
37271 #include <linux/mtd/nand.h>
37272 #include <linux/mtd/nftl.h>
37273 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
37274 index 70dba5d..11a0919 100644
37275 --- a/drivers/net/ethernet/8390/ax88796.c
37276 +++ b/drivers/net/ethernet/8390/ax88796.c
37277 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
37278 if (ax->plat->reg_offsets)
37279 ei_local->reg_offset = ax->plat->reg_offsets;
37280 else {
37281 + resource_size_t _mem_size = mem_size;
37282 + do_div(_mem_size, 0x18);
37283 ei_local->reg_offset = ax->reg_offsets;
37284 for (ret = 0; ret < 0x18; ret++)
37285 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
37286 + ax->reg_offsets[ret] = _mem_size * ret;
37287 }
37288
37289 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
37290 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37291 index 0991534..8098e92 100644
37292 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37293 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37294 @@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
37295 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
37296 {
37297 /* RX_MODE controlling object */
37298 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
37299 + bnx2x_init_rx_mode_obj(bp);
37300
37301 /* multicast configuration controlling object */
37302 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
37303 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37304 index 09b625e..15b16fe 100644
37305 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37306 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37307 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
37308 return rc;
37309 }
37310
37311 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37312 - struct bnx2x_rx_mode_obj *o)
37313 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
37314 {
37315 if (CHIP_IS_E1x(bp)) {
37316 - o->wait_comp = bnx2x_empty_rx_mode_wait;
37317 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
37318 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
37319 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
37320 } else {
37321 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
37322 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
37323 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
37324 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
37325 }
37326 }
37327
37328 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37329 index adbd91b..58ec94a 100644
37330 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37331 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37332 @@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
37333
37334 /********************* RX MODE ****************/
37335
37336 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37337 - struct bnx2x_rx_mode_obj *o);
37338 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
37339
37340 /**
37341 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
37342 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
37343 index d330e81..ce1fb9a 100644
37344 --- a/drivers/net/ethernet/broadcom/tg3.h
37345 +++ b/drivers/net/ethernet/broadcom/tg3.h
37346 @@ -146,6 +146,7 @@
37347 #define CHIPREV_ID_5750_A0 0x4000
37348 #define CHIPREV_ID_5750_A1 0x4001
37349 #define CHIPREV_ID_5750_A3 0x4003
37350 +#define CHIPREV_ID_5750_C1 0x4201
37351 #define CHIPREV_ID_5750_C2 0x4202
37352 #define CHIPREV_ID_5752_A0_HW 0x5000
37353 #define CHIPREV_ID_5752_A0 0x6000
37354 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37355 index 8cffcdf..aadf043 100644
37356 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37357 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37358 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37359 */
37360 struct l2t_skb_cb {
37361 arp_failure_handler_func arp_failure_handler;
37362 -};
37363 +} __no_const;
37364
37365 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37366
37367 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
37368 index 4c83003..2a2a5b9 100644
37369 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
37370 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
37371 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37372 for (i=0; i<ETH_ALEN; i++) {
37373 tmp.addr[i] = dev->dev_addr[i];
37374 }
37375 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37376 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37377 break;
37378
37379 case DE4X5_SET_HWADDR: /* Set the hardware address */
37380 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37381 spin_lock_irqsave(&lp->lock, flags);
37382 memcpy(&statbuf, &lp->pktStats, ioc->len);
37383 spin_unlock_irqrestore(&lp->lock, flags);
37384 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
37385 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
37386 return -EFAULT;
37387 break;
37388 }
37389 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
37390 index 4d6f3c5..6169e60 100644
37391 --- a/drivers/net/ethernet/emulex/benet/be_main.c
37392 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
37393 @@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
37394
37395 if (wrapped)
37396 newacc += 65536;
37397 - ACCESS_ONCE(*acc) = newacc;
37398 + ACCESS_ONCE_RW(*acc) = newacc;
37399 }
37400
37401 void be_parse_stats(struct be_adapter *adapter)
37402 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
37403 index 74d749e..eefb1bd 100644
37404 --- a/drivers/net/ethernet/faraday/ftgmac100.c
37405 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
37406 @@ -31,6 +31,8 @@
37407 #include <linux/netdevice.h>
37408 #include <linux/phy.h>
37409 #include <linux/platform_device.h>
37410 +#include <linux/interrupt.h>
37411 +#include <linux/irqreturn.h>
37412 #include <net/ip.h>
37413
37414 #include "ftgmac100.h"
37415 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
37416 index b901a01..1ff32ee 100644
37417 --- a/drivers/net/ethernet/faraday/ftmac100.c
37418 +++ b/drivers/net/ethernet/faraday/ftmac100.c
37419 @@ -31,6 +31,8 @@
37420 #include <linux/module.h>
37421 #include <linux/netdevice.h>
37422 #include <linux/platform_device.h>
37423 +#include <linux/interrupt.h>
37424 +#include <linux/irqreturn.h>
37425
37426 #include "ftmac100.h"
37427
37428 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37429 index bb9256a..56d8752 100644
37430 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37431 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37432 @@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
37433 }
37434
37435 /* update the base incval used to calculate frequency adjustment */
37436 - ACCESS_ONCE(adapter->base_incval) = incval;
37437 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
37438 smp_mb();
37439
37440 /* need lock to prevent incorrect read while modifying cyclecounter */
37441 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37442 index fbe5363..266b4e3 100644
37443 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
37444 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37445 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37446 struct __vxge_hw_fifo *fifo;
37447 struct vxge_hw_fifo_config *config;
37448 u32 txdl_size, txdl_per_memblock;
37449 - struct vxge_hw_mempool_cbs fifo_mp_callback;
37450 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
37451 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
37452 + };
37453 +
37454 struct __vxge_hw_virtualpath *vpath;
37455
37456 if ((vp == NULL) || (attr == NULL)) {
37457 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37458 goto exit;
37459 }
37460
37461 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
37462 -
37463 fifo->mempool =
37464 __vxge_hw_mempool_create(vpath->hldev,
37465 fifo->config->memblock_size,
37466 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
37467 index 998974f..ecd26db 100644
37468 --- a/drivers/net/ethernet/realtek/r8169.c
37469 +++ b/drivers/net/ethernet/realtek/r8169.c
37470 @@ -741,22 +741,22 @@ struct rtl8169_private {
37471 struct mdio_ops {
37472 void (*write)(struct rtl8169_private *, int, int);
37473 int (*read)(struct rtl8169_private *, int);
37474 - } mdio_ops;
37475 + } __no_const mdio_ops;
37476
37477 struct pll_power_ops {
37478 void (*down)(struct rtl8169_private *);
37479 void (*up)(struct rtl8169_private *);
37480 - } pll_power_ops;
37481 + } __no_const pll_power_ops;
37482
37483 struct jumbo_ops {
37484 void (*enable)(struct rtl8169_private *);
37485 void (*disable)(struct rtl8169_private *);
37486 - } jumbo_ops;
37487 + } __no_const jumbo_ops;
37488
37489 struct csi_ops {
37490 void (*write)(struct rtl8169_private *, int, int);
37491 u32 (*read)(struct rtl8169_private *, int);
37492 - } csi_ops;
37493 + } __no_const csi_ops;
37494
37495 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
37496 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
37497 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
37498 index 0767043f..08c2553 100644
37499 --- a/drivers/net/ethernet/sfc/ptp.c
37500 +++ b/drivers/net/ethernet/sfc/ptp.c
37501 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
37502 (u32)((u64)ptp->start.dma_addr >> 32));
37503
37504 /* Clear flag that signals MC ready */
37505 - ACCESS_ONCE(*start) = 0;
37506 + ACCESS_ONCE_RW(*start) = 0;
37507 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
37508 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
37509
37510 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37511 index 0c74a70..3bc6f68 100644
37512 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37513 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37514 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
37515
37516 writel(value, ioaddr + MMC_CNTRL);
37517
37518 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37519 - MMC_CNTRL, value);
37520 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37521 +// MMC_CNTRL, value);
37522 }
37523
37524 /* To mask all all interrupts.*/
37525 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
37526 index e6fe0d8..2b7d752 100644
37527 --- a/drivers/net/hyperv/hyperv_net.h
37528 +++ b/drivers/net/hyperv/hyperv_net.h
37529 @@ -101,7 +101,7 @@ struct rndis_device {
37530
37531 enum rndis_device_state state;
37532 bool link_state;
37533 - atomic_t new_req_id;
37534 + atomic_unchecked_t new_req_id;
37535
37536 spinlock_t request_lock;
37537 struct list_head req_list;
37538 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
37539 index 2b657d4..9903bc0 100644
37540 --- a/drivers/net/hyperv/rndis_filter.c
37541 +++ b/drivers/net/hyperv/rndis_filter.c
37542 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
37543 * template
37544 */
37545 set = &rndis_msg->msg.set_req;
37546 - set->req_id = atomic_inc_return(&dev->new_req_id);
37547 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37548
37549 /* Add to the request list */
37550 spin_lock_irqsave(&dev->request_lock, flags);
37551 @@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
37552
37553 /* Setup the rndis set */
37554 halt = &request->request_msg.msg.halt_req;
37555 - halt->req_id = atomic_inc_return(&dev->new_req_id);
37556 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37557
37558 /* Ignore return since this msg is optional. */
37559 rndis_filter_send_request(dev, request);
37560 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
37561 index 1e9cb0b..7839125 100644
37562 --- a/drivers/net/ieee802154/fakehard.c
37563 +++ b/drivers/net/ieee802154/fakehard.c
37564 @@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
37565 phy->transmit_power = 0xbf;
37566
37567 dev->netdev_ops = &fake_ops;
37568 - dev->ml_priv = &fake_mlme;
37569 + dev->ml_priv = (void *)&fake_mlme;
37570
37571 priv = netdev_priv(dev);
37572 priv->phy = phy;
37573 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
37574 index d3fb97d..e229d3e 100644
37575 --- a/drivers/net/macvlan.c
37576 +++ b/drivers/net/macvlan.c
37577 @@ -913,7 +913,7 @@ static int macvlan_device_event(struct notifier_block *unused,
37578 return NOTIFY_DONE;
37579 }
37580
37581 -static struct notifier_block macvlan_notifier_block __read_mostly = {
37582 +static struct notifier_block macvlan_notifier_block = {
37583 .notifier_call = macvlan_device_event,
37584 };
37585
37586 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
37587 index 0f0f9ce..0ca5819 100644
37588 --- a/drivers/net/macvtap.c
37589 +++ b/drivers/net/macvtap.c
37590 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
37591 return NOTIFY_DONE;
37592 }
37593
37594 -static struct notifier_block macvtap_notifier_block __read_mostly = {
37595 +static struct notifier_block macvtap_notifier_block = {
37596 .notifier_call = macvtap_device_event,
37597 };
37598
37599 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
37600 index daec9b0..6428fcb 100644
37601 --- a/drivers/net/phy/mdio-bitbang.c
37602 +++ b/drivers/net/phy/mdio-bitbang.c
37603 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
37604 struct mdiobb_ctrl *ctrl = bus->priv;
37605
37606 module_put(ctrl->ops->owner);
37607 + mdiobus_unregister(bus);
37608 mdiobus_free(bus);
37609 }
37610 EXPORT_SYMBOL(free_mdio_bitbang);
37611 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
37612 index 0b2706a..ba1430d 100644
37613 --- a/drivers/net/ppp/ppp_generic.c
37614 +++ b/drivers/net/ppp/ppp_generic.c
37615 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37616 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
37617 struct ppp_stats stats;
37618 struct ppp_comp_stats cstats;
37619 - char *vers;
37620
37621 switch (cmd) {
37622 case SIOCGPPPSTATS:
37623 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37624 break;
37625
37626 case SIOCGPPPVER:
37627 - vers = PPP_VERSION;
37628 - if (copy_to_user(addr, vers, strlen(vers) + 1))
37629 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
37630 break;
37631 err = 0;
37632 break;
37633 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
37634 index ad86660..9fd0884 100644
37635 --- a/drivers/net/team/team.c
37636 +++ b/drivers/net/team/team.c
37637 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
37638 return NOTIFY_DONE;
37639 }
37640
37641 -static struct notifier_block team_notifier_block __read_mostly = {
37642 +static struct notifier_block team_notifier_block = {
37643 .notifier_call = team_device_event,
37644 };
37645
37646 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
37647 index 2917a86..edd463f 100644
37648 --- a/drivers/net/tun.c
37649 +++ b/drivers/net/tun.c
37650 @@ -1836,7 +1836,7 @@ unlock:
37651 }
37652
37653 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37654 - unsigned long arg, int ifreq_len)
37655 + unsigned long arg, size_t ifreq_len)
37656 {
37657 struct tun_file *tfile = file->private_data;
37658 struct tun_struct *tun;
37659 @@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37660 int vnet_hdr_sz;
37661 int ret;
37662
37663 + if (ifreq_len > sizeof ifr)
37664 + return -EFAULT;
37665 +
37666 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
37667 if (copy_from_user(&ifr, argp, ifreq_len))
37668 return -EFAULT;
37669 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
37670 index cd8ccb2..cff5144 100644
37671 --- a/drivers/net/usb/hso.c
37672 +++ b/drivers/net/usb/hso.c
37673 @@ -71,7 +71,7 @@
37674 #include <asm/byteorder.h>
37675 #include <linux/serial_core.h>
37676 #include <linux/serial.h>
37677 -
37678 +#include <asm/local.h>
37679
37680 #define MOD_AUTHOR "Option Wireless"
37681 #define MOD_DESCRIPTION "USB High Speed Option driver"
37682 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
37683 struct urb *urb;
37684
37685 urb = serial->rx_urb[0];
37686 - if (serial->port.count > 0) {
37687 + if (atomic_read(&serial->port.count) > 0) {
37688 count = put_rxbuf_data(urb, serial);
37689 if (count == -1)
37690 return;
37691 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37692 DUMP1(urb->transfer_buffer, urb->actual_length);
37693
37694 /* Anyone listening? */
37695 - if (serial->port.count == 0)
37696 + if (atomic_read(&serial->port.count) == 0)
37697 return;
37698
37699 if (status == 0) {
37700 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37701 tty_port_tty_set(&serial->port, tty);
37702
37703 /* check for port already opened, if not set the termios */
37704 - serial->port.count++;
37705 - if (serial->port.count == 1) {
37706 + if (atomic_inc_return(&serial->port.count) == 1) {
37707 serial->rx_state = RX_IDLE;
37708 /* Force default termio settings */
37709 _hso_serial_set_termios(tty, NULL);
37710 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37711 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37712 if (result) {
37713 hso_stop_serial_device(serial->parent);
37714 - serial->port.count--;
37715 + atomic_dec(&serial->port.count);
37716 kref_put(&serial->parent->ref, hso_serial_ref_free);
37717 }
37718 } else {
37719 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37720
37721 /* reset the rts and dtr */
37722 /* do the actual close */
37723 - serial->port.count--;
37724 + atomic_dec(&serial->port.count);
37725
37726 - if (serial->port.count <= 0) {
37727 - serial->port.count = 0;
37728 + if (atomic_read(&serial->port.count) <= 0) {
37729 + atomic_set(&serial->port.count, 0);
37730 tty_port_tty_set(&serial->port, NULL);
37731 if (!usb_gone)
37732 hso_stop_serial_device(serial->parent);
37733 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37734
37735 /* the actual setup */
37736 spin_lock_irqsave(&serial->serial_lock, flags);
37737 - if (serial->port.count)
37738 + if (atomic_read(&serial->port.count))
37739 _hso_serial_set_termios(tty, old);
37740 else
37741 tty->termios = *old;
37742 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37743 D1("Pending read interrupt on port %d\n", i);
37744 spin_lock(&serial->serial_lock);
37745 if (serial->rx_state == RX_IDLE &&
37746 - serial->port.count > 0) {
37747 + atomic_read(&serial->port.count) > 0) {
37748 /* Setup and send a ctrl req read on
37749 * port i */
37750 if (!serial->rx_urb_filled[0]) {
37751 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
37752 /* Start all serial ports */
37753 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37754 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37755 - if (dev2ser(serial_table[i])->port.count) {
37756 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37757 result =
37758 hso_start_serial_device(serial_table[i], GFP_NOIO);
37759 hso_kick_transmit(dev2ser(serial_table[i]));
37760 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37761 index 8d78253..bebbb68 100644
37762 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37763 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37764 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37765 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37766 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37767
37768 - ACCESS_ONCE(ads->ds_link) = i->link;
37769 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37770 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
37771 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37772
37773 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37774 ctl6 = SM(i->keytype, AR_EncrType);
37775 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37776
37777 if ((i->is_first || i->is_last) &&
37778 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37779 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37780 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37781 | set11nTries(i->rates, 1)
37782 | set11nTries(i->rates, 2)
37783 | set11nTries(i->rates, 3)
37784 | (i->dur_update ? AR_DurUpdateEna : 0)
37785 | SM(0, AR_BurstDur);
37786
37787 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37788 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37789 | set11nRate(i->rates, 1)
37790 | set11nRate(i->rates, 2)
37791 | set11nRate(i->rates, 3);
37792 } else {
37793 - ACCESS_ONCE(ads->ds_ctl2) = 0;
37794 - ACCESS_ONCE(ads->ds_ctl3) = 0;
37795 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37796 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37797 }
37798
37799 if (!i->is_first) {
37800 - ACCESS_ONCE(ads->ds_ctl0) = 0;
37801 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37802 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37803 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37804 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37805 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37806 return;
37807 }
37808
37809 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37810 break;
37811 }
37812
37813 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37814 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37815 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37816 | SM(i->txpower, AR_XmitPower)
37817 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37818 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37819 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37820 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37821
37822 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37823 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37824 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37825 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37826
37827 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37828 return;
37829
37830 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37831 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37832 | set11nPktDurRTSCTS(i->rates, 1);
37833
37834 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37835 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37836 | set11nPktDurRTSCTS(i->rates, 3);
37837
37838 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37839 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37840 | set11nRateFlags(i->rates, 1)
37841 | set11nRateFlags(i->rates, 2)
37842 | set11nRateFlags(i->rates, 3)
37843 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37844 index 301bf72..3f5654f 100644
37845 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37846 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37847 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37848 (i->qcu << AR_TxQcuNum_S) | desc_len;
37849
37850 checksum += val;
37851 - ACCESS_ONCE(ads->info) = val;
37852 + ACCESS_ONCE_RW(ads->info) = val;
37853
37854 checksum += i->link;
37855 - ACCESS_ONCE(ads->link) = i->link;
37856 + ACCESS_ONCE_RW(ads->link) = i->link;
37857
37858 checksum += i->buf_addr[0];
37859 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37860 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37861 checksum += i->buf_addr[1];
37862 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37863 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37864 checksum += i->buf_addr[2];
37865 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37866 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37867 checksum += i->buf_addr[3];
37868 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37869 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37870
37871 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37872 - ACCESS_ONCE(ads->ctl3) = val;
37873 + ACCESS_ONCE_RW(ads->ctl3) = val;
37874 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37875 - ACCESS_ONCE(ads->ctl5) = val;
37876 + ACCESS_ONCE_RW(ads->ctl5) = val;
37877 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37878 - ACCESS_ONCE(ads->ctl7) = val;
37879 + ACCESS_ONCE_RW(ads->ctl7) = val;
37880 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37881 - ACCESS_ONCE(ads->ctl9) = val;
37882 + ACCESS_ONCE_RW(ads->ctl9) = val;
37883
37884 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37885 - ACCESS_ONCE(ads->ctl10) = checksum;
37886 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
37887
37888 if (i->is_first || i->is_last) {
37889 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37890 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37891 | set11nTries(i->rates, 1)
37892 | set11nTries(i->rates, 2)
37893 | set11nTries(i->rates, 3)
37894 | (i->dur_update ? AR_DurUpdateEna : 0)
37895 | SM(0, AR_BurstDur);
37896
37897 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37898 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37899 | set11nRate(i->rates, 1)
37900 | set11nRate(i->rates, 2)
37901 | set11nRate(i->rates, 3);
37902 } else {
37903 - ACCESS_ONCE(ads->ctl13) = 0;
37904 - ACCESS_ONCE(ads->ctl14) = 0;
37905 + ACCESS_ONCE_RW(ads->ctl13) = 0;
37906 + ACCESS_ONCE_RW(ads->ctl14) = 0;
37907 }
37908
37909 ads->ctl20 = 0;
37910 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37911
37912 ctl17 = SM(i->keytype, AR_EncrType);
37913 if (!i->is_first) {
37914 - ACCESS_ONCE(ads->ctl11) = 0;
37915 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37916 - ACCESS_ONCE(ads->ctl15) = 0;
37917 - ACCESS_ONCE(ads->ctl16) = 0;
37918 - ACCESS_ONCE(ads->ctl17) = ctl17;
37919 - ACCESS_ONCE(ads->ctl18) = 0;
37920 - ACCESS_ONCE(ads->ctl19) = 0;
37921 + ACCESS_ONCE_RW(ads->ctl11) = 0;
37922 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37923 + ACCESS_ONCE_RW(ads->ctl15) = 0;
37924 + ACCESS_ONCE_RW(ads->ctl16) = 0;
37925 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37926 + ACCESS_ONCE_RW(ads->ctl18) = 0;
37927 + ACCESS_ONCE_RW(ads->ctl19) = 0;
37928 return;
37929 }
37930
37931 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37932 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37933 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37934 | SM(i->txpower, AR_XmitPower)
37935 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37936 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37937 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37938 ctl12 |= SM(val, AR_PAPRDChainMask);
37939
37940 - ACCESS_ONCE(ads->ctl12) = ctl12;
37941 - ACCESS_ONCE(ads->ctl17) = ctl17;
37942 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37943 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37944
37945 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37946 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37947 | set11nPktDurRTSCTS(i->rates, 1);
37948
37949 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37950 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37951 | set11nPktDurRTSCTS(i->rates, 3);
37952
37953 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37954 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37955 | set11nRateFlags(i->rates, 1)
37956 | set11nRateFlags(i->rates, 2)
37957 | set11nRateFlags(i->rates, 3)
37958 | SM(i->rtscts_rate, AR_RTSCTSRate);
37959
37960 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37961 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37962 }
37963
37964 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37965 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37966 index 9d26fc5..60d9f14 100644
37967 --- a/drivers/net/wireless/ath/ath9k/hw.h
37968 +++ b/drivers/net/wireless/ath/ath9k/hw.h
37969 @@ -658,7 +658,7 @@ struct ath_hw_private_ops {
37970
37971 /* ANI */
37972 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37973 -};
37974 +} __no_const;
37975
37976 /**
37977 * struct ath_hw_ops - callbacks used by hardware code and driver code
37978 @@ -688,7 +688,7 @@ struct ath_hw_ops {
37979 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37980 struct ath_hw_antcomb_conf *antconf);
37981 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37982 -};
37983 +} __no_const;
37984
37985 struct ath_nf_limits {
37986 s16 max;
37987 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37988 index 3726cd6..b655808 100644
37989 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
37990 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37991 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37992 */
37993 if (il3945_mod_params.disable_hw_scan) {
37994 D_INFO("Disabling hw_scan\n");
37995 - il3945_mac_ops.hw_scan = NULL;
37996 + pax_open_kernel();
37997 + *(void **)&il3945_mac_ops.hw_scan = NULL;
37998 + pax_close_kernel();
37999 }
38000
38001 D_INFO("*** LOAD DRIVER ***\n");
38002 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38003 index 5b9533e..7733880 100644
38004 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38005 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38006 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
38007 {
38008 struct iwl_priv *priv = file->private_data;
38009 char buf[64];
38010 - int buf_size;
38011 + size_t buf_size;
38012 u32 offset, len;
38013
38014 memset(buf, 0, sizeof(buf));
38015 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
38016 struct iwl_priv *priv = file->private_data;
38017
38018 char buf[8];
38019 - int buf_size;
38020 + size_t buf_size;
38021 u32 reset_flag;
38022
38023 memset(buf, 0, sizeof(buf));
38024 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
38025 {
38026 struct iwl_priv *priv = file->private_data;
38027 char buf[8];
38028 - int buf_size;
38029 + size_t buf_size;
38030 int ht40;
38031
38032 memset(buf, 0, sizeof(buf));
38033 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
38034 {
38035 struct iwl_priv *priv = file->private_data;
38036 char buf[8];
38037 - int buf_size;
38038 + size_t buf_size;
38039 int value;
38040
38041 memset(buf, 0, sizeof(buf));
38042 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
38043 {
38044 struct iwl_priv *priv = file->private_data;
38045 char buf[8];
38046 - int buf_size;
38047 + size_t buf_size;
38048 int clear;
38049
38050 memset(buf, 0, sizeof(buf));
38051 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
38052 {
38053 struct iwl_priv *priv = file->private_data;
38054 char buf[8];
38055 - int buf_size;
38056 + size_t buf_size;
38057 int trace;
38058
38059 memset(buf, 0, sizeof(buf));
38060 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
38061 {
38062 struct iwl_priv *priv = file->private_data;
38063 char buf[8];
38064 - int buf_size;
38065 + size_t buf_size;
38066 int missed;
38067
38068 memset(buf, 0, sizeof(buf));
38069 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
38070
38071 struct iwl_priv *priv = file->private_data;
38072 char buf[8];
38073 - int buf_size;
38074 + size_t buf_size;
38075 int plcp;
38076
38077 memset(buf, 0, sizeof(buf));
38078 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
38079
38080 struct iwl_priv *priv = file->private_data;
38081 char buf[8];
38082 - int buf_size;
38083 + size_t buf_size;
38084 int flush;
38085
38086 memset(buf, 0, sizeof(buf));
38087 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
38088
38089 struct iwl_priv *priv = file->private_data;
38090 char buf[8];
38091 - int buf_size;
38092 + size_t buf_size;
38093 int rts;
38094
38095 if (!priv->cfg->ht_params)
38096 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
38097 {
38098 struct iwl_priv *priv = file->private_data;
38099 char buf[8];
38100 - int buf_size;
38101 + size_t buf_size;
38102
38103 memset(buf, 0, sizeof(buf));
38104 buf_size = min(count, sizeof(buf) - 1);
38105 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
38106 struct iwl_priv *priv = file->private_data;
38107 u32 event_log_flag;
38108 char buf[8];
38109 - int buf_size;
38110 + size_t buf_size;
38111
38112 /* check that the interface is up */
38113 if (!iwl_is_ready(priv))
38114 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
38115 struct iwl_priv *priv = file->private_data;
38116 char buf[8];
38117 u32 calib_disabled;
38118 - int buf_size;
38119 + size_t buf_size;
38120
38121 memset(buf, 0, sizeof(buf));
38122 buf_size = min(count, sizeof(buf) - 1);
38123 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
38124 index 35708b9..31f7754 100644
38125 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
38126 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
38127 @@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
38128 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
38129
38130 char buf[8];
38131 - int buf_size;
38132 + size_t buf_size;
38133 u32 reset_flag;
38134
38135 memset(buf, 0, sizeof(buf));
38136 @@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
38137 {
38138 struct iwl_trans *trans = file->private_data;
38139 char buf[8];
38140 - int buf_size;
38141 + size_t buf_size;
38142 int csr;
38143
38144 memset(buf, 0, sizeof(buf));
38145 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
38146 index ff90855..e46d223 100644
38147 --- a/drivers/net/wireless/mac80211_hwsim.c
38148 +++ b/drivers/net/wireless/mac80211_hwsim.c
38149 @@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
38150
38151 if (channels > 1) {
38152 hwsim_if_comb.num_different_channels = channels;
38153 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38154 - mac80211_hwsim_ops.cancel_hw_scan =
38155 - mac80211_hwsim_cancel_hw_scan;
38156 - mac80211_hwsim_ops.sw_scan_start = NULL;
38157 - mac80211_hwsim_ops.sw_scan_complete = NULL;
38158 - mac80211_hwsim_ops.remain_on_channel =
38159 - mac80211_hwsim_roc;
38160 - mac80211_hwsim_ops.cancel_remain_on_channel =
38161 - mac80211_hwsim_croc;
38162 - mac80211_hwsim_ops.add_chanctx =
38163 - mac80211_hwsim_add_chanctx;
38164 - mac80211_hwsim_ops.remove_chanctx =
38165 - mac80211_hwsim_remove_chanctx;
38166 - mac80211_hwsim_ops.change_chanctx =
38167 - mac80211_hwsim_change_chanctx;
38168 - mac80211_hwsim_ops.assign_vif_chanctx =
38169 - mac80211_hwsim_assign_vif_chanctx;
38170 - mac80211_hwsim_ops.unassign_vif_chanctx =
38171 - mac80211_hwsim_unassign_vif_chanctx;
38172 + pax_open_kernel();
38173 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38174 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
38175 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
38176 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
38177 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
38178 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
38179 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
38180 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
38181 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
38182 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
38183 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
38184 + pax_close_kernel();
38185 }
38186
38187 spin_lock_init(&hwsim_radio_lock);
38188 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
38189 index abe1d03..fb02c22 100644
38190 --- a/drivers/net/wireless/rndis_wlan.c
38191 +++ b/drivers/net/wireless/rndis_wlan.c
38192 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
38193
38194 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
38195
38196 - if (rts_threshold < 0 || rts_threshold > 2347)
38197 + if (rts_threshold > 2347)
38198 rts_threshold = 2347;
38199
38200 tmp = cpu_to_le32(rts_threshold);
38201 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
38202 index 0751b35..246ba3e 100644
38203 --- a/drivers/net/wireless/rt2x00/rt2x00.h
38204 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
38205 @@ -398,7 +398,7 @@ struct rt2x00_intf {
38206 * for hardware which doesn't support hardware
38207 * sequence counting.
38208 */
38209 - atomic_t seqno;
38210 + atomic_unchecked_t seqno;
38211 };
38212
38213 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
38214 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
38215 index e488b94..14b6a0c 100644
38216 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
38217 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
38218 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
38219 * sequence counter given by mac80211.
38220 */
38221 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
38222 - seqno = atomic_add_return(0x10, &intf->seqno);
38223 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
38224 else
38225 - seqno = atomic_read(&intf->seqno);
38226 + seqno = atomic_read_unchecked(&intf->seqno);
38227
38228 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
38229 hdr->seq_ctrl |= cpu_to_le16(seqno);
38230 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
38231 index e57ee48..541cf6c 100644
38232 --- a/drivers/net/wireless/ti/wl1251/sdio.c
38233 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
38234 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
38235
38236 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
38237
38238 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38239 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38240 + pax_open_kernel();
38241 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38242 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38243 + pax_close_kernel();
38244
38245 wl1251_info("using dedicated interrupt line");
38246 } else {
38247 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38248 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38249 + pax_open_kernel();
38250 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38251 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38252 + pax_close_kernel();
38253
38254 wl1251_info("using SDIO interrupt");
38255 }
38256 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
38257 index e5f5f8f..fdf15b7 100644
38258 --- a/drivers/net/wireless/ti/wl12xx/main.c
38259 +++ b/drivers/net/wireless/ti/wl12xx/main.c
38260 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38261 sizeof(wl->conf.mem));
38262
38263 /* read data preparation is only needed by wl127x */
38264 - wl->ops->prepare_read = wl127x_prepare_read;
38265 + pax_open_kernel();
38266 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38267 + pax_close_kernel();
38268
38269 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38270 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38271 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38272 sizeof(wl->conf.mem));
38273
38274 /* read data preparation is only needed by wl127x */
38275 - wl->ops->prepare_read = wl127x_prepare_read;
38276 + pax_open_kernel();
38277 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38278 + pax_close_kernel();
38279
38280 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38281 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38282 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
38283 index 8d8c1f8..e754844 100644
38284 --- a/drivers/net/wireless/ti/wl18xx/main.c
38285 +++ b/drivers/net/wireless/ti/wl18xx/main.c
38286 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
38287 }
38288
38289 if (!checksum_param) {
38290 - wl18xx_ops.set_rx_csum = NULL;
38291 - wl18xx_ops.init_vif = NULL;
38292 + pax_open_kernel();
38293 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
38294 + *(void **)&wl18xx_ops.init_vif = NULL;
38295 + pax_close_kernel();
38296 }
38297
38298 /* Enable 11a Band only if we have 5G antennas */
38299 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
38300 index d93b2b6..ae50401 100644
38301 --- a/drivers/oprofile/buffer_sync.c
38302 +++ b/drivers/oprofile/buffer_sync.c
38303 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
38304 if (cookie == NO_COOKIE)
38305 offset = pc;
38306 if (cookie == INVALID_COOKIE) {
38307 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38308 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38309 offset = pc;
38310 }
38311 if (cookie != last_cookie) {
38312 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
38313 /* add userspace sample */
38314
38315 if (!mm) {
38316 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
38317 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
38318 return 0;
38319 }
38320
38321 cookie = lookup_dcookie(mm, s->eip, &offset);
38322
38323 if (cookie == INVALID_COOKIE) {
38324 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38325 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38326 return 0;
38327 }
38328
38329 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
38330 /* ignore backtraces if failed to add a sample */
38331 if (state == sb_bt_start) {
38332 state = sb_bt_ignore;
38333 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
38334 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
38335 }
38336 }
38337 release_mm(mm);
38338 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
38339 index c0cc4e7..44d4e54 100644
38340 --- a/drivers/oprofile/event_buffer.c
38341 +++ b/drivers/oprofile/event_buffer.c
38342 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
38343 }
38344
38345 if (buffer_pos == buffer_size) {
38346 - atomic_inc(&oprofile_stats.event_lost_overflow);
38347 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
38348 return;
38349 }
38350
38351 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
38352 index ed2c3ec..deda85a 100644
38353 --- a/drivers/oprofile/oprof.c
38354 +++ b/drivers/oprofile/oprof.c
38355 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
38356 if (oprofile_ops.switch_events())
38357 return;
38358
38359 - atomic_inc(&oprofile_stats.multiplex_counter);
38360 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
38361 start_switch_worker();
38362 }
38363
38364 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
38365 index 917d28e..d62d981 100644
38366 --- a/drivers/oprofile/oprofile_stats.c
38367 +++ b/drivers/oprofile/oprofile_stats.c
38368 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
38369 cpu_buf->sample_invalid_eip = 0;
38370 }
38371
38372 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
38373 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
38374 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
38375 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
38376 - atomic_set(&oprofile_stats.multiplex_counter, 0);
38377 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
38378 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
38379 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
38380 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
38381 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
38382 }
38383
38384
38385 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
38386 index 38b6fc0..b5cbfce 100644
38387 --- a/drivers/oprofile/oprofile_stats.h
38388 +++ b/drivers/oprofile/oprofile_stats.h
38389 @@ -13,11 +13,11 @@
38390 #include <linux/atomic.h>
38391
38392 struct oprofile_stat_struct {
38393 - atomic_t sample_lost_no_mm;
38394 - atomic_t sample_lost_no_mapping;
38395 - atomic_t bt_lost_no_mapping;
38396 - atomic_t event_lost_overflow;
38397 - atomic_t multiplex_counter;
38398 + atomic_unchecked_t sample_lost_no_mm;
38399 + atomic_unchecked_t sample_lost_no_mapping;
38400 + atomic_unchecked_t bt_lost_no_mapping;
38401 + atomic_unchecked_t event_lost_overflow;
38402 + atomic_unchecked_t multiplex_counter;
38403 };
38404
38405 extern struct oprofile_stat_struct oprofile_stats;
38406 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
38407 index 849357c..b83c1e0 100644
38408 --- a/drivers/oprofile/oprofilefs.c
38409 +++ b/drivers/oprofile/oprofilefs.c
38410 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
38411
38412
38413 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
38414 - char const *name, atomic_t *val)
38415 + char const *name, atomic_unchecked_t *val)
38416 {
38417 return __oprofilefs_create_file(sb, root, name,
38418 &atomic_ro_fops, 0444, val);
38419 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
38420 index 93404f7..4a313d8 100644
38421 --- a/drivers/oprofile/timer_int.c
38422 +++ b/drivers/oprofile/timer_int.c
38423 @@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
38424 return NOTIFY_OK;
38425 }
38426
38427 -static struct notifier_block __refdata oprofile_cpu_notifier = {
38428 +static struct notifier_block oprofile_cpu_notifier = {
38429 .notifier_call = oprofile_cpu_notify,
38430 };
38431
38432 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
38433 index 3f56bc0..707d642 100644
38434 --- a/drivers/parport/procfs.c
38435 +++ b/drivers/parport/procfs.c
38436 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
38437
38438 *ppos += len;
38439
38440 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
38441 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
38442 }
38443
38444 #ifdef CONFIG_PARPORT_1284
38445 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
38446
38447 *ppos += len;
38448
38449 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
38450 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
38451 }
38452 #endif /* IEEE1284.3 support. */
38453
38454 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
38455 index a6a71c4..c91097b 100644
38456 --- a/drivers/pci/hotplug/cpcihp_generic.c
38457 +++ b/drivers/pci/hotplug/cpcihp_generic.c
38458 @@ -73,7 +73,6 @@ static u16 port;
38459 static unsigned int enum_bit;
38460 static u8 enum_mask;
38461
38462 -static struct cpci_hp_controller_ops generic_hpc_ops;
38463 static struct cpci_hp_controller generic_hpc;
38464
38465 static int __init validate_parameters(void)
38466 @@ -139,6 +138,10 @@ static int query_enum(void)
38467 return ((value & enum_mask) == enum_mask);
38468 }
38469
38470 +static struct cpci_hp_controller_ops generic_hpc_ops = {
38471 + .query_enum = query_enum,
38472 +};
38473 +
38474 static int __init cpcihp_generic_init(void)
38475 {
38476 int status;
38477 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
38478 pci_dev_put(dev);
38479
38480 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
38481 - generic_hpc_ops.query_enum = query_enum;
38482 generic_hpc.ops = &generic_hpc_ops;
38483
38484 status = cpci_hp_register_controller(&generic_hpc);
38485 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
38486 index 449b4bb..257e2e8 100644
38487 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
38488 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
38489 @@ -59,7 +59,6 @@
38490 /* local variables */
38491 static bool debug;
38492 static bool poll;
38493 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
38494 static struct cpci_hp_controller zt5550_hpc;
38495
38496 /* Primary cPCI bus bridge device */
38497 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
38498 return 0;
38499 }
38500
38501 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
38502 + .query_enum = zt5550_hc_query_enum,
38503 +};
38504 +
38505 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
38506 {
38507 int status;
38508 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
38509 dbg("returned from zt5550_hc_config");
38510
38511 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
38512 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
38513 zt5550_hpc.ops = &zt5550_hpc_ops;
38514 if(!poll) {
38515 zt5550_hpc.irq = hc_dev->irq;
38516 zt5550_hpc.irq_flags = IRQF_SHARED;
38517 zt5550_hpc.dev_id = hc_dev;
38518
38519 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38520 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38521 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38522 + pax_open_kernel();
38523 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38524 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38525 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38526 + pax_open_kernel();
38527 } else {
38528 info("using ENUM# polling mode");
38529 }
38530 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
38531 index 76ba8a1..20ca857 100644
38532 --- a/drivers/pci/hotplug/cpqphp_nvram.c
38533 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
38534 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
38535
38536 void compaq_nvram_init (void __iomem *rom_start)
38537 {
38538 +
38539 +#ifndef CONFIG_PAX_KERNEXEC
38540 if (rom_start) {
38541 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
38542 }
38543 +#endif
38544 +
38545 dbg("int15 entry = %p\n", compaq_int15_entry_point);
38546
38547 /* initialize our int15 lock */
38548 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
38549 index 8474b6a..ee81993 100644
38550 --- a/drivers/pci/pcie/aspm.c
38551 +++ b/drivers/pci/pcie/aspm.c
38552 @@ -27,9 +27,9 @@
38553 #define MODULE_PARAM_PREFIX "pcie_aspm."
38554
38555 /* Note: those are not register definitions */
38556 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
38557 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
38558 -#define ASPM_STATE_L1 (4) /* L1 state */
38559 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
38560 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
38561 +#define ASPM_STATE_L1 (4U) /* L1 state */
38562 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
38563 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
38564
38565 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
38566 index 6186f03..1a78714 100644
38567 --- a/drivers/pci/probe.c
38568 +++ b/drivers/pci/probe.c
38569 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
38570 struct pci_bus_region region;
38571 bool bar_too_big = false, bar_disabled = false;
38572
38573 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
38574 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
38575
38576 /* No printks while decoding is disabled! */
38577 if (!dev->mmio_always_on) {
38578 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
38579 index 9b8505c..f00870a 100644
38580 --- a/drivers/pci/proc.c
38581 +++ b/drivers/pci/proc.c
38582 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
38583 static int __init pci_proc_init(void)
38584 {
38585 struct pci_dev *dev = NULL;
38586 +
38587 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
38588 +#ifdef CONFIG_GRKERNSEC_PROC_USER
38589 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
38590 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38591 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
38592 +#endif
38593 +#else
38594 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
38595 +#endif
38596 proc_create("devices", 0, proc_bus_pci_dir,
38597 &proc_bus_pci_dev_operations);
38598 proc_initialized = 1;
38599 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
38600 index f946ca7..f25c833 100644
38601 --- a/drivers/platform/x86/thinkpad_acpi.c
38602 +++ b/drivers/platform/x86/thinkpad_acpi.c
38603 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
38604 return 0;
38605 }
38606
38607 -void static hotkey_mask_warn_incomplete_mask(void)
38608 +static void hotkey_mask_warn_incomplete_mask(void)
38609 {
38610 /* log only what the user can fix... */
38611 const u32 wantedmask = hotkey_driver_mask &
38612 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
38613 }
38614 }
38615
38616 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38617 - struct tp_nvram_state *newn,
38618 - const u32 event_mask)
38619 -{
38620 -
38621 #define TPACPI_COMPARE_KEY(__scancode, __member) \
38622 do { \
38623 if ((event_mask & (1 << __scancode)) && \
38624 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38625 tpacpi_hotkey_send_key(__scancode); \
38626 } while (0)
38627
38628 - void issue_volchange(const unsigned int oldvol,
38629 - const unsigned int newvol)
38630 - {
38631 - unsigned int i = oldvol;
38632 +static void issue_volchange(const unsigned int oldvol,
38633 + const unsigned int newvol,
38634 + const u32 event_mask)
38635 +{
38636 + unsigned int i = oldvol;
38637
38638 - while (i > newvol) {
38639 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38640 - i--;
38641 - }
38642 - while (i < newvol) {
38643 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38644 - i++;
38645 - }
38646 + while (i > newvol) {
38647 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38648 + i--;
38649 }
38650 + while (i < newvol) {
38651 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38652 + i++;
38653 + }
38654 +}
38655
38656 - void issue_brightnesschange(const unsigned int oldbrt,
38657 - const unsigned int newbrt)
38658 - {
38659 - unsigned int i = oldbrt;
38660 +static void issue_brightnesschange(const unsigned int oldbrt,
38661 + const unsigned int newbrt,
38662 + const u32 event_mask)
38663 +{
38664 + unsigned int i = oldbrt;
38665
38666 - while (i > newbrt) {
38667 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38668 - i--;
38669 - }
38670 - while (i < newbrt) {
38671 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38672 - i++;
38673 - }
38674 + while (i > newbrt) {
38675 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38676 + i--;
38677 + }
38678 + while (i < newbrt) {
38679 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38680 + i++;
38681 }
38682 +}
38683
38684 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38685 + struct tp_nvram_state *newn,
38686 + const u32 event_mask)
38687 +{
38688 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
38689 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
38690 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
38691 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38692 oldn->volume_level != newn->volume_level) {
38693 /* recently muted, or repeated mute keypress, or
38694 * multiple presses ending in mute */
38695 - issue_volchange(oldn->volume_level, newn->volume_level);
38696 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38697 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
38698 }
38699 } else {
38700 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38701 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38702 }
38703 if (oldn->volume_level != newn->volume_level) {
38704 - issue_volchange(oldn->volume_level, newn->volume_level);
38705 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38706 } else if (oldn->volume_toggle != newn->volume_toggle) {
38707 /* repeated vol up/down keypress at end of scale ? */
38708 if (newn->volume_level == 0)
38709 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38710 /* handle brightness */
38711 if (oldn->brightness_level != newn->brightness_level) {
38712 issue_brightnesschange(oldn->brightness_level,
38713 - newn->brightness_level);
38714 + newn->brightness_level,
38715 + event_mask);
38716 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38717 /* repeated key presses that didn't change state */
38718 if (newn->brightness_level == 0)
38719 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38720 && !tp_features.bright_unkfw)
38721 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38722 }
38723 +}
38724
38725 #undef TPACPI_COMPARE_KEY
38726 #undef TPACPI_MAY_SEND_KEY
38727 -}
38728
38729 /*
38730 * Polling driver
38731 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38732 index 769d265..a3a05ca 100644
38733 --- a/drivers/pnp/pnpbios/bioscalls.c
38734 +++ b/drivers/pnp/pnpbios/bioscalls.c
38735 @@ -58,7 +58,7 @@ do { \
38736 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38737 } while(0)
38738
38739 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38740 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38741 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38742
38743 /*
38744 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38745
38746 cpu = get_cpu();
38747 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38748 +
38749 + pax_open_kernel();
38750 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38751 + pax_close_kernel();
38752
38753 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38754 spin_lock_irqsave(&pnp_bios_lock, flags);
38755 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38756 :"memory");
38757 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38758
38759 + pax_open_kernel();
38760 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38761 + pax_close_kernel();
38762 +
38763 put_cpu();
38764
38765 /* If we get here and this is set then the PnP BIOS faulted on us. */
38766 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38767 return status;
38768 }
38769
38770 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
38771 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38772 {
38773 int i;
38774
38775 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38776 pnp_bios_callpoint.offset = header->fields.pm16offset;
38777 pnp_bios_callpoint.segment = PNP_CS16;
38778
38779 + pax_open_kernel();
38780 +
38781 for_each_possible_cpu(i) {
38782 struct desc_struct *gdt = get_cpu_gdt_table(i);
38783 if (!gdt)
38784 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38785 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38786 (unsigned long)__va(header->fields.pm16dseg));
38787 }
38788 +
38789 + pax_close_kernel();
38790 }
38791 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38792 index 3e6db1c..1fbbdae 100644
38793 --- a/drivers/pnp/resource.c
38794 +++ b/drivers/pnp/resource.c
38795 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38796 return 1;
38797
38798 /* check if the resource is valid */
38799 - if (*irq < 0 || *irq > 15)
38800 + if (*irq > 15)
38801 return 0;
38802
38803 /* check if the resource is reserved */
38804 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38805 return 1;
38806
38807 /* check if the resource is valid */
38808 - if (*dma < 0 || *dma == 4 || *dma > 7)
38809 + if (*dma == 4 || *dma > 7)
38810 return 0;
38811
38812 /* check if the resource is reserved */
38813 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38814 index 7df7c5f..bd48c47 100644
38815 --- a/drivers/power/pda_power.c
38816 +++ b/drivers/power/pda_power.c
38817 @@ -37,7 +37,11 @@ static int polling;
38818
38819 #ifdef CONFIG_USB_OTG_UTILS
38820 static struct usb_phy *transceiver;
38821 -static struct notifier_block otg_nb;
38822 +static int otg_handle_notification(struct notifier_block *nb,
38823 + unsigned long event, void *unused);
38824 +static struct notifier_block otg_nb = {
38825 + .notifier_call = otg_handle_notification
38826 +};
38827 #endif
38828
38829 static struct regulator *ac_draw;
38830 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38831
38832 #ifdef CONFIG_USB_OTG_UTILS
38833 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38834 - otg_nb.notifier_call = otg_handle_notification;
38835 ret = usb_register_notifier(transceiver, &otg_nb);
38836 if (ret) {
38837 dev_err(dev, "failure to register otg notifier\n");
38838 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38839 index 4d7c635..9860196 100644
38840 --- a/drivers/regulator/max8660.c
38841 +++ b/drivers/regulator/max8660.c
38842 @@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
38843 max8660->shadow_regs[MAX8660_OVER1] = 5;
38844 } else {
38845 /* Otherwise devices can be toggled via software */
38846 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
38847 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
38848 + pax_open_kernel();
38849 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38850 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38851 + pax_close_kernel();
38852 }
38853
38854 /*
38855 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
38856 index 9a8ea91..c483dd9 100644
38857 --- a/drivers/regulator/max8973-regulator.c
38858 +++ b/drivers/regulator/max8973-regulator.c
38859 @@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
38860 if (!pdata->enable_ext_control) {
38861 max->desc.enable_reg = MAX8973_VOUT;
38862 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
38863 - max8973_dcdc_ops.enable = regulator_enable_regmap;
38864 - max8973_dcdc_ops.disable = regulator_disable_regmap;
38865 - max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38866 + pax_open_kernel();
38867 + *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
38868 + *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
38869 + *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38870 + pax_close_kernel();
38871 }
38872
38873 max->enable_external_control = pdata->enable_ext_control;
38874 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38875 index 0d84b1f..c2da6ac 100644
38876 --- a/drivers/regulator/mc13892-regulator.c
38877 +++ b/drivers/regulator/mc13892-regulator.c
38878 @@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
38879 }
38880 mc13xxx_unlock(mc13892);
38881
38882 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38883 + pax_open_kernel();
38884 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38885 = mc13892_vcam_set_mode;
38886 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38887 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38888 = mc13892_vcam_get_mode;
38889 + pax_close_kernel();
38890
38891 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38892 ARRAY_SIZE(mc13892_regulators));
38893 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38894 index 9a86b4b..3a383dc 100644
38895 --- a/drivers/rtc/rtc-dev.c
38896 +++ b/drivers/rtc/rtc-dev.c
38897 @@ -14,6 +14,7 @@
38898 #include <linux/module.h>
38899 #include <linux/rtc.h>
38900 #include <linux/sched.h>
38901 +#include <linux/grsecurity.h>
38902 #include "rtc-core.h"
38903
38904 static dev_t rtc_devt;
38905 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38906 if (copy_from_user(&tm, uarg, sizeof(tm)))
38907 return -EFAULT;
38908
38909 + gr_log_timechange();
38910 +
38911 return rtc_set_time(rtc, &tm);
38912
38913 case RTC_PIE_ON:
38914 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38915 index 4ad7e36..d004679 100644
38916 --- a/drivers/scsi/bfa/bfa.h
38917 +++ b/drivers/scsi/bfa/bfa.h
38918 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
38919 u32 *end);
38920 int cpe_vec_q0;
38921 int rme_vec_q0;
38922 -};
38923 +} __no_const;
38924 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38925
38926 struct bfa_faa_cbfn_s {
38927 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38928 index e693af6..2e525b6 100644
38929 --- a/drivers/scsi/bfa/bfa_fcpim.h
38930 +++ b/drivers/scsi/bfa/bfa_fcpim.h
38931 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
38932
38933 struct bfa_itn_s {
38934 bfa_isr_func_t isr;
38935 -};
38936 +} __no_const;
38937
38938 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38939 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38940 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38941 index 23a90e7..9cf04ee 100644
38942 --- a/drivers/scsi/bfa/bfa_ioc.h
38943 +++ b/drivers/scsi/bfa/bfa_ioc.h
38944 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38945 bfa_ioc_disable_cbfn_t disable_cbfn;
38946 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38947 bfa_ioc_reset_cbfn_t reset_cbfn;
38948 -};
38949 +} __no_const;
38950
38951 /*
38952 * IOC event notification mechanism.
38953 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38954 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38955 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38956 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38957 -};
38958 +} __no_const;
38959
38960 /*
38961 * Queue element to wait for room in request queue. FIFO order is
38962 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38963 index 593085a..47aa999 100644
38964 --- a/drivers/scsi/hosts.c
38965 +++ b/drivers/scsi/hosts.c
38966 @@ -42,7 +42,7 @@
38967 #include "scsi_logging.h"
38968
38969
38970 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38971 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38972
38973
38974 static void scsi_host_cls_release(struct device *dev)
38975 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38976 * subtract one because we increment first then return, but we need to
38977 * know what the next host number was before increment
38978 */
38979 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38980 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38981 shost->dma_channel = 0xff;
38982
38983 /* These three are default values which can be overridden */
38984 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38985 index 4f33806..afd6f60 100644
38986 --- a/drivers/scsi/hpsa.c
38987 +++ b/drivers/scsi/hpsa.c
38988 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38989 unsigned long flags;
38990
38991 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38992 - return h->access.command_completed(h, q);
38993 + return h->access->command_completed(h, q);
38994
38995 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38996 a = rq->head[rq->current_entry];
38997 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38998 while (!list_empty(&h->reqQ)) {
38999 c = list_entry(h->reqQ.next, struct CommandList, list);
39000 /* can't do anything if fifo is full */
39001 - if ((h->access.fifo_full(h))) {
39002 + if ((h->access->fifo_full(h))) {
39003 dev_warn(&h->pdev->dev, "fifo full\n");
39004 break;
39005 }
39006 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
39007
39008 /* Tell the controller execute command */
39009 spin_unlock_irqrestore(&h->lock, flags);
39010 - h->access.submit_command(h, c);
39011 + h->access->submit_command(h, c);
39012 spin_lock_irqsave(&h->lock, flags);
39013 }
39014 spin_unlock_irqrestore(&h->lock, flags);
39015 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
39016
39017 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
39018 {
39019 - return h->access.command_completed(h, q);
39020 + return h->access->command_completed(h, q);
39021 }
39022
39023 static inline bool interrupt_pending(struct ctlr_info *h)
39024 {
39025 - return h->access.intr_pending(h);
39026 + return h->access->intr_pending(h);
39027 }
39028
39029 static inline long interrupt_not_for_us(struct ctlr_info *h)
39030 {
39031 - return (h->access.intr_pending(h) == 0) ||
39032 + return (h->access->intr_pending(h) == 0) ||
39033 (h->interrupts_enabled == 0);
39034 }
39035
39036 @@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
39037 if (prod_index < 0)
39038 return -ENODEV;
39039 h->product_name = products[prod_index].product_name;
39040 - h->access = *(products[prod_index].access);
39041 + h->access = products[prod_index].access;
39042
39043 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
39044 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
39045 @@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
39046
39047 assert_spin_locked(&lockup_detector_lock);
39048 remove_ctlr_from_lockup_detector_list(h);
39049 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39050 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39051 spin_lock_irqsave(&h->lock, flags);
39052 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
39053 spin_unlock_irqrestore(&h->lock, flags);
39054 @@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
39055 }
39056
39057 /* make sure the board interrupts are off */
39058 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39059 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39060
39061 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
39062 goto clean2;
39063 @@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
39064 * fake ones to scoop up any residual completions.
39065 */
39066 spin_lock_irqsave(&h->lock, flags);
39067 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39068 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39069 spin_unlock_irqrestore(&h->lock, flags);
39070 free_irqs(h);
39071 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
39072 @@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
39073 dev_info(&h->pdev->dev, "Board READY.\n");
39074 dev_info(&h->pdev->dev,
39075 "Waiting for stale completions to drain.\n");
39076 - h->access.set_intr_mask(h, HPSA_INTR_ON);
39077 + h->access->set_intr_mask(h, HPSA_INTR_ON);
39078 msleep(10000);
39079 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39080 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39081
39082 rc = controller_reset_failed(h->cfgtable);
39083 if (rc)
39084 @@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
39085 }
39086
39087 /* Turn the interrupts on so we can service requests */
39088 - h->access.set_intr_mask(h, HPSA_INTR_ON);
39089 + h->access->set_intr_mask(h, HPSA_INTR_ON);
39090
39091 hpsa_hba_inquiry(h);
39092 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
39093 @@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
39094 * To write all data in the battery backed cache to disks
39095 */
39096 hpsa_flush_cache(h);
39097 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39098 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39099 hpsa_free_irqs_and_disable_msix(h);
39100 }
39101
39102 @@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
39103 return;
39104 }
39105 /* Change the access methods to the performant access methods */
39106 - h->access = SA5_performant_access;
39107 + h->access = &SA5_performant_access;
39108 h->transMethod = CFGTBL_Trans_Performant;
39109 }
39110
39111 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
39112 index 9816479..c5d4e97 100644
39113 --- a/drivers/scsi/hpsa.h
39114 +++ b/drivers/scsi/hpsa.h
39115 @@ -79,7 +79,7 @@ struct ctlr_info {
39116 unsigned int msix_vector;
39117 unsigned int msi_vector;
39118 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
39119 - struct access_method access;
39120 + struct access_method *access;
39121
39122 /* queue and queue Info */
39123 struct list_head reqQ;
39124 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
39125 index c772d8d..35c362c 100644
39126 --- a/drivers/scsi/libfc/fc_exch.c
39127 +++ b/drivers/scsi/libfc/fc_exch.c
39128 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
39129 u16 pool_max_index;
39130
39131 struct {
39132 - atomic_t no_free_exch;
39133 - atomic_t no_free_exch_xid;
39134 - atomic_t xid_not_found;
39135 - atomic_t xid_busy;
39136 - atomic_t seq_not_found;
39137 - atomic_t non_bls_resp;
39138 + atomic_unchecked_t no_free_exch;
39139 + atomic_unchecked_t no_free_exch_xid;
39140 + atomic_unchecked_t xid_not_found;
39141 + atomic_unchecked_t xid_busy;
39142 + atomic_unchecked_t seq_not_found;
39143 + atomic_unchecked_t non_bls_resp;
39144 } stats;
39145 };
39146
39147 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
39148 /* allocate memory for exchange */
39149 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
39150 if (!ep) {
39151 - atomic_inc(&mp->stats.no_free_exch);
39152 + atomic_inc_unchecked(&mp->stats.no_free_exch);
39153 goto out;
39154 }
39155 memset(ep, 0, sizeof(*ep));
39156 @@ -786,7 +786,7 @@ out:
39157 return ep;
39158 err:
39159 spin_unlock_bh(&pool->lock);
39160 - atomic_inc(&mp->stats.no_free_exch_xid);
39161 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
39162 mempool_free(ep, mp->ep_pool);
39163 return NULL;
39164 }
39165 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39166 xid = ntohs(fh->fh_ox_id); /* we originated exch */
39167 ep = fc_exch_find(mp, xid);
39168 if (!ep) {
39169 - atomic_inc(&mp->stats.xid_not_found);
39170 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39171 reject = FC_RJT_OX_ID;
39172 goto out;
39173 }
39174 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39175 ep = fc_exch_find(mp, xid);
39176 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
39177 if (ep) {
39178 - atomic_inc(&mp->stats.xid_busy);
39179 + atomic_inc_unchecked(&mp->stats.xid_busy);
39180 reject = FC_RJT_RX_ID;
39181 goto rel;
39182 }
39183 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39184 }
39185 xid = ep->xid; /* get our XID */
39186 } else if (!ep) {
39187 - atomic_inc(&mp->stats.xid_not_found);
39188 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39189 reject = FC_RJT_RX_ID; /* XID not found */
39190 goto out;
39191 }
39192 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39193 } else {
39194 sp = &ep->seq;
39195 if (sp->id != fh->fh_seq_id) {
39196 - atomic_inc(&mp->stats.seq_not_found);
39197 + atomic_inc_unchecked(&mp->stats.seq_not_found);
39198 if (f_ctl & FC_FC_END_SEQ) {
39199 /*
39200 * Update sequence_id based on incoming last
39201 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39202
39203 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
39204 if (!ep) {
39205 - atomic_inc(&mp->stats.xid_not_found);
39206 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39207 goto out;
39208 }
39209 if (ep->esb_stat & ESB_ST_COMPLETE) {
39210 - atomic_inc(&mp->stats.xid_not_found);
39211 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39212 goto rel;
39213 }
39214 if (ep->rxid == FC_XID_UNKNOWN)
39215 ep->rxid = ntohs(fh->fh_rx_id);
39216 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
39217 - atomic_inc(&mp->stats.xid_not_found);
39218 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39219 goto rel;
39220 }
39221 if (ep->did != ntoh24(fh->fh_s_id) &&
39222 ep->did != FC_FID_FLOGI) {
39223 - atomic_inc(&mp->stats.xid_not_found);
39224 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39225 goto rel;
39226 }
39227 sof = fr_sof(fp);
39228 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39229 sp->ssb_stat |= SSB_ST_RESP;
39230 sp->id = fh->fh_seq_id;
39231 } else if (sp->id != fh->fh_seq_id) {
39232 - atomic_inc(&mp->stats.seq_not_found);
39233 + atomic_inc_unchecked(&mp->stats.seq_not_found);
39234 goto rel;
39235 }
39236
39237 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39238 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
39239
39240 if (!sp)
39241 - atomic_inc(&mp->stats.xid_not_found);
39242 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39243 else
39244 - atomic_inc(&mp->stats.non_bls_resp);
39245 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
39246
39247 fc_frame_free(fp);
39248 }
39249 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
39250
39251 list_for_each_entry(ema, &lport->ema_list, ema_list) {
39252 mp = ema->mp;
39253 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
39254 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
39255 st->fc_no_free_exch_xid +=
39256 - atomic_read(&mp->stats.no_free_exch_xid);
39257 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
39258 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
39259 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
39260 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
39261 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
39262 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
39263 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
39264 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
39265 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
39266 }
39267 }
39268 EXPORT_SYMBOL(fc_exch_update_stats);
39269 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
39270 index bdb81cd..d3c7c2c 100644
39271 --- a/drivers/scsi/libsas/sas_ata.c
39272 +++ b/drivers/scsi/libsas/sas_ata.c
39273 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
39274 .postreset = ata_std_postreset,
39275 .error_handler = ata_std_error_handler,
39276 .post_internal_cmd = sas_ata_post_internal,
39277 - .qc_defer = ata_std_qc_defer,
39278 + .qc_defer = ata_std_qc_defer,
39279 .qc_prep = ata_noop_qc_prep,
39280 .qc_issue = sas_ata_qc_issue,
39281 .qc_fill_rtf = sas_ata_qc_fill_rtf,
39282 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
39283 index df4c13a..a51e90c 100644
39284 --- a/drivers/scsi/lpfc/lpfc.h
39285 +++ b/drivers/scsi/lpfc/lpfc.h
39286 @@ -424,7 +424,7 @@ struct lpfc_vport {
39287 struct dentry *debug_nodelist;
39288 struct dentry *vport_debugfs_root;
39289 struct lpfc_debugfs_trc *disc_trc;
39290 - atomic_t disc_trc_cnt;
39291 + atomic_unchecked_t disc_trc_cnt;
39292 #endif
39293 uint8_t stat_data_enabled;
39294 uint8_t stat_data_blocked;
39295 @@ -842,8 +842,8 @@ struct lpfc_hba {
39296 struct timer_list fabric_block_timer;
39297 unsigned long bit_flags;
39298 #define FABRIC_COMANDS_BLOCKED 0
39299 - atomic_t num_rsrc_err;
39300 - atomic_t num_cmd_success;
39301 + atomic_unchecked_t num_rsrc_err;
39302 + atomic_unchecked_t num_cmd_success;
39303 unsigned long last_rsrc_error_time;
39304 unsigned long last_ramp_down_time;
39305 unsigned long last_ramp_up_time;
39306 @@ -879,7 +879,7 @@ struct lpfc_hba {
39307
39308 struct dentry *debug_slow_ring_trc;
39309 struct lpfc_debugfs_trc *slow_ring_trc;
39310 - atomic_t slow_ring_trc_cnt;
39311 + atomic_unchecked_t slow_ring_trc_cnt;
39312 /* iDiag debugfs sub-directory */
39313 struct dentry *idiag_root;
39314 struct dentry *idiag_pci_cfg;
39315 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
39316 index f63f5ff..de29189 100644
39317 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
39318 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
39319 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
39320
39321 #include <linux/debugfs.h>
39322
39323 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39324 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39325 static unsigned long lpfc_debugfs_start_time = 0L;
39326
39327 /* iDiag */
39328 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
39329 lpfc_debugfs_enable = 0;
39330
39331 len = 0;
39332 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
39333 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
39334 (lpfc_debugfs_max_disc_trc - 1);
39335 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
39336 dtp = vport->disc_trc + i;
39337 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
39338 lpfc_debugfs_enable = 0;
39339
39340 len = 0;
39341 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
39342 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
39343 (lpfc_debugfs_max_slow_ring_trc - 1);
39344 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
39345 dtp = phba->slow_ring_trc + i;
39346 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
39347 !vport || !vport->disc_trc)
39348 return;
39349
39350 - index = atomic_inc_return(&vport->disc_trc_cnt) &
39351 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
39352 (lpfc_debugfs_max_disc_trc - 1);
39353 dtp = vport->disc_trc + index;
39354 dtp->fmt = fmt;
39355 dtp->data1 = data1;
39356 dtp->data2 = data2;
39357 dtp->data3 = data3;
39358 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39359 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39360 dtp->jif = jiffies;
39361 #endif
39362 return;
39363 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
39364 !phba || !phba->slow_ring_trc)
39365 return;
39366
39367 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
39368 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
39369 (lpfc_debugfs_max_slow_ring_trc - 1);
39370 dtp = phba->slow_ring_trc + index;
39371 dtp->fmt = fmt;
39372 dtp->data1 = data1;
39373 dtp->data2 = data2;
39374 dtp->data3 = data3;
39375 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39376 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39377 dtp->jif = jiffies;
39378 #endif
39379 return;
39380 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39381 "slow_ring buffer\n");
39382 goto debug_failed;
39383 }
39384 - atomic_set(&phba->slow_ring_trc_cnt, 0);
39385 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
39386 memset(phba->slow_ring_trc, 0,
39387 (sizeof(struct lpfc_debugfs_trc) *
39388 lpfc_debugfs_max_slow_ring_trc));
39389 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39390 "buffer\n");
39391 goto debug_failed;
39392 }
39393 - atomic_set(&vport->disc_trc_cnt, 0);
39394 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
39395
39396 snprintf(name, sizeof(name), "discovery_trace");
39397 vport->debug_disc_trc =
39398 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
39399 index 89ad558..76956c4 100644
39400 --- a/drivers/scsi/lpfc/lpfc_init.c
39401 +++ b/drivers/scsi/lpfc/lpfc_init.c
39402 @@ -10618,8 +10618,10 @@ lpfc_init(void)
39403 "misc_register returned with status %d", error);
39404
39405 if (lpfc_enable_npiv) {
39406 - lpfc_transport_functions.vport_create = lpfc_vport_create;
39407 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39408 + pax_open_kernel();
39409 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
39410 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39411 + pax_close_kernel();
39412 }
39413 lpfc_transport_template =
39414 fc_attach_transport(&lpfc_transport_functions);
39415 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
39416 index 60e5a17..ff7a793 100644
39417 --- a/drivers/scsi/lpfc/lpfc_scsi.c
39418 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
39419 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
39420 uint32_t evt_posted;
39421
39422 spin_lock_irqsave(&phba->hbalock, flags);
39423 - atomic_inc(&phba->num_rsrc_err);
39424 + atomic_inc_unchecked(&phba->num_rsrc_err);
39425 phba->last_rsrc_error_time = jiffies;
39426
39427 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
39428 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
39429 unsigned long flags;
39430 struct lpfc_hba *phba = vport->phba;
39431 uint32_t evt_posted;
39432 - atomic_inc(&phba->num_cmd_success);
39433 + atomic_inc_unchecked(&phba->num_cmd_success);
39434
39435 if (vport->cfg_lun_queue_depth <= queue_depth)
39436 return;
39437 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39438 unsigned long num_rsrc_err, num_cmd_success;
39439 int i;
39440
39441 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
39442 - num_cmd_success = atomic_read(&phba->num_cmd_success);
39443 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
39444 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
39445
39446 /*
39447 * The error and success command counters are global per
39448 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39449 }
39450 }
39451 lpfc_destroy_vport_work_array(phba, vports);
39452 - atomic_set(&phba->num_rsrc_err, 0);
39453 - atomic_set(&phba->num_cmd_success, 0);
39454 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
39455 + atomic_set_unchecked(&phba->num_cmd_success, 0);
39456 }
39457
39458 /**
39459 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
39460 }
39461 }
39462 lpfc_destroy_vport_work_array(phba, vports);
39463 - atomic_set(&phba->num_rsrc_err, 0);
39464 - atomic_set(&phba->num_cmd_success, 0);
39465 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
39466 + atomic_set_unchecked(&phba->num_cmd_success, 0);
39467 }
39468
39469 /**
39470 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
39471 index b46f5e9..c4c4ccb 100644
39472 --- a/drivers/scsi/pmcraid.c
39473 +++ b/drivers/scsi/pmcraid.c
39474 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
39475 res->scsi_dev = scsi_dev;
39476 scsi_dev->hostdata = res;
39477 res->change_detected = 0;
39478 - atomic_set(&res->read_failures, 0);
39479 - atomic_set(&res->write_failures, 0);
39480 + atomic_set_unchecked(&res->read_failures, 0);
39481 + atomic_set_unchecked(&res->write_failures, 0);
39482 rc = 0;
39483 }
39484 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
39485 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
39486
39487 /* If this was a SCSI read/write command keep count of errors */
39488 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
39489 - atomic_inc(&res->read_failures);
39490 + atomic_inc_unchecked(&res->read_failures);
39491 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
39492 - atomic_inc(&res->write_failures);
39493 + atomic_inc_unchecked(&res->write_failures);
39494
39495 if (!RES_IS_GSCSI(res->cfg_entry) &&
39496 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
39497 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
39498 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39499 * hrrq_id assigned here in queuecommand
39500 */
39501 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39502 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39503 pinstance->num_hrrq;
39504 cmd->cmd_done = pmcraid_io_done;
39505
39506 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
39507 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39508 * hrrq_id assigned here in queuecommand
39509 */
39510 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39511 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39512 pinstance->num_hrrq;
39513
39514 if (request_size) {
39515 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
39516
39517 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
39518 /* add resources only after host is added into system */
39519 - if (!atomic_read(&pinstance->expose_resources))
39520 + if (!atomic_read_unchecked(&pinstance->expose_resources))
39521 return;
39522
39523 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
39524 @@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
39525 init_waitqueue_head(&pinstance->reset_wait_q);
39526
39527 atomic_set(&pinstance->outstanding_cmds, 0);
39528 - atomic_set(&pinstance->last_message_id, 0);
39529 - atomic_set(&pinstance->expose_resources, 0);
39530 + atomic_set_unchecked(&pinstance->last_message_id, 0);
39531 + atomic_set_unchecked(&pinstance->expose_resources, 0);
39532
39533 INIT_LIST_HEAD(&pinstance->free_res_q);
39534 INIT_LIST_HEAD(&pinstance->used_res_q);
39535 @@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
39536 /* Schedule worker thread to handle CCN and take care of adding and
39537 * removing devices to OS
39538 */
39539 - atomic_set(&pinstance->expose_resources, 1);
39540 + atomic_set_unchecked(&pinstance->expose_resources, 1);
39541 schedule_work(&pinstance->worker_q);
39542 return rc;
39543
39544 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
39545 index e1d150f..6c6df44 100644
39546 --- a/drivers/scsi/pmcraid.h
39547 +++ b/drivers/scsi/pmcraid.h
39548 @@ -748,7 +748,7 @@ struct pmcraid_instance {
39549 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
39550
39551 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
39552 - atomic_t last_message_id;
39553 + atomic_unchecked_t last_message_id;
39554
39555 /* configuration table */
39556 struct pmcraid_config_table *cfg_table;
39557 @@ -777,7 +777,7 @@ struct pmcraid_instance {
39558 atomic_t outstanding_cmds;
39559
39560 /* should add/delete resources to mid-layer now ?*/
39561 - atomic_t expose_resources;
39562 + atomic_unchecked_t expose_resources;
39563
39564
39565
39566 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
39567 struct pmcraid_config_table_entry_ext cfg_entry_ext;
39568 };
39569 struct scsi_device *scsi_dev; /* Link scsi_device structure */
39570 - atomic_t read_failures; /* count of failed READ commands */
39571 - atomic_t write_failures; /* count of failed WRITE commands */
39572 + atomic_unchecked_t read_failures; /* count of failed READ commands */
39573 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
39574
39575 /* To indicate add/delete/modify during CCN */
39576 u8 change_detected;
39577 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
39578 index 83d7984..a27d947 100644
39579 --- a/drivers/scsi/qla2xxx/qla_attr.c
39580 +++ b/drivers/scsi/qla2xxx/qla_attr.c
39581 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
39582 return 0;
39583 }
39584
39585 -struct fc_function_template qla2xxx_transport_functions = {
39586 +fc_function_template_no_const qla2xxx_transport_functions = {
39587
39588 .show_host_node_name = 1,
39589 .show_host_port_name = 1,
39590 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
39591 .bsg_timeout = qla24xx_bsg_timeout,
39592 };
39593
39594 -struct fc_function_template qla2xxx_transport_vport_functions = {
39595 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
39596
39597 .show_host_node_name = 1,
39598 .show_host_port_name = 1,
39599 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
39600 index 2411d1a..4673766 100644
39601 --- a/drivers/scsi/qla2xxx/qla_gbl.h
39602 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
39603 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
39604 struct device_attribute;
39605 extern struct device_attribute *qla2x00_host_attrs[];
39606 struct fc_function_template;
39607 -extern struct fc_function_template qla2xxx_transport_functions;
39608 -extern struct fc_function_template qla2xxx_transport_vport_functions;
39609 +extern fc_function_template_no_const qla2xxx_transport_functions;
39610 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
39611 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
39612 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
39613 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
39614 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
39615 index 10d23f8..a7d5d4c 100644
39616 --- a/drivers/scsi/qla2xxx/qla_os.c
39617 +++ b/drivers/scsi/qla2xxx/qla_os.c
39618 @@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
39619 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
39620 /* Ok, a 64bit DMA mask is applicable. */
39621 ha->flags.enable_64bit_addressing = 1;
39622 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39623 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39624 + pax_open_kernel();
39625 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39626 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39627 + pax_close_kernel();
39628 return;
39629 }
39630 }
39631 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
39632 index 329d553..f20d31d 100644
39633 --- a/drivers/scsi/qla4xxx/ql4_def.h
39634 +++ b/drivers/scsi/qla4xxx/ql4_def.h
39635 @@ -273,7 +273,7 @@ struct ddb_entry {
39636 * (4000 only) */
39637 atomic_t relogin_timer; /* Max Time to wait for
39638 * relogin to complete */
39639 - atomic_t relogin_retry_count; /* Num of times relogin has been
39640 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
39641 * retried */
39642 uint32_t default_time2wait; /* Default Min time between
39643 * relogins (+aens) */
39644 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
39645 index 4cec123..7c1329f 100644
39646 --- a/drivers/scsi/qla4xxx/ql4_os.c
39647 +++ b/drivers/scsi/qla4xxx/ql4_os.c
39648 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
39649 */
39650 if (!iscsi_is_session_online(cls_sess)) {
39651 /* Reset retry relogin timer */
39652 - atomic_inc(&ddb_entry->relogin_retry_count);
39653 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
39654 DEBUG2(ql4_printk(KERN_INFO, ha,
39655 "%s: index[%d] relogin timed out-retrying"
39656 " relogin (%d), retry (%d)\n", __func__,
39657 ddb_entry->fw_ddb_index,
39658 - atomic_read(&ddb_entry->relogin_retry_count),
39659 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
39660 ddb_entry->default_time2wait + 4));
39661 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
39662 atomic_set(&ddb_entry->retry_relogin_timer,
39663 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
39664
39665 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
39666 atomic_set(&ddb_entry->relogin_timer, 0);
39667 - atomic_set(&ddb_entry->relogin_retry_count, 0);
39668 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
39669 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
39670 ddb_entry->default_relogin_timeout =
39671 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
39672 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
39673 index 2c0d0ec..4e8681a 100644
39674 --- a/drivers/scsi/scsi.c
39675 +++ b/drivers/scsi/scsi.c
39676 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
39677 unsigned long timeout;
39678 int rtn = 0;
39679
39680 - atomic_inc(&cmd->device->iorequest_cnt);
39681 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39682
39683 /* check if the device is still usable */
39684 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39685 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
39686 index f1bf5af..f67e943 100644
39687 --- a/drivers/scsi/scsi_lib.c
39688 +++ b/drivers/scsi/scsi_lib.c
39689 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
39690 shost = sdev->host;
39691 scsi_init_cmd_errh(cmd);
39692 cmd->result = DID_NO_CONNECT << 16;
39693 - atomic_inc(&cmd->device->iorequest_cnt);
39694 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39695
39696 /*
39697 * SCSI request completion path will do scsi_device_unbusy(),
39698 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
39699
39700 INIT_LIST_HEAD(&cmd->eh_entry);
39701
39702 - atomic_inc(&cmd->device->iodone_cnt);
39703 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
39704 if (cmd->result)
39705 - atomic_inc(&cmd->device->ioerr_cnt);
39706 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39707
39708 disposition = scsi_decide_disposition(cmd);
39709 if (disposition != SUCCESS &&
39710 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
39711 index 931a7d9..0c2a754 100644
39712 --- a/drivers/scsi/scsi_sysfs.c
39713 +++ b/drivers/scsi/scsi_sysfs.c
39714 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
39715 char *buf) \
39716 { \
39717 struct scsi_device *sdev = to_scsi_device(dev); \
39718 - unsigned long long count = atomic_read(&sdev->field); \
39719 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
39720 return snprintf(buf, 20, "0x%llx\n", count); \
39721 } \
39722 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39723 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39724 index 84a1fdf..693b0d6 100644
39725 --- a/drivers/scsi/scsi_tgt_lib.c
39726 +++ b/drivers/scsi/scsi_tgt_lib.c
39727 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39728 int err;
39729
39730 dprintk("%lx %u\n", uaddr, len);
39731 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39732 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39733 if (err) {
39734 /*
39735 * TODO: need to fixup sg_tablesize, max_segment_size,
39736 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39737 index e894ca7..de9d7660 100644
39738 --- a/drivers/scsi/scsi_transport_fc.c
39739 +++ b/drivers/scsi/scsi_transport_fc.c
39740 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39741 * Netlink Infrastructure
39742 */
39743
39744 -static atomic_t fc_event_seq;
39745 +static atomic_unchecked_t fc_event_seq;
39746
39747 /**
39748 * fc_get_event_number - Obtain the next sequential FC event number
39749 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39750 u32
39751 fc_get_event_number(void)
39752 {
39753 - return atomic_add_return(1, &fc_event_seq);
39754 + return atomic_add_return_unchecked(1, &fc_event_seq);
39755 }
39756 EXPORT_SYMBOL(fc_get_event_number);
39757
39758 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39759 {
39760 int error;
39761
39762 - atomic_set(&fc_event_seq, 0);
39763 + atomic_set_unchecked(&fc_event_seq, 0);
39764
39765 error = transport_class_register(&fc_host_class);
39766 if (error)
39767 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39768 char *cp;
39769
39770 *val = simple_strtoul(buf, &cp, 0);
39771 - if ((*cp && (*cp != '\n')) || (*val < 0))
39772 + if (*cp && (*cp != '\n'))
39773 return -EINVAL;
39774 /*
39775 * Check for overflow; dev_loss_tmo is u32
39776 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39777 index 31969f2..2b348f0 100644
39778 --- a/drivers/scsi/scsi_transport_iscsi.c
39779 +++ b/drivers/scsi/scsi_transport_iscsi.c
39780 @@ -79,7 +79,7 @@ struct iscsi_internal {
39781 struct transport_container session_cont;
39782 };
39783
39784 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39785 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39786 static struct workqueue_struct *iscsi_eh_timer_workq;
39787
39788 static DEFINE_IDA(iscsi_sess_ida);
39789 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39790 int err;
39791
39792 ihost = shost->shost_data;
39793 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39794 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39795
39796 if (target_id == ISCSI_MAX_TARGET) {
39797 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39798 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39799 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39800 ISCSI_TRANSPORT_VERSION);
39801
39802 - atomic_set(&iscsi_session_nr, 0);
39803 + atomic_set_unchecked(&iscsi_session_nr, 0);
39804
39805 err = class_register(&iscsi_transport_class);
39806 if (err)
39807 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39808 index f379c7f..e8fc69c 100644
39809 --- a/drivers/scsi/scsi_transport_srp.c
39810 +++ b/drivers/scsi/scsi_transport_srp.c
39811 @@ -33,7 +33,7 @@
39812 #include "scsi_transport_srp_internal.h"
39813
39814 struct srp_host_attrs {
39815 - atomic_t next_port_id;
39816 + atomic_unchecked_t next_port_id;
39817 };
39818 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39819
39820 @@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39821 struct Scsi_Host *shost = dev_to_shost(dev);
39822 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39823
39824 - atomic_set(&srp_host->next_port_id, 0);
39825 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39826 return 0;
39827 }
39828
39829 @@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39830 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39831 rport->roles = ids->roles;
39832
39833 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39834 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39835 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39836
39837 transport_setup_device(&rport->dev);
39838 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39839 index 7992635..609faf8 100644
39840 --- a/drivers/scsi/sd.c
39841 +++ b/drivers/scsi/sd.c
39842 @@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
39843 sdkp->disk = gd;
39844 sdkp->index = index;
39845 atomic_set(&sdkp->openers, 0);
39846 - atomic_set(&sdkp->device->ioerr_cnt, 0);
39847 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39848
39849 if (!sdp->request_queue->rq_timeout) {
39850 if (sdp->type != TYPE_MOD)
39851 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39852 index be2c9a6..275525c 100644
39853 --- a/drivers/scsi/sg.c
39854 +++ b/drivers/scsi/sg.c
39855 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39856 sdp->disk->disk_name,
39857 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39858 NULL,
39859 - (char *)arg);
39860 + (char __user *)arg);
39861 case BLKTRACESTART:
39862 return blk_trace_startstop(sdp->device->request_queue, 1);
39863 case BLKTRACESTOP:
39864 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39865 index 19ee901..6e8c2ef 100644
39866 --- a/drivers/spi/spi.c
39867 +++ b/drivers/spi/spi.c
39868 @@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
39869 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39870
39871 /* portable code must never pass more than 32 bytes */
39872 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39873 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39874
39875 static u8 *buf;
39876
39877 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39878 index 34afc16..ffe44dd 100644
39879 --- a/drivers/staging/octeon/ethernet-rx.c
39880 +++ b/drivers/staging/octeon/ethernet-rx.c
39881 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39882 /* Increment RX stats for virtual ports */
39883 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39884 #ifdef CONFIG_64BIT
39885 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39886 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39887 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39888 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39889 #else
39890 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39891 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39892 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39893 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39894 #endif
39895 }
39896 netif_receive_skb(skb);
39897 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39898 dev->name);
39899 */
39900 #ifdef CONFIG_64BIT
39901 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39902 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39903 #else
39904 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39905 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39906 #endif
39907 dev_kfree_skb_irq(skb);
39908 }
39909 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39910 index ef32dc1..a159d68 100644
39911 --- a/drivers/staging/octeon/ethernet.c
39912 +++ b/drivers/staging/octeon/ethernet.c
39913 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39914 * since the RX tasklet also increments it.
39915 */
39916 #ifdef CONFIG_64BIT
39917 - atomic64_add(rx_status.dropped_packets,
39918 - (atomic64_t *)&priv->stats.rx_dropped);
39919 + atomic64_add_unchecked(rx_status.dropped_packets,
39920 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39921 #else
39922 - atomic_add(rx_status.dropped_packets,
39923 - (atomic_t *)&priv->stats.rx_dropped);
39924 + atomic_add_unchecked(rx_status.dropped_packets,
39925 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39926 #endif
39927 }
39928
39929 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39930 index a2b7e03..aaf3630 100644
39931 --- a/drivers/staging/ramster/tmem.c
39932 +++ b/drivers/staging/ramster/tmem.c
39933 @@ -50,25 +50,25 @@
39934 * A tmem host implementation must use this function to register callbacks
39935 * for memory allocation.
39936 */
39937 -static struct tmem_hostops tmem_hostops;
39938 +static struct tmem_hostops *tmem_hostops;
39939
39940 static void tmem_objnode_tree_init(void);
39941
39942 void tmem_register_hostops(struct tmem_hostops *m)
39943 {
39944 tmem_objnode_tree_init();
39945 - tmem_hostops = *m;
39946 + tmem_hostops = m;
39947 }
39948
39949 /*
39950 * A tmem host implementation must use this function to register
39951 * callbacks for a page-accessible memory (PAM) implementation.
39952 */
39953 -static struct tmem_pamops tmem_pamops;
39954 +static struct tmem_pamops *tmem_pamops;
39955
39956 void tmem_register_pamops(struct tmem_pamops *m)
39957 {
39958 - tmem_pamops = *m;
39959 + tmem_pamops = m;
39960 }
39961
39962 /*
39963 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39964 obj->pampd_count = 0;
39965 #ifdef CONFIG_RAMSTER
39966 if (tmem_pamops.new_obj != NULL)
39967 - (*tmem_pamops.new_obj)(obj);
39968 + (tmem_pamops->new_obj)(obj);
39969 #endif
39970 SET_SENTINEL(obj, OBJ);
39971
39972 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39973 rbnode = rb_next(rbnode);
39974 tmem_pampd_destroy_all_in_obj(obj, true);
39975 tmem_obj_free(obj, hb);
39976 - (*tmem_hostops.obj_free)(obj, pool);
39977 + (tmem_hostops->obj_free)(obj, pool);
39978 }
39979 spin_unlock(&hb->lock);
39980 }
39981 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39982 ASSERT_SENTINEL(obj, OBJ);
39983 BUG_ON(obj->pool == NULL);
39984 ASSERT_SENTINEL(obj->pool, POOL);
39985 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39986 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39987 if (unlikely(objnode == NULL))
39988 goto out;
39989 objnode->obj = obj;
39990 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39991 ASSERT_SENTINEL(pool, POOL);
39992 objnode->obj->objnode_count--;
39993 objnode->obj = NULL;
39994 - (*tmem_hostops.objnode_free)(objnode, pool);
39995 + (tmem_hostops->objnode_free)(objnode, pool);
39996 }
39997
39998 /*
39999 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
40000 void *old_pampd = *(void **)slot;
40001 *(void **)slot = new_pampd;
40002 if (!no_free)
40003 - (*tmem_pamops.free)(old_pampd, obj->pool,
40004 + (tmem_pamops->free)(old_pampd, obj->pool,
40005 NULL, 0, false);
40006 ret = new_pampd;
40007 }
40008 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
40009 if (objnode->slots[i]) {
40010 if (ht == 1) {
40011 obj->pampd_count--;
40012 - (*tmem_pamops.free)(objnode->slots[i],
40013 + (tmem_pamops->free)(objnode->slots[i],
40014 obj->pool, NULL, 0, true);
40015 objnode->slots[i] = NULL;
40016 continue;
40017 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40018 return;
40019 if (obj->objnode_tree_height == 0) {
40020 obj->pampd_count--;
40021 - (*tmem_pamops.free)(obj->objnode_tree_root,
40022 + (tmem_pamops->free)(obj->objnode_tree_root,
40023 obj->pool, NULL, 0, true);
40024 } else {
40025 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
40026 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40027 obj->objnode_tree_root = NULL;
40028 #ifdef CONFIG_RAMSTER
40029 if (tmem_pamops.free_obj != NULL)
40030 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
40031 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
40032 #endif
40033 }
40034
40035 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40036 /* if found, is a dup put, flush the old one */
40037 pampd_del = tmem_pampd_delete_from_obj(obj, index);
40038 BUG_ON(pampd_del != pampd);
40039 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40040 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
40041 if (obj->pampd_count == 0) {
40042 objnew = obj;
40043 objfound = NULL;
40044 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40045 pampd = NULL;
40046 }
40047 } else {
40048 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
40049 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
40050 if (unlikely(obj == NULL)) {
40051 ret = -ENOMEM;
40052 goto out;
40053 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40054 if (unlikely(ret == -ENOMEM))
40055 /* may have partially built objnode tree ("stump") */
40056 goto delete_and_free;
40057 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
40058 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
40059 goto out;
40060
40061 delete_and_free:
40062 (void)tmem_pampd_delete_from_obj(obj, index);
40063 if (pampd)
40064 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
40065 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
40066 if (objnew) {
40067 tmem_obj_free(objnew, hb);
40068 - (*tmem_hostops.obj_free)(objnew, pool);
40069 + (tmem_hostops->obj_free)(objnew, pool);
40070 }
40071 out:
40072 spin_unlock(&hb->lock);
40073 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
40074 if (pampd != NULL) {
40075 BUG_ON(obj == NULL);
40076 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
40077 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
40078 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
40079 } else if (delete) {
40080 BUG_ON(obj == NULL);
40081 (void)tmem_pampd_delete_from_obj(obj, index);
40082 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40083 int ret = 0;
40084
40085 if (!is_ephemeral(pool))
40086 - new_pampd = (*tmem_pamops.repatriate_preload)(
40087 + new_pampd = (tmem_pamops->repatriate_preload)(
40088 old_pampd, pool, oidp, index, &intransit);
40089 if (intransit)
40090 ret = -EAGAIN;
40091 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40092 /* must release the hb->lock else repatriate can't sleep */
40093 spin_unlock(&hb->lock);
40094 if (!intransit)
40095 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
40096 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
40097 oidp, index, free, data);
40098 if (ret == -EAGAIN) {
40099 /* rare I think, but should cond_resched()??? */
40100 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
40101 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
40102 /* if we bug here, pamops wasn't properly set up for ramster */
40103 BUG_ON(tmem_pamops.replace_in_obj == NULL);
40104 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
40105 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
40106 out:
40107 spin_unlock(&hb->lock);
40108 return ret;
40109 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40110 if (free) {
40111 if (obj->pampd_count == 0) {
40112 tmem_obj_free(obj, hb);
40113 - (*tmem_hostops.obj_free)(obj, pool);
40114 + (tmem_hostops->obj_free)(obj, pool);
40115 obj = NULL;
40116 }
40117 }
40118 if (free)
40119 - ret = (*tmem_pamops.get_data_and_free)(
40120 + ret = (tmem_pamops->get_data_and_free)(
40121 data, sizep, raw, pampd, pool, oidp, index);
40122 else
40123 - ret = (*tmem_pamops.get_data)(
40124 + ret = (tmem_pamops->get_data)(
40125 data, sizep, raw, pampd, pool, oidp, index);
40126 if (ret < 0)
40127 goto out;
40128 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
40129 pampd = tmem_pampd_delete_from_obj(obj, index);
40130 if (pampd == NULL)
40131 goto out;
40132 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40133 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
40134 if (obj->pampd_count == 0) {
40135 tmem_obj_free(obj, hb);
40136 - (*tmem_hostops.obj_free)(obj, pool);
40137 + (tmem_hostops->obj_free)(obj, pool);
40138 }
40139 ret = 0;
40140
40141 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
40142 goto out;
40143 tmem_pampd_destroy_all_in_obj(obj, false);
40144 tmem_obj_free(obj, hb);
40145 - (*tmem_hostops.obj_free)(obj, pool);
40146 + (tmem_hostops->obj_free)(obj, pool);
40147 ret = 0;
40148
40149 out:
40150 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
40151 index dc23395..cf7e9b1 100644
40152 --- a/drivers/staging/rtl8712/rtl871x_io.h
40153 +++ b/drivers/staging/rtl8712/rtl871x_io.h
40154 @@ -108,7 +108,7 @@ struct _io_ops {
40155 u8 *pmem);
40156 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
40157 u8 *pmem);
40158 -};
40159 +} __no_const;
40160
40161 struct io_req {
40162 struct list_head list;
40163 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
40164 index 1f5088b..0e59820 100644
40165 --- a/drivers/staging/sbe-2t3e3/netdev.c
40166 +++ b/drivers/staging/sbe-2t3e3/netdev.c
40167 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40168 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
40169
40170 if (rlen)
40171 - if (copy_to_user(data, &resp, rlen))
40172 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
40173 return -EFAULT;
40174
40175 return 0;
40176 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
40177 index 5dddc4d..34fcb2f 100644
40178 --- a/drivers/staging/usbip/vhci.h
40179 +++ b/drivers/staging/usbip/vhci.h
40180 @@ -83,7 +83,7 @@ struct vhci_hcd {
40181 unsigned resuming:1;
40182 unsigned long re_timeout;
40183
40184 - atomic_t seqnum;
40185 + atomic_unchecked_t seqnum;
40186
40187 /*
40188 * NOTE:
40189 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
40190 index c3aa219..bf8b3de 100644
40191 --- a/drivers/staging/usbip/vhci_hcd.c
40192 +++ b/drivers/staging/usbip/vhci_hcd.c
40193 @@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
40194 return;
40195 }
40196
40197 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40198 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40199 if (priv->seqnum == 0xffff)
40200 dev_info(&urb->dev->dev, "seqnum max\n");
40201
40202 @@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
40203 return -ENOMEM;
40204 }
40205
40206 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40207 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40208 if (unlink->seqnum == 0xffff)
40209 pr_info("seqnum max\n");
40210
40211 @@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
40212 vdev->rhport = rhport;
40213 }
40214
40215 - atomic_set(&vhci->seqnum, 0);
40216 + atomic_set_unchecked(&vhci->seqnum, 0);
40217 spin_lock_init(&vhci->lock);
40218
40219 hcd->power_budget = 0; /* no limit */
40220 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
40221 index ba5f1c0..11d8122 100644
40222 --- a/drivers/staging/usbip/vhci_rx.c
40223 +++ b/drivers/staging/usbip/vhci_rx.c
40224 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
40225 if (!urb) {
40226 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
40227 pr_info("max seqnum %d\n",
40228 - atomic_read(&the_controller->seqnum));
40229 + atomic_read_unchecked(&the_controller->seqnum));
40230 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40231 return;
40232 }
40233 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
40234 index 5f13890..36a044b 100644
40235 --- a/drivers/staging/vt6655/hostap.c
40236 +++ b/drivers/staging/vt6655/hostap.c
40237 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
40238 *
40239 */
40240
40241 +static net_device_ops_no_const apdev_netdev_ops;
40242 +
40243 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40244 {
40245 PSDevice apdev_priv;
40246 struct net_device *dev = pDevice->dev;
40247 int ret;
40248 - const struct net_device_ops apdev_netdev_ops = {
40249 - .ndo_start_xmit = pDevice->tx_80211,
40250 - };
40251
40252 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40253
40254 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40255 *apdev_priv = *pDevice;
40256 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40257
40258 + /* only half broken now */
40259 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40260 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40261
40262 pDevice->apdev->type = ARPHRD_IEEE80211;
40263 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
40264 index 26a7d0e..897b083 100644
40265 --- a/drivers/staging/vt6656/hostap.c
40266 +++ b/drivers/staging/vt6656/hostap.c
40267 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
40268 *
40269 */
40270
40271 +static net_device_ops_no_const apdev_netdev_ops;
40272 +
40273 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40274 {
40275 PSDevice apdev_priv;
40276 struct net_device *dev = pDevice->dev;
40277 int ret;
40278 - const struct net_device_ops apdev_netdev_ops = {
40279 - .ndo_start_xmit = pDevice->tx_80211,
40280 - };
40281
40282 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40283
40284 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40285 *apdev_priv = *pDevice;
40286 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40287
40288 + /* only half broken now */
40289 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40290 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40291
40292 pDevice->apdev->type = ARPHRD_IEEE80211;
40293 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
40294 index 56c8e60..1920c63 100644
40295 --- a/drivers/staging/zcache/tmem.c
40296 +++ b/drivers/staging/zcache/tmem.c
40297 @@ -39,7 +39,7 @@
40298 * A tmem host implementation must use this function to register callbacks
40299 * for memory allocation.
40300 */
40301 -static struct tmem_hostops tmem_hostops;
40302 +static tmem_hostops_no_const tmem_hostops;
40303
40304 static void tmem_objnode_tree_init(void);
40305
40306 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
40307 * A tmem host implementation must use this function to register
40308 * callbacks for a page-accessible memory (PAM) implementation
40309 */
40310 -static struct tmem_pamops tmem_pamops;
40311 +static tmem_pamops_no_const tmem_pamops;
40312
40313 void tmem_register_pamops(struct tmem_pamops *m)
40314 {
40315 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
40316 index 0d4aa82..f7832d4 100644
40317 --- a/drivers/staging/zcache/tmem.h
40318 +++ b/drivers/staging/zcache/tmem.h
40319 @@ -180,6 +180,7 @@ struct tmem_pamops {
40320 void (*new_obj)(struct tmem_obj *);
40321 int (*replace_in_obj)(void *, struct tmem_obj *);
40322 };
40323 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
40324 extern void tmem_register_pamops(struct tmem_pamops *m);
40325
40326 /* memory allocation methods provided by the host implementation */
40327 @@ -189,6 +190,7 @@ struct tmem_hostops {
40328 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
40329 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
40330 };
40331 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
40332 extern void tmem_register_hostops(struct tmem_hostops *m);
40333
40334 /* core tmem accessor functions */
40335 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
40336 index f2aa754..11337b1 100644
40337 --- a/drivers/target/target_core_device.c
40338 +++ b/drivers/target/target_core_device.c
40339 @@ -1375,7 +1375,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
40340 spin_lock_init(&dev->se_port_lock);
40341 spin_lock_init(&dev->se_tmr_lock);
40342 spin_lock_init(&dev->qf_cmd_lock);
40343 - atomic_set(&dev->dev_ordered_id, 0);
40344 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
40345 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
40346 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
40347 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
40348 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
40349 index bd587b7..173daf3 100644
40350 --- a/drivers/target/target_core_transport.c
40351 +++ b/drivers/target/target_core_transport.c
40352 @@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
40353 * Used to determine when ORDERED commands should go from
40354 * Dormant to Active status.
40355 */
40356 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
40357 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
40358 smp_mb__after_atomic_inc();
40359 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40360 cmd->se_ordered_id, cmd->sam_task_attr,
40361 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
40362 index b09c8d1f..c4225c0 100644
40363 --- a/drivers/tty/cyclades.c
40364 +++ b/drivers/tty/cyclades.c
40365 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
40366 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
40367 info->port.count);
40368 #endif
40369 - info->port.count++;
40370 + atomic_inc(&info->port.count);
40371 #ifdef CY_DEBUG_COUNT
40372 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
40373 - current->pid, info->port.count);
40374 + current->pid, atomic_read(&info->port.count));
40375 #endif
40376
40377 /*
40378 @@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
40379 for (j = 0; j < cy_card[i].nports; j++) {
40380 info = &cy_card[i].ports[j];
40381
40382 - if (info->port.count) {
40383 + if (atomic_read(&info->port.count)) {
40384 /* XXX is the ldisc num worth this? */
40385 struct tty_struct *tty;
40386 struct tty_ldisc *ld;
40387 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
40388 index 13ee53b..418d164 100644
40389 --- a/drivers/tty/hvc/hvc_console.c
40390 +++ b/drivers/tty/hvc/hvc_console.c
40391 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
40392
40393 spin_lock_irqsave(&hp->port.lock, flags);
40394 /* Check and then increment for fast path open. */
40395 - if (hp->port.count++ > 0) {
40396 + if (atomic_inc_return(&hp->port.count) > 1) {
40397 spin_unlock_irqrestore(&hp->port.lock, flags);
40398 hvc_kick();
40399 return 0;
40400 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40401
40402 spin_lock_irqsave(&hp->port.lock, flags);
40403
40404 - if (--hp->port.count == 0) {
40405 + if (atomic_dec_return(&hp->port.count) == 0) {
40406 spin_unlock_irqrestore(&hp->port.lock, flags);
40407 /* We are done with the tty pointer now. */
40408 tty_port_tty_set(&hp->port, NULL);
40409 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40410 */
40411 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
40412 } else {
40413 - if (hp->port.count < 0)
40414 + if (atomic_read(&hp->port.count) < 0)
40415 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
40416 - hp->vtermno, hp->port.count);
40417 + hp->vtermno, atomic_read(&hp->port.count));
40418 spin_unlock_irqrestore(&hp->port.lock, flags);
40419 }
40420 }
40421 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
40422 * open->hangup case this can be called after the final close so prevent
40423 * that from happening for now.
40424 */
40425 - if (hp->port.count <= 0) {
40426 + if (atomic_read(&hp->port.count) <= 0) {
40427 spin_unlock_irqrestore(&hp->port.lock, flags);
40428 return;
40429 }
40430
40431 - hp->port.count = 0;
40432 + atomic_set(&hp->port.count, 0);
40433 spin_unlock_irqrestore(&hp->port.lock, flags);
40434 tty_port_tty_set(&hp->port, NULL);
40435
40436 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
40437 return -EPIPE;
40438
40439 /* FIXME what's this (unprotected) check for? */
40440 - if (hp->port.count <= 0)
40441 + if (atomic_read(&hp->port.count) <= 0)
40442 return -EIO;
40443
40444 spin_lock_irqsave(&hp->lock, flags);
40445 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
40446 index 8776357..b2d4afd 100644
40447 --- a/drivers/tty/hvc/hvcs.c
40448 +++ b/drivers/tty/hvc/hvcs.c
40449 @@ -83,6 +83,7 @@
40450 #include <asm/hvcserver.h>
40451 #include <asm/uaccess.h>
40452 #include <asm/vio.h>
40453 +#include <asm/local.h>
40454
40455 /*
40456 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40457 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
40458
40459 spin_lock_irqsave(&hvcsd->lock, flags);
40460
40461 - if (hvcsd->port.count > 0) {
40462 + if (atomic_read(&hvcsd->port.count) > 0) {
40463 spin_unlock_irqrestore(&hvcsd->lock, flags);
40464 printk(KERN_INFO "HVCS: vterm state unchanged. "
40465 "The hvcs device node is still in use.\n");
40466 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
40467 }
40468 }
40469
40470 - hvcsd->port.count = 0;
40471 + atomic_set(&hvcsd->port.count, 0);
40472 hvcsd->port.tty = tty;
40473 tty->driver_data = hvcsd;
40474
40475 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
40476 unsigned long flags;
40477
40478 spin_lock_irqsave(&hvcsd->lock, flags);
40479 - hvcsd->port.count++;
40480 + atomic_inc(&hvcsd->port.count);
40481 hvcsd->todo_mask |= HVCS_SCHED_READ;
40482 spin_unlock_irqrestore(&hvcsd->lock, flags);
40483
40484 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40485 hvcsd = tty->driver_data;
40486
40487 spin_lock_irqsave(&hvcsd->lock, flags);
40488 - if (--hvcsd->port.count == 0) {
40489 + if (atomic_dec_and_test(&hvcsd->port.count)) {
40490
40491 vio_disable_interrupts(hvcsd->vdev);
40492
40493 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40494
40495 free_irq(irq, hvcsd);
40496 return;
40497 - } else if (hvcsd->port.count < 0) {
40498 + } else if (atomic_read(&hvcsd->port.count) < 0) {
40499 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40500 " is missmanaged.\n",
40501 - hvcsd->vdev->unit_address, hvcsd->port.count);
40502 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
40503 }
40504
40505 spin_unlock_irqrestore(&hvcsd->lock, flags);
40506 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40507
40508 spin_lock_irqsave(&hvcsd->lock, flags);
40509 /* Preserve this so that we know how many kref refs to put */
40510 - temp_open_count = hvcsd->port.count;
40511 + temp_open_count = atomic_read(&hvcsd->port.count);
40512
40513 /*
40514 * Don't kref put inside the spinlock because the destruction
40515 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40516 tty->driver_data = NULL;
40517 hvcsd->port.tty = NULL;
40518
40519 - hvcsd->port.count = 0;
40520 + atomic_set(&hvcsd->port.count, 0);
40521
40522 /* This will drop any buffered data on the floor which is OK in a hangup
40523 * scenario. */
40524 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
40525 * the middle of a write operation? This is a crummy place to do this
40526 * but we want to keep it all in the spinlock.
40527 */
40528 - if (hvcsd->port.count <= 0) {
40529 + if (atomic_read(&hvcsd->port.count) <= 0) {
40530 spin_unlock_irqrestore(&hvcsd->lock, flags);
40531 return -ENODEV;
40532 }
40533 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
40534 {
40535 struct hvcs_struct *hvcsd = tty->driver_data;
40536
40537 - if (!hvcsd || hvcsd->port.count <= 0)
40538 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
40539 return 0;
40540
40541 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40542 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
40543 index 2cde13d..645d78f 100644
40544 --- a/drivers/tty/ipwireless/tty.c
40545 +++ b/drivers/tty/ipwireless/tty.c
40546 @@ -29,6 +29,7 @@
40547 #include <linux/tty_driver.h>
40548 #include <linux/tty_flip.h>
40549 #include <linux/uaccess.h>
40550 +#include <asm/local.h>
40551
40552 #include "tty.h"
40553 #include "network.h"
40554 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40555 mutex_unlock(&tty->ipw_tty_mutex);
40556 return -ENODEV;
40557 }
40558 - if (tty->port.count == 0)
40559 + if (atomic_read(&tty->port.count) == 0)
40560 tty->tx_bytes_queued = 0;
40561
40562 - tty->port.count++;
40563 + atomic_inc(&tty->port.count);
40564
40565 tty->port.tty = linux_tty;
40566 linux_tty->driver_data = tty;
40567 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40568
40569 static void do_ipw_close(struct ipw_tty *tty)
40570 {
40571 - tty->port.count--;
40572 -
40573 - if (tty->port.count == 0) {
40574 + if (atomic_dec_return(&tty->port.count) == 0) {
40575 struct tty_struct *linux_tty = tty->port.tty;
40576
40577 if (linux_tty != NULL) {
40578 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
40579 return;
40580
40581 mutex_lock(&tty->ipw_tty_mutex);
40582 - if (tty->port.count == 0) {
40583 + if (atomic_read(&tty->port.count) == 0) {
40584 mutex_unlock(&tty->ipw_tty_mutex);
40585 return;
40586 }
40587 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
40588 return;
40589 }
40590
40591 - if (!tty->port.count) {
40592 + if (!atomic_read(&tty->port.count)) {
40593 mutex_unlock(&tty->ipw_tty_mutex);
40594 return;
40595 }
40596 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
40597 return -ENODEV;
40598
40599 mutex_lock(&tty->ipw_tty_mutex);
40600 - if (!tty->port.count) {
40601 + if (!atomic_read(&tty->port.count)) {
40602 mutex_unlock(&tty->ipw_tty_mutex);
40603 return -EINVAL;
40604 }
40605 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
40606 if (!tty)
40607 return -ENODEV;
40608
40609 - if (!tty->port.count)
40610 + if (!atomic_read(&tty->port.count))
40611 return -EINVAL;
40612
40613 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40614 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
40615 if (!tty)
40616 return 0;
40617
40618 - if (!tty->port.count)
40619 + if (!atomic_read(&tty->port.count))
40620 return 0;
40621
40622 return tty->tx_bytes_queued;
40623 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
40624 if (!tty)
40625 return -ENODEV;
40626
40627 - if (!tty->port.count)
40628 + if (!atomic_read(&tty->port.count))
40629 return -EINVAL;
40630
40631 return get_control_lines(tty);
40632 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
40633 if (!tty)
40634 return -ENODEV;
40635
40636 - if (!tty->port.count)
40637 + if (!atomic_read(&tty->port.count))
40638 return -EINVAL;
40639
40640 return set_control_lines(tty, set, clear);
40641 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
40642 if (!tty)
40643 return -ENODEV;
40644
40645 - if (!tty->port.count)
40646 + if (!atomic_read(&tty->port.count))
40647 return -EINVAL;
40648
40649 /* FIXME: Exactly how is the tty object locked here .. */
40650 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
40651 * are gone */
40652 mutex_lock(&ttyj->ipw_tty_mutex);
40653 }
40654 - while (ttyj->port.count)
40655 + while (atomic_read(&ttyj->port.count))
40656 do_ipw_close(ttyj);
40657 ipwireless_disassociate_network_ttys(network,
40658 ttyj->channel_idx);
40659 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
40660 index f9d2850..b006f04 100644
40661 --- a/drivers/tty/moxa.c
40662 +++ b/drivers/tty/moxa.c
40663 @@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
40664 }
40665
40666 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
40667 - ch->port.count++;
40668 + atomic_inc(&ch->port.count);
40669 tty->driver_data = ch;
40670 tty_port_tty_set(&ch->port, tty);
40671 mutex_lock(&ch->port.mutex);
40672 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
40673 index dcc0430..040bef9 100644
40674 --- a/drivers/tty/n_gsm.c
40675 +++ b/drivers/tty/n_gsm.c
40676 @@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
40677 spin_lock_init(&dlci->lock);
40678 mutex_init(&dlci->mutex);
40679 dlci->fifo = &dlci->_fifo;
40680 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40681 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40682 kfree(dlci);
40683 return NULL;
40684 }
40685 @@ -2924,7 +2924,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
40686 struct gsm_dlci *dlci = tty->driver_data;
40687 struct tty_port *port = &dlci->port;
40688
40689 - port->count++;
40690 + atomic_inc(&port->count);
40691 dlci_get(dlci);
40692 dlci_get(dlci->gsm->dlci[0]);
40693 mux_get(dlci->gsm);
40694 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
40695 index 19083ef..6e34e97 100644
40696 --- a/drivers/tty/n_tty.c
40697 +++ b/drivers/tty/n_tty.c
40698 @@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
40699 {
40700 *ops = tty_ldisc_N_TTY;
40701 ops->owner = NULL;
40702 - ops->refcount = ops->flags = 0;
40703 + atomic_set(&ops->refcount, 0);
40704 + ops->flags = 0;
40705 }
40706 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40707 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
40708 index 79ff3a5..1fe9399 100644
40709 --- a/drivers/tty/pty.c
40710 +++ b/drivers/tty/pty.c
40711 @@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
40712 panic("Couldn't register Unix98 pts driver");
40713
40714 /* Now create the /dev/ptmx special device */
40715 + pax_open_kernel();
40716 tty_default_fops(&ptmx_fops);
40717 - ptmx_fops.open = ptmx_open;
40718 + *(void **)&ptmx_fops.open = ptmx_open;
40719 + pax_close_kernel();
40720
40721 cdev_init(&ptmx_cdev, &ptmx_fops);
40722 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40723 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40724 index e42009a..566a036 100644
40725 --- a/drivers/tty/rocket.c
40726 +++ b/drivers/tty/rocket.c
40727 @@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40728 tty->driver_data = info;
40729 tty_port_tty_set(port, tty);
40730
40731 - if (port->count++ == 0) {
40732 + if (atomic_inc_return(&port->count) == 1) {
40733 atomic_inc(&rp_num_ports_open);
40734
40735 #ifdef ROCKET_DEBUG_OPEN
40736 @@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40737 #endif
40738 }
40739 #ifdef ROCKET_DEBUG_OPEN
40740 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40741 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40742 #endif
40743
40744 /*
40745 @@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
40746 spin_unlock_irqrestore(&info->port.lock, flags);
40747 return;
40748 }
40749 - if (info->port.count)
40750 + if (atomic_read(&info->port.count))
40751 atomic_dec(&rp_num_ports_open);
40752 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40753 spin_unlock_irqrestore(&info->port.lock, flags);
40754 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40755 index 1002054..dd644a8 100644
40756 --- a/drivers/tty/serial/kgdboc.c
40757 +++ b/drivers/tty/serial/kgdboc.c
40758 @@ -24,8 +24,9 @@
40759 #define MAX_CONFIG_LEN 40
40760
40761 static struct kgdb_io kgdboc_io_ops;
40762 +static struct kgdb_io kgdboc_io_ops_console;
40763
40764 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40765 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40766 static int configured = -1;
40767
40768 static char config[MAX_CONFIG_LEN];
40769 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40770 kgdboc_unregister_kbd();
40771 if (configured == 1)
40772 kgdb_unregister_io_module(&kgdboc_io_ops);
40773 + else if (configured == 2)
40774 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
40775 }
40776
40777 static int configure_kgdboc(void)
40778 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40779 int err;
40780 char *cptr = config;
40781 struct console *cons;
40782 + int is_console = 0;
40783
40784 err = kgdboc_option_setup(config);
40785 if (err || !strlen(config) || isspace(config[0]))
40786 goto noconfig;
40787
40788 err = -ENODEV;
40789 - kgdboc_io_ops.is_console = 0;
40790 kgdb_tty_driver = NULL;
40791
40792 kgdboc_use_kms = 0;
40793 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40794 int idx;
40795 if (cons->device && cons->device(cons, &idx) == p &&
40796 idx == tty_line) {
40797 - kgdboc_io_ops.is_console = 1;
40798 + is_console = 1;
40799 break;
40800 }
40801 cons = cons->next;
40802 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40803 kgdb_tty_line = tty_line;
40804
40805 do_register:
40806 - err = kgdb_register_io_module(&kgdboc_io_ops);
40807 + if (is_console) {
40808 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
40809 + configured = 2;
40810 + } else {
40811 + err = kgdb_register_io_module(&kgdboc_io_ops);
40812 + configured = 1;
40813 + }
40814 if (err)
40815 goto noconfig;
40816
40817 @@ -205,8 +214,6 @@ do_register:
40818 if (err)
40819 goto nmi_con_failed;
40820
40821 - configured = 1;
40822 -
40823 return 0;
40824
40825 nmi_con_failed:
40826 @@ -223,7 +230,7 @@ noconfig:
40827 static int __init init_kgdboc(void)
40828 {
40829 /* Already configured? */
40830 - if (configured == 1)
40831 + if (configured >= 1)
40832 return 0;
40833
40834 return configure_kgdboc();
40835 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40836 if (config[len - 1] == '\n')
40837 config[len - 1] = '\0';
40838
40839 - if (configured == 1)
40840 + if (configured >= 1)
40841 cleanup_kgdboc();
40842
40843 /* Go and configure with the new params. */
40844 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40845 .post_exception = kgdboc_post_exp_handler,
40846 };
40847
40848 +static struct kgdb_io kgdboc_io_ops_console = {
40849 + .name = "kgdboc",
40850 + .read_char = kgdboc_get_char,
40851 + .write_char = kgdboc_put_char,
40852 + .pre_exception = kgdboc_pre_exp_handler,
40853 + .post_exception = kgdboc_post_exp_handler,
40854 + .is_console = 1
40855 +};
40856 +
40857 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40858 /* This is only available if kgdboc is a built in for early debugging */
40859 static int __init kgdboc_early_init(char *opt)
40860 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40861 index e514b3a..c73d614 100644
40862 --- a/drivers/tty/serial/samsung.c
40863 +++ b/drivers/tty/serial/samsung.c
40864 @@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40865 }
40866 }
40867
40868 +static int s3c64xx_serial_startup(struct uart_port *port);
40869 static int s3c24xx_serial_startup(struct uart_port *port)
40870 {
40871 struct s3c24xx_uart_port *ourport = to_ourport(port);
40872 int ret;
40873
40874 + /* Startup sequence is different for s3c64xx and higher SoC's */
40875 + if (s3c24xx_serial_has_interrupt_mask(port))
40876 + return s3c64xx_serial_startup(port);
40877 +
40878 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40879 port->mapbase, port->membase);
40880
40881 @@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40882 /* setup info for port */
40883 port->dev = &platdev->dev;
40884
40885 - /* Startup sequence is different for s3c64xx and higher SoC's */
40886 - if (s3c24xx_serial_has_interrupt_mask(port))
40887 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40888 -
40889 port->uartclk = 1;
40890
40891 if (cfg->uart_flags & UPF_CONS_FLOW) {
40892 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40893 index 2c7230a..2104f16 100644
40894 --- a/drivers/tty/serial/serial_core.c
40895 +++ b/drivers/tty/serial/serial_core.c
40896 @@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
40897 uart_flush_buffer(tty);
40898 uart_shutdown(tty, state);
40899 spin_lock_irqsave(&port->lock, flags);
40900 - port->count = 0;
40901 + atomic_set(&port->count, 0);
40902 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40903 spin_unlock_irqrestore(&port->lock, flags);
40904 tty_port_tty_set(port, NULL);
40905 @@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40906 goto end;
40907 }
40908
40909 - port->count++;
40910 + atomic_inc(&port->count);
40911 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40912 retval = -ENXIO;
40913 goto err_dec_count;
40914 @@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40915 /*
40916 * Make sure the device is in D0 state.
40917 */
40918 - if (port->count == 1)
40919 + if (atomic_read(&port->count) == 1)
40920 uart_change_pm(state, 0);
40921
40922 /*
40923 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40924 end:
40925 return retval;
40926 err_dec_count:
40927 - port->count--;
40928 + atomic_inc(&port->count);
40929 mutex_unlock(&port->mutex);
40930 goto end;
40931 }
40932 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40933 index 9e071f6..f30ae69 100644
40934 --- a/drivers/tty/synclink.c
40935 +++ b/drivers/tty/synclink.c
40936 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40937
40938 if (debug_level >= DEBUG_LEVEL_INFO)
40939 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40940 - __FILE__,__LINE__, info->device_name, info->port.count);
40941 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40942
40943 if (tty_port_close_start(&info->port, tty, filp) == 0)
40944 goto cleanup;
40945 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40946 cleanup:
40947 if (debug_level >= DEBUG_LEVEL_INFO)
40948 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40949 - tty->driver->name, info->port.count);
40950 + tty->driver->name, atomic_read(&info->port.count));
40951
40952 } /* end of mgsl_close() */
40953
40954 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40955
40956 mgsl_flush_buffer(tty);
40957 shutdown(info);
40958 -
40959 - info->port.count = 0;
40960 +
40961 + atomic_set(&info->port.count, 0);
40962 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40963 info->port.tty = NULL;
40964
40965 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40966
40967 if (debug_level >= DEBUG_LEVEL_INFO)
40968 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40969 - __FILE__,__LINE__, tty->driver->name, port->count );
40970 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40971
40972 spin_lock_irqsave(&info->irq_spinlock, flags);
40973 if (!tty_hung_up_p(filp)) {
40974 extra_count = true;
40975 - port->count--;
40976 + atomic_dec(&port->count);
40977 }
40978 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40979 port->blocked_open++;
40980 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40981
40982 if (debug_level >= DEBUG_LEVEL_INFO)
40983 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40984 - __FILE__,__LINE__, tty->driver->name, port->count );
40985 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40986
40987 tty_unlock(tty);
40988 schedule();
40989 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40990
40991 /* FIXME: Racy on hangup during close wait */
40992 if (extra_count)
40993 - port->count++;
40994 + atomic_inc(&port->count);
40995 port->blocked_open--;
40996
40997 if (debug_level >= DEBUG_LEVEL_INFO)
40998 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40999 - __FILE__,__LINE__, tty->driver->name, port->count );
41000 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41001
41002 if (!retval)
41003 port->flags |= ASYNC_NORMAL_ACTIVE;
41004 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41005
41006 if (debug_level >= DEBUG_LEVEL_INFO)
41007 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
41008 - __FILE__,__LINE__,tty->driver->name, info->port.count);
41009 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41010
41011 /* If port is closing, signal caller to try again */
41012 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41013 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41014 spin_unlock_irqrestore(&info->netlock, flags);
41015 goto cleanup;
41016 }
41017 - info->port.count++;
41018 + atomic_inc(&info->port.count);
41019 spin_unlock_irqrestore(&info->netlock, flags);
41020
41021 - if (info->port.count == 1) {
41022 + if (atomic_read(&info->port.count) == 1) {
41023 /* 1st open on this device, init hardware */
41024 retval = startup(info);
41025 if (retval < 0)
41026 @@ -3451,8 +3451,8 @@ cleanup:
41027 if (retval) {
41028 if (tty->count == 1)
41029 info->port.tty = NULL; /* tty layer will release tty struct */
41030 - if(info->port.count)
41031 - info->port.count--;
41032 + if (atomic_read(&info->port.count))
41033 + atomic_dec(&info->port.count);
41034 }
41035
41036 return retval;
41037 @@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41038 unsigned short new_crctype;
41039
41040 /* return error if TTY interface open */
41041 - if (info->port.count)
41042 + if (atomic_read(&info->port.count))
41043 return -EBUSY;
41044
41045 switch (encoding)
41046 @@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
41047
41048 /* arbitrate between network and tty opens */
41049 spin_lock_irqsave(&info->netlock, flags);
41050 - if (info->port.count != 0 || info->netcount != 0) {
41051 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41052 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41053 spin_unlock_irqrestore(&info->netlock, flags);
41054 return -EBUSY;
41055 @@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41056 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41057
41058 /* return error if TTY interface open */
41059 - if (info->port.count)
41060 + if (atomic_read(&info->port.count))
41061 return -EBUSY;
41062
41063 if (cmd != SIOCWANDEV)
41064 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
41065 index aba1e59..877ac33 100644
41066 --- a/drivers/tty/synclink_gt.c
41067 +++ b/drivers/tty/synclink_gt.c
41068 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41069 tty->driver_data = info;
41070 info->port.tty = tty;
41071
41072 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
41073 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
41074
41075 /* If port is closing, signal caller to try again */
41076 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41077 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41078 mutex_unlock(&info->port.mutex);
41079 goto cleanup;
41080 }
41081 - info->port.count++;
41082 + atomic_inc(&info->port.count);
41083 spin_unlock_irqrestore(&info->netlock, flags);
41084
41085 - if (info->port.count == 1) {
41086 + if (atomic_read(&info->port.count) == 1) {
41087 /* 1st open on this device, init hardware */
41088 retval = startup(info);
41089 if (retval < 0) {
41090 @@ -716,8 +716,8 @@ cleanup:
41091 if (retval) {
41092 if (tty->count == 1)
41093 info->port.tty = NULL; /* tty layer will release tty struct */
41094 - if(info->port.count)
41095 - info->port.count--;
41096 + if(atomic_read(&info->port.count))
41097 + atomic_dec(&info->port.count);
41098 }
41099
41100 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
41101 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41102
41103 if (sanity_check(info, tty->name, "close"))
41104 return;
41105 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
41106 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
41107
41108 if (tty_port_close_start(&info->port, tty, filp) == 0)
41109 goto cleanup;
41110 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41111 tty_port_close_end(&info->port, tty);
41112 info->port.tty = NULL;
41113 cleanup:
41114 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
41115 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
41116 }
41117
41118 static void hangup(struct tty_struct *tty)
41119 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
41120 shutdown(info);
41121
41122 spin_lock_irqsave(&info->port.lock, flags);
41123 - info->port.count = 0;
41124 + atomic_set(&info->port.count, 0);
41125 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41126 info->port.tty = NULL;
41127 spin_unlock_irqrestore(&info->port.lock, flags);
41128 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41129 unsigned short new_crctype;
41130
41131 /* return error if TTY interface open */
41132 - if (info->port.count)
41133 + if (atomic_read(&info->port.count))
41134 return -EBUSY;
41135
41136 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
41137 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
41138
41139 /* arbitrate between network and tty opens */
41140 spin_lock_irqsave(&info->netlock, flags);
41141 - if (info->port.count != 0 || info->netcount != 0) {
41142 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41143 DBGINFO(("%s hdlc_open busy\n", dev->name));
41144 spin_unlock_irqrestore(&info->netlock, flags);
41145 return -EBUSY;
41146 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41147 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
41148
41149 /* return error if TTY interface open */
41150 - if (info->port.count)
41151 + if (atomic_read(&info->port.count))
41152 return -EBUSY;
41153
41154 if (cmd != SIOCWANDEV)
41155 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
41156 if (port == NULL)
41157 continue;
41158 spin_lock(&port->lock);
41159 - if ((port->port.count || port->netcount) &&
41160 + if ((atomic_read(&port->port.count) || port->netcount) &&
41161 port->pending_bh && !port->bh_running &&
41162 !port->bh_requested) {
41163 DBGISR(("%s bh queued\n", port->device_name));
41164 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41165 spin_lock_irqsave(&info->lock, flags);
41166 if (!tty_hung_up_p(filp)) {
41167 extra_count = true;
41168 - port->count--;
41169 + atomic_dec(&port->count);
41170 }
41171 spin_unlock_irqrestore(&info->lock, flags);
41172 port->blocked_open++;
41173 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41174 remove_wait_queue(&port->open_wait, &wait);
41175
41176 if (extra_count)
41177 - port->count++;
41178 + atomic_inc(&port->count);
41179 port->blocked_open--;
41180
41181 if (!retval)
41182 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
41183 index fd43fb6..34704ad 100644
41184 --- a/drivers/tty/synclinkmp.c
41185 +++ b/drivers/tty/synclinkmp.c
41186 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41187
41188 if (debug_level >= DEBUG_LEVEL_INFO)
41189 printk("%s(%d):%s open(), old ref count = %d\n",
41190 - __FILE__,__LINE__,tty->driver->name, info->port.count);
41191 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41192
41193 /* If port is closing, signal caller to try again */
41194 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41195 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41196 spin_unlock_irqrestore(&info->netlock, flags);
41197 goto cleanup;
41198 }
41199 - info->port.count++;
41200 + atomic_inc(&info->port.count);
41201 spin_unlock_irqrestore(&info->netlock, flags);
41202
41203 - if (info->port.count == 1) {
41204 + if (atomic_read(&info->port.count) == 1) {
41205 /* 1st open on this device, init hardware */
41206 retval = startup(info);
41207 if (retval < 0)
41208 @@ -797,8 +797,8 @@ cleanup:
41209 if (retval) {
41210 if (tty->count == 1)
41211 info->port.tty = NULL; /* tty layer will release tty struct */
41212 - if(info->port.count)
41213 - info->port.count--;
41214 + if(atomic_read(&info->port.count))
41215 + atomic_dec(&info->port.count);
41216 }
41217
41218 return retval;
41219 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41220
41221 if (debug_level >= DEBUG_LEVEL_INFO)
41222 printk("%s(%d):%s close() entry, count=%d\n",
41223 - __FILE__,__LINE__, info->device_name, info->port.count);
41224 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
41225
41226 if (tty_port_close_start(&info->port, tty, filp) == 0)
41227 goto cleanup;
41228 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41229 cleanup:
41230 if (debug_level >= DEBUG_LEVEL_INFO)
41231 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
41232 - tty->driver->name, info->port.count);
41233 + tty->driver->name, atomic_read(&info->port.count));
41234 }
41235
41236 /* Called by tty_hangup() when a hangup is signaled.
41237 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
41238 shutdown(info);
41239
41240 spin_lock_irqsave(&info->port.lock, flags);
41241 - info->port.count = 0;
41242 + atomic_set(&info->port.count, 0);
41243 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41244 info->port.tty = NULL;
41245 spin_unlock_irqrestore(&info->port.lock, flags);
41246 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41247 unsigned short new_crctype;
41248
41249 /* return error if TTY interface open */
41250 - if (info->port.count)
41251 + if (atomic_read(&info->port.count))
41252 return -EBUSY;
41253
41254 switch (encoding)
41255 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
41256
41257 /* arbitrate between network and tty opens */
41258 spin_lock_irqsave(&info->netlock, flags);
41259 - if (info->port.count != 0 || info->netcount != 0) {
41260 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41261 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41262 spin_unlock_irqrestore(&info->netlock, flags);
41263 return -EBUSY;
41264 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41265 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41266
41267 /* return error if TTY interface open */
41268 - if (info->port.count)
41269 + if (atomic_read(&info->port.count))
41270 return -EBUSY;
41271
41272 if (cmd != SIOCWANDEV)
41273 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
41274 * do not request bottom half processing if the
41275 * device is not open in a normal mode.
41276 */
41277 - if ( port && (port->port.count || port->netcount) &&
41278 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
41279 port->pending_bh && !port->bh_running &&
41280 !port->bh_requested ) {
41281 if ( debug_level >= DEBUG_LEVEL_ISR )
41282 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41283
41284 if (debug_level >= DEBUG_LEVEL_INFO)
41285 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
41286 - __FILE__,__LINE__, tty->driver->name, port->count );
41287 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41288
41289 spin_lock_irqsave(&info->lock, flags);
41290 if (!tty_hung_up_p(filp)) {
41291 extra_count = true;
41292 - port->count--;
41293 + atomic_dec(&port->count);
41294 }
41295 spin_unlock_irqrestore(&info->lock, flags);
41296 port->blocked_open++;
41297 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41298
41299 if (debug_level >= DEBUG_LEVEL_INFO)
41300 printk("%s(%d):%s block_til_ready() count=%d\n",
41301 - __FILE__,__LINE__, tty->driver->name, port->count );
41302 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41303
41304 tty_unlock(tty);
41305 schedule();
41306 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41307 remove_wait_queue(&port->open_wait, &wait);
41308
41309 if (extra_count)
41310 - port->count++;
41311 + atomic_inc(&port->count);
41312 port->blocked_open--;
41313
41314 if (debug_level >= DEBUG_LEVEL_INFO)
41315 printk("%s(%d):%s block_til_ready() after, count=%d\n",
41316 - __FILE__,__LINE__, tty->driver->name, port->count );
41317 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41318
41319 if (!retval)
41320 port->flags |= ASYNC_NORMAL_ACTIVE;
41321 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
41322 index b3c4a25..723916f 100644
41323 --- a/drivers/tty/sysrq.c
41324 +++ b/drivers/tty/sysrq.c
41325 @@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
41326 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
41327 size_t count, loff_t *ppos)
41328 {
41329 - if (count) {
41330 + if (count && capable(CAP_SYS_ADMIN)) {
41331 char c;
41332
41333 if (get_user(c, buf))
41334 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
41335 index da9fde8..c07975f 100644
41336 --- a/drivers/tty/tty_io.c
41337 +++ b/drivers/tty/tty_io.c
41338 @@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
41339
41340 void tty_default_fops(struct file_operations *fops)
41341 {
41342 - *fops = tty_fops;
41343 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
41344 }
41345
41346 /*
41347 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
41348 index c578229..45aa9ee 100644
41349 --- a/drivers/tty/tty_ldisc.c
41350 +++ b/drivers/tty/tty_ldisc.c
41351 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
41352 if (atomic_dec_and_test(&ld->users)) {
41353 struct tty_ldisc_ops *ldo = ld->ops;
41354
41355 - ldo->refcount--;
41356 + atomic_dec(&ldo->refcount);
41357 module_put(ldo->owner);
41358 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41359
41360 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
41361 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41362 tty_ldiscs[disc] = new_ldisc;
41363 new_ldisc->num = disc;
41364 - new_ldisc->refcount = 0;
41365 + atomic_set(&new_ldisc->refcount, 0);
41366 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41367
41368 return ret;
41369 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
41370 return -EINVAL;
41371
41372 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41373 - if (tty_ldiscs[disc]->refcount)
41374 + if (atomic_read(&tty_ldiscs[disc]->refcount))
41375 ret = -EBUSY;
41376 else
41377 tty_ldiscs[disc] = NULL;
41378 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
41379 if (ldops) {
41380 ret = ERR_PTR(-EAGAIN);
41381 if (try_module_get(ldops->owner)) {
41382 - ldops->refcount++;
41383 + atomic_inc(&ldops->refcount);
41384 ret = ldops;
41385 }
41386 }
41387 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
41388 unsigned long flags;
41389
41390 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41391 - ldops->refcount--;
41392 + atomic_dec(&ldops->refcount);
41393 module_put(ldops->owner);
41394 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41395 }
41396 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
41397 index b7ff59d..7c6105e 100644
41398 --- a/drivers/tty/tty_port.c
41399 +++ b/drivers/tty/tty_port.c
41400 @@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
41401 unsigned long flags;
41402
41403 spin_lock_irqsave(&port->lock, flags);
41404 - port->count = 0;
41405 + atomic_set(&port->count, 0);
41406 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41407 if (port->tty) {
41408 set_bit(TTY_IO_ERROR, &port->tty->flags);
41409 @@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41410 /* The port lock protects the port counts */
41411 spin_lock_irqsave(&port->lock, flags);
41412 if (!tty_hung_up_p(filp))
41413 - port->count--;
41414 + atomic_dec(&port->count);
41415 port->blocked_open++;
41416 spin_unlock_irqrestore(&port->lock, flags);
41417
41418 @@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41419 we must not mess that up further */
41420 spin_lock_irqsave(&port->lock, flags);
41421 if (!tty_hung_up_p(filp))
41422 - port->count++;
41423 + atomic_inc(&port->count);
41424 port->blocked_open--;
41425 if (retval == 0)
41426 port->flags |= ASYNC_NORMAL_ACTIVE;
41427 @@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
41428 return 0;
41429 }
41430
41431 - if (tty->count == 1 && port->count != 1) {
41432 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
41433 printk(KERN_WARNING
41434 "tty_port_close_start: tty->count = 1 port count = %d.\n",
41435 - port->count);
41436 - port->count = 1;
41437 + atomic_read(&port->count));
41438 + atomic_set(&port->count, 1);
41439 }
41440 - if (--port->count < 0) {
41441 + if (atomic_dec_return(&port->count) < 0) {
41442 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
41443 - port->count);
41444 - port->count = 0;
41445 + atomic_read(&port->count));
41446 + atomic_set(&port->count, 0);
41447 }
41448
41449 - if (port->count) {
41450 + if (atomic_read(&port->count)) {
41451 spin_unlock_irqrestore(&port->lock, flags);
41452 if (port->ops->drop)
41453 port->ops->drop(port);
41454 @@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
41455 {
41456 spin_lock_irq(&port->lock);
41457 if (!tty_hung_up_p(filp))
41458 - ++port->count;
41459 + atomic_inc(&port->count);
41460 spin_unlock_irq(&port->lock);
41461 tty_port_tty_set(port, tty);
41462
41463 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
41464 index 681765b..d3ccdf2 100644
41465 --- a/drivers/tty/vt/keyboard.c
41466 +++ b/drivers/tty/vt/keyboard.c
41467 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
41468 kbd->kbdmode == VC_OFF) &&
41469 value != KVAL(K_SAK))
41470 return; /* SAK is allowed even in raw mode */
41471 +
41472 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41473 + {
41474 + void *func = fn_handler[value];
41475 + if (func == fn_show_state || func == fn_show_ptregs ||
41476 + func == fn_show_mem)
41477 + return;
41478 + }
41479 +#endif
41480 +
41481 fn_handler[value](vc);
41482 }
41483
41484 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41485 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41486 return -EFAULT;
41487
41488 - if (!capable(CAP_SYS_TTY_CONFIG))
41489 - perm = 0;
41490 -
41491 switch (cmd) {
41492 case KDGKBENT:
41493 /* Ensure another thread doesn't free it under us */
41494 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41495 spin_unlock_irqrestore(&kbd_event_lock, flags);
41496 return put_user(val, &user_kbe->kb_value);
41497 case KDSKBENT:
41498 + if (!capable(CAP_SYS_TTY_CONFIG))
41499 + perm = 0;
41500 +
41501 if (!perm)
41502 return -EPERM;
41503 if (!i && v == K_NOSUCHMAP) {
41504 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41505 int i, j, k;
41506 int ret;
41507
41508 - if (!capable(CAP_SYS_TTY_CONFIG))
41509 - perm = 0;
41510 -
41511 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41512 if (!kbs) {
41513 ret = -ENOMEM;
41514 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41515 kfree(kbs);
41516 return ((p && *p) ? -EOVERFLOW : 0);
41517 case KDSKBSENT:
41518 + if (!capable(CAP_SYS_TTY_CONFIG))
41519 + perm = 0;
41520 +
41521 if (!perm) {
41522 ret = -EPERM;
41523 goto reterr;
41524 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
41525 index 5110f36..8dc0a74 100644
41526 --- a/drivers/uio/uio.c
41527 +++ b/drivers/uio/uio.c
41528 @@ -25,6 +25,7 @@
41529 #include <linux/kobject.h>
41530 #include <linux/cdev.h>
41531 #include <linux/uio_driver.h>
41532 +#include <asm/local.h>
41533
41534 #define UIO_MAX_DEVICES (1U << MINORBITS)
41535
41536 @@ -32,10 +33,10 @@ struct uio_device {
41537 struct module *owner;
41538 struct device *dev;
41539 int minor;
41540 - atomic_t event;
41541 + atomic_unchecked_t event;
41542 struct fasync_struct *async_queue;
41543 wait_queue_head_t wait;
41544 - int vma_count;
41545 + local_t vma_count;
41546 struct uio_info *info;
41547 struct kobject *map_dir;
41548 struct kobject *portio_dir;
41549 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
41550 struct device_attribute *attr, char *buf)
41551 {
41552 struct uio_device *idev = dev_get_drvdata(dev);
41553 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41554 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41555 }
41556
41557 static struct device_attribute uio_class_attributes[] = {
41558 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
41559 {
41560 struct uio_device *idev = info->uio_dev;
41561
41562 - atomic_inc(&idev->event);
41563 + atomic_inc_unchecked(&idev->event);
41564 wake_up_interruptible(&idev->wait);
41565 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41566 }
41567 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
41568 }
41569
41570 listener->dev = idev;
41571 - listener->event_count = atomic_read(&idev->event);
41572 + listener->event_count = atomic_read_unchecked(&idev->event);
41573 filep->private_data = listener;
41574
41575 if (idev->info->open) {
41576 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
41577 return -EIO;
41578
41579 poll_wait(filep, &idev->wait, wait);
41580 - if (listener->event_count != atomic_read(&idev->event))
41581 + if (listener->event_count != atomic_read_unchecked(&idev->event))
41582 return POLLIN | POLLRDNORM;
41583 return 0;
41584 }
41585 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
41586 do {
41587 set_current_state(TASK_INTERRUPTIBLE);
41588
41589 - event_count = atomic_read(&idev->event);
41590 + event_count = atomic_read_unchecked(&idev->event);
41591 if (event_count != listener->event_count) {
41592 if (copy_to_user(buf, &event_count, count))
41593 retval = -EFAULT;
41594 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
41595 static void uio_vma_open(struct vm_area_struct *vma)
41596 {
41597 struct uio_device *idev = vma->vm_private_data;
41598 - idev->vma_count++;
41599 + local_inc(&idev->vma_count);
41600 }
41601
41602 static void uio_vma_close(struct vm_area_struct *vma)
41603 {
41604 struct uio_device *idev = vma->vm_private_data;
41605 - idev->vma_count--;
41606 + local_dec(&idev->vma_count);
41607 }
41608
41609 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41610 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
41611 idev->owner = owner;
41612 idev->info = info;
41613 init_waitqueue_head(&idev->wait);
41614 - atomic_set(&idev->event, 0);
41615 + atomic_set_unchecked(&idev->event, 0);
41616
41617 ret = uio_get_minor(idev);
41618 if (ret)
41619 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
41620 index b7eb86a..36d28af 100644
41621 --- a/drivers/usb/atm/cxacru.c
41622 +++ b/drivers/usb/atm/cxacru.c
41623 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
41624 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41625 if (ret < 2)
41626 return -EINVAL;
41627 - if (index < 0 || index > 0x7f)
41628 + if (index > 0x7f)
41629 return -EINVAL;
41630 pos += tmp;
41631
41632 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
41633 index 35f10bf..6a38a0b 100644
41634 --- a/drivers/usb/atm/usbatm.c
41635 +++ b/drivers/usb/atm/usbatm.c
41636 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41637 if (printk_ratelimit())
41638 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
41639 __func__, vpi, vci);
41640 - atomic_inc(&vcc->stats->rx_err);
41641 + atomic_inc_unchecked(&vcc->stats->rx_err);
41642 return;
41643 }
41644
41645 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41646 if (length > ATM_MAX_AAL5_PDU) {
41647 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41648 __func__, length, vcc);
41649 - atomic_inc(&vcc->stats->rx_err);
41650 + atomic_inc_unchecked(&vcc->stats->rx_err);
41651 goto out;
41652 }
41653
41654 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41655 if (sarb->len < pdu_length) {
41656 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41657 __func__, pdu_length, sarb->len, vcc);
41658 - atomic_inc(&vcc->stats->rx_err);
41659 + atomic_inc_unchecked(&vcc->stats->rx_err);
41660 goto out;
41661 }
41662
41663 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
41664 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41665 __func__, vcc);
41666 - atomic_inc(&vcc->stats->rx_err);
41667 + atomic_inc_unchecked(&vcc->stats->rx_err);
41668 goto out;
41669 }
41670
41671 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41672 if (printk_ratelimit())
41673 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41674 __func__, length);
41675 - atomic_inc(&vcc->stats->rx_drop);
41676 + atomic_inc_unchecked(&vcc->stats->rx_drop);
41677 goto out;
41678 }
41679
41680 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41681
41682 vcc->push(vcc, skb);
41683
41684 - atomic_inc(&vcc->stats->rx);
41685 + atomic_inc_unchecked(&vcc->stats->rx);
41686 out:
41687 skb_trim(sarb, 0);
41688 }
41689 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
41690 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41691
41692 usbatm_pop(vcc, skb);
41693 - atomic_inc(&vcc->stats->tx);
41694 + atomic_inc_unchecked(&vcc->stats->tx);
41695
41696 skb = skb_dequeue(&instance->sndqueue);
41697 }
41698 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
41699 if (!left--)
41700 return sprintf(page,
41701 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41702 - atomic_read(&atm_dev->stats.aal5.tx),
41703 - atomic_read(&atm_dev->stats.aal5.tx_err),
41704 - atomic_read(&atm_dev->stats.aal5.rx),
41705 - atomic_read(&atm_dev->stats.aal5.rx_err),
41706 - atomic_read(&atm_dev->stats.aal5.rx_drop));
41707 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41708 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41709 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41710 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41711 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
41712
41713 if (!left--) {
41714 if (instance->disconnected)
41715 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
41716 index cbacea9..246cccd 100644
41717 --- a/drivers/usb/core/devices.c
41718 +++ b/drivers/usb/core/devices.c
41719 @@ -126,7 +126,7 @@ static const char format_endpt[] =
41720 * time it gets called.
41721 */
41722 static struct device_connect_event {
41723 - atomic_t count;
41724 + atomic_unchecked_t count;
41725 wait_queue_head_t wait;
41726 } device_event = {
41727 .count = ATOMIC_INIT(1),
41728 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41729
41730 void usbfs_conn_disc_event(void)
41731 {
41732 - atomic_add(2, &device_event.count);
41733 + atomic_add_unchecked(2, &device_event.count);
41734 wake_up(&device_event.wait);
41735 }
41736
41737 @@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
41738
41739 poll_wait(file, &device_event.wait, wait);
41740
41741 - event_count = atomic_read(&device_event.count);
41742 + event_count = atomic_read_unchecked(&device_event.count);
41743 if (file->f_version != event_count) {
41744 file->f_version = event_count;
41745 return POLLIN | POLLRDNORM;
41746 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41747 index 8e64adf..9a33a3c 100644
41748 --- a/drivers/usb/core/hcd.c
41749 +++ b/drivers/usb/core/hcd.c
41750 @@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41751 */
41752 usb_get_urb(urb);
41753 atomic_inc(&urb->use_count);
41754 - atomic_inc(&urb->dev->urbnum);
41755 + atomic_inc_unchecked(&urb->dev->urbnum);
41756 usbmon_urb_submit(&hcd->self, urb);
41757
41758 /* NOTE requirements on root-hub callers (usbfs and the hub
41759 @@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41760 urb->hcpriv = NULL;
41761 INIT_LIST_HEAD(&urb->urb_list);
41762 atomic_dec(&urb->use_count);
41763 - atomic_dec(&urb->dev->urbnum);
41764 + atomic_dec_unchecked(&urb->dev->urbnum);
41765 if (atomic_read(&urb->reject))
41766 wake_up(&usb_kill_urb_queue);
41767 usb_put_urb(urb);
41768 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41769 index 818e4a0..0fc9589 100644
41770 --- a/drivers/usb/core/sysfs.c
41771 +++ b/drivers/usb/core/sysfs.c
41772 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41773 struct usb_device *udev;
41774
41775 udev = to_usb_device(dev);
41776 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41777 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41778 }
41779 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41780
41781 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41782 index f81b925..78d22ec 100644
41783 --- a/drivers/usb/core/usb.c
41784 +++ b/drivers/usb/core/usb.c
41785 @@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41786 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41787 dev->state = USB_STATE_ATTACHED;
41788 dev->lpm_disable_count = 1;
41789 - atomic_set(&dev->urbnum, 0);
41790 + atomic_set_unchecked(&dev->urbnum, 0);
41791
41792 INIT_LIST_HEAD(&dev->ep0.urb_list);
41793 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41794 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41795 index 5e29dde..eca992f 100644
41796 --- a/drivers/usb/early/ehci-dbgp.c
41797 +++ b/drivers/usb/early/ehci-dbgp.c
41798 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41799
41800 #ifdef CONFIG_KGDB
41801 static struct kgdb_io kgdbdbgp_io_ops;
41802 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41803 +static struct kgdb_io kgdbdbgp_io_ops_console;
41804 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41805 #else
41806 #define dbgp_kgdb_mode (0)
41807 #endif
41808 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41809 .write_char = kgdbdbgp_write_char,
41810 };
41811
41812 +static struct kgdb_io kgdbdbgp_io_ops_console = {
41813 + .name = "kgdbdbgp",
41814 + .read_char = kgdbdbgp_read_char,
41815 + .write_char = kgdbdbgp_write_char,
41816 + .is_console = 1
41817 +};
41818 +
41819 static int kgdbdbgp_wait_time;
41820
41821 static int __init kgdbdbgp_parse_config(char *str)
41822 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41823 ptr++;
41824 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41825 }
41826 - kgdb_register_io_module(&kgdbdbgp_io_ops);
41827 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41828 + if (early_dbgp_console.index != -1)
41829 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41830 + else
41831 + kgdb_register_io_module(&kgdbdbgp_io_ops);
41832
41833 return 0;
41834 }
41835 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41836 index 598dcc1..032dd4f 100644
41837 --- a/drivers/usb/gadget/u_serial.c
41838 +++ b/drivers/usb/gadget/u_serial.c
41839 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41840 spin_lock_irq(&port->port_lock);
41841
41842 /* already open? Great. */
41843 - if (port->port.count) {
41844 + if (atomic_read(&port->port.count)) {
41845 status = 0;
41846 - port->port.count++;
41847 + atomic_inc(&port->port.count);
41848
41849 /* currently opening/closing? wait ... */
41850 } else if (port->openclose) {
41851 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41852 tty->driver_data = port;
41853 port->port.tty = tty;
41854
41855 - port->port.count = 1;
41856 + atomic_set(&port->port.count, 1);
41857 port->openclose = false;
41858
41859 /* if connected, start the I/O stream */
41860 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41861
41862 spin_lock_irq(&port->port_lock);
41863
41864 - if (port->port.count != 1) {
41865 - if (port->port.count == 0)
41866 + if (atomic_read(&port->port.count) != 1) {
41867 + if (atomic_read(&port->port.count) == 0)
41868 WARN_ON(1);
41869 else
41870 - --port->port.count;
41871 + atomic_dec(&port->port.count);
41872 goto exit;
41873 }
41874
41875 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41876 * and sleep if necessary
41877 */
41878 port->openclose = true;
41879 - port->port.count = 0;
41880 + atomic_set(&port->port.count, 0);
41881
41882 gser = port->port_usb;
41883 if (gser && gser->disconnect)
41884 @@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
41885 int cond;
41886
41887 spin_lock_irq(&port->port_lock);
41888 - cond = (port->port.count == 0) && !port->openclose;
41889 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41890 spin_unlock_irq(&port->port_lock);
41891 return cond;
41892 }
41893 @@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41894 /* if it's already open, start I/O ... and notify the serial
41895 * protocol about open/close status (connect/disconnect).
41896 */
41897 - if (port->port.count) {
41898 + if (atomic_read(&port->port.count)) {
41899 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41900 gs_start_io(port);
41901 if (gser->connect)
41902 @@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
41903
41904 port->port_usb = NULL;
41905 gser->ioport = NULL;
41906 - if (port->port.count > 0 || port->openclose) {
41907 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
41908 wake_up_interruptible(&port->drain_wait);
41909 if (port->port.tty)
41910 tty_hangup(port->port.tty);
41911 @@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
41912
41913 /* finally, free any unused/unusable I/O buffers */
41914 spin_lock_irqsave(&port->port_lock, flags);
41915 - if (port->port.count == 0 && !port->openclose)
41916 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
41917 gs_buf_free(&port->port_write_buf);
41918 gs_free_requests(gser->out, &port->read_pool, NULL);
41919 gs_free_requests(gser->out, &port->read_queue, NULL);
41920 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41921 index 5f3bcd3..bfca43f 100644
41922 --- a/drivers/usb/serial/console.c
41923 +++ b/drivers/usb/serial/console.c
41924 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41925
41926 info->port = port;
41927
41928 - ++port->port.count;
41929 + atomic_inc(&port->port.count);
41930 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41931 if (serial->type->set_termios) {
41932 /*
41933 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41934 }
41935 /* Now that any required fake tty operations are completed restore
41936 * the tty port count */
41937 - --port->port.count;
41938 + atomic_dec(&port->port.count);
41939 /* The console is special in terms of closing the device so
41940 * indicate this port is now acting as a system console. */
41941 port->port.console = 1;
41942 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41943 free_tty:
41944 kfree(tty);
41945 reset_open_count:
41946 - port->port.count = 0;
41947 + atomic_set(&port->port.count, 0);
41948 usb_autopm_put_interface(serial->interface);
41949 error_get_interface:
41950 usb_serial_put(serial);
41951 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41952 index d6bea3e..60b250e 100644
41953 --- a/drivers/usb/wusbcore/wa-hc.h
41954 +++ b/drivers/usb/wusbcore/wa-hc.h
41955 @@ -192,7 +192,7 @@ struct wahc {
41956 struct list_head xfer_delayed_list;
41957 spinlock_t xfer_list_lock;
41958 struct work_struct xfer_work;
41959 - atomic_t xfer_id_count;
41960 + atomic_unchecked_t xfer_id_count;
41961 };
41962
41963
41964 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41965 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41966 spin_lock_init(&wa->xfer_list_lock);
41967 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41968 - atomic_set(&wa->xfer_id_count, 1);
41969 + atomic_set_unchecked(&wa->xfer_id_count, 1);
41970 }
41971
41972 /**
41973 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41974 index 57c01ab..8a05959 100644
41975 --- a/drivers/usb/wusbcore/wa-xfer.c
41976 +++ b/drivers/usb/wusbcore/wa-xfer.c
41977 @@ -296,7 +296,7 @@ out:
41978 */
41979 static void wa_xfer_id_init(struct wa_xfer *xfer)
41980 {
41981 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41982 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41983 }
41984
41985 /*
41986 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41987 index 8c55011..eed4ae1a 100644
41988 --- a/drivers/video/aty/aty128fb.c
41989 +++ b/drivers/video/aty/aty128fb.c
41990 @@ -149,7 +149,7 @@ enum {
41991 };
41992
41993 /* Must match above enum */
41994 -static char * const r128_family[] = {
41995 +static const char * const r128_family[] = {
41996 "AGP",
41997 "PCI",
41998 "PRO AGP",
41999 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42000 index 5c3960d..15cf8fc 100644
42001 --- a/drivers/video/fbcmap.c
42002 +++ b/drivers/video/fbcmap.c
42003 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42004 rc = -ENODEV;
42005 goto out;
42006 }
42007 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42008 - !info->fbops->fb_setcmap)) {
42009 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42010 rc = -EINVAL;
42011 goto out1;
42012 }
42013 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42014 index 3ff0105..7589d98 100644
42015 --- a/drivers/video/fbmem.c
42016 +++ b/drivers/video/fbmem.c
42017 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42018 image->dx += image->width + 8;
42019 }
42020 } else if (rotate == FB_ROTATE_UD) {
42021 - for (x = 0; x < num && image->dx >= 0; x++) {
42022 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42023 info->fbops->fb_imageblit(info, image);
42024 image->dx -= image->width + 8;
42025 }
42026 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42027 image->dy += image->height + 8;
42028 }
42029 } else if (rotate == FB_ROTATE_CCW) {
42030 - for (x = 0; x < num && image->dy >= 0; x++) {
42031 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42032 info->fbops->fb_imageblit(info, image);
42033 image->dy -= image->height + 8;
42034 }
42035 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42036 return -EFAULT;
42037 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42038 return -EINVAL;
42039 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42040 + if (con2fb.framebuffer >= FB_MAX)
42041 return -EINVAL;
42042 if (!registered_fb[con2fb.framebuffer])
42043 request_module("fb%d", con2fb.framebuffer);
42044 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42045 index 7672d2e..b56437f 100644
42046 --- a/drivers/video/i810/i810_accel.c
42047 +++ b/drivers/video/i810/i810_accel.c
42048 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42049 }
42050 }
42051 printk("ringbuffer lockup!!!\n");
42052 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42053 i810_report_error(mmio);
42054 par->dev_flags |= LOCKUP;
42055 info->pixmap.scan_align = 1;
42056 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42057 index 3c14e43..eafa544 100644
42058 --- a/drivers/video/logo/logo_linux_clut224.ppm
42059 +++ b/drivers/video/logo/logo_linux_clut224.ppm
42060 @@ -1,1604 +1,1123 @@
42061 P3
42062 -# Standard 224-color Linux logo
42063 80 80
42064 255
42065 - 0 0 0 0 0 0 0 0 0 0 0 0
42066 - 0 0 0 0 0 0 0 0 0 0 0 0
42067 - 0 0 0 0 0 0 0 0 0 0 0 0
42068 - 0 0 0 0 0 0 0 0 0 0 0 0
42069 - 0 0 0 0 0 0 0 0 0 0 0 0
42070 - 0 0 0 0 0 0 0 0 0 0 0 0
42071 - 0 0 0 0 0 0 0 0 0 0 0 0
42072 - 0 0 0 0 0 0 0 0 0 0 0 0
42073 - 0 0 0 0 0 0 0 0 0 0 0 0
42074 - 6 6 6 6 6 6 10 10 10 10 10 10
42075 - 10 10 10 6 6 6 6 6 6 6 6 6
42076 - 0 0 0 0 0 0 0 0 0 0 0 0
42077 - 0 0 0 0 0 0 0 0 0 0 0 0
42078 - 0 0 0 0 0 0 0 0 0 0 0 0
42079 - 0 0 0 0 0 0 0 0 0 0 0 0
42080 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 0 0 0 0 0
42087 - 0 0 0 0 0 0 0 0 0 0 0 0
42088 - 0 0 0 0 0 0 0 0 0 0 0 0
42089 - 0 0 0 0 0 0 0 0 0 0 0 0
42090 - 0 0 0 0 0 0 0 0 0 0 0 0
42091 - 0 0 0 0 0 0 0 0 0 0 0 0
42092 - 0 0 0 0 0 0 0 0 0 0 0 0
42093 - 0 0 0 6 6 6 10 10 10 14 14 14
42094 - 22 22 22 26 26 26 30 30 30 34 34 34
42095 - 30 30 30 30 30 30 26 26 26 18 18 18
42096 - 14 14 14 10 10 10 6 6 6 0 0 0
42097 - 0 0 0 0 0 0 0 0 0 0 0 0
42098 - 0 0 0 0 0 0 0 0 0 0 0 0
42099 - 0 0 0 0 0 0 0 0 0 0 0 0
42100 - 0 0 0 0 0 0 0 0 0 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 - 0 0 0 0 0 1 0 0 1 0 0 0
42107 - 0 0 0 0 0 0 0 0 0 0 0 0
42108 - 0 0 0 0 0 0 0 0 0 0 0 0
42109 - 0 0 0 0 0 0 0 0 0 0 0 0
42110 - 0 0 0 0 0 0 0 0 0 0 0 0
42111 - 0 0 0 0 0 0 0 0 0 0 0 0
42112 - 0 0 0 0 0 0 0 0 0 0 0 0
42113 - 6 6 6 14 14 14 26 26 26 42 42 42
42114 - 54 54 54 66 66 66 78 78 78 78 78 78
42115 - 78 78 78 74 74 74 66 66 66 54 54 54
42116 - 42 42 42 26 26 26 18 18 18 10 10 10
42117 - 6 6 6 0 0 0 0 0 0 0 0 0
42118 - 0 0 0 0 0 0 0 0 0 0 0 0
42119 - 0 0 0 0 0 0 0 0 0 0 0 0
42120 - 0 0 0 0 0 0 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 - 0 0 1 0 0 0 0 0 0 0 0 0
42127 - 0 0 0 0 0 0 0 0 0 0 0 0
42128 - 0 0 0 0 0 0 0 0 0 0 0 0
42129 - 0 0 0 0 0 0 0 0 0 0 0 0
42130 - 0 0 0 0 0 0 0 0 0 0 0 0
42131 - 0 0 0 0 0 0 0 0 0 0 0 0
42132 - 0 0 0 0 0 0 0 0 0 10 10 10
42133 - 22 22 22 42 42 42 66 66 66 86 86 86
42134 - 66 66 66 38 38 38 38 38 38 22 22 22
42135 - 26 26 26 34 34 34 54 54 54 66 66 66
42136 - 86 86 86 70 70 70 46 46 46 26 26 26
42137 - 14 14 14 6 6 6 0 0 0 0 0 0
42138 - 0 0 0 0 0 0 0 0 0 0 0 0
42139 - 0 0 0 0 0 0 0 0 0 0 0 0
42140 - 0 0 0 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 0 0 0
42146 - 0 0 1 0 0 1 0 0 1 0 0 0
42147 - 0 0 0 0 0 0 0 0 0 0 0 0
42148 - 0 0 0 0 0 0 0 0 0 0 0 0
42149 - 0 0 0 0 0 0 0 0 0 0 0 0
42150 - 0 0 0 0 0 0 0 0 0 0 0 0
42151 - 0 0 0 0 0 0 0 0 0 0 0 0
42152 - 0 0 0 0 0 0 10 10 10 26 26 26
42153 - 50 50 50 82 82 82 58 58 58 6 6 6
42154 - 2 2 6 2 2 6 2 2 6 2 2 6
42155 - 2 2 6 2 2 6 2 2 6 2 2 6
42156 - 6 6 6 54 54 54 86 86 86 66 66 66
42157 - 38 38 38 18 18 18 6 6 6 0 0 0
42158 - 0 0 0 0 0 0 0 0 0 0 0 0
42159 - 0 0 0 0 0 0 0 0 0 0 0 0
42160 - 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 0 0 0
42166 - 0 0 0 0 0 0 0 0 0 0 0 0
42167 - 0 0 0 0 0 0 0 0 0 0 0 0
42168 - 0 0 0 0 0 0 0 0 0 0 0 0
42169 - 0 0 0 0 0 0 0 0 0 0 0 0
42170 - 0 0 0 0 0 0 0 0 0 0 0 0
42171 - 0 0 0 0 0 0 0 0 0 0 0 0
42172 - 0 0 0 6 6 6 22 22 22 50 50 50
42173 - 78 78 78 34 34 34 2 2 6 2 2 6
42174 - 2 2 6 2 2 6 2 2 6 2 2 6
42175 - 2 2 6 2 2 6 2 2 6 2 2 6
42176 - 2 2 6 2 2 6 6 6 6 70 70 70
42177 - 78 78 78 46 46 46 22 22 22 6 6 6
42178 - 0 0 0 0 0 0 0 0 0 0 0 0
42179 - 0 0 0 0 0 0 0 0 0 0 0 0
42180 - 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 0 0 0
42186 - 0 0 1 0 0 1 0 0 1 0 0 0
42187 - 0 0 0 0 0 0 0 0 0 0 0 0
42188 - 0 0 0 0 0 0 0 0 0 0 0 0
42189 - 0 0 0 0 0 0 0 0 0 0 0 0
42190 - 0 0 0 0 0 0 0 0 0 0 0 0
42191 - 0 0 0 0 0 0 0 0 0 0 0 0
42192 - 6 6 6 18 18 18 42 42 42 82 82 82
42193 - 26 26 26 2 2 6 2 2 6 2 2 6
42194 - 2 2 6 2 2 6 2 2 6 2 2 6
42195 - 2 2 6 2 2 6 2 2 6 14 14 14
42196 - 46 46 46 34 34 34 6 6 6 2 2 6
42197 - 42 42 42 78 78 78 42 42 42 18 18 18
42198 - 6 6 6 0 0 0 0 0 0 0 0 0
42199 - 0 0 0 0 0 0 0 0 0 0 0 0
42200 - 0 0 0 0 0 0 0 0 0 0 0 0
42201 - 0 0 0 0 0 0 0 0 0 0 0 0
42202 - 0 0 0 0 0 0 0 0 0 0 0 0
42203 - 0 0 0 0 0 0 0 0 0 0 0 0
42204 - 0 0 0 0 0 0 0 0 0 0 0 0
42205 - 0 0 0 0 0 0 0 0 0 0 0 0
42206 - 0 0 1 0 0 0 0 0 1 0 0 0
42207 - 0 0 0 0 0 0 0 0 0 0 0 0
42208 - 0 0 0 0 0 0 0 0 0 0 0 0
42209 - 0 0 0 0 0 0 0 0 0 0 0 0
42210 - 0 0 0 0 0 0 0 0 0 0 0 0
42211 - 0 0 0 0 0 0 0 0 0 0 0 0
42212 - 10 10 10 30 30 30 66 66 66 58 58 58
42213 - 2 2 6 2 2 6 2 2 6 2 2 6
42214 - 2 2 6 2 2 6 2 2 6 2 2 6
42215 - 2 2 6 2 2 6 2 2 6 26 26 26
42216 - 86 86 86 101 101 101 46 46 46 10 10 10
42217 - 2 2 6 58 58 58 70 70 70 34 34 34
42218 - 10 10 10 0 0 0 0 0 0 0 0 0
42219 - 0 0 0 0 0 0 0 0 0 0 0 0
42220 - 0 0 0 0 0 0 0 0 0 0 0 0
42221 - 0 0 0 0 0 0 0 0 0 0 0 0
42222 - 0 0 0 0 0 0 0 0 0 0 0 0
42223 - 0 0 0 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 0 0 0 0 0 0
42226 - 0 0 1 0 0 1 0 0 1 0 0 0
42227 - 0 0 0 0 0 0 0 0 0 0 0 0
42228 - 0 0 0 0 0 0 0 0 0 0 0 0
42229 - 0 0 0 0 0 0 0 0 0 0 0 0
42230 - 0 0 0 0 0 0 0 0 0 0 0 0
42231 - 0 0 0 0 0 0 0 0 0 0 0 0
42232 - 14 14 14 42 42 42 86 86 86 10 10 10
42233 - 2 2 6 2 2 6 2 2 6 2 2 6
42234 - 2 2 6 2 2 6 2 2 6 2 2 6
42235 - 2 2 6 2 2 6 2 2 6 30 30 30
42236 - 94 94 94 94 94 94 58 58 58 26 26 26
42237 - 2 2 6 6 6 6 78 78 78 54 54 54
42238 - 22 22 22 6 6 6 0 0 0 0 0 0
42239 - 0 0 0 0 0 0 0 0 0 0 0 0
42240 - 0 0 0 0 0 0 0 0 0 0 0 0
42241 - 0 0 0 0 0 0 0 0 0 0 0 0
42242 - 0 0 0 0 0 0 0 0 0 0 0 0
42243 - 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 0 0 0 0 0 0
42246 - 0 0 0 0 0 0 0 0 0 0 0 0
42247 - 0 0 0 0 0 0 0 0 0 0 0 0
42248 - 0 0 0 0 0 0 0 0 0 0 0 0
42249 - 0 0 0 0 0 0 0 0 0 0 0 0
42250 - 0 0 0 0 0 0 0 0 0 0 0 0
42251 - 0 0 0 0 0 0 0 0 0 6 6 6
42252 - 22 22 22 62 62 62 62 62 62 2 2 6
42253 - 2 2 6 2 2 6 2 2 6 2 2 6
42254 - 2 2 6 2 2 6 2 2 6 2 2 6
42255 - 2 2 6 2 2 6 2 2 6 26 26 26
42256 - 54 54 54 38 38 38 18 18 18 10 10 10
42257 - 2 2 6 2 2 6 34 34 34 82 82 82
42258 - 38 38 38 14 14 14 0 0 0 0 0 0
42259 - 0 0 0 0 0 0 0 0 0 0 0 0
42260 - 0 0 0 0 0 0 0 0 0 0 0 0
42261 - 0 0 0 0 0 0 0 0 0 0 0 0
42262 - 0 0 0 0 0 0 0 0 0 0 0 0
42263 - 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 0 0 0 0 0 0
42266 - 0 0 0 0 0 1 0 0 1 0 0 0
42267 - 0 0 0 0 0 0 0 0 0 0 0 0
42268 - 0 0 0 0 0 0 0 0 0 0 0 0
42269 - 0 0 0 0 0 0 0 0 0 0 0 0
42270 - 0 0 0 0 0 0 0 0 0 0 0 0
42271 - 0 0 0 0 0 0 0 0 0 6 6 6
42272 - 30 30 30 78 78 78 30 30 30 2 2 6
42273 - 2 2 6 2 2 6 2 2 6 2 2 6
42274 - 2 2 6 2 2 6 2 2 6 2 2 6
42275 - 2 2 6 2 2 6 2 2 6 10 10 10
42276 - 10 10 10 2 2 6 2 2 6 2 2 6
42277 - 2 2 6 2 2 6 2 2 6 78 78 78
42278 - 50 50 50 18 18 18 6 6 6 0 0 0
42279 - 0 0 0 0 0 0 0 0 0 0 0 0
42280 - 0 0 0 0 0 0 0 0 0 0 0 0
42281 - 0 0 0 0 0 0 0 0 0 0 0 0
42282 - 0 0 0 0 0 0 0 0 0 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 0 0 0
42285 - 0 0 0 0 0 0 0 0 0 0 0 0
42286 - 0 0 1 0 0 0 0 0 0 0 0 0
42287 - 0 0 0 0 0 0 0 0 0 0 0 0
42288 - 0 0 0 0 0 0 0 0 0 0 0 0
42289 - 0 0 0 0 0 0 0 0 0 0 0 0
42290 - 0 0 0 0 0 0 0 0 0 0 0 0
42291 - 0 0 0 0 0 0 0 0 0 10 10 10
42292 - 38 38 38 86 86 86 14 14 14 2 2 6
42293 - 2 2 6 2 2 6 2 2 6 2 2 6
42294 - 2 2 6 2 2 6 2 2 6 2 2 6
42295 - 2 2 6 2 2 6 2 2 6 2 2 6
42296 - 2 2 6 2 2 6 2 2 6 2 2 6
42297 - 2 2 6 2 2 6 2 2 6 54 54 54
42298 - 66 66 66 26 26 26 6 6 6 0 0 0
42299 - 0 0 0 0 0 0 0 0 0 0 0 0
42300 - 0 0 0 0 0 0 0 0 0 0 0 0
42301 - 0 0 0 0 0 0 0 0 0 0 0 0
42302 - 0 0 0 0 0 0 0 0 0 0 0 0
42303 - 0 0 0 0 0 0 0 0 0 0 0 0
42304 - 0 0 0 0 0 0 0 0 0 0 0 0
42305 - 0 0 0 0 0 0 0 0 0 0 0 0
42306 - 0 0 0 0 0 1 0 0 1 0 0 0
42307 - 0 0 0 0 0 0 0 0 0 0 0 0
42308 - 0 0 0 0 0 0 0 0 0 0 0 0
42309 - 0 0 0 0 0 0 0 0 0 0 0 0
42310 - 0 0 0 0 0 0 0 0 0 0 0 0
42311 - 0 0 0 0 0 0 0 0 0 14 14 14
42312 - 42 42 42 82 82 82 2 2 6 2 2 6
42313 - 2 2 6 6 6 6 10 10 10 2 2 6
42314 - 2 2 6 2 2 6 2 2 6 2 2 6
42315 - 2 2 6 2 2 6 2 2 6 6 6 6
42316 - 14 14 14 10 10 10 2 2 6 2 2 6
42317 - 2 2 6 2 2 6 2 2 6 18 18 18
42318 - 82 82 82 34 34 34 10 10 10 0 0 0
42319 - 0 0 0 0 0 0 0 0 0 0 0 0
42320 - 0 0 0 0 0 0 0 0 0 0 0 0
42321 - 0 0 0 0 0 0 0 0 0 0 0 0
42322 - 0 0 0 0 0 0 0 0 0 0 0 0
42323 - 0 0 0 0 0 0 0 0 0 0 0 0
42324 - 0 0 0 0 0 0 0 0 0 0 0 0
42325 - 0 0 0 0 0 0 0 0 0 0 0 0
42326 - 0 0 1 0 0 0 0 0 0 0 0 0
42327 - 0 0 0 0 0 0 0 0 0 0 0 0
42328 - 0 0 0 0 0 0 0 0 0 0 0 0
42329 - 0 0 0 0 0 0 0 0 0 0 0 0
42330 - 0 0 0 0 0 0 0 0 0 0 0 0
42331 - 0 0 0 0 0 0 0 0 0 14 14 14
42332 - 46 46 46 86 86 86 2 2 6 2 2 6
42333 - 6 6 6 6 6 6 22 22 22 34 34 34
42334 - 6 6 6 2 2 6 2 2 6 2 2 6
42335 - 2 2 6 2 2 6 18 18 18 34 34 34
42336 - 10 10 10 50 50 50 22 22 22 2 2 6
42337 - 2 2 6 2 2 6 2 2 6 10 10 10
42338 - 86 86 86 42 42 42 14 14 14 0 0 0
42339 - 0 0 0 0 0 0 0 0 0 0 0 0
42340 - 0 0 0 0 0 0 0 0 0 0 0 0
42341 - 0 0 0 0 0 0 0 0 0 0 0 0
42342 - 0 0 0 0 0 0 0 0 0 0 0 0
42343 - 0 0 0 0 0 0 0 0 0 0 0 0
42344 - 0 0 0 0 0 0 0 0 0 0 0 0
42345 - 0 0 0 0 0 0 0 0 0 0 0 0
42346 - 0 0 1 0 0 1 0 0 1 0 0 0
42347 - 0 0 0 0 0 0 0 0 0 0 0 0
42348 - 0 0 0 0 0 0 0 0 0 0 0 0
42349 - 0 0 0 0 0 0 0 0 0 0 0 0
42350 - 0 0 0 0 0 0 0 0 0 0 0 0
42351 - 0 0 0 0 0 0 0 0 0 14 14 14
42352 - 46 46 46 86 86 86 2 2 6 2 2 6
42353 - 38 38 38 116 116 116 94 94 94 22 22 22
42354 - 22 22 22 2 2 6 2 2 6 2 2 6
42355 - 14 14 14 86 86 86 138 138 138 162 162 162
42356 -154 154 154 38 38 38 26 26 26 6 6 6
42357 - 2 2 6 2 2 6 2 2 6 2 2 6
42358 - 86 86 86 46 46 46 14 14 14 0 0 0
42359 - 0 0 0 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 0 0 0
42364 - 0 0 0 0 0 0 0 0 0 0 0 0
42365 - 0 0 0 0 0 0 0 0 0 0 0 0
42366 - 0 0 0 0 0 0 0 0 0 0 0 0
42367 - 0 0 0 0 0 0 0 0 0 0 0 0
42368 - 0 0 0 0 0 0 0 0 0 0 0 0
42369 - 0 0 0 0 0 0 0 0 0 0 0 0
42370 - 0 0 0 0 0 0 0 0 0 0 0 0
42371 - 0 0 0 0 0 0 0 0 0 14 14 14
42372 - 46 46 46 86 86 86 2 2 6 14 14 14
42373 -134 134 134 198 198 198 195 195 195 116 116 116
42374 - 10 10 10 2 2 6 2 2 6 6 6 6
42375 -101 98 89 187 187 187 210 210 210 218 218 218
42376 -214 214 214 134 134 134 14 14 14 6 6 6
42377 - 2 2 6 2 2 6 2 2 6 2 2 6
42378 - 86 86 86 50 50 50 18 18 18 6 6 6
42379 - 0 0 0 0 0 0 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 0 0 0
42384 - 0 0 0 0 0 0 0 0 0 0 0 0
42385 - 0 0 0 0 0 0 0 0 1 0 0 0
42386 - 0 0 1 0 0 1 0 0 1 0 0 0
42387 - 0 0 0 0 0 0 0 0 0 0 0 0
42388 - 0 0 0 0 0 0 0 0 0 0 0 0
42389 - 0 0 0 0 0 0 0 0 0 0 0 0
42390 - 0 0 0 0 0 0 0 0 0 0 0 0
42391 - 0 0 0 0 0 0 0 0 0 14 14 14
42392 - 46 46 46 86 86 86 2 2 6 54 54 54
42393 -218 218 218 195 195 195 226 226 226 246 246 246
42394 - 58 58 58 2 2 6 2 2 6 30 30 30
42395 -210 210 210 253 253 253 174 174 174 123 123 123
42396 -221 221 221 234 234 234 74 74 74 2 2 6
42397 - 2 2 6 2 2 6 2 2 6 2 2 6
42398 - 70 70 70 58 58 58 22 22 22 6 6 6
42399 - 0 0 0 0 0 0 0 0 0 0 0 0
42400 - 0 0 0 0 0 0 0 0 0 0 0 0
42401 - 0 0 0 0 0 0 0 0 0 0 0 0
42402 - 0 0 0 0 0 0 0 0 0 0 0 0
42403 - 0 0 0 0 0 0 0 0 0 0 0 0
42404 - 0 0 0 0 0 0 0 0 0 0 0 0
42405 - 0 0 0 0 0 0 0 0 0 0 0 0
42406 - 0 0 0 0 0 0 0 0 0 0 0 0
42407 - 0 0 0 0 0 0 0 0 0 0 0 0
42408 - 0 0 0 0 0 0 0 0 0 0 0 0
42409 - 0 0 0 0 0 0 0 0 0 0 0 0
42410 - 0 0 0 0 0 0 0 0 0 0 0 0
42411 - 0 0 0 0 0 0 0 0 0 14 14 14
42412 - 46 46 46 82 82 82 2 2 6 106 106 106
42413 -170 170 170 26 26 26 86 86 86 226 226 226
42414 -123 123 123 10 10 10 14 14 14 46 46 46
42415 -231 231 231 190 190 190 6 6 6 70 70 70
42416 - 90 90 90 238 238 238 158 158 158 2 2 6
42417 - 2 2 6 2 2 6 2 2 6 2 2 6
42418 - 70 70 70 58 58 58 22 22 22 6 6 6
42419 - 0 0 0 0 0 0 0 0 0 0 0 0
42420 - 0 0 0 0 0 0 0 0 0 0 0 0
42421 - 0 0 0 0 0 0 0 0 0 0 0 0
42422 - 0 0 0 0 0 0 0 0 0 0 0 0
42423 - 0 0 0 0 0 0 0 0 0 0 0 0
42424 - 0 0 0 0 0 0 0 0 0 0 0 0
42425 - 0 0 0 0 0 0 0 0 1 0 0 0
42426 - 0 0 1 0 0 1 0 0 1 0 0 0
42427 - 0 0 0 0 0 0 0 0 0 0 0 0
42428 - 0 0 0 0 0 0 0 0 0 0 0 0
42429 - 0 0 0 0 0 0 0 0 0 0 0 0
42430 - 0 0 0 0 0 0 0 0 0 0 0 0
42431 - 0 0 0 0 0 0 0 0 0 14 14 14
42432 - 42 42 42 86 86 86 6 6 6 116 116 116
42433 -106 106 106 6 6 6 70 70 70 149 149 149
42434 -128 128 128 18 18 18 38 38 38 54 54 54
42435 -221 221 221 106 106 106 2 2 6 14 14 14
42436 - 46 46 46 190 190 190 198 198 198 2 2 6
42437 - 2 2 6 2 2 6 2 2 6 2 2 6
42438 - 74 74 74 62 62 62 22 22 22 6 6 6
42439 - 0 0 0 0 0 0 0 0 0 0 0 0
42440 - 0 0 0 0 0 0 0 0 0 0 0 0
42441 - 0 0 0 0 0 0 0 0 0 0 0 0
42442 - 0 0 0 0 0 0 0 0 0 0 0 0
42443 - 0 0 0 0 0 0 0 0 0 0 0 0
42444 - 0 0 0 0 0 0 0 0 0 0 0 0
42445 - 0 0 0 0 0 0 0 0 1 0 0 0
42446 - 0 0 1 0 0 0 0 0 1 0 0 0
42447 - 0 0 0 0 0 0 0 0 0 0 0 0
42448 - 0 0 0 0 0 0 0 0 0 0 0 0
42449 - 0 0 0 0 0 0 0 0 0 0 0 0
42450 - 0 0 0 0 0 0 0 0 0 0 0 0
42451 - 0 0 0 0 0 0 0 0 0 14 14 14
42452 - 42 42 42 94 94 94 14 14 14 101 101 101
42453 -128 128 128 2 2 6 18 18 18 116 116 116
42454 -118 98 46 121 92 8 121 92 8 98 78 10
42455 -162 162 162 106 106 106 2 2 6 2 2 6
42456 - 2 2 6 195 195 195 195 195 195 6 6 6
42457 - 2 2 6 2 2 6 2 2 6 2 2 6
42458 - 74 74 74 62 62 62 22 22 22 6 6 6
42459 - 0 0 0 0 0 0 0 0 0 0 0 0
42460 - 0 0 0 0 0 0 0 0 0 0 0 0
42461 - 0 0 0 0 0 0 0 0 0 0 0 0
42462 - 0 0 0 0 0 0 0 0 0 0 0 0
42463 - 0 0 0 0 0 0 0 0 0 0 0 0
42464 - 0 0 0 0 0 0 0 0 0 0 0 0
42465 - 0 0 0 0 0 0 0 0 1 0 0 1
42466 - 0 0 1 0 0 0 0 0 1 0 0 0
42467 - 0 0 0 0 0 0 0 0 0 0 0 0
42468 - 0 0 0 0 0 0 0 0 0 0 0 0
42469 - 0 0 0 0 0 0 0 0 0 0 0 0
42470 - 0 0 0 0 0 0 0 0 0 0 0 0
42471 - 0 0 0 0 0 0 0 0 0 10 10 10
42472 - 38 38 38 90 90 90 14 14 14 58 58 58
42473 -210 210 210 26 26 26 54 38 6 154 114 10
42474 -226 170 11 236 186 11 225 175 15 184 144 12
42475 -215 174 15 175 146 61 37 26 9 2 2 6
42476 - 70 70 70 246 246 246 138 138 138 2 2 6
42477 - 2 2 6 2 2 6 2 2 6 2 2 6
42478 - 70 70 70 66 66 66 26 26 26 6 6 6
42479 - 0 0 0 0 0 0 0 0 0 0 0 0
42480 - 0 0 0 0 0 0 0 0 0 0 0 0
42481 - 0 0 0 0 0 0 0 0 0 0 0 0
42482 - 0 0 0 0 0 0 0 0 0 0 0 0
42483 - 0 0 0 0 0 0 0 0 0 0 0 0
42484 - 0 0 0 0 0 0 0 0 0 0 0 0
42485 - 0 0 0 0 0 0 0 0 0 0 0 0
42486 - 0 0 0 0 0 0 0 0 0 0 0 0
42487 - 0 0 0 0 0 0 0 0 0 0 0 0
42488 - 0 0 0 0 0 0 0 0 0 0 0 0
42489 - 0 0 0 0 0 0 0 0 0 0 0 0
42490 - 0 0 0 0 0 0 0 0 0 0 0 0
42491 - 0 0 0 0 0 0 0 0 0 10 10 10
42492 - 38 38 38 86 86 86 14 14 14 10 10 10
42493 -195 195 195 188 164 115 192 133 9 225 175 15
42494 -239 182 13 234 190 10 232 195 16 232 200 30
42495 -245 207 45 241 208 19 232 195 16 184 144 12
42496 -218 194 134 211 206 186 42 42 42 2 2 6
42497 - 2 2 6 2 2 6 2 2 6 2 2 6
42498 - 50 50 50 74 74 74 30 30 30 6 6 6
42499 - 0 0 0 0 0 0 0 0 0 0 0 0
42500 - 0 0 0 0 0 0 0 0 0 0 0 0
42501 - 0 0 0 0 0 0 0 0 0 0 0 0
42502 - 0 0 0 0 0 0 0 0 0 0 0 0
42503 - 0 0 0 0 0 0 0 0 0 0 0 0
42504 - 0 0 0 0 0 0 0 0 0 0 0 0
42505 - 0 0 0 0 0 0 0 0 0 0 0 0
42506 - 0 0 0 0 0 0 0 0 0 0 0 0
42507 - 0 0 0 0 0 0 0 0 0 0 0 0
42508 - 0 0 0 0 0 0 0 0 0 0 0 0
42509 - 0 0 0 0 0 0 0 0 0 0 0 0
42510 - 0 0 0 0 0 0 0 0 0 0 0 0
42511 - 0 0 0 0 0 0 0 0 0 10 10 10
42512 - 34 34 34 86 86 86 14 14 14 2 2 6
42513 -121 87 25 192 133 9 219 162 10 239 182 13
42514 -236 186 11 232 195 16 241 208 19 244 214 54
42515 -246 218 60 246 218 38 246 215 20 241 208 19
42516 -241 208 19 226 184 13 121 87 25 2 2 6
42517 - 2 2 6 2 2 6 2 2 6 2 2 6
42518 - 50 50 50 82 82 82 34 34 34 10 10 10
42519 - 0 0 0 0 0 0 0 0 0 0 0 0
42520 - 0 0 0 0 0 0 0 0 0 0 0 0
42521 - 0 0 0 0 0 0 0 0 0 0 0 0
42522 - 0 0 0 0 0 0 0 0 0 0 0 0
42523 - 0 0 0 0 0 0 0 0 0 0 0 0
42524 - 0 0 0 0 0 0 0 0 0 0 0 0
42525 - 0 0 0 0 0 0 0 0 0 0 0 0
42526 - 0 0 0 0 0 0 0 0 0 0 0 0
42527 - 0 0 0 0 0 0 0 0 0 0 0 0
42528 - 0 0 0 0 0 0 0 0 0 0 0 0
42529 - 0 0 0 0 0 0 0 0 0 0 0 0
42530 - 0 0 0 0 0 0 0 0 0 0 0 0
42531 - 0 0 0 0 0 0 0 0 0 10 10 10
42532 - 34 34 34 82 82 82 30 30 30 61 42 6
42533 -180 123 7 206 145 10 230 174 11 239 182 13
42534 -234 190 10 238 202 15 241 208 19 246 218 74
42535 -246 218 38 246 215 20 246 215 20 246 215 20
42536 -226 184 13 215 174 15 184 144 12 6 6 6
42537 - 2 2 6 2 2 6 2 2 6 2 2 6
42538 - 26 26 26 94 94 94 42 42 42 14 14 14
42539 - 0 0 0 0 0 0 0 0 0 0 0 0
42540 - 0 0 0 0 0 0 0 0 0 0 0 0
42541 - 0 0 0 0 0 0 0 0 0 0 0 0
42542 - 0 0 0 0 0 0 0 0 0 0 0 0
42543 - 0 0 0 0 0 0 0 0 0 0 0 0
42544 - 0 0 0 0 0 0 0 0 0 0 0 0
42545 - 0 0 0 0 0 0 0 0 0 0 0 0
42546 - 0 0 0 0 0 0 0 0 0 0 0 0
42547 - 0 0 0 0 0 0 0 0 0 0 0 0
42548 - 0 0 0 0 0 0 0 0 0 0 0 0
42549 - 0 0 0 0 0 0 0 0 0 0 0 0
42550 - 0 0 0 0 0 0 0 0 0 0 0 0
42551 - 0 0 0 0 0 0 0 0 0 10 10 10
42552 - 30 30 30 78 78 78 50 50 50 104 69 6
42553 -192 133 9 216 158 10 236 178 12 236 186 11
42554 -232 195 16 241 208 19 244 214 54 245 215 43
42555 -246 215 20 246 215 20 241 208 19 198 155 10
42556 -200 144 11 216 158 10 156 118 10 2 2 6
42557 - 2 2 6 2 2 6 2 2 6 2 2 6
42558 - 6 6 6 90 90 90 54 54 54 18 18 18
42559 - 6 6 6 0 0 0 0 0 0 0 0 0
42560 - 0 0 0 0 0 0 0 0 0 0 0 0
42561 - 0 0 0 0 0 0 0 0 0 0 0 0
42562 - 0 0 0 0 0 0 0 0 0 0 0 0
42563 - 0 0 0 0 0 0 0 0 0 0 0 0
42564 - 0 0 0 0 0 0 0 0 0 0 0 0
42565 - 0 0 0 0 0 0 0 0 0 0 0 0
42566 - 0 0 0 0 0 0 0 0 0 0 0 0
42567 - 0 0 0 0 0 0 0 0 0 0 0 0
42568 - 0 0 0 0 0 0 0 0 0 0 0 0
42569 - 0 0 0 0 0 0 0 0 0 0 0 0
42570 - 0 0 0 0 0 0 0 0 0 0 0 0
42571 - 0 0 0 0 0 0 0 0 0 10 10 10
42572 - 30 30 30 78 78 78 46 46 46 22 22 22
42573 -137 92 6 210 162 10 239 182 13 238 190 10
42574 -238 202 15 241 208 19 246 215 20 246 215 20
42575 -241 208 19 203 166 17 185 133 11 210 150 10
42576 -216 158 10 210 150 10 102 78 10 2 2 6
42577 - 6 6 6 54 54 54 14 14 14 2 2 6
42578 - 2 2 6 62 62 62 74 74 74 30 30 30
42579 - 10 10 10 0 0 0 0 0 0 0 0 0
42580 - 0 0 0 0 0 0 0 0 0 0 0 0
42581 - 0 0 0 0 0 0 0 0 0 0 0 0
42582 - 0 0 0 0 0 0 0 0 0 0 0 0
42583 - 0 0 0 0 0 0 0 0 0 0 0 0
42584 - 0 0 0 0 0 0 0 0 0 0 0 0
42585 - 0 0 0 0 0 0 0 0 0 0 0 0
42586 - 0 0 0 0 0 0 0 0 0 0 0 0
42587 - 0 0 0 0 0 0 0 0 0 0 0 0
42588 - 0 0 0 0 0 0 0 0 0 0 0 0
42589 - 0 0 0 0 0 0 0 0 0 0 0 0
42590 - 0 0 0 0 0 0 0 0 0 0 0 0
42591 - 0 0 0 0 0 0 0 0 0 10 10 10
42592 - 34 34 34 78 78 78 50 50 50 6 6 6
42593 - 94 70 30 139 102 15 190 146 13 226 184 13
42594 -232 200 30 232 195 16 215 174 15 190 146 13
42595 -168 122 10 192 133 9 210 150 10 213 154 11
42596 -202 150 34 182 157 106 101 98 89 2 2 6
42597 - 2 2 6 78 78 78 116 116 116 58 58 58
42598 - 2 2 6 22 22 22 90 90 90 46 46 46
42599 - 18 18 18 6 6 6 0 0 0 0 0 0
42600 - 0 0 0 0 0 0 0 0 0 0 0 0
42601 - 0 0 0 0 0 0 0 0 0 0 0 0
42602 - 0 0 0 0 0 0 0 0 0 0 0 0
42603 - 0 0 0 0 0 0 0 0 0 0 0 0
42604 - 0 0 0 0 0 0 0 0 0 0 0 0
42605 - 0 0 0 0 0 0 0 0 0 0 0 0
42606 - 0 0 0 0 0 0 0 0 0 0 0 0
42607 - 0 0 0 0 0 0 0 0 0 0 0 0
42608 - 0 0 0 0 0 0 0 0 0 0 0 0
42609 - 0 0 0 0 0 0 0 0 0 0 0 0
42610 - 0 0 0 0 0 0 0 0 0 0 0 0
42611 - 0 0 0 0 0 0 0 0 0 10 10 10
42612 - 38 38 38 86 86 86 50 50 50 6 6 6
42613 -128 128 128 174 154 114 156 107 11 168 122 10
42614 -198 155 10 184 144 12 197 138 11 200 144 11
42615 -206 145 10 206 145 10 197 138 11 188 164 115
42616 -195 195 195 198 198 198 174 174 174 14 14 14
42617 - 2 2 6 22 22 22 116 116 116 116 116 116
42618 - 22 22 22 2 2 6 74 74 74 70 70 70
42619 - 30 30 30 10 10 10 0 0 0 0 0 0
42620 - 0 0 0 0 0 0 0 0 0 0 0 0
42621 - 0 0 0 0 0 0 0 0 0 0 0 0
42622 - 0 0 0 0 0 0 0 0 0 0 0 0
42623 - 0 0 0 0 0 0 0 0 0 0 0 0
42624 - 0 0 0 0 0 0 0 0 0 0 0 0
42625 - 0 0 0 0 0 0 0 0 0 0 0 0
42626 - 0 0 0 0 0 0 0 0 0 0 0 0
42627 - 0 0 0 0 0 0 0 0 0 0 0 0
42628 - 0 0 0 0 0 0 0 0 0 0 0 0
42629 - 0 0 0 0 0 0 0 0 0 0 0 0
42630 - 0 0 0 0 0 0 0 0 0 0 0 0
42631 - 0 0 0 0 0 0 6 6 6 18 18 18
42632 - 50 50 50 101 101 101 26 26 26 10 10 10
42633 -138 138 138 190 190 190 174 154 114 156 107 11
42634 -197 138 11 200 144 11 197 138 11 192 133 9
42635 -180 123 7 190 142 34 190 178 144 187 187 187
42636 -202 202 202 221 221 221 214 214 214 66 66 66
42637 - 2 2 6 2 2 6 50 50 50 62 62 62
42638 - 6 6 6 2 2 6 10 10 10 90 90 90
42639 - 50 50 50 18 18 18 6 6 6 0 0 0
42640 - 0 0 0 0 0 0 0 0 0 0 0 0
42641 - 0 0 0 0 0 0 0 0 0 0 0 0
42642 - 0 0 0 0 0 0 0 0 0 0 0 0
42643 - 0 0 0 0 0 0 0 0 0 0 0 0
42644 - 0 0 0 0 0 0 0 0 0 0 0 0
42645 - 0 0 0 0 0 0 0 0 0 0 0 0
42646 - 0 0 0 0 0 0 0 0 0 0 0 0
42647 - 0 0 0 0 0 0 0 0 0 0 0 0
42648 - 0 0 0 0 0 0 0 0 0 0 0 0
42649 - 0 0 0 0 0 0 0 0 0 0 0 0
42650 - 0 0 0 0 0 0 0 0 0 0 0 0
42651 - 0 0 0 0 0 0 10 10 10 34 34 34
42652 - 74 74 74 74 74 74 2 2 6 6 6 6
42653 -144 144 144 198 198 198 190 190 190 178 166 146
42654 -154 121 60 156 107 11 156 107 11 168 124 44
42655 -174 154 114 187 187 187 190 190 190 210 210 210
42656 -246 246 246 253 253 253 253 253 253 182 182 182
42657 - 6 6 6 2 2 6 2 2 6 2 2 6
42658 - 2 2 6 2 2 6 2 2 6 62 62 62
42659 - 74 74 74 34 34 34 14 14 14 0 0 0
42660 - 0 0 0 0 0 0 0 0 0 0 0 0
42661 - 0 0 0 0 0 0 0 0 0 0 0 0
42662 - 0 0 0 0 0 0 0 0 0 0 0 0
42663 - 0 0 0 0 0 0 0 0 0 0 0 0
42664 - 0 0 0 0 0 0 0 0 0 0 0 0
42665 - 0 0 0 0 0 0 0 0 0 0 0 0
42666 - 0 0 0 0 0 0 0 0 0 0 0 0
42667 - 0 0 0 0 0 0 0 0 0 0 0 0
42668 - 0 0 0 0 0 0 0 0 0 0 0 0
42669 - 0 0 0 0 0 0 0 0 0 0 0 0
42670 - 0 0 0 0 0 0 0 0 0 0 0 0
42671 - 0 0 0 10 10 10 22 22 22 54 54 54
42672 - 94 94 94 18 18 18 2 2 6 46 46 46
42673 -234 234 234 221 221 221 190 190 190 190 190 190
42674 -190 190 190 187 187 187 187 187 187 190 190 190
42675 -190 190 190 195 195 195 214 214 214 242 242 242
42676 -253 253 253 253 253 253 253 253 253 253 253 253
42677 - 82 82 82 2 2 6 2 2 6 2 2 6
42678 - 2 2 6 2 2 6 2 2 6 14 14 14
42679 - 86 86 86 54 54 54 22 22 22 6 6 6
42680 - 0 0 0 0 0 0 0 0 0 0 0 0
42681 - 0 0 0 0 0 0 0 0 0 0 0 0
42682 - 0 0 0 0 0 0 0 0 0 0 0 0
42683 - 0 0 0 0 0 0 0 0 0 0 0 0
42684 - 0 0 0 0 0 0 0 0 0 0 0 0
42685 - 0 0 0 0 0 0 0 0 0 0 0 0
42686 - 0 0 0 0 0 0 0 0 0 0 0 0
42687 - 0 0 0 0 0 0 0 0 0 0 0 0
42688 - 0 0 0 0 0 0 0 0 0 0 0 0
42689 - 0 0 0 0 0 0 0 0 0 0 0 0
42690 - 0 0 0 0 0 0 0 0 0 0 0 0
42691 - 6 6 6 18 18 18 46 46 46 90 90 90
42692 - 46 46 46 18 18 18 6 6 6 182 182 182
42693 -253 253 253 246 246 246 206 206 206 190 190 190
42694 -190 190 190 190 190 190 190 190 190 190 190 190
42695 -206 206 206 231 231 231 250 250 250 253 253 253
42696 -253 253 253 253 253 253 253 253 253 253 253 253
42697 -202 202 202 14 14 14 2 2 6 2 2 6
42698 - 2 2 6 2 2 6 2 2 6 2 2 6
42699 - 42 42 42 86 86 86 42 42 42 18 18 18
42700 - 6 6 6 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 0 0 0 0 0 0 0 0 0
42706 - 0 0 0 0 0 0 0 0 0 0 0 0
42707 - 0 0 0 0 0 0 0 0 0 0 0 0
42708 - 0 0 0 0 0 0 0 0 0 0 0 0
42709 - 0 0 0 0 0 0 0 0 0 0 0 0
42710 - 0 0 0 0 0 0 0 0 0 6 6 6
42711 - 14 14 14 38 38 38 74 74 74 66 66 66
42712 - 2 2 6 6 6 6 90 90 90 250 250 250
42713 -253 253 253 253 253 253 238 238 238 198 198 198
42714 -190 190 190 190 190 190 195 195 195 221 221 221
42715 -246 246 246 253 253 253 253 253 253 253 253 253
42716 -253 253 253 253 253 253 253 253 253 253 253 253
42717 -253 253 253 82 82 82 2 2 6 2 2 6
42718 - 2 2 6 2 2 6 2 2 6 2 2 6
42719 - 2 2 6 78 78 78 70 70 70 34 34 34
42720 - 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
42727 - 0 0 0 0 0 0 0 0 0 0 0 0
42728 - 0 0 0 0 0 0 0 0 0 0 0 0
42729 - 0 0 0 0 0 0 0 0 0 0 0 0
42730 - 0 0 0 0 0 0 0 0 0 14 14 14
42731 - 34 34 34 66 66 66 78 78 78 6 6 6
42732 - 2 2 6 18 18 18 218 218 218 253 253 253
42733 -253 253 253 253 253 253 253 253 253 246 246 246
42734 -226 226 226 231 231 231 246 246 246 253 253 253
42735 -253 253 253 253 253 253 253 253 253 253 253 253
42736 -253 253 253 253 253 253 253 253 253 253 253 253
42737 -253 253 253 178 178 178 2 2 6 2 2 6
42738 - 2 2 6 2 2 6 2 2 6 2 2 6
42739 - 2 2 6 18 18 18 90 90 90 62 62 62
42740 - 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
42748 - 0 0 0 0 0 0 0 0 0 0 0 0
42749 - 0 0 0 0 0 0 0 0 0 0 0 0
42750 - 0 0 0 0 0 0 10 10 10 26 26 26
42751 - 58 58 58 90 90 90 18 18 18 2 2 6
42752 - 2 2 6 110 110 110 253 253 253 253 253 253
42753 -253 253 253 253 253 253 253 253 253 253 253 253
42754 -250 250 250 253 253 253 253 253 253 253 253 253
42755 -253 253 253 253 253 253 253 253 253 253 253 253
42756 -253 253 253 253 253 253 253 253 253 253 253 253
42757 -253 253 253 231 231 231 18 18 18 2 2 6
42758 - 2 2 6 2 2 6 2 2 6 2 2 6
42759 - 2 2 6 2 2 6 18 18 18 94 94 94
42760 - 54 54 54 26 26 26 10 10 10 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 0 0 0
42768 - 0 0 0 0 0 0 0 0 0 0 0 0
42769 - 0 0 0 0 0 0 0 0 0 0 0 0
42770 - 0 0 0 6 6 6 22 22 22 50 50 50
42771 - 90 90 90 26 26 26 2 2 6 2 2 6
42772 - 14 14 14 195 195 195 250 250 250 253 253 253
42773 -253 253 253 253 253 253 253 253 253 253 253 253
42774 -253 253 253 253 253 253 253 253 253 253 253 253
42775 -253 253 253 253 253 253 253 253 253 253 253 253
42776 -253 253 253 253 253 253 253 253 253 253 253 253
42777 -250 250 250 242 242 242 54 54 54 2 2 6
42778 - 2 2 6 2 2 6 2 2 6 2 2 6
42779 - 2 2 6 2 2 6 2 2 6 38 38 38
42780 - 86 86 86 50 50 50 22 22 22 6 6 6
42781 - 0 0 0 0 0 0 0 0 0 0 0 0
42782 - 0 0 0 0 0 0 0 0 0 0 0 0
42783 - 0 0 0 0 0 0 0 0 0 0 0 0
42784 - 0 0 0 0 0 0 0 0 0 0 0 0
42785 - 0 0 0 0 0 0 0 0 0 0 0 0
42786 - 0 0 0 0 0 0 0 0 0 0 0 0
42787 - 0 0 0 0 0 0 0 0 0 0 0 0
42788 - 0 0 0 0 0 0 0 0 0 0 0 0
42789 - 0 0 0 0 0 0 0 0 0 0 0 0
42790 - 6 6 6 14 14 14 38 38 38 82 82 82
42791 - 34 34 34 2 2 6 2 2 6 2 2 6
42792 - 42 42 42 195 195 195 246 246 246 253 253 253
42793 -253 253 253 253 253 253 253 253 253 250 250 250
42794 -242 242 242 242 242 242 250 250 250 253 253 253
42795 -253 253 253 253 253 253 253 253 253 253 253 253
42796 -253 253 253 250 250 250 246 246 246 238 238 238
42797 -226 226 226 231 231 231 101 101 101 6 6 6
42798 - 2 2 6 2 2 6 2 2 6 2 2 6
42799 - 2 2 6 2 2 6 2 2 6 2 2 6
42800 - 38 38 38 82 82 82 42 42 42 14 14 14
42801 - 6 6 6 0 0 0 0 0 0 0 0 0
42802 - 0 0 0 0 0 0 0 0 0 0 0 0
42803 - 0 0 0 0 0 0 0 0 0 0 0 0
42804 - 0 0 0 0 0 0 0 0 0 0 0 0
42805 - 0 0 0 0 0 0 0 0 0 0 0 0
42806 - 0 0 0 0 0 0 0 0 0 0 0 0
42807 - 0 0 0 0 0 0 0 0 0 0 0 0
42808 - 0 0 0 0 0 0 0 0 0 0 0 0
42809 - 0 0 0 0 0 0 0 0 0 0 0 0
42810 - 10 10 10 26 26 26 62 62 62 66 66 66
42811 - 2 2 6 2 2 6 2 2 6 6 6 6
42812 - 70 70 70 170 170 170 206 206 206 234 234 234
42813 -246 246 246 250 250 250 250 250 250 238 238 238
42814 -226 226 226 231 231 231 238 238 238 250 250 250
42815 -250 250 250 250 250 250 246 246 246 231 231 231
42816 -214 214 214 206 206 206 202 202 202 202 202 202
42817 -198 198 198 202 202 202 182 182 182 18 18 18
42818 - 2 2 6 2 2 6 2 2 6 2 2 6
42819 - 2 2 6 2 2 6 2 2 6 2 2 6
42820 - 2 2 6 62 62 62 66 66 66 30 30 30
42821 - 10 10 10 0 0 0 0 0 0 0 0 0
42822 - 0 0 0 0 0 0 0 0 0 0 0 0
42823 - 0 0 0 0 0 0 0 0 0 0 0 0
42824 - 0 0 0 0 0 0 0 0 0 0 0 0
42825 - 0 0 0 0 0 0 0 0 0 0 0 0
42826 - 0 0 0 0 0 0 0 0 0 0 0 0
42827 - 0 0 0 0 0 0 0 0 0 0 0 0
42828 - 0 0 0 0 0 0 0 0 0 0 0 0
42829 - 0 0 0 0 0 0 0 0 0 0 0 0
42830 - 14 14 14 42 42 42 82 82 82 18 18 18
42831 - 2 2 6 2 2 6 2 2 6 10 10 10
42832 - 94 94 94 182 182 182 218 218 218 242 242 242
42833 -250 250 250 253 253 253 253 253 253 250 250 250
42834 -234 234 234 253 253 253 253 253 253 253 253 253
42835 -253 253 253 253 253 253 253 253 253 246 246 246
42836 -238 238 238 226 226 226 210 210 210 202 202 202
42837 -195 195 195 195 195 195 210 210 210 158 158 158
42838 - 6 6 6 14 14 14 50 50 50 14 14 14
42839 - 2 2 6 2 2 6 2 2 6 2 2 6
42840 - 2 2 6 6 6 6 86 86 86 46 46 46
42841 - 18 18 18 6 6 6 0 0 0 0 0 0
42842 - 0 0 0 0 0 0 0 0 0 0 0 0
42843 - 0 0 0 0 0 0 0 0 0 0 0 0
42844 - 0 0 0 0 0 0 0 0 0 0 0 0
42845 - 0 0 0 0 0 0 0 0 0 0 0 0
42846 - 0 0 0 0 0 0 0 0 0 0 0 0
42847 - 0 0 0 0 0 0 0 0 0 0 0 0
42848 - 0 0 0 0 0 0 0 0 0 0 0 0
42849 - 0 0 0 0 0 0 0 0 0 6 6 6
42850 - 22 22 22 54 54 54 70 70 70 2 2 6
42851 - 2 2 6 10 10 10 2 2 6 22 22 22
42852 -166 166 166 231 231 231 250 250 250 253 253 253
42853 -253 253 253 253 253 253 253 253 253 250 250 250
42854 -242 242 242 253 253 253 253 253 253 253 253 253
42855 -253 253 253 253 253 253 253 253 253 253 253 253
42856 -253 253 253 253 253 253 253 253 253 246 246 246
42857 -231 231 231 206 206 206 198 198 198 226 226 226
42858 - 94 94 94 2 2 6 6 6 6 38 38 38
42859 - 30 30 30 2 2 6 2 2 6 2 2 6
42860 - 2 2 6 2 2 6 62 62 62 66 66 66
42861 - 26 26 26 10 10 10 0 0 0 0 0 0
42862 - 0 0 0 0 0 0 0 0 0 0 0 0
42863 - 0 0 0 0 0 0 0 0 0 0 0 0
42864 - 0 0 0 0 0 0 0 0 0 0 0 0
42865 - 0 0 0 0 0 0 0 0 0 0 0 0
42866 - 0 0 0 0 0 0 0 0 0 0 0 0
42867 - 0 0 0 0 0 0 0 0 0 0 0 0
42868 - 0 0 0 0 0 0 0 0 0 0 0 0
42869 - 0 0 0 0 0 0 0 0 0 10 10 10
42870 - 30 30 30 74 74 74 50 50 50 2 2 6
42871 - 26 26 26 26 26 26 2 2 6 106 106 106
42872 -238 238 238 253 253 253 253 253 253 253 253 253
42873 -253 253 253 253 253 253 253 253 253 253 253 253
42874 -253 253 253 253 253 253 253 253 253 253 253 253
42875 -253 253 253 253 253 253 253 253 253 253 253 253
42876 -253 253 253 253 253 253 253 253 253 253 253 253
42877 -253 253 253 246 246 246 218 218 218 202 202 202
42878 -210 210 210 14 14 14 2 2 6 2 2 6
42879 - 30 30 30 22 22 22 2 2 6 2 2 6
42880 - 2 2 6 2 2 6 18 18 18 86 86 86
42881 - 42 42 42 14 14 14 0 0 0 0 0 0
42882 - 0 0 0 0 0 0 0 0 0 0 0 0
42883 - 0 0 0 0 0 0 0 0 0 0 0 0
42884 - 0 0 0 0 0 0 0 0 0 0 0 0
42885 - 0 0 0 0 0 0 0 0 0 0 0 0
42886 - 0 0 0 0 0 0 0 0 0 0 0 0
42887 - 0 0 0 0 0 0 0 0 0 0 0 0
42888 - 0 0 0 0 0 0 0 0 0 0 0 0
42889 - 0 0 0 0 0 0 0 0 0 14 14 14
42890 - 42 42 42 90 90 90 22 22 22 2 2 6
42891 - 42 42 42 2 2 6 18 18 18 218 218 218
42892 -253 253 253 253 253 253 253 253 253 253 253 253
42893 -253 253 253 253 253 253 253 253 253 253 253 253
42894 -253 253 253 253 253 253 253 253 253 253 253 253
42895 -253 253 253 253 253 253 253 253 253 253 253 253
42896 -253 253 253 253 253 253 253 253 253 253 253 253
42897 -253 253 253 253 253 253 250 250 250 221 221 221
42898 -218 218 218 101 101 101 2 2 6 14 14 14
42899 - 18 18 18 38 38 38 10 10 10 2 2 6
42900 - 2 2 6 2 2 6 2 2 6 78 78 78
42901 - 58 58 58 22 22 22 6 6 6 0 0 0
42902 - 0 0 0 0 0 0 0 0 0 0 0 0
42903 - 0 0 0 0 0 0 0 0 0 0 0 0
42904 - 0 0 0 0 0 0 0 0 0 0 0 0
42905 - 0 0 0 0 0 0 0 0 0 0 0 0
42906 - 0 0 0 0 0 0 0 0 0 0 0 0
42907 - 0 0 0 0 0 0 0 0 0 0 0 0
42908 - 0 0 0 0 0 0 0 0 0 0 0 0
42909 - 0 0 0 0 0 0 6 6 6 18 18 18
42910 - 54 54 54 82 82 82 2 2 6 26 26 26
42911 - 22 22 22 2 2 6 123 123 123 253 253 253
42912 -253 253 253 253 253 253 253 253 253 253 253 253
42913 -253 253 253 253 253 253 253 253 253 253 253 253
42914 -253 253 253 253 253 253 253 253 253 253 253 253
42915 -253 253 253 253 253 253 253 253 253 253 253 253
42916 -253 253 253 253 253 253 253 253 253 253 253 253
42917 -253 253 253 253 253 253 253 253 253 250 250 250
42918 -238 238 238 198 198 198 6 6 6 38 38 38
42919 - 58 58 58 26 26 26 38 38 38 2 2 6
42920 - 2 2 6 2 2 6 2 2 6 46 46 46
42921 - 78 78 78 30 30 30 10 10 10 0 0 0
42922 - 0 0 0 0 0 0 0 0 0 0 0 0
42923 - 0 0 0 0 0 0 0 0 0 0 0 0
42924 - 0 0 0 0 0 0 0 0 0 0 0 0
42925 - 0 0 0 0 0 0 0 0 0 0 0 0
42926 - 0 0 0 0 0 0 0 0 0 0 0 0
42927 - 0 0 0 0 0 0 0 0 0 0 0 0
42928 - 0 0 0 0 0 0 0 0 0 0 0 0
42929 - 0 0 0 0 0 0 10 10 10 30 30 30
42930 - 74 74 74 58 58 58 2 2 6 42 42 42
42931 - 2 2 6 22 22 22 231 231 231 253 253 253
42932 -253 253 253 253 253 253 253 253 253 253 253 253
42933 -253 253 253 253 253 253 253 253 253 250 250 250
42934 -253 253 253 253 253 253 253 253 253 253 253 253
42935 -253 253 253 253 253 253 253 253 253 253 253 253
42936 -253 253 253 253 253 253 253 253 253 253 253 253
42937 -253 253 253 253 253 253 253 253 253 253 253 253
42938 -253 253 253 246 246 246 46 46 46 38 38 38
42939 - 42 42 42 14 14 14 38 38 38 14 14 14
42940 - 2 2 6 2 2 6 2 2 6 6 6 6
42941 - 86 86 86 46 46 46 14 14 14 0 0 0
42942 - 0 0 0 0 0 0 0 0 0 0 0 0
42943 - 0 0 0 0 0 0 0 0 0 0 0 0
42944 - 0 0 0 0 0 0 0 0 0 0 0 0
42945 - 0 0 0 0 0 0 0 0 0 0 0 0
42946 - 0 0 0 0 0 0 0 0 0 0 0 0
42947 - 0 0 0 0 0 0 0 0 0 0 0 0
42948 - 0 0 0 0 0 0 0 0 0 0 0 0
42949 - 0 0 0 6 6 6 14 14 14 42 42 42
42950 - 90 90 90 18 18 18 18 18 18 26 26 26
42951 - 2 2 6 116 116 116 253 253 253 253 253 253
42952 -253 253 253 253 253 253 253 253 253 253 253 253
42953 -253 253 253 253 253 253 250 250 250 238 238 238
42954 -253 253 253 253 253 253 253 253 253 253 253 253
42955 -253 253 253 253 253 253 253 253 253 253 253 253
42956 -253 253 253 253 253 253 253 253 253 253 253 253
42957 -253 253 253 253 253 253 253 253 253 253 253 253
42958 -253 253 253 253 253 253 94 94 94 6 6 6
42959 - 2 2 6 2 2 6 10 10 10 34 34 34
42960 - 2 2 6 2 2 6 2 2 6 2 2 6
42961 - 74 74 74 58 58 58 22 22 22 6 6 6
42962 - 0 0 0 0 0 0 0 0 0 0 0 0
42963 - 0 0 0 0 0 0 0 0 0 0 0 0
42964 - 0 0 0 0 0 0 0 0 0 0 0 0
42965 - 0 0 0 0 0 0 0 0 0 0 0 0
42966 - 0 0 0 0 0 0 0 0 0 0 0 0
42967 - 0 0 0 0 0 0 0 0 0 0 0 0
42968 - 0 0 0 0 0 0 0 0 0 0 0 0
42969 - 0 0 0 10 10 10 26 26 26 66 66 66
42970 - 82 82 82 2 2 6 38 38 38 6 6 6
42971 - 14 14 14 210 210 210 253 253 253 253 253 253
42972 -253 253 253 253 253 253 253 253 253 253 253 253
42973 -253 253 253 253 253 253 246 246 246 242 242 242
42974 -253 253 253 253 253 253 253 253 253 253 253 253
42975 -253 253 253 253 253 253 253 253 253 253 253 253
42976 -253 253 253 253 253 253 253 253 253 253 253 253
42977 -253 253 253 253 253 253 253 253 253 253 253 253
42978 -253 253 253 253 253 253 144 144 144 2 2 6
42979 - 2 2 6 2 2 6 2 2 6 46 46 46
42980 - 2 2 6 2 2 6 2 2 6 2 2 6
42981 - 42 42 42 74 74 74 30 30 30 10 10 10
42982 - 0 0 0 0 0 0 0 0 0 0 0 0
42983 - 0 0 0 0 0 0 0 0 0 0 0 0
42984 - 0 0 0 0 0 0 0 0 0 0 0 0
42985 - 0 0 0 0 0 0 0 0 0 0 0 0
42986 - 0 0 0 0 0 0 0 0 0 0 0 0
42987 - 0 0 0 0 0 0 0 0 0 0 0 0
42988 - 0 0 0 0 0 0 0 0 0 0 0 0
42989 - 6 6 6 14 14 14 42 42 42 90 90 90
42990 - 26 26 26 6 6 6 42 42 42 2 2 6
42991 - 74 74 74 250 250 250 253 253 253 253 253 253
42992 -253 253 253 253 253 253 253 253 253 253 253 253
42993 -253 253 253 253 253 253 242 242 242 242 242 242
42994 -253 253 253 253 253 253 253 253 253 253 253 253
42995 -253 253 253 253 253 253 253 253 253 253 253 253
42996 -253 253 253 253 253 253 253 253 253 253 253 253
42997 -253 253 253 253 253 253 253 253 253 253 253 253
42998 -253 253 253 253 253 253 182 182 182 2 2 6
42999 - 2 2 6 2 2 6 2 2 6 46 46 46
43000 - 2 2 6 2 2 6 2 2 6 2 2 6
43001 - 10 10 10 86 86 86 38 38 38 10 10 10
43002 - 0 0 0 0 0 0 0 0 0 0 0 0
43003 - 0 0 0 0 0 0 0 0 0 0 0 0
43004 - 0 0 0 0 0 0 0 0 0 0 0 0
43005 - 0 0 0 0 0 0 0 0 0 0 0 0
43006 - 0 0 0 0 0 0 0 0 0 0 0 0
43007 - 0 0 0 0 0 0 0 0 0 0 0 0
43008 - 0 0 0 0 0 0 0 0 0 0 0 0
43009 - 10 10 10 26 26 26 66 66 66 82 82 82
43010 - 2 2 6 22 22 22 18 18 18 2 2 6
43011 -149 149 149 253 253 253 253 253 253 253 253 253
43012 -253 253 253 253 253 253 253 253 253 253 253 253
43013 -253 253 253 253 253 253 234 234 234 242 242 242
43014 -253 253 253 253 253 253 253 253 253 253 253 253
43015 -253 253 253 253 253 253 253 253 253 253 253 253
43016 -253 253 253 253 253 253 253 253 253 253 253 253
43017 -253 253 253 253 253 253 253 253 253 253 253 253
43018 -253 253 253 253 253 253 206 206 206 2 2 6
43019 - 2 2 6 2 2 6 2 2 6 38 38 38
43020 - 2 2 6 2 2 6 2 2 6 2 2 6
43021 - 6 6 6 86 86 86 46 46 46 14 14 14
43022 - 0 0 0 0 0 0 0 0 0 0 0 0
43023 - 0 0 0 0 0 0 0 0 0 0 0 0
43024 - 0 0 0 0 0 0 0 0 0 0 0 0
43025 - 0 0 0 0 0 0 0 0 0 0 0 0
43026 - 0 0 0 0 0 0 0 0 0 0 0 0
43027 - 0 0 0 0 0 0 0 0 0 0 0 0
43028 - 0 0 0 0 0 0 0 0 0 6 6 6
43029 - 18 18 18 46 46 46 86 86 86 18 18 18
43030 - 2 2 6 34 34 34 10 10 10 6 6 6
43031 -210 210 210 253 253 253 253 253 253 253 253 253
43032 -253 253 253 253 253 253 253 253 253 253 253 253
43033 -253 253 253 253 253 253 234 234 234 242 242 242
43034 -253 253 253 253 253 253 253 253 253 253 253 253
43035 -253 253 253 253 253 253 253 253 253 253 253 253
43036 -253 253 253 253 253 253 253 253 253 253 253 253
43037 -253 253 253 253 253 253 253 253 253 253 253 253
43038 -253 253 253 253 253 253 221 221 221 6 6 6
43039 - 2 2 6 2 2 6 6 6 6 30 30 30
43040 - 2 2 6 2 2 6 2 2 6 2 2 6
43041 - 2 2 6 82 82 82 54 54 54 18 18 18
43042 - 6 6 6 0 0 0 0 0 0 0 0 0
43043 - 0 0 0 0 0 0 0 0 0 0 0 0
43044 - 0 0 0 0 0 0 0 0 0 0 0 0
43045 - 0 0 0 0 0 0 0 0 0 0 0 0
43046 - 0 0 0 0 0 0 0 0 0 0 0 0
43047 - 0 0 0 0 0 0 0 0 0 0 0 0
43048 - 0 0 0 0 0 0 0 0 0 10 10 10
43049 - 26 26 26 66 66 66 62 62 62 2 2 6
43050 - 2 2 6 38 38 38 10 10 10 26 26 26
43051 -238 238 238 253 253 253 253 253 253 253 253 253
43052 -253 253 253 253 253 253 253 253 253 253 253 253
43053 -253 253 253 253 253 253 231 231 231 238 238 238
43054 -253 253 253 253 253 253 253 253 253 253 253 253
43055 -253 253 253 253 253 253 253 253 253 253 253 253
43056 -253 253 253 253 253 253 253 253 253 253 253 253
43057 -253 253 253 253 253 253 253 253 253 253 253 253
43058 -253 253 253 253 253 253 231 231 231 6 6 6
43059 - 2 2 6 2 2 6 10 10 10 30 30 30
43060 - 2 2 6 2 2 6 2 2 6 2 2 6
43061 - 2 2 6 66 66 66 58 58 58 22 22 22
43062 - 6 6 6 0 0 0 0 0 0 0 0 0
43063 - 0 0 0 0 0 0 0 0 0 0 0 0
43064 - 0 0 0 0 0 0 0 0 0 0 0 0
43065 - 0 0 0 0 0 0 0 0 0 0 0 0
43066 - 0 0 0 0 0 0 0 0 0 0 0 0
43067 - 0 0 0 0 0 0 0 0 0 0 0 0
43068 - 0 0 0 0 0 0 0 0 0 10 10 10
43069 - 38 38 38 78 78 78 6 6 6 2 2 6
43070 - 2 2 6 46 46 46 14 14 14 42 42 42
43071 -246 246 246 253 253 253 253 253 253 253 253 253
43072 -253 253 253 253 253 253 253 253 253 253 253 253
43073 -253 253 253 253 253 253 231 231 231 242 242 242
43074 -253 253 253 253 253 253 253 253 253 253 253 253
43075 -253 253 253 253 253 253 253 253 253 253 253 253
43076 -253 253 253 253 253 253 253 253 253 253 253 253
43077 -253 253 253 253 253 253 253 253 253 253 253 253
43078 -253 253 253 253 253 253 234 234 234 10 10 10
43079 - 2 2 6 2 2 6 22 22 22 14 14 14
43080 - 2 2 6 2 2 6 2 2 6 2 2 6
43081 - 2 2 6 66 66 66 62 62 62 22 22 22
43082 - 6 6 6 0 0 0 0 0 0 0 0 0
43083 - 0 0 0 0 0 0 0 0 0 0 0 0
43084 - 0 0 0 0 0 0 0 0 0 0 0 0
43085 - 0 0 0 0 0 0 0 0 0 0 0 0
43086 - 0 0 0 0 0 0 0 0 0 0 0 0
43087 - 0 0 0 0 0 0 0 0 0 0 0 0
43088 - 0 0 0 0 0 0 6 6 6 18 18 18
43089 - 50 50 50 74 74 74 2 2 6 2 2 6
43090 - 14 14 14 70 70 70 34 34 34 62 62 62
43091 -250 250 250 253 253 253 253 253 253 253 253 253
43092 -253 253 253 253 253 253 253 253 253 253 253 253
43093 -253 253 253 253 253 253 231 231 231 246 246 246
43094 -253 253 253 253 253 253 253 253 253 253 253 253
43095 -253 253 253 253 253 253 253 253 253 253 253 253
43096 -253 253 253 253 253 253 253 253 253 253 253 253
43097 -253 253 253 253 253 253 253 253 253 253 253 253
43098 -253 253 253 253 253 253 234 234 234 14 14 14
43099 - 2 2 6 2 2 6 30 30 30 2 2 6
43100 - 2 2 6 2 2 6 2 2 6 2 2 6
43101 - 2 2 6 66 66 66 62 62 62 22 22 22
43102 - 6 6 6 0 0 0 0 0 0 0 0 0
43103 - 0 0 0 0 0 0 0 0 0 0 0 0
43104 - 0 0 0 0 0 0 0 0 0 0 0 0
43105 - 0 0 0 0 0 0 0 0 0 0 0 0
43106 - 0 0 0 0 0 0 0 0 0 0 0 0
43107 - 0 0 0 0 0 0 0 0 0 0 0 0
43108 - 0 0 0 0 0 0 6 6 6 18 18 18
43109 - 54 54 54 62 62 62 2 2 6 2 2 6
43110 - 2 2 6 30 30 30 46 46 46 70 70 70
43111 -250 250 250 253 253 253 253 253 253 253 253 253
43112 -253 253 253 253 253 253 253 253 253 253 253 253
43113 -253 253 253 253 253 253 231 231 231 246 246 246
43114 -253 253 253 253 253 253 253 253 253 253 253 253
43115 -253 253 253 253 253 253 253 253 253 253 253 253
43116 -253 253 253 253 253 253 253 253 253 253 253 253
43117 -253 253 253 253 253 253 253 253 253 253 253 253
43118 -253 253 253 253 253 253 226 226 226 10 10 10
43119 - 2 2 6 6 6 6 30 30 30 2 2 6
43120 - 2 2 6 2 2 6 2 2 6 2 2 6
43121 - 2 2 6 66 66 66 58 58 58 22 22 22
43122 - 6 6 6 0 0 0 0 0 0 0 0 0
43123 - 0 0 0 0 0 0 0 0 0 0 0 0
43124 - 0 0 0 0 0 0 0 0 0 0 0 0
43125 - 0 0 0 0 0 0 0 0 0 0 0 0
43126 - 0 0 0 0 0 0 0 0 0 0 0 0
43127 - 0 0 0 0 0 0 0 0 0 0 0 0
43128 - 0 0 0 0 0 0 6 6 6 22 22 22
43129 - 58 58 58 62 62 62 2 2 6 2 2 6
43130 - 2 2 6 2 2 6 30 30 30 78 78 78
43131 -250 250 250 253 253 253 253 253 253 253 253 253
43132 -253 253 253 253 253 253 253 253 253 253 253 253
43133 -253 253 253 253 253 253 231 231 231 246 246 246
43134 -253 253 253 253 253 253 253 253 253 253 253 253
43135 -253 253 253 253 253 253 253 253 253 253 253 253
43136 -253 253 253 253 253 253 253 253 253 253 253 253
43137 -253 253 253 253 253 253 253 253 253 253 253 253
43138 -253 253 253 253 253 253 206 206 206 2 2 6
43139 - 22 22 22 34 34 34 18 14 6 22 22 22
43140 - 26 26 26 18 18 18 6 6 6 2 2 6
43141 - 2 2 6 82 82 82 54 54 54 18 18 18
43142 - 6 6 6 0 0 0 0 0 0 0 0 0
43143 - 0 0 0 0 0 0 0 0 0 0 0 0
43144 - 0 0 0 0 0 0 0 0 0 0 0 0
43145 - 0 0 0 0 0 0 0 0 0 0 0 0
43146 - 0 0 0 0 0 0 0 0 0 0 0 0
43147 - 0 0 0 0 0 0 0 0 0 0 0 0
43148 - 0 0 0 0 0 0 6 6 6 26 26 26
43149 - 62 62 62 106 106 106 74 54 14 185 133 11
43150 -210 162 10 121 92 8 6 6 6 62 62 62
43151 -238 238 238 253 253 253 253 253 253 253 253 253
43152 -253 253 253 253 253 253 253 253 253 253 253 253
43153 -253 253 253 253 253 253 231 231 231 246 246 246
43154 -253 253 253 253 253 253 253 253 253 253 253 253
43155 -253 253 253 253 253 253 253 253 253 253 253 253
43156 -253 253 253 253 253 253 253 253 253 253 253 253
43157 -253 253 253 253 253 253 253 253 253 253 253 253
43158 -253 253 253 253 253 253 158 158 158 18 18 18
43159 - 14 14 14 2 2 6 2 2 6 2 2 6
43160 - 6 6 6 18 18 18 66 66 66 38 38 38
43161 - 6 6 6 94 94 94 50 50 50 18 18 18
43162 - 6 6 6 0 0 0 0 0 0 0 0 0
43163 - 0 0 0 0 0 0 0 0 0 0 0 0
43164 - 0 0 0 0 0 0 0 0 0 0 0 0
43165 - 0 0 0 0 0 0 0 0 0 0 0 0
43166 - 0 0 0 0 0 0 0 0 0 0 0 0
43167 - 0 0 0 0 0 0 0 0 0 6 6 6
43168 - 10 10 10 10 10 10 18 18 18 38 38 38
43169 - 78 78 78 142 134 106 216 158 10 242 186 14
43170 -246 190 14 246 190 14 156 118 10 10 10 10
43171 - 90 90 90 238 238 238 253 253 253 253 253 253
43172 -253 253 253 253 253 253 253 253 253 253 253 253
43173 -253 253 253 253 253 253 231 231 231 250 250 250
43174 -253 253 253 253 253 253 253 253 253 253 253 253
43175 -253 253 253 253 253 253 253 253 253 253 253 253
43176 -253 253 253 253 253 253 253 253 253 253 253 253
43177 -253 253 253 253 253 253 253 253 253 246 230 190
43178 -238 204 91 238 204 91 181 142 44 37 26 9
43179 - 2 2 6 2 2 6 2 2 6 2 2 6
43180 - 2 2 6 2 2 6 38 38 38 46 46 46
43181 - 26 26 26 106 106 106 54 54 54 18 18 18
43182 - 6 6 6 0 0 0 0 0 0 0 0 0
43183 - 0 0 0 0 0 0 0 0 0 0 0 0
43184 - 0 0 0 0 0 0 0 0 0 0 0 0
43185 - 0 0 0 0 0 0 0 0 0 0 0 0
43186 - 0 0 0 0 0 0 0 0 0 0 0 0
43187 - 0 0 0 6 6 6 14 14 14 22 22 22
43188 - 30 30 30 38 38 38 50 50 50 70 70 70
43189 -106 106 106 190 142 34 226 170 11 242 186 14
43190 -246 190 14 246 190 14 246 190 14 154 114 10
43191 - 6 6 6 74 74 74 226 226 226 253 253 253
43192 -253 253 253 253 253 253 253 253 253 253 253 253
43193 -253 253 253 253 253 253 231 231 231 250 250 250
43194 -253 253 253 253 253 253 253 253 253 253 253 253
43195 -253 253 253 253 253 253 253 253 253 253 253 253
43196 -253 253 253 253 253 253 253 253 253 253 253 253
43197 -253 253 253 253 253 253 253 253 253 228 184 62
43198 -241 196 14 241 208 19 232 195 16 38 30 10
43199 - 2 2 6 2 2 6 2 2 6 2 2 6
43200 - 2 2 6 6 6 6 30 30 30 26 26 26
43201 -203 166 17 154 142 90 66 66 66 26 26 26
43202 - 6 6 6 0 0 0 0 0 0 0 0 0
43203 - 0 0 0 0 0 0 0 0 0 0 0 0
43204 - 0 0 0 0 0 0 0 0 0 0 0 0
43205 - 0 0 0 0 0 0 0 0 0 0 0 0
43206 - 0 0 0 0 0 0 0 0 0 0 0 0
43207 - 6 6 6 18 18 18 38 38 38 58 58 58
43208 - 78 78 78 86 86 86 101 101 101 123 123 123
43209 -175 146 61 210 150 10 234 174 13 246 186 14
43210 -246 190 14 246 190 14 246 190 14 238 190 10
43211 -102 78 10 2 2 6 46 46 46 198 198 198
43212 -253 253 253 253 253 253 253 253 253 253 253 253
43213 -253 253 253 253 253 253 234 234 234 242 242 242
43214 -253 253 253 253 253 253 253 253 253 253 253 253
43215 -253 253 253 253 253 253 253 253 253 253 253 253
43216 -253 253 253 253 253 253 253 253 253 253 253 253
43217 -253 253 253 253 253 253 253 253 253 224 178 62
43218 -242 186 14 241 196 14 210 166 10 22 18 6
43219 - 2 2 6 2 2 6 2 2 6 2 2 6
43220 - 2 2 6 2 2 6 6 6 6 121 92 8
43221 -238 202 15 232 195 16 82 82 82 34 34 34
43222 - 10 10 10 0 0 0 0 0 0 0 0 0
43223 - 0 0 0 0 0 0 0 0 0 0 0 0
43224 - 0 0 0 0 0 0 0 0 0 0 0 0
43225 - 0 0 0 0 0 0 0 0 0 0 0 0
43226 - 0 0 0 0 0 0 0 0 0 0 0 0
43227 - 14 14 14 38 38 38 70 70 70 154 122 46
43228 -190 142 34 200 144 11 197 138 11 197 138 11
43229 -213 154 11 226 170 11 242 186 14 246 190 14
43230 -246 190 14 246 190 14 246 190 14 246 190 14
43231 -225 175 15 46 32 6 2 2 6 22 22 22
43232 -158 158 158 250 250 250 253 253 253 253 253 253
43233 -253 253 253 253 253 253 253 253 253 253 253 253
43234 -253 253 253 253 253 253 253 253 253 253 253 253
43235 -253 253 253 253 253 253 253 253 253 253 253 253
43236 -253 253 253 253 253 253 253 253 253 253 253 253
43237 -253 253 253 250 250 250 242 242 242 224 178 62
43238 -239 182 13 236 186 11 213 154 11 46 32 6
43239 - 2 2 6 2 2 6 2 2 6 2 2 6
43240 - 2 2 6 2 2 6 61 42 6 225 175 15
43241 -238 190 10 236 186 11 112 100 78 42 42 42
43242 - 14 14 14 0 0 0 0 0 0 0 0 0
43243 - 0 0 0 0 0 0 0 0 0 0 0 0
43244 - 0 0 0 0 0 0 0 0 0 0 0 0
43245 - 0 0 0 0 0 0 0 0 0 0 0 0
43246 - 0 0 0 0 0 0 0 0 0 6 6 6
43247 - 22 22 22 54 54 54 154 122 46 213 154 11
43248 -226 170 11 230 174 11 226 170 11 226 170 11
43249 -236 178 12 242 186 14 246 190 14 246 190 14
43250 -246 190 14 246 190 14 246 190 14 246 190 14
43251 -241 196 14 184 144 12 10 10 10 2 2 6
43252 - 6 6 6 116 116 116 242 242 242 253 253 253
43253 -253 253 253 253 253 253 253 253 253 253 253 253
43254 -253 253 253 253 253 253 253 253 253 253 253 253
43255 -253 253 253 253 253 253 253 253 253 253 253 253
43256 -253 253 253 253 253 253 253 253 253 253 253 253
43257 -253 253 253 231 231 231 198 198 198 214 170 54
43258 -236 178 12 236 178 12 210 150 10 137 92 6
43259 - 18 14 6 2 2 6 2 2 6 2 2 6
43260 - 6 6 6 70 47 6 200 144 11 236 178 12
43261 -239 182 13 239 182 13 124 112 88 58 58 58
43262 - 22 22 22 6 6 6 0 0 0 0 0 0
43263 - 0 0 0 0 0 0 0 0 0 0 0 0
43264 - 0 0 0 0 0 0 0 0 0 0 0 0
43265 - 0 0 0 0 0 0 0 0 0 0 0 0
43266 - 0 0 0 0 0 0 0 0 0 10 10 10
43267 - 30 30 30 70 70 70 180 133 36 226 170 11
43268 -239 182 13 242 186 14 242 186 14 246 186 14
43269 -246 190 14 246 190 14 246 190 14 246 190 14
43270 -246 190 14 246 190 14 246 190 14 246 190 14
43271 -246 190 14 232 195 16 98 70 6 2 2 6
43272 - 2 2 6 2 2 6 66 66 66 221 221 221
43273 -253 253 253 253 253 253 253 253 253 253 253 253
43274 -253 253 253 253 253 253 253 253 253 253 253 253
43275 -253 253 253 253 253 253 253 253 253 253 253 253
43276 -253 253 253 253 253 253 253 253 253 253 253 253
43277 -253 253 253 206 206 206 198 198 198 214 166 58
43278 -230 174 11 230 174 11 216 158 10 192 133 9
43279 -163 110 8 116 81 8 102 78 10 116 81 8
43280 -167 114 7 197 138 11 226 170 11 239 182 13
43281 -242 186 14 242 186 14 162 146 94 78 78 78
43282 - 34 34 34 14 14 14 6 6 6 0 0 0
43283 - 0 0 0 0 0 0 0 0 0 0 0 0
43284 - 0 0 0 0 0 0 0 0 0 0 0 0
43285 - 0 0 0 0 0 0 0 0 0 0 0 0
43286 - 0 0 0 0 0 0 0 0 0 6 6 6
43287 - 30 30 30 78 78 78 190 142 34 226 170 11
43288 -239 182 13 246 190 14 246 190 14 246 190 14
43289 -246 190 14 246 190 14 246 190 14 246 190 14
43290 -246 190 14 246 190 14 246 190 14 246 190 14
43291 -246 190 14 241 196 14 203 166 17 22 18 6
43292 - 2 2 6 2 2 6 2 2 6 38 38 38
43293 -218 218 218 253 253 253 253 253 253 253 253 253
43294 -253 253 253 253 253 253 253 253 253 253 253 253
43295 -253 253 253 253 253 253 253 253 253 253 253 253
43296 -253 253 253 253 253 253 253 253 253 253 253 253
43297 -250 250 250 206 206 206 198 198 198 202 162 69
43298 -226 170 11 236 178 12 224 166 10 210 150 10
43299 -200 144 11 197 138 11 192 133 9 197 138 11
43300 -210 150 10 226 170 11 242 186 14 246 190 14
43301 -246 190 14 246 186 14 225 175 15 124 112 88
43302 - 62 62 62 30 30 30 14 14 14 6 6 6
43303 - 0 0 0 0 0 0 0 0 0 0 0 0
43304 - 0 0 0 0 0 0 0 0 0 0 0 0
43305 - 0 0 0 0 0 0 0 0 0 0 0 0
43306 - 0 0 0 0 0 0 0 0 0 10 10 10
43307 - 30 30 30 78 78 78 174 135 50 224 166 10
43308 -239 182 13 246 190 14 246 190 14 246 190 14
43309 -246 190 14 246 190 14 246 190 14 246 190 14
43310 -246 190 14 246 190 14 246 190 14 246 190 14
43311 -246 190 14 246 190 14 241 196 14 139 102 15
43312 - 2 2 6 2 2 6 2 2 6 2 2 6
43313 - 78 78 78 250 250 250 253 253 253 253 253 253
43314 -253 253 253 253 253 253 253 253 253 253 253 253
43315 -253 253 253 253 253 253 253 253 253 253 253 253
43316 -253 253 253 253 253 253 253 253 253 253 253 253
43317 -250 250 250 214 214 214 198 198 198 190 150 46
43318 -219 162 10 236 178 12 234 174 13 224 166 10
43319 -216 158 10 213 154 11 213 154 11 216 158 10
43320 -226 170 11 239 182 13 246 190 14 246 190 14
43321 -246 190 14 246 190 14 242 186 14 206 162 42
43322 -101 101 101 58 58 58 30 30 30 14 14 14
43323 - 6 6 6 0 0 0 0 0 0 0 0 0
43324 - 0 0 0 0 0 0 0 0 0 0 0 0
43325 - 0 0 0 0 0 0 0 0 0 0 0 0
43326 - 0 0 0 0 0 0 0 0 0 10 10 10
43327 - 30 30 30 74 74 74 174 135 50 216 158 10
43328 -236 178 12 246 190 14 246 190 14 246 190 14
43329 -246 190 14 246 190 14 246 190 14 246 190 14
43330 -246 190 14 246 190 14 246 190 14 246 190 14
43331 -246 190 14 246 190 14 241 196 14 226 184 13
43332 - 61 42 6 2 2 6 2 2 6 2 2 6
43333 - 22 22 22 238 238 238 253 253 253 253 253 253
43334 -253 253 253 253 253 253 253 253 253 253 253 253
43335 -253 253 253 253 253 253 253 253 253 253 253 253
43336 -253 253 253 253 253 253 253 253 253 253 253 253
43337 -253 253 253 226 226 226 187 187 187 180 133 36
43338 -216 158 10 236 178 12 239 182 13 236 178 12
43339 -230 174 11 226 170 11 226 170 11 230 174 11
43340 -236 178 12 242 186 14 246 190 14 246 190 14
43341 -246 190 14 246 190 14 246 186 14 239 182 13
43342 -206 162 42 106 106 106 66 66 66 34 34 34
43343 - 14 14 14 6 6 6 0 0 0 0 0 0
43344 - 0 0 0 0 0 0 0 0 0 0 0 0
43345 - 0 0 0 0 0 0 0 0 0 0 0 0
43346 - 0 0 0 0 0 0 0 0 0 6 6 6
43347 - 26 26 26 70 70 70 163 133 67 213 154 11
43348 -236 178 12 246 190 14 246 190 14 246 190 14
43349 -246 190 14 246 190 14 246 190 14 246 190 14
43350 -246 190 14 246 190 14 246 190 14 246 190 14
43351 -246 190 14 246 190 14 246 190 14 241 196 14
43352 -190 146 13 18 14 6 2 2 6 2 2 6
43353 - 46 46 46 246 246 246 253 253 253 253 253 253
43354 -253 253 253 253 253 253 253 253 253 253 253 253
43355 -253 253 253 253 253 253 253 253 253 253 253 253
43356 -253 253 253 253 253 253 253 253 253 253 253 253
43357 -253 253 253 221 221 221 86 86 86 156 107 11
43358 -216 158 10 236 178 12 242 186 14 246 186 14
43359 -242 186 14 239 182 13 239 182 13 242 186 14
43360 -242 186 14 246 186 14 246 190 14 246 190 14
43361 -246 190 14 246 190 14 246 190 14 246 190 14
43362 -242 186 14 225 175 15 142 122 72 66 66 66
43363 - 30 30 30 10 10 10 0 0 0 0 0 0
43364 - 0 0 0 0 0 0 0 0 0 0 0 0
43365 - 0 0 0 0 0 0 0 0 0 0 0 0
43366 - 0 0 0 0 0 0 0 0 0 6 6 6
43367 - 26 26 26 70 70 70 163 133 67 210 150 10
43368 -236 178 12 246 190 14 246 190 14 246 190 14
43369 -246 190 14 246 190 14 246 190 14 246 190 14
43370 -246 190 14 246 190 14 246 190 14 246 190 14
43371 -246 190 14 246 190 14 246 190 14 246 190 14
43372 -232 195 16 121 92 8 34 34 34 106 106 106
43373 -221 221 221 253 253 253 253 253 253 253 253 253
43374 -253 253 253 253 253 253 253 253 253 253 253 253
43375 -253 253 253 253 253 253 253 253 253 253 253 253
43376 -253 253 253 253 253 253 253 253 253 253 253 253
43377 -242 242 242 82 82 82 18 14 6 163 110 8
43378 -216 158 10 236 178 12 242 186 14 246 190 14
43379 -246 190 14 246 190 14 246 190 14 246 190 14
43380 -246 190 14 246 190 14 246 190 14 246 190 14
43381 -246 190 14 246 190 14 246 190 14 246 190 14
43382 -246 190 14 246 190 14 242 186 14 163 133 67
43383 - 46 46 46 18 18 18 6 6 6 0 0 0
43384 - 0 0 0 0 0 0 0 0 0 0 0 0
43385 - 0 0 0 0 0 0 0 0 0 0 0 0
43386 - 0 0 0 0 0 0 0 0 0 10 10 10
43387 - 30 30 30 78 78 78 163 133 67 210 150 10
43388 -236 178 12 246 186 14 246 190 14 246 190 14
43389 -246 190 14 246 190 14 246 190 14 246 190 14
43390 -246 190 14 246 190 14 246 190 14 246 190 14
43391 -246 190 14 246 190 14 246 190 14 246 190 14
43392 -241 196 14 215 174 15 190 178 144 253 253 253
43393 -253 253 253 253 253 253 253 253 253 253 253 253
43394 -253 253 253 253 253 253 253 253 253 253 253 253
43395 -253 253 253 253 253 253 253 253 253 253 253 253
43396 -253 253 253 253 253 253 253 253 253 218 218 218
43397 - 58 58 58 2 2 6 22 18 6 167 114 7
43398 -216 158 10 236 178 12 246 186 14 246 190 14
43399 -246 190 14 246 190 14 246 190 14 246 190 14
43400 -246 190 14 246 190 14 246 190 14 246 190 14
43401 -246 190 14 246 190 14 246 190 14 246 190 14
43402 -246 190 14 246 186 14 242 186 14 190 150 46
43403 - 54 54 54 22 22 22 6 6 6 0 0 0
43404 - 0 0 0 0 0 0 0 0 0 0 0 0
43405 - 0 0 0 0 0 0 0 0 0 0 0 0
43406 - 0 0 0 0 0 0 0 0 0 14 14 14
43407 - 38 38 38 86 86 86 180 133 36 213 154 11
43408 -236 178 12 246 186 14 246 190 14 246 190 14
43409 -246 190 14 246 190 14 246 190 14 246 190 14
43410 -246 190 14 246 190 14 246 190 14 246 190 14
43411 -246 190 14 246 190 14 246 190 14 246 190 14
43412 -246 190 14 232 195 16 190 146 13 214 214 214
43413 -253 253 253 253 253 253 253 253 253 253 253 253
43414 -253 253 253 253 253 253 253 253 253 253 253 253
43415 -253 253 253 253 253 253 253 253 253 253 253 253
43416 -253 253 253 250 250 250 170 170 170 26 26 26
43417 - 2 2 6 2 2 6 37 26 9 163 110 8
43418 -219 162 10 239 182 13 246 186 14 246 190 14
43419 -246 190 14 246 190 14 246 190 14 246 190 14
43420 -246 190 14 246 190 14 246 190 14 246 190 14
43421 -246 190 14 246 190 14 246 190 14 246 190 14
43422 -246 186 14 236 178 12 224 166 10 142 122 72
43423 - 46 46 46 18 18 18 6 6 6 0 0 0
43424 - 0 0 0 0 0 0 0 0 0 0 0 0
43425 - 0 0 0 0 0 0 0 0 0 0 0 0
43426 - 0 0 0 0 0 0 6 6 6 18 18 18
43427 - 50 50 50 109 106 95 192 133 9 224 166 10
43428 -242 186 14 246 190 14 246 190 14 246 190 14
43429 -246 190 14 246 190 14 246 190 14 246 190 14
43430 -246 190 14 246 190 14 246 190 14 246 190 14
43431 -246 190 14 246 190 14 246 190 14 246 190 14
43432 -242 186 14 226 184 13 210 162 10 142 110 46
43433 -226 226 226 253 253 253 253 253 253 253 253 253
43434 -253 253 253 253 253 253 253 253 253 253 253 253
43435 -253 253 253 253 253 253 253 253 253 253 253 253
43436 -198 198 198 66 66 66 2 2 6 2 2 6
43437 - 2 2 6 2 2 6 50 34 6 156 107 11
43438 -219 162 10 239 182 13 246 186 14 246 190 14
43439 -246 190 14 246 190 14 246 190 14 246 190 14
43440 -246 190 14 246 190 14 246 190 14 246 190 14
43441 -246 190 14 246 190 14 246 190 14 242 186 14
43442 -234 174 13 213 154 11 154 122 46 66 66 66
43443 - 30 30 30 10 10 10 0 0 0 0 0 0
43444 - 0 0 0 0 0 0 0 0 0 0 0 0
43445 - 0 0 0 0 0 0 0 0 0 0 0 0
43446 - 0 0 0 0 0 0 6 6 6 22 22 22
43447 - 58 58 58 154 121 60 206 145 10 234 174 13
43448 -242 186 14 246 186 14 246 190 14 246 190 14
43449 -246 190 14 246 190 14 246 190 14 246 190 14
43450 -246 190 14 246 190 14 246 190 14 246 190 14
43451 -246 190 14 246 190 14 246 190 14 246 190 14
43452 -246 186 14 236 178 12 210 162 10 163 110 8
43453 - 61 42 6 138 138 138 218 218 218 250 250 250
43454 -253 253 253 253 253 253 253 253 253 250 250 250
43455 -242 242 242 210 210 210 144 144 144 66 66 66
43456 - 6 6 6 2 2 6 2 2 6 2 2 6
43457 - 2 2 6 2 2 6 61 42 6 163 110 8
43458 -216 158 10 236 178 12 246 190 14 246 190 14
43459 -246 190 14 246 190 14 246 190 14 246 190 14
43460 -246 190 14 246 190 14 246 190 14 246 190 14
43461 -246 190 14 239 182 13 230 174 11 216 158 10
43462 -190 142 34 124 112 88 70 70 70 38 38 38
43463 - 18 18 18 6 6 6 0 0 0 0 0 0
43464 - 0 0 0 0 0 0 0 0 0 0 0 0
43465 - 0 0 0 0 0 0 0 0 0 0 0 0
43466 - 0 0 0 0 0 0 6 6 6 22 22 22
43467 - 62 62 62 168 124 44 206 145 10 224 166 10
43468 -236 178 12 239 182 13 242 186 14 242 186 14
43469 -246 186 14 246 190 14 246 190 14 246 190 14
43470 -246 190 14 246 190 14 246 190 14 246 190 14
43471 -246 190 14 246 190 14 246 190 14 246 190 14
43472 -246 190 14 236 178 12 216 158 10 175 118 6
43473 - 80 54 7 2 2 6 6 6 6 30 30 30
43474 - 54 54 54 62 62 62 50 50 50 38 38 38
43475 - 14 14 14 2 2 6 2 2 6 2 2 6
43476 - 2 2 6 2 2 6 2 2 6 2 2 6
43477 - 2 2 6 6 6 6 80 54 7 167 114 7
43478 -213 154 11 236 178 12 246 190 14 246 190 14
43479 -246 190 14 246 190 14 246 190 14 246 190 14
43480 -246 190 14 242 186 14 239 182 13 239 182 13
43481 -230 174 11 210 150 10 174 135 50 124 112 88
43482 - 82 82 82 54 54 54 34 34 34 18 18 18
43483 - 6 6 6 0 0 0 0 0 0 0 0 0
43484 - 0 0 0 0 0 0 0 0 0 0 0 0
43485 - 0 0 0 0 0 0 0 0 0 0 0 0
43486 - 0 0 0 0 0 0 6 6 6 18 18 18
43487 - 50 50 50 158 118 36 192 133 9 200 144 11
43488 -216 158 10 219 162 10 224 166 10 226 170 11
43489 -230 174 11 236 178 12 239 182 13 239 182 13
43490 -242 186 14 246 186 14 246 190 14 246 190 14
43491 -246 190 14 246 190 14 246 190 14 246 190 14
43492 -246 186 14 230 174 11 210 150 10 163 110 8
43493 -104 69 6 10 10 10 2 2 6 2 2 6
43494 - 2 2 6 2 2 6 2 2 6 2 2 6
43495 - 2 2 6 2 2 6 2 2 6 2 2 6
43496 - 2 2 6 2 2 6 2 2 6 2 2 6
43497 - 2 2 6 6 6 6 91 60 6 167 114 7
43498 -206 145 10 230 174 11 242 186 14 246 190 14
43499 -246 190 14 246 190 14 246 186 14 242 186 14
43500 -239 182 13 230 174 11 224 166 10 213 154 11
43501 -180 133 36 124 112 88 86 86 86 58 58 58
43502 - 38 38 38 22 22 22 10 10 10 6 6 6
43503 - 0 0 0 0 0 0 0 0 0 0 0 0
43504 - 0 0 0 0 0 0 0 0 0 0 0 0
43505 - 0 0 0 0 0 0 0 0 0 0 0 0
43506 - 0 0 0 0 0 0 0 0 0 14 14 14
43507 - 34 34 34 70 70 70 138 110 50 158 118 36
43508 -167 114 7 180 123 7 192 133 9 197 138 11
43509 -200 144 11 206 145 10 213 154 11 219 162 10
43510 -224 166 10 230 174 11 239 182 13 242 186 14
43511 -246 186 14 246 186 14 246 186 14 246 186 14
43512 -239 182 13 216 158 10 185 133 11 152 99 6
43513 -104 69 6 18 14 6 2 2 6 2 2 6
43514 - 2 2 6 2 2 6 2 2 6 2 2 6
43515 - 2 2 6 2 2 6 2 2 6 2 2 6
43516 - 2 2 6 2 2 6 2 2 6 2 2 6
43517 - 2 2 6 6 6 6 80 54 7 152 99 6
43518 -192 133 9 219 162 10 236 178 12 239 182 13
43519 -246 186 14 242 186 14 239 182 13 236 178 12
43520 -224 166 10 206 145 10 192 133 9 154 121 60
43521 - 94 94 94 62 62 62 42 42 42 22 22 22
43522 - 14 14 14 6 6 6 0 0 0 0 0 0
43523 - 0 0 0 0 0 0 0 0 0 0 0 0
43524 - 0 0 0 0 0 0 0 0 0 0 0 0
43525 - 0 0 0 0 0 0 0 0 0 0 0 0
43526 - 0 0 0 0 0 0 0 0 0 6 6 6
43527 - 18 18 18 34 34 34 58 58 58 78 78 78
43528 -101 98 89 124 112 88 142 110 46 156 107 11
43529 -163 110 8 167 114 7 175 118 6 180 123 7
43530 -185 133 11 197 138 11 210 150 10 219 162 10
43531 -226 170 11 236 178 12 236 178 12 234 174 13
43532 -219 162 10 197 138 11 163 110 8 130 83 6
43533 - 91 60 6 10 10 10 2 2 6 2 2 6
43534 - 18 18 18 38 38 38 38 38 38 38 38 38
43535 - 38 38 38 38 38 38 38 38 38 38 38 38
43536 - 38 38 38 38 38 38 26 26 26 2 2 6
43537 - 2 2 6 6 6 6 70 47 6 137 92 6
43538 -175 118 6 200 144 11 219 162 10 230 174 11
43539 -234 174 13 230 174 11 219 162 10 210 150 10
43540 -192 133 9 163 110 8 124 112 88 82 82 82
43541 - 50 50 50 30 30 30 14 14 14 6 6 6
43542 - 0 0 0 0 0 0 0 0 0 0 0 0
43543 - 0 0 0 0 0 0 0 0 0 0 0 0
43544 - 0 0 0 0 0 0 0 0 0 0 0 0
43545 - 0 0 0 0 0 0 0 0 0 0 0 0
43546 - 0 0 0 0 0 0 0 0 0 0 0 0
43547 - 6 6 6 14 14 14 22 22 22 34 34 34
43548 - 42 42 42 58 58 58 74 74 74 86 86 86
43549 -101 98 89 122 102 70 130 98 46 121 87 25
43550 -137 92 6 152 99 6 163 110 8 180 123 7
43551 -185 133 11 197 138 11 206 145 10 200 144 11
43552 -180 123 7 156 107 11 130 83 6 104 69 6
43553 - 50 34 6 54 54 54 110 110 110 101 98 89
43554 - 86 86 86 82 82 82 78 78 78 78 78 78
43555 - 78 78 78 78 78 78 78 78 78 78 78 78
43556 - 78 78 78 82 82 82 86 86 86 94 94 94
43557 -106 106 106 101 101 101 86 66 34 124 80 6
43558 -156 107 11 180 123 7 192 133 9 200 144 11
43559 -206 145 10 200 144 11 192 133 9 175 118 6
43560 -139 102 15 109 106 95 70 70 70 42 42 42
43561 - 22 22 22 10 10 10 0 0 0 0 0 0
43562 - 0 0 0 0 0 0 0 0 0 0 0 0
43563 - 0 0 0 0 0 0 0 0 0 0 0 0
43564 - 0 0 0 0 0 0 0 0 0 0 0 0
43565 - 0 0 0 0 0 0 0 0 0 0 0 0
43566 - 0 0 0 0 0 0 0 0 0 0 0 0
43567 - 0 0 0 0 0 0 6 6 6 10 10 10
43568 - 14 14 14 22 22 22 30 30 30 38 38 38
43569 - 50 50 50 62 62 62 74 74 74 90 90 90
43570 -101 98 89 112 100 78 121 87 25 124 80 6
43571 -137 92 6 152 99 6 152 99 6 152 99 6
43572 -138 86 6 124 80 6 98 70 6 86 66 30
43573 -101 98 89 82 82 82 58 58 58 46 46 46
43574 - 38 38 38 34 34 34 34 34 34 34 34 34
43575 - 34 34 34 34 34 34 34 34 34 34 34 34
43576 - 34 34 34 34 34 34 38 38 38 42 42 42
43577 - 54 54 54 82 82 82 94 86 76 91 60 6
43578 -134 86 6 156 107 11 167 114 7 175 118 6
43579 -175 118 6 167 114 7 152 99 6 121 87 25
43580 -101 98 89 62 62 62 34 34 34 18 18 18
43581 - 6 6 6 0 0 0 0 0 0 0 0 0
43582 - 0 0 0 0 0 0 0 0 0 0 0 0
43583 - 0 0 0 0 0 0 0 0 0 0 0 0
43584 - 0 0 0 0 0 0 0 0 0 0 0 0
43585 - 0 0 0 0 0 0 0 0 0 0 0 0
43586 - 0 0 0 0 0 0 0 0 0 0 0 0
43587 - 0 0 0 0 0 0 0 0 0 0 0 0
43588 - 0 0 0 6 6 6 6 6 6 10 10 10
43589 - 18 18 18 22 22 22 30 30 30 42 42 42
43590 - 50 50 50 66 66 66 86 86 86 101 98 89
43591 -106 86 58 98 70 6 104 69 6 104 69 6
43592 -104 69 6 91 60 6 82 62 34 90 90 90
43593 - 62 62 62 38 38 38 22 22 22 14 14 14
43594 - 10 10 10 10 10 10 10 10 10 10 10 10
43595 - 10 10 10 10 10 10 6 6 6 10 10 10
43596 - 10 10 10 10 10 10 10 10 10 14 14 14
43597 - 22 22 22 42 42 42 70 70 70 89 81 66
43598 - 80 54 7 104 69 6 124 80 6 137 92 6
43599 -134 86 6 116 81 8 100 82 52 86 86 86
43600 - 58 58 58 30 30 30 14 14 14 6 6 6
43601 - 0 0 0 0 0 0 0 0 0 0 0 0
43602 - 0 0 0 0 0 0 0 0 0 0 0 0
43603 - 0 0 0 0 0 0 0 0 0 0 0 0
43604 - 0 0 0 0 0 0 0 0 0 0 0 0
43605 - 0 0 0 0 0 0 0 0 0 0 0 0
43606 - 0 0 0 0 0 0 0 0 0 0 0 0
43607 - 0 0 0 0 0 0 0 0 0 0 0 0
43608 - 0 0 0 0 0 0 0 0 0 0 0 0
43609 - 0 0 0 6 6 6 10 10 10 14 14 14
43610 - 18 18 18 26 26 26 38 38 38 54 54 54
43611 - 70 70 70 86 86 86 94 86 76 89 81 66
43612 - 89 81 66 86 86 86 74 74 74 50 50 50
43613 - 30 30 30 14 14 14 6 6 6 0 0 0
43614 - 0 0 0 0 0 0 0 0 0 0 0 0
43615 - 0 0 0 0 0 0 0 0 0 0 0 0
43616 - 0 0 0 0 0 0 0 0 0 0 0 0
43617 - 6 6 6 18 18 18 34 34 34 58 58 58
43618 - 82 82 82 89 81 66 89 81 66 89 81 66
43619 - 94 86 66 94 86 76 74 74 74 50 50 50
43620 - 26 26 26 14 14 14 6 6 6 0 0 0
43621 - 0 0 0 0 0 0 0 0 0 0 0 0
43622 - 0 0 0 0 0 0 0 0 0 0 0 0
43623 - 0 0 0 0 0 0 0 0 0 0 0 0
43624 - 0 0 0 0 0 0 0 0 0 0 0 0
43625 - 0 0 0 0 0 0 0 0 0 0 0 0
43626 - 0 0 0 0 0 0 0 0 0 0 0 0
43627 - 0 0 0 0 0 0 0 0 0 0 0 0
43628 - 0 0 0 0 0 0 0 0 0 0 0 0
43629 - 0 0 0 0 0 0 0 0 0 0 0 0
43630 - 6 6 6 6 6 6 14 14 14 18 18 18
43631 - 30 30 30 38 38 38 46 46 46 54 54 54
43632 - 50 50 50 42 42 42 30 30 30 18 18 18
43633 - 10 10 10 0 0 0 0 0 0 0 0 0
43634 - 0 0 0 0 0 0 0 0 0 0 0 0
43635 - 0 0 0 0 0 0 0 0 0 0 0 0
43636 - 0 0 0 0 0 0 0 0 0 0 0 0
43637 - 0 0 0 6 6 6 14 14 14 26 26 26
43638 - 38 38 38 50 50 50 58 58 58 58 58 58
43639 - 54 54 54 42 42 42 30 30 30 18 18 18
43640 - 10 10 10 0 0 0 0 0 0 0 0 0
43641 - 0 0 0 0 0 0 0 0 0 0 0 0
43642 - 0 0 0 0 0 0 0 0 0 0 0 0
43643 - 0 0 0 0 0 0 0 0 0 0 0 0
43644 - 0 0 0 0 0 0 0 0 0 0 0 0
43645 - 0 0 0 0 0 0 0 0 0 0 0 0
43646 - 0 0 0 0 0 0 0 0 0 0 0 0
43647 - 0 0 0 0 0 0 0 0 0 0 0 0
43648 - 0 0 0 0 0 0 0 0 0 0 0 0
43649 - 0 0 0 0 0 0 0 0 0 0 0 0
43650 - 0 0 0 0 0 0 0 0 0 6 6 6
43651 - 6 6 6 10 10 10 14 14 14 18 18 18
43652 - 18 18 18 14 14 14 10 10 10 6 6 6
43653 - 0 0 0 0 0 0 0 0 0 0 0 0
43654 - 0 0 0 0 0 0 0 0 0 0 0 0
43655 - 0 0 0 0 0 0 0 0 0 0 0 0
43656 - 0 0 0 0 0 0 0 0 0 0 0 0
43657 - 0 0 0 0 0 0 0 0 0 6 6 6
43658 - 14 14 14 18 18 18 22 22 22 22 22 22
43659 - 18 18 18 14 14 14 10 10 10 6 6 6
43660 - 0 0 0 0 0 0 0 0 0 0 0 0
43661 - 0 0 0 0 0 0 0 0 0 0 0 0
43662 - 0 0 0 0 0 0 0 0 0 0 0 0
43663 - 0 0 0 0 0 0 0 0 0 0 0 0
43664 - 0 0 0 0 0 0 0 0 0 0 0 0
43665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43672 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43678 +4 4 4 4 4 4
43679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43686 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43692 +4 4 4 4 4 4
43693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
43706 +4 4 4 4 4 4
43707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43713 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43720 +4 4 4 4 4 4
43721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43727 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43734 +4 4 4 4 4 4
43735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43741 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
43748 +4 4 4 4 4 4
43749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43753 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
43754 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43755 +4 4 4 4 4 4 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 1 1 1 0 0 0
43759 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43760 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43762 +4 4 4 4 4 4
43763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43767 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43768 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43769 +5 5 5 4 4 4 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 3 3 3 0 0 0 1 1 1 6 6 6
43773 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43774 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43775 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43776 +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 4 4 4
43779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43781 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43782 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43783 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
43787 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43788 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43789 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43790 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43794 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43795 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43796 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43797 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
43800 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43801 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43802 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43803 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43804 +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 4 4 4 4 4 4 4 4 4 4 4 4
43808 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43809 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43810 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43811 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43812 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43813 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43814 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43815 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43816 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43817 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43818 +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 4 4 4 4 4 4 5 5 5
43822 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43823 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43824 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43825 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43826 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43827 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43828 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43829 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43830 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43831 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43832 +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 5 5 5 3 3 3
43836 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43837 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43838 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43839 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43840 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43841 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43842 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43843 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43844 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43845 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43846 +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 2 2 2 0 0 0 4 0 0
43850 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43851 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43852 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43853 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43854 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43855 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43856 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43857 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43858 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43859 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43860 +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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43864 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43865 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43866 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43867 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43868 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43869 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43870 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43871 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43872 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43873 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43874 +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 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43878 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43879 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43880 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43881 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43882 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43883 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43884 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43885 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43886 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43887 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43888 +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 3 3 3 0 0 0
43891 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43892 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43893 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43894 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43895 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43896 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43897 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43898 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43899 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43900 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43901 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43902 +4 4 4 4 4 4
43903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43904 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43905 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43906 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43907 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43908 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43909 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43910 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43911 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43912 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43913 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43914 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43915 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43916 +0 0 0 4 4 4
43917 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43918 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43919 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43920 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43921 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43922 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43923 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43924 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43925 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43926 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43927 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43928 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43929 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43930 +2 0 0 0 0 0
43931 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43932 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43933 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43934 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43935 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43936 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43937 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43938 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43939 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43940 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43941 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43942 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43943 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43944 +37 38 37 0 0 0
43945 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43946 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43947 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43948 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43949 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43950 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43951 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43952 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43953 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43954 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43955 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43956 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43957 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43958 +85 115 134 4 0 0
43959 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43960 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43961 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43962 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43963 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43964 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43965 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43966 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43967 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43968 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43969 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43970 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43971 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43972 +60 73 81 4 0 0
43973 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43974 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43975 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43976 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43977 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43978 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43979 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43980 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43981 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43982 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43983 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43984 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43985 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43986 +16 19 21 4 0 0
43987 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43988 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43989 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43990 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43991 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43992 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43993 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43994 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43995 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43996 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43997 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43998 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43999 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
44000 +4 0 0 4 3 3
44001 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44002 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44003 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44005 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44006 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44007 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44008 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44009 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44010 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44011 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44012 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44013 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44014 +3 2 2 4 4 4
44015 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44016 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44017 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44018 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44019 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44020 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44021 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44022 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44023 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44024 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44025 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44026 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44027 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44028 +4 4 4 4 4 4
44029 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44030 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44031 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44032 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44033 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44034 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44035 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44036 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44037 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44038 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44039 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44040 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44041 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44042 +4 4 4 4 4 4
44043 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44044 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44045 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44046 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44047 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44048 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44049 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44050 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44051 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44052 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44053 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44054 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44055 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44056 +5 5 5 5 5 5
44057 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44058 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44059 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44060 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44061 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44062 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44063 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44064 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
44065 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
44066 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
44067 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
44068 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
44069 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44070 +5 5 5 4 4 4
44071 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
44072 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
44073 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
44074 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
44075 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44076 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
44077 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
44078 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
44079 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
44080 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
44081 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
44082 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44084 +4 4 4 4 4 4
44085 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
44086 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
44087 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
44088 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
44089 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
44090 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44091 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44092 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
44093 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
44094 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
44095 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
44096 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
44097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44098 +4 4 4 4 4 4
44099 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
44100 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
44101 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
44102 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
44103 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44104 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
44105 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
44106 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
44107 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
44108 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
44109 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
44110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44112 +4 4 4 4 4 4
44113 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
44114 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
44115 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
44116 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
44117 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44118 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44119 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44120 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
44121 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
44122 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
44123 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
44124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44126 +4 4 4 4 4 4
44127 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
44128 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
44129 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
44130 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
44131 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44132 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
44133 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44134 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
44135 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
44136 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
44137 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44140 +4 4 4 4 4 4
44141 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
44142 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
44143 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
44144 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
44145 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44146 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
44147 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
44148 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
44149 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
44150 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
44151 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
44152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44154 +4 4 4 4 4 4
44155 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
44156 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
44157 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
44158 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
44159 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44160 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
44161 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
44162 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
44163 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
44164 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
44165 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
44166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44168 +4 4 4 4 4 4
44169 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
44170 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
44171 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
44172 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44173 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
44174 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
44175 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
44176 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
44177 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
44178 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
44179 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44182 +4 4 4 4 4 4
44183 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
44184 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
44185 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
44186 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44187 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44188 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
44189 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
44190 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
44191 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
44192 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
44193 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44196 +4 4 4 4 4 4
44197 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
44198 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
44199 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44200 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44201 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44202 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
44203 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
44204 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
44205 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
44206 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
44207 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44210 +4 4 4 4 4 4
44211 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
44212 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
44213 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44214 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44215 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44216 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
44217 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
44218 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
44219 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44220 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44221 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44224 +4 4 4 4 4 4
44225 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44226 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
44227 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44228 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
44229 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
44230 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
44231 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
44232 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
44233 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44234 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44235 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44238 +4 4 4 4 4 4
44239 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44240 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
44241 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44242 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
44243 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44244 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
44245 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
44246 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
44247 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44248 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44249 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44252 +4 4 4 4 4 4
44253 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
44254 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
44255 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44256 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
44257 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
44258 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
44259 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
44260 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
44261 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44262 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44263 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44266 +4 4 4 4 4 4
44267 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
44268 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
44269 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44270 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
44271 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
44272 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
44273 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
44274 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
44275 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44276 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44277 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44280 +4 4 4 4 4 4
44281 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44282 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
44283 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44284 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
44285 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
44286 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
44287 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
44288 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
44289 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44290 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44291 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44294 +4 4 4 4 4 4
44295 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
44296 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
44297 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44298 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
44299 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
44300 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
44301 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
44302 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
44303 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
44304 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44305 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44308 +4 4 4 4 4 4
44309 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44310 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
44311 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
44312 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
44313 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
44314 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
44315 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
44316 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
44317 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44318 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44319 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44322 +4 4 4 4 4 4
44323 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44324 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
44325 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44326 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
44327 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
44328 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
44329 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
44330 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
44331 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44332 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44333 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44336 +4 4 4 4 4 4
44337 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44338 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
44339 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
44340 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
44341 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
44342 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
44343 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44344 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
44345 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44346 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44347 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44350 +4 4 4 4 4 4
44351 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44352 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
44353 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
44354 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44355 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
44356 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
44357 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44358 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
44359 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44360 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44361 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44364 +4 4 4 4 4 4
44365 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44366 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
44367 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
44368 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
44369 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
44370 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
44371 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
44372 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
44373 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
44374 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44375 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44378 +4 4 4 4 4 4
44379 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44380 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
44381 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
44382 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
44383 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
44384 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
44385 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
44386 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
44387 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
44388 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44389 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44392 +4 4 4 4 4 4
44393 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
44394 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
44395 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
44396 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
44397 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44398 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
44399 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
44400 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
44401 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
44402 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44403 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44406 +4 4 4 4 4 4
44407 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44408 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
44409 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
44410 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
44411 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
44412 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
44413 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
44414 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
44415 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
44416 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44417 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44420 +4 4 4 4 4 4
44421 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
44422 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
44423 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
44424 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
44425 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
44426 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
44427 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
44428 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
44429 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
44430 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
44431 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44434 +4 4 4 4 4 4
44435 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
44436 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44437 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
44438 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
44439 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
44440 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
44441 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
44442 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
44443 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
44444 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
44445 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44448 +4 4 4 4 4 4
44449 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
44450 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44451 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
44452 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
44453 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
44454 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
44455 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44456 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
44457 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
44458 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
44459 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44462 +4 4 4 4 4 4
44463 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
44464 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
44465 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
44466 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
44467 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
44468 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
44469 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
44470 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
44471 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
44472 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
44473 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44476 +4 4 4 4 4 4
44477 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
44478 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
44479 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44480 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
44481 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
44482 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
44483 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
44484 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
44485 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
44486 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
44487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44490 +4 4 4 4 4 4
44491 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44492 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
44493 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
44494 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
44495 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
44496 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
44497 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
44498 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
44499 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
44500 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44504 +4 4 4 4 4 4
44505 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
44506 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
44507 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
44508 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
44509 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
44510 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
44511 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
44512 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
44513 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
44514 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44518 +4 4 4 4 4 4
44519 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
44520 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
44521 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
44522 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
44523 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
44524 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
44525 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
44526 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
44527 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44528 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44532 +4 4 4 4 4 4
44533 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
44534 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44535 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
44536 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44537 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
44538 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
44539 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
44540 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
44541 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
44542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44546 +4 4 4 4 4 4
44547 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
44548 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
44549 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
44550 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
44551 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
44552 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
44553 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
44554 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
44555 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
44556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44560 +4 4 4 4 4 4
44561 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44562 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
44563 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
44564 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
44565 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
44566 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
44567 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
44568 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
44569 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44574 +4 4 4 4 4 4
44575 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
44576 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
44577 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44578 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
44579 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
44580 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
44581 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
44582 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
44583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44588 +4 4 4 4 4 4
44589 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44590 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
44591 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
44592 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
44593 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
44594 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
44595 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
44596 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44602 +4 4 4 4 4 4
44603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44604 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
44605 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44606 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
44607 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
44608 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
44609 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
44610 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
44611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44616 +4 4 4 4 4 4
44617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44618 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
44619 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
44620 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
44621 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
44622 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
44623 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
44624 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
44625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44630 +4 4 4 4 4 4
44631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44632 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44633 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
44634 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44635 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
44636 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
44637 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
44638 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44644 +4 4 4 4 4 4
44645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44647 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44648 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
44649 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
44650 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
44651 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
44652 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44658 +4 4 4 4 4 4
44659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44662 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44663 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
44664 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
44665 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
44666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44672 +4 4 4 4 4 4
44673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44676 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44677 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44678 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
44679 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
44680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44686 +4 4 4 4 4 4
44687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44690 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44691 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44692 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44693 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
44694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44700 +4 4 4 4 4 4
44701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44704 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
44705 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
44706 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
44707 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
44708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44714 +4 4 4 4 4 4
44715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44719 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44720 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44721 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44728 +4 4 4 4 4 4
44729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44733 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44734 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44735 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44742 +4 4 4 4 4 4
44743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44747 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44748 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44749 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44756 +4 4 4 4 4 4
44757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44761 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44762 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44770 +4 4 4 4 4 4
44771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44775 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44776 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44784 +4 4 4 4 4 4
44785 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44786 index 86d449e..af6a7f7 100644
44787 --- a/drivers/video/udlfb.c
44788 +++ b/drivers/video/udlfb.c
44789 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44790 dlfb_urb_completion(urb);
44791
44792 error:
44793 - atomic_add(bytes_sent, &dev->bytes_sent);
44794 - atomic_add(bytes_identical, &dev->bytes_identical);
44795 - atomic_add(width*height*2, &dev->bytes_rendered);
44796 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44797 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44798 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44799 end_cycles = get_cycles();
44800 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44801 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44802 >> 10)), /* Kcycles */
44803 &dev->cpu_kcycles_used);
44804
44805 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44806 dlfb_urb_completion(urb);
44807
44808 error:
44809 - atomic_add(bytes_sent, &dev->bytes_sent);
44810 - atomic_add(bytes_identical, &dev->bytes_identical);
44811 - atomic_add(bytes_rendered, &dev->bytes_rendered);
44812 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44813 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44814 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44815 end_cycles = get_cycles();
44816 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44817 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44818 >> 10)), /* Kcycles */
44819 &dev->cpu_kcycles_used);
44820 }
44821 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44822 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44823 struct dlfb_data *dev = fb_info->par;
44824 return snprintf(buf, PAGE_SIZE, "%u\n",
44825 - atomic_read(&dev->bytes_rendered));
44826 + atomic_read_unchecked(&dev->bytes_rendered));
44827 }
44828
44829 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44830 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44831 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44832 struct dlfb_data *dev = fb_info->par;
44833 return snprintf(buf, PAGE_SIZE, "%u\n",
44834 - atomic_read(&dev->bytes_identical));
44835 + atomic_read_unchecked(&dev->bytes_identical));
44836 }
44837
44838 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44839 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44840 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44841 struct dlfb_data *dev = fb_info->par;
44842 return snprintf(buf, PAGE_SIZE, "%u\n",
44843 - atomic_read(&dev->bytes_sent));
44844 + atomic_read_unchecked(&dev->bytes_sent));
44845 }
44846
44847 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44848 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44849 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44850 struct dlfb_data *dev = fb_info->par;
44851 return snprintf(buf, PAGE_SIZE, "%u\n",
44852 - atomic_read(&dev->cpu_kcycles_used));
44853 + atomic_read_unchecked(&dev->cpu_kcycles_used));
44854 }
44855
44856 static ssize_t edid_show(
44857 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44858 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44859 struct dlfb_data *dev = fb_info->par;
44860
44861 - atomic_set(&dev->bytes_rendered, 0);
44862 - atomic_set(&dev->bytes_identical, 0);
44863 - atomic_set(&dev->bytes_sent, 0);
44864 - atomic_set(&dev->cpu_kcycles_used, 0);
44865 + atomic_set_unchecked(&dev->bytes_rendered, 0);
44866 + atomic_set_unchecked(&dev->bytes_identical, 0);
44867 + atomic_set_unchecked(&dev->bytes_sent, 0);
44868 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44869
44870 return count;
44871 }
44872 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44873 index b75db01..5631c6d 100644
44874 --- a/drivers/video/uvesafb.c
44875 +++ b/drivers/video/uvesafb.c
44876 @@ -19,6 +19,7 @@
44877 #include <linux/io.h>
44878 #include <linux/mutex.h>
44879 #include <linux/slab.h>
44880 +#include <linux/moduleloader.h>
44881 #include <video/edid.h>
44882 #include <video/uvesafb.h>
44883 #ifdef CONFIG_X86
44884 @@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44885 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44886 par->pmi_setpal = par->ypan = 0;
44887 } else {
44888 +
44889 +#ifdef CONFIG_PAX_KERNEXEC
44890 +#ifdef CONFIG_MODULES
44891 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44892 +#endif
44893 + if (!par->pmi_code) {
44894 + par->pmi_setpal = par->ypan = 0;
44895 + return 0;
44896 + }
44897 +#endif
44898 +
44899 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44900 + task->t.regs.edi);
44901 +
44902 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44903 + pax_open_kernel();
44904 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44905 + pax_close_kernel();
44906 +
44907 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44908 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44909 +#else
44910 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44911 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44912 +#endif
44913 +
44914 printk(KERN_INFO "uvesafb: protected mode interface info at "
44915 "%04x:%04x\n",
44916 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44917 @@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
44918 par->ypan = ypan;
44919
44920 if (par->pmi_setpal || par->ypan) {
44921 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44922 if (__supported_pte_mask & _PAGE_NX) {
44923 par->pmi_setpal = par->ypan = 0;
44924 printk(KERN_WARNING "uvesafb: NX protection is actively."
44925 "We have better not to use the PMI.\n");
44926 - } else {
44927 + } else
44928 +#endif
44929 uvesafb_vbe_getpmi(task, par);
44930 - }
44931 }
44932 #else
44933 /* The protected mode interface is not available on non-x86. */
44934 @@ -1836,6 +1860,11 @@ out:
44935 if (par->vbe_modes)
44936 kfree(par->vbe_modes);
44937
44938 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44939 + if (par->pmi_code)
44940 + module_free_exec(NULL, par->pmi_code);
44941 +#endif
44942 +
44943 framebuffer_release(info);
44944 return err;
44945 }
44946 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
44947 kfree(par->vbe_state_orig);
44948 if (par->vbe_state_saved)
44949 kfree(par->vbe_state_saved);
44950 +
44951 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44952 + if (par->pmi_code)
44953 + module_free_exec(NULL, par->pmi_code);
44954 +#endif
44955 +
44956 }
44957
44958 framebuffer_release(info);
44959 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44960 index 501b340..86bd4cf 100644
44961 --- a/drivers/video/vesafb.c
44962 +++ b/drivers/video/vesafb.c
44963 @@ -9,6 +9,7 @@
44964 */
44965
44966 #include <linux/module.h>
44967 +#include <linux/moduleloader.h>
44968 #include <linux/kernel.h>
44969 #include <linux/errno.h>
44970 #include <linux/string.h>
44971 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44972 static int vram_total __initdata; /* Set total amount of memory */
44973 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44974 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44975 -static void (*pmi_start)(void) __read_mostly;
44976 -static void (*pmi_pal) (void) __read_mostly;
44977 +static void (*pmi_start)(void) __read_only;
44978 +static void (*pmi_pal) (void) __read_only;
44979 static int depth __read_mostly;
44980 static int vga_compat __read_mostly;
44981 /* --------------------------------------------------------------------- */
44982 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44983 unsigned int size_vmode;
44984 unsigned int size_remap;
44985 unsigned int size_total;
44986 + void *pmi_code = NULL;
44987
44988 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44989 return -ENODEV;
44990 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44991 size_remap = size_total;
44992 vesafb_fix.smem_len = size_remap;
44993
44994 -#ifndef __i386__
44995 - screen_info.vesapm_seg = 0;
44996 -#endif
44997 -
44998 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44999 printk(KERN_WARNING
45000 "vesafb: cannot reserve video memory at 0x%lx\n",
45001 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45002 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45003 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45004
45005 +#ifdef __i386__
45006 +
45007 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45008 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
45009 + if (!pmi_code)
45010 +#elif !defined(CONFIG_PAX_KERNEXEC)
45011 + if (0)
45012 +#endif
45013 +
45014 +#endif
45015 + screen_info.vesapm_seg = 0;
45016 +
45017 if (screen_info.vesapm_seg) {
45018 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45019 - screen_info.vesapm_seg,screen_info.vesapm_off);
45020 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45021 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45022 }
45023
45024 if (screen_info.vesapm_seg < 0xc000)
45025 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45026
45027 if (ypan || pmi_setpal) {
45028 unsigned short *pmi_base;
45029 +
45030 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45031 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45032 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45033 +
45034 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45035 + pax_open_kernel();
45036 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45037 +#else
45038 + pmi_code = pmi_base;
45039 +#endif
45040 +
45041 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45042 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45043 +
45044 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45045 + pmi_start = ktva_ktla(pmi_start);
45046 + pmi_pal = ktva_ktla(pmi_pal);
45047 + pax_close_kernel();
45048 +#endif
45049 +
45050 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45051 if (pmi_base[3]) {
45052 printk(KERN_INFO "vesafb: pmi: ports = ");
45053 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45054 info->node, info->fix.id);
45055 return 0;
45056 err:
45057 +
45058 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45059 + module_free_exec(NULL, pmi_code);
45060 +#endif
45061 +
45062 if (info->screen_base)
45063 iounmap(info->screen_base);
45064 framebuffer_release(info);
45065 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
45066 index 88714ae..16c2e11 100644
45067 --- a/drivers/video/via/via_clock.h
45068 +++ b/drivers/video/via/via_clock.h
45069 @@ -56,7 +56,7 @@ struct via_clock {
45070
45071 void (*set_engine_pll_state)(u8 state);
45072 void (*set_engine_pll)(struct via_pll_config config);
45073 -};
45074 +} __no_const;
45075
45076
45077 static inline u32 get_pll_internal_frequency(u32 ref_freq,
45078 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
45079 index fef20db..d28b1ab 100644
45080 --- a/drivers/xen/xenfs/xenstored.c
45081 +++ b/drivers/xen/xenfs/xenstored.c
45082 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
45083 static int xsd_kva_open(struct inode *inode, struct file *file)
45084 {
45085 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
45086 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45087 + NULL);
45088 +#else
45089 xen_store_interface);
45090 +#endif
45091 +
45092 if (!file->private_data)
45093 return -ENOMEM;
45094 return 0;
45095 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45096 index 890bed5..17ae73e 100644
45097 --- a/fs/9p/vfs_inode.c
45098 +++ b/fs/9p/vfs_inode.c
45099 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45100 void
45101 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45102 {
45103 - char *s = nd_get_link(nd);
45104 + const char *s = nd_get_link(nd);
45105
45106 p9_debug(P9_DEBUG_VFS, " %s %s\n",
45107 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
45108 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45109 index 0efd152..b5802ad 100644
45110 --- a/fs/Kconfig.binfmt
45111 +++ b/fs/Kconfig.binfmt
45112 @@ -89,7 +89,7 @@ config HAVE_AOUT
45113
45114 config BINFMT_AOUT
45115 tristate "Kernel support for a.out and ECOFF binaries"
45116 - depends on HAVE_AOUT
45117 + depends on HAVE_AOUT && BROKEN
45118 ---help---
45119 A.out (Assembler.OUTput) is a set of formats for libraries and
45120 executables used in the earliest versions of UNIX. Linux used
45121 diff --git a/fs/aio.c b/fs/aio.c
45122 index 71f613c..9d01f1f 100644
45123 --- a/fs/aio.c
45124 +++ b/fs/aio.c
45125 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45126 size += sizeof(struct io_event) * nr_events;
45127 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45128
45129 - if (nr_pages < 0)
45130 + if (nr_pages <= 0)
45131 return -EINVAL;
45132
45133 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45134 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45135 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45136 {
45137 ssize_t ret;
45138 + struct iovec iovstack;
45139
45140 #ifdef CONFIG_COMPAT
45141 if (compat)
45142 ret = compat_rw_copy_check_uvector(type,
45143 (struct compat_iovec __user *)kiocb->ki_buf,
45144 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45145 + kiocb->ki_nbytes, 1, &iovstack,
45146 &kiocb->ki_iovec);
45147 else
45148 #endif
45149 ret = rw_copy_check_uvector(type,
45150 (struct iovec __user *)kiocb->ki_buf,
45151 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45152 + kiocb->ki_nbytes, 1, &iovstack,
45153 &kiocb->ki_iovec);
45154 if (ret < 0)
45155 goto out;
45156 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45157 if (ret < 0)
45158 goto out;
45159
45160 + if (kiocb->ki_iovec == &iovstack) {
45161 + kiocb->ki_inline_vec = iovstack;
45162 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
45163 + }
45164 kiocb->ki_nr_segs = kiocb->ki_nbytes;
45165 kiocb->ki_cur_seg = 0;
45166 /* ki_nbytes/left now reflect bytes instead of segs */
45167 diff --git a/fs/attr.c b/fs/attr.c
45168 index 1449adb..a2038c2 100644
45169 --- a/fs/attr.c
45170 +++ b/fs/attr.c
45171 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
45172 unsigned long limit;
45173
45174 limit = rlimit(RLIMIT_FSIZE);
45175 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
45176 if (limit != RLIM_INFINITY && offset > limit)
45177 goto out_sig;
45178 if (offset > inode->i_sb->s_maxbytes)
45179 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
45180 index 03bc1d3..6205356 100644
45181 --- a/fs/autofs4/waitq.c
45182 +++ b/fs/autofs4/waitq.c
45183 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
45184 {
45185 unsigned long sigpipe, flags;
45186 mm_segment_t fs;
45187 - const char *data = (const char *)addr;
45188 + const char __user *data = (const char __force_user *)addr;
45189 ssize_t wr = 0;
45190
45191 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
45192 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
45193 return 1;
45194 }
45195
45196 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45197 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
45198 +#endif
45199 +
45200 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45201 enum autofs_notify notify)
45202 {
45203 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45204
45205 /* If this is a direct mount request create a dummy name */
45206 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
45207 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45208 + /* this name does get written to userland via autofs4_write() */
45209 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
45210 +#else
45211 qstr.len = sprintf(name, "%p", dentry);
45212 +#endif
45213 else {
45214 qstr.len = autofs4_getpath(sbi, dentry, &name);
45215 if (!qstr.len) {
45216 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
45217 index 2b3bda8..6a2d4be 100644
45218 --- a/fs/befs/linuxvfs.c
45219 +++ b/fs/befs/linuxvfs.c
45220 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45221 {
45222 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
45223 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
45224 - char *link = nd_get_link(nd);
45225 + const char *link = nd_get_link(nd);
45226 if (!IS_ERR(link))
45227 kfree(link);
45228 }
45229 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
45230 index 6043567..16a9239 100644
45231 --- a/fs/binfmt_aout.c
45232 +++ b/fs/binfmt_aout.c
45233 @@ -16,6 +16,7 @@
45234 #include <linux/string.h>
45235 #include <linux/fs.h>
45236 #include <linux/file.h>
45237 +#include <linux/security.h>
45238 #include <linux/stat.h>
45239 #include <linux/fcntl.h>
45240 #include <linux/ptrace.h>
45241 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
45242 #endif
45243 # define START_STACK(u) ((void __user *)u.start_stack)
45244
45245 + memset(&dump, 0, sizeof(dump));
45246 +
45247 fs = get_fs();
45248 set_fs(KERNEL_DS);
45249 has_dumped = 1;
45250 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
45251
45252 /* If the size of the dump file exceeds the rlimit, then see what would happen
45253 if we wrote the stack, but not the data area. */
45254 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
45255 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
45256 dump.u_dsize = 0;
45257
45258 /* Make sure we have enough room to write the stack and data areas. */
45259 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
45260 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
45261 dump.u_ssize = 0;
45262
45263 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
45264 rlim = rlimit(RLIMIT_DATA);
45265 if (rlim >= RLIM_INFINITY)
45266 rlim = ~0;
45267 +
45268 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
45269 if (ex.a_data + ex.a_bss > rlim)
45270 return -ENOMEM;
45271
45272 @@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
45273
45274 install_exec_creds(bprm);
45275
45276 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45277 + current->mm->pax_flags = 0UL;
45278 +#endif
45279 +
45280 +#ifdef CONFIG_PAX_PAGEEXEC
45281 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
45282 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
45283 +
45284 +#ifdef CONFIG_PAX_EMUTRAMP
45285 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
45286 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
45287 +#endif
45288 +
45289 +#ifdef CONFIG_PAX_MPROTECT
45290 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
45291 + current->mm->pax_flags |= MF_PAX_MPROTECT;
45292 +#endif
45293 +
45294 + }
45295 +#endif
45296 +
45297 if (N_MAGIC(ex) == OMAGIC) {
45298 unsigned long text_addr, map_size;
45299 loff_t pos;
45300 @@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
45301 }
45302
45303 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
45304 - PROT_READ | PROT_WRITE | PROT_EXEC,
45305 + PROT_READ | PROT_WRITE,
45306 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
45307 fd_offset + ex.a_text);
45308 if (error != N_DATADDR(ex)) {
45309 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
45310 index 0c42cdb..f4be023 100644
45311 --- a/fs/binfmt_elf.c
45312 +++ b/fs/binfmt_elf.c
45313 @@ -33,6 +33,7 @@
45314 #include <linux/elf.h>
45315 #include <linux/utsname.h>
45316 #include <linux/coredump.h>
45317 +#include <linux/xattr.h>
45318 #include <asm/uaccess.h>
45319 #include <asm/param.h>
45320 #include <asm/page.h>
45321 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
45322 #define elf_core_dump NULL
45323 #endif
45324
45325 +#ifdef CONFIG_PAX_MPROTECT
45326 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
45327 +#endif
45328 +
45329 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
45330 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
45331 #else
45332 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
45333 .load_binary = load_elf_binary,
45334 .load_shlib = load_elf_library,
45335 .core_dump = elf_core_dump,
45336 +
45337 +#ifdef CONFIG_PAX_MPROTECT
45338 + .handle_mprotect= elf_handle_mprotect,
45339 +#endif
45340 +
45341 .min_coredump = ELF_EXEC_PAGESIZE,
45342 };
45343
45344 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
45345
45346 static int set_brk(unsigned long start, unsigned long end)
45347 {
45348 + unsigned long e = end;
45349 +
45350 start = ELF_PAGEALIGN(start);
45351 end = ELF_PAGEALIGN(end);
45352 if (end > start) {
45353 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
45354 if (BAD_ADDR(addr))
45355 return addr;
45356 }
45357 - current->mm->start_brk = current->mm->brk = end;
45358 + current->mm->start_brk = current->mm->brk = e;
45359 return 0;
45360 }
45361
45362 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45363 elf_addr_t __user *u_rand_bytes;
45364 const char *k_platform = ELF_PLATFORM;
45365 const char *k_base_platform = ELF_BASE_PLATFORM;
45366 - unsigned char k_rand_bytes[16];
45367 + u32 k_rand_bytes[4];
45368 int items;
45369 elf_addr_t *elf_info;
45370 int ei_index = 0;
45371 const struct cred *cred = current_cred();
45372 struct vm_area_struct *vma;
45373 + unsigned long saved_auxv[AT_VECTOR_SIZE];
45374
45375 /*
45376 * In some cases (e.g. Hyper-Threading), we want to avoid L1
45377 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45378 * Generate 16 random bytes for userspace PRNG seeding.
45379 */
45380 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
45381 - u_rand_bytes = (elf_addr_t __user *)
45382 - STACK_ALLOC(p, sizeof(k_rand_bytes));
45383 + srandom32(k_rand_bytes[0] ^ random32());
45384 + srandom32(k_rand_bytes[1] ^ random32());
45385 + srandom32(k_rand_bytes[2] ^ random32());
45386 + srandom32(k_rand_bytes[3] ^ random32());
45387 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
45388 + u_rand_bytes = (elf_addr_t __user *) p;
45389 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
45390 return -EFAULT;
45391
45392 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45393 return -EFAULT;
45394 current->mm->env_end = p;
45395
45396 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
45397 +
45398 /* Put the elf_info on the stack in the right place. */
45399 sp = (elf_addr_t __user *)envp + 1;
45400 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
45401 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
45402 return -EFAULT;
45403 return 0;
45404 }
45405 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
45406 an ELF header */
45407
45408 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45409 - struct file *interpreter, unsigned long *interp_map_addr,
45410 - unsigned long no_base)
45411 + struct file *interpreter, unsigned long no_base)
45412 {
45413 struct elf_phdr *elf_phdata;
45414 struct elf_phdr *eppnt;
45415 - unsigned long load_addr = 0;
45416 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
45417 int load_addr_set = 0;
45418 unsigned long last_bss = 0, elf_bss = 0;
45419 - unsigned long error = ~0UL;
45420 + unsigned long error = -EINVAL;
45421 unsigned long total_size;
45422 int retval, i, size;
45423
45424 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45425 goto out_close;
45426 }
45427
45428 +#ifdef CONFIG_PAX_SEGMEXEC
45429 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
45430 + pax_task_size = SEGMEXEC_TASK_SIZE;
45431 +#endif
45432 +
45433 eppnt = elf_phdata;
45434 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
45435 if (eppnt->p_type == PT_LOAD) {
45436 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45437 map_addr = elf_map(interpreter, load_addr + vaddr,
45438 eppnt, elf_prot, elf_type, total_size);
45439 total_size = 0;
45440 - if (!*interp_map_addr)
45441 - *interp_map_addr = map_addr;
45442 error = map_addr;
45443 if (BAD_ADDR(map_addr))
45444 goto out_close;
45445 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45446 k = load_addr + eppnt->p_vaddr;
45447 if (BAD_ADDR(k) ||
45448 eppnt->p_filesz > eppnt->p_memsz ||
45449 - eppnt->p_memsz > TASK_SIZE ||
45450 - TASK_SIZE - eppnt->p_memsz < k) {
45451 + eppnt->p_memsz > pax_task_size ||
45452 + pax_task_size - eppnt->p_memsz < k) {
45453 error = -ENOMEM;
45454 goto out_close;
45455 }
45456 @@ -530,6 +551,315 @@ out:
45457 return error;
45458 }
45459
45460 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
45461 +#ifdef CONFIG_PAX_SOFTMODE
45462 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
45463 +{
45464 + unsigned long pax_flags = 0UL;
45465 +
45466 +#ifdef CONFIG_PAX_PAGEEXEC
45467 + if (elf_phdata->p_flags & PF_PAGEEXEC)
45468 + pax_flags |= MF_PAX_PAGEEXEC;
45469 +#endif
45470 +
45471 +#ifdef CONFIG_PAX_SEGMEXEC
45472 + if (elf_phdata->p_flags & PF_SEGMEXEC)
45473 + pax_flags |= MF_PAX_SEGMEXEC;
45474 +#endif
45475 +
45476 +#ifdef CONFIG_PAX_EMUTRAMP
45477 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
45478 + pax_flags |= MF_PAX_EMUTRAMP;
45479 +#endif
45480 +
45481 +#ifdef CONFIG_PAX_MPROTECT
45482 + if (elf_phdata->p_flags & PF_MPROTECT)
45483 + pax_flags |= MF_PAX_MPROTECT;
45484 +#endif
45485 +
45486 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45487 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
45488 + pax_flags |= MF_PAX_RANDMMAP;
45489 +#endif
45490 +
45491 + return pax_flags;
45492 +}
45493 +#endif
45494 +
45495 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
45496 +{
45497 + unsigned long pax_flags = 0UL;
45498 +
45499 +#ifdef CONFIG_PAX_PAGEEXEC
45500 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
45501 + pax_flags |= MF_PAX_PAGEEXEC;
45502 +#endif
45503 +
45504 +#ifdef CONFIG_PAX_SEGMEXEC
45505 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
45506 + pax_flags |= MF_PAX_SEGMEXEC;
45507 +#endif
45508 +
45509 +#ifdef CONFIG_PAX_EMUTRAMP
45510 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
45511 + pax_flags |= MF_PAX_EMUTRAMP;
45512 +#endif
45513 +
45514 +#ifdef CONFIG_PAX_MPROTECT
45515 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
45516 + pax_flags |= MF_PAX_MPROTECT;
45517 +#endif
45518 +
45519 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45520 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
45521 + pax_flags |= MF_PAX_RANDMMAP;
45522 +#endif
45523 +
45524 + return pax_flags;
45525 +}
45526 +#endif
45527 +
45528 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45529 +#ifdef CONFIG_PAX_SOFTMODE
45530 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
45531 +{
45532 + unsigned long pax_flags = 0UL;
45533 +
45534 +#ifdef CONFIG_PAX_PAGEEXEC
45535 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
45536 + pax_flags |= MF_PAX_PAGEEXEC;
45537 +#endif
45538 +
45539 +#ifdef CONFIG_PAX_SEGMEXEC
45540 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
45541 + pax_flags |= MF_PAX_SEGMEXEC;
45542 +#endif
45543 +
45544 +#ifdef CONFIG_PAX_EMUTRAMP
45545 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
45546 + pax_flags |= MF_PAX_EMUTRAMP;
45547 +#endif
45548 +
45549 +#ifdef CONFIG_PAX_MPROTECT
45550 + if (pax_flags_softmode & MF_PAX_MPROTECT)
45551 + pax_flags |= MF_PAX_MPROTECT;
45552 +#endif
45553 +
45554 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45555 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
45556 + pax_flags |= MF_PAX_RANDMMAP;
45557 +#endif
45558 +
45559 + return pax_flags;
45560 +}
45561 +#endif
45562 +
45563 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
45564 +{
45565 + unsigned long pax_flags = 0UL;
45566 +
45567 +#ifdef CONFIG_PAX_PAGEEXEC
45568 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
45569 + pax_flags |= MF_PAX_PAGEEXEC;
45570 +#endif
45571 +
45572 +#ifdef CONFIG_PAX_SEGMEXEC
45573 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
45574 + pax_flags |= MF_PAX_SEGMEXEC;
45575 +#endif
45576 +
45577 +#ifdef CONFIG_PAX_EMUTRAMP
45578 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
45579 + pax_flags |= MF_PAX_EMUTRAMP;
45580 +#endif
45581 +
45582 +#ifdef CONFIG_PAX_MPROTECT
45583 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
45584 + pax_flags |= MF_PAX_MPROTECT;
45585 +#endif
45586 +
45587 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45588 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
45589 + pax_flags |= MF_PAX_RANDMMAP;
45590 +#endif
45591 +
45592 + return pax_flags;
45593 +}
45594 +#endif
45595 +
45596 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45597 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
45598 +{
45599 + unsigned long pax_flags = 0UL;
45600 +
45601 +#ifdef CONFIG_PAX_EI_PAX
45602 +
45603 +#ifdef CONFIG_PAX_PAGEEXEC
45604 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
45605 + pax_flags |= MF_PAX_PAGEEXEC;
45606 +#endif
45607 +
45608 +#ifdef CONFIG_PAX_SEGMEXEC
45609 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
45610 + pax_flags |= MF_PAX_SEGMEXEC;
45611 +#endif
45612 +
45613 +#ifdef CONFIG_PAX_EMUTRAMP
45614 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
45615 + pax_flags |= MF_PAX_EMUTRAMP;
45616 +#endif
45617 +
45618 +#ifdef CONFIG_PAX_MPROTECT
45619 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
45620 + pax_flags |= MF_PAX_MPROTECT;
45621 +#endif
45622 +
45623 +#ifdef CONFIG_PAX_ASLR
45624 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
45625 + pax_flags |= MF_PAX_RANDMMAP;
45626 +#endif
45627 +
45628 +#else
45629 +
45630 +#ifdef CONFIG_PAX_PAGEEXEC
45631 + pax_flags |= MF_PAX_PAGEEXEC;
45632 +#endif
45633 +
45634 +#ifdef CONFIG_PAX_SEGMEXEC
45635 + pax_flags |= MF_PAX_SEGMEXEC;
45636 +#endif
45637 +
45638 +#ifdef CONFIG_PAX_MPROTECT
45639 + pax_flags |= MF_PAX_MPROTECT;
45640 +#endif
45641 +
45642 +#ifdef CONFIG_PAX_RANDMMAP
45643 + if (randomize_va_space)
45644 + pax_flags |= MF_PAX_RANDMMAP;
45645 +#endif
45646 +
45647 +#endif
45648 +
45649 + return pax_flags;
45650 +}
45651 +
45652 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
45653 +{
45654 +
45655 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
45656 + unsigned long i;
45657 +
45658 + for (i = 0UL; i < elf_ex->e_phnum; i++)
45659 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
45660 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
45661 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
45662 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
45663 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
45664 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
45665 + return ~0UL;
45666 +
45667 +#ifdef CONFIG_PAX_SOFTMODE
45668 + if (pax_softmode)
45669 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
45670 + else
45671 +#endif
45672 +
45673 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
45674 + break;
45675 + }
45676 +#endif
45677 +
45678 + return ~0UL;
45679 +}
45680 +
45681 +static unsigned long pax_parse_xattr_pax(struct file * const file)
45682 +{
45683 +
45684 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45685 + ssize_t xattr_size, i;
45686 + unsigned char xattr_value[5];
45687 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
45688 +
45689 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
45690 + if (xattr_size <= 0 || xattr_size > 5)
45691 + return ~0UL;
45692 +
45693 + for (i = 0; i < xattr_size; i++)
45694 + switch (xattr_value[i]) {
45695 + default:
45696 + return ~0UL;
45697 +
45698 +#define parse_flag(option1, option2, flag) \
45699 + case option1: \
45700 + if (pax_flags_hardmode & MF_PAX_##flag) \
45701 + return ~0UL; \
45702 + pax_flags_hardmode |= MF_PAX_##flag; \
45703 + break; \
45704 + case option2: \
45705 + if (pax_flags_softmode & MF_PAX_##flag) \
45706 + return ~0UL; \
45707 + pax_flags_softmode |= MF_PAX_##flag; \
45708 + break;
45709 +
45710 + parse_flag('p', 'P', PAGEEXEC);
45711 + parse_flag('e', 'E', EMUTRAMP);
45712 + parse_flag('m', 'M', MPROTECT);
45713 + parse_flag('r', 'R', RANDMMAP);
45714 + parse_flag('s', 'S', SEGMEXEC);
45715 +
45716 +#undef parse_flag
45717 + }
45718 +
45719 + if (pax_flags_hardmode & pax_flags_softmode)
45720 + return ~0UL;
45721 +
45722 +#ifdef CONFIG_PAX_SOFTMODE
45723 + if (pax_softmode)
45724 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45725 + else
45726 +#endif
45727 +
45728 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45729 +#else
45730 + return ~0UL;
45731 +#endif
45732 +
45733 +}
45734 +
45735 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45736 +{
45737 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45738 +
45739 + pax_flags = pax_parse_ei_pax(elf_ex);
45740 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45741 + xattr_pax_flags = pax_parse_xattr_pax(file);
45742 +
45743 + if (pt_pax_flags == ~0UL)
45744 + pt_pax_flags = xattr_pax_flags;
45745 + else if (xattr_pax_flags == ~0UL)
45746 + xattr_pax_flags = pt_pax_flags;
45747 + if (pt_pax_flags != xattr_pax_flags)
45748 + return -EINVAL;
45749 + if (pt_pax_flags != ~0UL)
45750 + pax_flags = pt_pax_flags;
45751 +
45752 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45753 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45754 + if ((__supported_pte_mask & _PAGE_NX))
45755 + pax_flags &= ~MF_PAX_SEGMEXEC;
45756 + else
45757 + pax_flags &= ~MF_PAX_PAGEEXEC;
45758 + }
45759 +#endif
45760 +
45761 + if (0 > pax_check_flags(&pax_flags))
45762 + return -EINVAL;
45763 +
45764 + current->mm->pax_flags = pax_flags;
45765 + return 0;
45766 +}
45767 +#endif
45768 +
45769 /*
45770 * These are the functions used to load ELF style executables and shared
45771 * libraries. There is no binary dependent code anywhere else.
45772 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45773 {
45774 unsigned int random_variable = 0;
45775
45776 +#ifdef CONFIG_PAX_RANDUSTACK
45777 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45778 + return stack_top - current->mm->delta_stack;
45779 +#endif
45780 +
45781 if ((current->flags & PF_RANDOMIZE) &&
45782 !(current->personality & ADDR_NO_RANDOMIZE)) {
45783 random_variable = get_random_int() & STACK_RND_MASK;
45784 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
45785 unsigned long load_addr = 0, load_bias = 0;
45786 int load_addr_set = 0;
45787 char * elf_interpreter = NULL;
45788 - unsigned long error;
45789 + unsigned long error = 0;
45790 struct elf_phdr *elf_ppnt, *elf_phdata;
45791 unsigned long elf_bss, elf_brk;
45792 int retval, i;
45793 @@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
45794 unsigned long start_code, end_code, start_data, end_data;
45795 unsigned long reloc_func_desc __maybe_unused = 0;
45796 int executable_stack = EXSTACK_DEFAULT;
45797 - unsigned long def_flags = 0;
45798 struct pt_regs *regs = current_pt_regs();
45799 struct {
45800 struct elfhdr elf_ex;
45801 struct elfhdr interp_elf_ex;
45802 } *loc;
45803 + unsigned long pax_task_size = TASK_SIZE;
45804
45805 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45806 if (!loc) {
45807 @@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
45808 goto out_free_dentry;
45809
45810 /* OK, This is the point of no return */
45811 - current->mm->def_flags = def_flags;
45812 +
45813 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45814 + current->mm->pax_flags = 0UL;
45815 +#endif
45816 +
45817 +#ifdef CONFIG_PAX_DLRESOLVE
45818 + current->mm->call_dl_resolve = 0UL;
45819 +#endif
45820 +
45821 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45822 + current->mm->call_syscall = 0UL;
45823 +#endif
45824 +
45825 +#ifdef CONFIG_PAX_ASLR
45826 + current->mm->delta_mmap = 0UL;
45827 + current->mm->delta_stack = 0UL;
45828 +#endif
45829 +
45830 + current->mm->def_flags = 0;
45831 +
45832 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45833 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45834 + send_sig(SIGKILL, current, 0);
45835 + goto out_free_dentry;
45836 + }
45837 +#endif
45838 +
45839 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45840 + pax_set_initial_flags(bprm);
45841 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45842 + if (pax_set_initial_flags_func)
45843 + (pax_set_initial_flags_func)(bprm);
45844 +#endif
45845 +
45846 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45847 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45848 + current->mm->context.user_cs_limit = PAGE_SIZE;
45849 + current->mm->def_flags |= VM_PAGEEXEC;
45850 + }
45851 +#endif
45852 +
45853 +#ifdef CONFIG_PAX_SEGMEXEC
45854 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45855 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45856 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45857 + pax_task_size = SEGMEXEC_TASK_SIZE;
45858 + current->mm->def_flags |= VM_NOHUGEPAGE;
45859 + }
45860 +#endif
45861 +
45862 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45863 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45864 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45865 + put_cpu();
45866 + }
45867 +#endif
45868
45869 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45870 may depend on the personality. */
45871 SET_PERSONALITY(loc->elf_ex);
45872 +
45873 +#ifdef CONFIG_PAX_ASLR
45874 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45875 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45876 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45877 + }
45878 +#endif
45879 +
45880 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45881 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45882 + executable_stack = EXSTACK_DISABLE_X;
45883 + current->personality &= ~READ_IMPLIES_EXEC;
45884 + } else
45885 +#endif
45886 +
45887 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45888 current->personality |= READ_IMPLIES_EXEC;
45889
45890 @@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
45891 #else
45892 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45893 #endif
45894 +
45895 +#ifdef CONFIG_PAX_RANDMMAP
45896 + /* PaX: randomize base address at the default exe base if requested */
45897 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45898 +#ifdef CONFIG_SPARC64
45899 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45900 +#else
45901 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45902 +#endif
45903 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45904 + elf_flags |= MAP_FIXED;
45905 + }
45906 +#endif
45907 +
45908 }
45909
45910 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45911 @@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
45912 * allowed task size. Note that p_filesz must always be
45913 * <= p_memsz so it is only necessary to check p_memsz.
45914 */
45915 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45916 - elf_ppnt->p_memsz > TASK_SIZE ||
45917 - TASK_SIZE - elf_ppnt->p_memsz < k) {
45918 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45919 + elf_ppnt->p_memsz > pax_task_size ||
45920 + pax_task_size - elf_ppnt->p_memsz < k) {
45921 /* set_brk can never work. Avoid overflows. */
45922 send_sig(SIGKILL, current, 0);
45923 retval = -EINVAL;
45924 @@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
45925 goto out_free_dentry;
45926 }
45927 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45928 - send_sig(SIGSEGV, current, 0);
45929 - retval = -EFAULT; /* Nobody gets to see this, but.. */
45930 - goto out_free_dentry;
45931 + /*
45932 + * This bss-zeroing can fail if the ELF
45933 + * file specifies odd protections. So
45934 + * we don't check the return value
45935 + */
45936 }
45937
45938 +#ifdef CONFIG_PAX_RANDMMAP
45939 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45940 + unsigned long start, size;
45941 +
45942 + start = ELF_PAGEALIGN(elf_brk);
45943 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45944 + down_read(&current->mm->mmap_sem);
45945 + retval = -ENOMEM;
45946 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45947 + unsigned long prot = PROT_NONE;
45948 +
45949 + up_read(&current->mm->mmap_sem);
45950 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45951 +// if (current->personality & ADDR_NO_RANDOMIZE)
45952 +// prot = PROT_READ;
45953 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45954 + retval = IS_ERR_VALUE(start) ? start : 0;
45955 + } else
45956 + up_read(&current->mm->mmap_sem);
45957 + if (retval == 0)
45958 + retval = set_brk(start + size, start + size + PAGE_SIZE);
45959 + if (retval < 0) {
45960 + send_sig(SIGKILL, current, 0);
45961 + goto out_free_dentry;
45962 + }
45963 + }
45964 +#endif
45965 +
45966 if (elf_interpreter) {
45967 - unsigned long interp_map_addr = 0;
45968 -
45969 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45970 interpreter,
45971 - &interp_map_addr,
45972 load_bias);
45973 if (!IS_ERR((void *)elf_entry)) {
45974 /*
45975 @@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45976 * Decide what to dump of a segment, part, all or none.
45977 */
45978 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45979 - unsigned long mm_flags)
45980 + unsigned long mm_flags, long signr)
45981 {
45982 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45983
45984 @@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45985 if (vma->vm_file == NULL)
45986 return 0;
45987
45988 - if (FILTER(MAPPED_PRIVATE))
45989 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45990 goto whole;
45991
45992 /*
45993 @@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45994 {
45995 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45996 int i = 0;
45997 - do
45998 + do {
45999 i += 2;
46000 - while (auxv[i - 2] != AT_NULL);
46001 + } while (auxv[i - 2] != AT_NULL);
46002 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46003 }
46004
46005 @@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
46006 }
46007
46008 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
46009 - unsigned long mm_flags)
46010 + struct coredump_params *cprm)
46011 {
46012 struct vm_area_struct *vma;
46013 size_t size = 0;
46014
46015 for (vma = first_vma(current, gate_vma); vma != NULL;
46016 vma = next_vma(vma, gate_vma))
46017 - size += vma_dump_size(vma, mm_flags);
46018 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46019 return size;
46020 }
46021
46022 @@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46023
46024 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
46025
46026 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
46027 + offset += elf_core_vma_data_size(gate_vma, cprm);
46028 offset += elf_core_extra_data_size();
46029 e_shoff = offset;
46030
46031 @@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
46032 offset = dataoff;
46033
46034 size += sizeof(*elf);
46035 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
46036 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
46037 goto end_coredump;
46038
46039 size += sizeof(*phdr4note);
46040 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
46041 if (size > cprm->limit
46042 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
46043 goto end_coredump;
46044 @@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46045 phdr.p_offset = offset;
46046 phdr.p_vaddr = vma->vm_start;
46047 phdr.p_paddr = 0;
46048 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
46049 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46050 phdr.p_memsz = vma->vm_end - vma->vm_start;
46051 offset += phdr.p_filesz;
46052 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46053 @@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46054 phdr.p_align = ELF_EXEC_PAGESIZE;
46055
46056 size += sizeof(phdr);
46057 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
46058 if (size > cprm->limit
46059 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
46060 goto end_coredump;
46061 @@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46062 unsigned long addr;
46063 unsigned long end;
46064
46065 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
46066 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46067
46068 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46069 struct page *page;
46070 @@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46071 page = get_dump_page(addr);
46072 if (page) {
46073 void *kaddr = kmap(page);
46074 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46075 stop = ((size += PAGE_SIZE) > cprm->limit) ||
46076 !dump_write(cprm->file, kaddr,
46077 PAGE_SIZE);
46078 @@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46079
46080 if (e_phnum == PN_XNUM) {
46081 size += sizeof(*shdr4extnum);
46082 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
46083 if (size > cprm->limit
46084 || !dump_write(cprm->file, shdr4extnum,
46085 sizeof(*shdr4extnum)))
46086 @@ -2219,6 +2670,97 @@ out:
46087
46088 #endif /* CONFIG_ELF_CORE */
46089
46090 +#ifdef CONFIG_PAX_MPROTECT
46091 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
46092 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46093 + * we'll remove VM_MAYWRITE for good on RELRO segments.
46094 + *
46095 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46096 + * basis because we want to allow the common case and not the special ones.
46097 + */
46098 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46099 +{
46100 + struct elfhdr elf_h;
46101 + struct elf_phdr elf_p;
46102 + unsigned long i;
46103 + unsigned long oldflags;
46104 + bool is_textrel_rw, is_textrel_rx, is_relro;
46105 +
46106 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46107 + return;
46108 +
46109 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46110 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46111 +
46112 +#ifdef CONFIG_PAX_ELFRELOCS
46113 + /* possible TEXTREL */
46114 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46115 + 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);
46116 +#else
46117 + is_textrel_rw = false;
46118 + is_textrel_rx = false;
46119 +#endif
46120 +
46121 + /* possible RELRO */
46122 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46123 +
46124 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46125 + return;
46126 +
46127 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46128 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46129 +
46130 +#ifdef CONFIG_PAX_ETEXECRELOCS
46131 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46132 +#else
46133 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46134 +#endif
46135 +
46136 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46137 + !elf_check_arch(&elf_h) ||
46138 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46139 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46140 + return;
46141 +
46142 + for (i = 0UL; i < elf_h.e_phnum; i++) {
46143 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46144 + return;
46145 + switch (elf_p.p_type) {
46146 + case PT_DYNAMIC:
46147 + if (!is_textrel_rw && !is_textrel_rx)
46148 + continue;
46149 + i = 0UL;
46150 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46151 + elf_dyn dyn;
46152 +
46153 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46154 + return;
46155 + if (dyn.d_tag == DT_NULL)
46156 + return;
46157 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46158 + gr_log_textrel(vma);
46159 + if (is_textrel_rw)
46160 + vma->vm_flags |= VM_MAYWRITE;
46161 + else
46162 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46163 + vma->vm_flags &= ~VM_MAYWRITE;
46164 + return;
46165 + }
46166 + i++;
46167 + }
46168 + return;
46169 +
46170 + case PT_GNU_RELRO:
46171 + if (!is_relro)
46172 + continue;
46173 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46174 + vma->vm_flags &= ~VM_MAYWRITE;
46175 + return;
46176 + }
46177 + }
46178 +}
46179 +#endif
46180 +
46181 static int __init init_elf_binfmt(void)
46182 {
46183 register_binfmt(&elf_format);
46184 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46185 index b563719..3868998 100644
46186 --- a/fs/binfmt_flat.c
46187 +++ b/fs/binfmt_flat.c
46188 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46189 realdatastart = (unsigned long) -ENOMEM;
46190 printk("Unable to allocate RAM for process data, errno %d\n",
46191 (int)-realdatastart);
46192 + down_write(&current->mm->mmap_sem);
46193 vm_munmap(textpos, text_len);
46194 + up_write(&current->mm->mmap_sem);
46195 ret = realdatastart;
46196 goto err;
46197 }
46198 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46199 }
46200 if (IS_ERR_VALUE(result)) {
46201 printk("Unable to read data+bss, errno %d\n", (int)-result);
46202 + down_write(&current->mm->mmap_sem);
46203 vm_munmap(textpos, text_len);
46204 vm_munmap(realdatastart, len);
46205 + up_write(&current->mm->mmap_sem);
46206 ret = result;
46207 goto err;
46208 }
46209 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46210 }
46211 if (IS_ERR_VALUE(result)) {
46212 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46213 + down_write(&current->mm->mmap_sem);
46214 vm_munmap(textpos, text_len + data_len + extra +
46215 MAX_SHARED_LIBS * sizeof(unsigned long));
46216 + up_write(&current->mm->mmap_sem);
46217 ret = result;
46218 goto err;
46219 }
46220 diff --git a/fs/bio.c b/fs/bio.c
46221 index b96fc6c..431d628 100644
46222 --- a/fs/bio.c
46223 +++ b/fs/bio.c
46224 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
46225 /*
46226 * Overflow, abort
46227 */
46228 - if (end < start)
46229 + if (end < start || end - start > INT_MAX - nr_pages)
46230 return ERR_PTR(-EINVAL);
46231
46232 nr_pages += end - start;
46233 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
46234 /*
46235 * Overflow, abort
46236 */
46237 - if (end < start)
46238 + if (end < start || end - start > INT_MAX - nr_pages)
46239 return ERR_PTR(-EINVAL);
46240
46241 nr_pages += end - start;
46242 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46243 const int read = bio_data_dir(bio) == READ;
46244 struct bio_map_data *bmd = bio->bi_private;
46245 int i;
46246 - char *p = bmd->sgvecs[0].iov_base;
46247 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46248
46249 __bio_for_each_segment(bvec, bio, i, 0) {
46250 char *addr = page_address(bvec->bv_page);
46251 diff --git a/fs/block_dev.c b/fs/block_dev.c
46252 index 172f849..6efbf24 100644
46253 --- a/fs/block_dev.c
46254 +++ b/fs/block_dev.c
46255 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
46256 else if (bdev->bd_contains == bdev)
46257 return true; /* is a whole device which isn't held */
46258
46259 - else if (whole->bd_holder == bd_may_claim)
46260 + else if (whole->bd_holder == (void *)bd_may_claim)
46261 return true; /* is a partition of a device that is being partitioned */
46262 else if (whole->bd_holder != NULL)
46263 return false; /* is a partition of a held device */
46264 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46265 index eea5da7..88fead70 100644
46266 --- a/fs/btrfs/ctree.c
46267 +++ b/fs/btrfs/ctree.c
46268 @@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46269 free_extent_buffer(buf);
46270 add_root_to_dirty_list(root);
46271 } else {
46272 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46273 - parent_start = parent->start;
46274 - else
46275 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46276 + if (parent)
46277 + parent_start = parent->start;
46278 + else
46279 + parent_start = 0;
46280 + } else
46281 parent_start = 0;
46282
46283 WARN_ON(trans->transid != btrfs_header_generation(parent));
46284 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
46285 index cc93b23..f3c42bf 100644
46286 --- a/fs/btrfs/inode.c
46287 +++ b/fs/btrfs/inode.c
46288 @@ -7296,7 +7296,7 @@ fail:
46289 return -ENOMEM;
46290 }
46291
46292 -static int btrfs_getattr(struct vfsmount *mnt,
46293 +int btrfs_getattr(struct vfsmount *mnt,
46294 struct dentry *dentry, struct kstat *stat)
46295 {
46296 struct inode *inode = dentry->d_inode;
46297 @@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
46298 return 0;
46299 }
46300
46301 +EXPORT_SYMBOL(btrfs_getattr);
46302 +
46303 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
46304 +{
46305 + return BTRFS_I(inode)->root->anon_dev;
46306 +}
46307 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
46308 +
46309 /*
46310 * If a file is moved, it will inherit the cow and compression flags of the new
46311 * directory.
46312 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
46313 index 338f259..b657640 100644
46314 --- a/fs/btrfs/ioctl.c
46315 +++ b/fs/btrfs/ioctl.c
46316 @@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46317 for (i = 0; i < num_types; i++) {
46318 struct btrfs_space_info *tmp;
46319
46320 + /* Don't copy in more than we allocated */
46321 if (!slot_count)
46322 break;
46323
46324 + slot_count--;
46325 +
46326 info = NULL;
46327 rcu_read_lock();
46328 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
46329 @@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46330 memcpy(dest, &space, sizeof(space));
46331 dest++;
46332 space_args.total_spaces++;
46333 - slot_count--;
46334 }
46335 - if (!slot_count)
46336 - break;
46337 }
46338 up_read(&info->groups_sem);
46339 }
46340 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
46341 index 300e09a..9fe4539 100644
46342 --- a/fs/btrfs/relocation.c
46343 +++ b/fs/btrfs/relocation.c
46344 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
46345 }
46346 spin_unlock(&rc->reloc_root_tree.lock);
46347
46348 - BUG_ON((struct btrfs_root *)node->data != root);
46349 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
46350
46351 if (!del) {
46352 spin_lock(&rc->reloc_root_tree.lock);
46353 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
46354 index d8982e9..29a85fa 100644
46355 --- a/fs/btrfs/super.c
46356 +++ b/fs/btrfs/super.c
46357 @@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
46358 function, line, errstr);
46359 return;
46360 }
46361 - ACCESS_ONCE(trans->transaction->aborted) = errno;
46362 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
46363 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
46364 }
46365 /*
46366 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
46367 index 622f469..e8d2d55 100644
46368 --- a/fs/cachefiles/bind.c
46369 +++ b/fs/cachefiles/bind.c
46370 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
46371 args);
46372
46373 /* start by checking things over */
46374 - ASSERT(cache->fstop_percent >= 0 &&
46375 - cache->fstop_percent < cache->fcull_percent &&
46376 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
46377 cache->fcull_percent < cache->frun_percent &&
46378 cache->frun_percent < 100);
46379
46380 - ASSERT(cache->bstop_percent >= 0 &&
46381 - cache->bstop_percent < cache->bcull_percent &&
46382 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
46383 cache->bcull_percent < cache->brun_percent &&
46384 cache->brun_percent < 100);
46385
46386 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
46387 index 0a1467b..6a53245 100644
46388 --- a/fs/cachefiles/daemon.c
46389 +++ b/fs/cachefiles/daemon.c
46390 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
46391 if (n > buflen)
46392 return -EMSGSIZE;
46393
46394 - if (copy_to_user(_buffer, buffer, n) != 0)
46395 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
46396 return -EFAULT;
46397
46398 return n;
46399 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
46400 if (test_bit(CACHEFILES_DEAD, &cache->flags))
46401 return -EIO;
46402
46403 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
46404 + if (datalen > PAGE_SIZE - 1)
46405 return -EOPNOTSUPP;
46406
46407 /* drag the command string into the kernel so we can parse it */
46408 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
46409 if (args[0] != '%' || args[1] != '\0')
46410 return -EINVAL;
46411
46412 - if (fstop < 0 || fstop >= cache->fcull_percent)
46413 + if (fstop >= cache->fcull_percent)
46414 return cachefiles_daemon_range_error(cache, args);
46415
46416 cache->fstop_percent = fstop;
46417 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
46418 if (args[0] != '%' || args[1] != '\0')
46419 return -EINVAL;
46420
46421 - if (bstop < 0 || bstop >= cache->bcull_percent)
46422 + if (bstop >= cache->bcull_percent)
46423 return cachefiles_daemon_range_error(cache, args);
46424
46425 cache->bstop_percent = bstop;
46426 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
46427 index 4938251..7e01445 100644
46428 --- a/fs/cachefiles/internal.h
46429 +++ b/fs/cachefiles/internal.h
46430 @@ -59,7 +59,7 @@ struct cachefiles_cache {
46431 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
46432 struct rb_root active_nodes; /* active nodes (can't be culled) */
46433 rwlock_t active_lock; /* lock for active_nodes */
46434 - atomic_t gravecounter; /* graveyard uniquifier */
46435 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
46436 unsigned frun_percent; /* when to stop culling (% files) */
46437 unsigned fcull_percent; /* when to start culling (% files) */
46438 unsigned fstop_percent; /* when to stop allocating (% files) */
46439 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
46440 * proc.c
46441 */
46442 #ifdef CONFIG_CACHEFILES_HISTOGRAM
46443 -extern atomic_t cachefiles_lookup_histogram[HZ];
46444 -extern atomic_t cachefiles_mkdir_histogram[HZ];
46445 -extern atomic_t cachefiles_create_histogram[HZ];
46446 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46447 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46448 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
46449
46450 extern int __init cachefiles_proc_init(void);
46451 extern void cachefiles_proc_cleanup(void);
46452 static inline
46453 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
46454 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
46455 {
46456 unsigned long jif = jiffies - start_jif;
46457 if (jif >= HZ)
46458 jif = HZ - 1;
46459 - atomic_inc(&histogram[jif]);
46460 + atomic_inc_unchecked(&histogram[jif]);
46461 }
46462
46463 #else
46464 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
46465 index 8c01c5fc..15f982e 100644
46466 --- a/fs/cachefiles/namei.c
46467 +++ b/fs/cachefiles/namei.c
46468 @@ -317,7 +317,7 @@ try_again:
46469 /* first step is to make up a grave dentry in the graveyard */
46470 sprintf(nbuffer, "%08x%08x",
46471 (uint32_t) get_seconds(),
46472 - (uint32_t) atomic_inc_return(&cache->gravecounter));
46473 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
46474
46475 /* do the multiway lock magic */
46476 trap = lock_rename(cache->graveyard, dir);
46477 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
46478 index eccd339..4c1d995 100644
46479 --- a/fs/cachefiles/proc.c
46480 +++ b/fs/cachefiles/proc.c
46481 @@ -14,9 +14,9 @@
46482 #include <linux/seq_file.h>
46483 #include "internal.h"
46484
46485 -atomic_t cachefiles_lookup_histogram[HZ];
46486 -atomic_t cachefiles_mkdir_histogram[HZ];
46487 -atomic_t cachefiles_create_histogram[HZ];
46488 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46489 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46490 +atomic_unchecked_t cachefiles_create_histogram[HZ];
46491
46492 /*
46493 * display the latency histogram
46494 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
46495 return 0;
46496 default:
46497 index = (unsigned long) v - 3;
46498 - x = atomic_read(&cachefiles_lookup_histogram[index]);
46499 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
46500 - z = atomic_read(&cachefiles_create_histogram[index]);
46501 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
46502 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
46503 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
46504 if (x == 0 && y == 0 && z == 0)
46505 return 0;
46506
46507 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
46508 index 4809922..aab2c39 100644
46509 --- a/fs/cachefiles/rdwr.c
46510 +++ b/fs/cachefiles/rdwr.c
46511 @@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
46512 old_fs = get_fs();
46513 set_fs(KERNEL_DS);
46514 ret = file->f_op->write(
46515 - file, (const void __user *) data, len, &pos);
46516 + file, (const void __force_user *) data, len, &pos);
46517 set_fs(old_fs);
46518 kunmap(page);
46519 if (ret != len)
46520 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
46521 index 8c1aabe..bbf856a 100644
46522 --- a/fs/ceph/dir.c
46523 +++ b/fs/ceph/dir.c
46524 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
46525 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
46526 struct ceph_mds_client *mdsc = fsc->mdsc;
46527 unsigned frag = fpos_frag(filp->f_pos);
46528 - int off = fpos_off(filp->f_pos);
46529 + unsigned int off = fpos_off(filp->f_pos);
46530 int err;
46531 u32 ftype;
46532 struct ceph_mds_reply_info_parsed *rinfo;
46533 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
46534 index d9ea6ed..1e6c8ac 100644
46535 --- a/fs/cifs/cifs_debug.c
46536 +++ b/fs/cifs/cifs_debug.c
46537 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46538
46539 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
46540 #ifdef CONFIG_CIFS_STATS2
46541 - atomic_set(&totBufAllocCount, 0);
46542 - atomic_set(&totSmBufAllocCount, 0);
46543 + atomic_set_unchecked(&totBufAllocCount, 0);
46544 + atomic_set_unchecked(&totSmBufAllocCount, 0);
46545 #endif /* CONFIG_CIFS_STATS2 */
46546 spin_lock(&cifs_tcp_ses_lock);
46547 list_for_each(tmp1, &cifs_tcp_ses_list) {
46548 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46549 tcon = list_entry(tmp3,
46550 struct cifs_tcon,
46551 tcon_list);
46552 - atomic_set(&tcon->num_smbs_sent, 0);
46553 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
46554 if (server->ops->clear_stats)
46555 server->ops->clear_stats(tcon);
46556 }
46557 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46558 smBufAllocCount.counter, cifs_min_small);
46559 #ifdef CONFIG_CIFS_STATS2
46560 seq_printf(m, "Total Large %d Small %d Allocations\n",
46561 - atomic_read(&totBufAllocCount),
46562 - atomic_read(&totSmBufAllocCount));
46563 + atomic_read_unchecked(&totBufAllocCount),
46564 + atomic_read_unchecked(&totSmBufAllocCount));
46565 #endif /* CONFIG_CIFS_STATS2 */
46566
46567 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
46568 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46569 if (tcon->need_reconnect)
46570 seq_puts(m, "\tDISCONNECTED ");
46571 seq_printf(m, "\nSMBs: %d",
46572 - atomic_read(&tcon->num_smbs_sent));
46573 + atomic_read_unchecked(&tcon->num_smbs_sent));
46574 if (server->ops->print_stats)
46575 server->ops->print_stats(m, tcon);
46576 }
46577 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
46578 index de7f916..6cb22a9 100644
46579 --- a/fs/cifs/cifsfs.c
46580 +++ b/fs/cifs/cifsfs.c
46581 @@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
46582 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
46583 cifs_req_cachep = kmem_cache_create("cifs_request",
46584 CIFSMaxBufSize + max_hdr_size, 0,
46585 - SLAB_HWCACHE_ALIGN, NULL);
46586 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
46587 if (cifs_req_cachep == NULL)
46588 return -ENOMEM;
46589
46590 @@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
46591 efficient to alloc 1 per page off the slab compared to 17K (5page)
46592 alloc of large cifs buffers even when page debugging is on */
46593 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
46594 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
46595 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
46596 NULL);
46597 if (cifs_sm_req_cachep == NULL) {
46598 mempool_destroy(cifs_req_poolp);
46599 @@ -1109,8 +1109,8 @@ init_cifs(void)
46600 atomic_set(&bufAllocCount, 0);
46601 atomic_set(&smBufAllocCount, 0);
46602 #ifdef CONFIG_CIFS_STATS2
46603 - atomic_set(&totBufAllocCount, 0);
46604 - atomic_set(&totSmBufAllocCount, 0);
46605 + atomic_set_unchecked(&totBufAllocCount, 0);
46606 + atomic_set_unchecked(&totSmBufAllocCount, 0);
46607 #endif /* CONFIG_CIFS_STATS2 */
46608
46609 atomic_set(&midCount, 0);
46610 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
46611 index e6899ce..d6b2920 100644
46612 --- a/fs/cifs/cifsglob.h
46613 +++ b/fs/cifs/cifsglob.h
46614 @@ -751,35 +751,35 @@ struct cifs_tcon {
46615 __u16 Flags; /* optional support bits */
46616 enum statusEnum tidStatus;
46617 #ifdef CONFIG_CIFS_STATS
46618 - atomic_t num_smbs_sent;
46619 + atomic_unchecked_t num_smbs_sent;
46620 union {
46621 struct {
46622 - atomic_t num_writes;
46623 - atomic_t num_reads;
46624 - atomic_t num_flushes;
46625 - atomic_t num_oplock_brks;
46626 - atomic_t num_opens;
46627 - atomic_t num_closes;
46628 - atomic_t num_deletes;
46629 - atomic_t num_mkdirs;
46630 - atomic_t num_posixopens;
46631 - atomic_t num_posixmkdirs;
46632 - atomic_t num_rmdirs;
46633 - atomic_t num_renames;
46634 - atomic_t num_t2renames;
46635 - atomic_t num_ffirst;
46636 - atomic_t num_fnext;
46637 - atomic_t num_fclose;
46638 - atomic_t num_hardlinks;
46639 - atomic_t num_symlinks;
46640 - atomic_t num_locks;
46641 - atomic_t num_acl_get;
46642 - atomic_t num_acl_set;
46643 + atomic_unchecked_t num_writes;
46644 + atomic_unchecked_t num_reads;
46645 + atomic_unchecked_t num_flushes;
46646 + atomic_unchecked_t num_oplock_brks;
46647 + atomic_unchecked_t num_opens;
46648 + atomic_unchecked_t num_closes;
46649 + atomic_unchecked_t num_deletes;
46650 + atomic_unchecked_t num_mkdirs;
46651 + atomic_unchecked_t num_posixopens;
46652 + atomic_unchecked_t num_posixmkdirs;
46653 + atomic_unchecked_t num_rmdirs;
46654 + atomic_unchecked_t num_renames;
46655 + atomic_unchecked_t num_t2renames;
46656 + atomic_unchecked_t num_ffirst;
46657 + atomic_unchecked_t num_fnext;
46658 + atomic_unchecked_t num_fclose;
46659 + atomic_unchecked_t num_hardlinks;
46660 + atomic_unchecked_t num_symlinks;
46661 + atomic_unchecked_t num_locks;
46662 + atomic_unchecked_t num_acl_get;
46663 + atomic_unchecked_t num_acl_set;
46664 } cifs_stats;
46665 #ifdef CONFIG_CIFS_SMB2
46666 struct {
46667 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46668 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46669 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46670 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46671 } smb2_stats;
46672 #endif /* CONFIG_CIFS_SMB2 */
46673 } stats;
46674 @@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
46675 }
46676
46677 #ifdef CONFIG_CIFS_STATS
46678 -#define cifs_stats_inc atomic_inc
46679 +#define cifs_stats_inc atomic_inc_unchecked
46680
46681 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
46682 unsigned int bytes)
46683 @@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
46684 /* Various Debug counters */
46685 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
46686 #ifdef CONFIG_CIFS_STATS2
46687 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
46688 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
46689 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
46690 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
46691 #endif
46692 GLOBAL_EXTERN atomic_t smBufAllocCount;
46693 GLOBAL_EXTERN atomic_t midCount;
46694 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
46695 index 51dc2fb..1e12a33 100644
46696 --- a/fs/cifs/link.c
46697 +++ b/fs/cifs/link.c
46698 @@ -616,7 +616,7 @@ symlink_exit:
46699
46700 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
46701 {
46702 - char *p = nd_get_link(nd);
46703 + const char *p = nd_get_link(nd);
46704 if (!IS_ERR(p))
46705 kfree(p);
46706 }
46707 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
46708 index 3a00c0d..42d901c 100644
46709 --- a/fs/cifs/misc.c
46710 +++ b/fs/cifs/misc.c
46711 @@ -169,7 +169,7 @@ cifs_buf_get(void)
46712 memset(ret_buf, 0, buf_size + 3);
46713 atomic_inc(&bufAllocCount);
46714 #ifdef CONFIG_CIFS_STATS2
46715 - atomic_inc(&totBufAllocCount);
46716 + atomic_inc_unchecked(&totBufAllocCount);
46717 #endif /* CONFIG_CIFS_STATS2 */
46718 }
46719
46720 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46721 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46722 atomic_inc(&smBufAllocCount);
46723 #ifdef CONFIG_CIFS_STATS2
46724 - atomic_inc(&totSmBufAllocCount);
46725 + atomic_inc_unchecked(&totSmBufAllocCount);
46726 #endif /* CONFIG_CIFS_STATS2 */
46727
46728 }
46729 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46730 index 47bc5a8..10decbe 100644
46731 --- a/fs/cifs/smb1ops.c
46732 +++ b/fs/cifs/smb1ops.c
46733 @@ -586,27 +586,27 @@ static void
46734 cifs_clear_stats(struct cifs_tcon *tcon)
46735 {
46736 #ifdef CONFIG_CIFS_STATS
46737 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46738 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46739 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46740 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46741 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46742 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46743 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46744 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46745 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46746 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46747 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46748 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46749 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46750 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46751 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46752 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46753 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46754 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46755 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46756 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46757 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46758 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46759 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46760 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46761 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46762 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46763 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46764 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46765 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46766 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46767 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46768 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46769 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46770 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46771 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46772 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46773 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46774 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46775 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46776 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46777 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46778 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46779 #endif
46780 }
46781
46782 @@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46783 {
46784 #ifdef CONFIG_CIFS_STATS
46785 seq_printf(m, " Oplocks breaks: %d",
46786 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46787 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46788 seq_printf(m, "\nReads: %d Bytes: %llu",
46789 - atomic_read(&tcon->stats.cifs_stats.num_reads),
46790 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46791 (long long)(tcon->bytes_read));
46792 seq_printf(m, "\nWrites: %d Bytes: %llu",
46793 - atomic_read(&tcon->stats.cifs_stats.num_writes),
46794 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46795 (long long)(tcon->bytes_written));
46796 seq_printf(m, "\nFlushes: %d",
46797 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
46798 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46799 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46800 - atomic_read(&tcon->stats.cifs_stats.num_locks),
46801 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46802 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46803 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46804 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46805 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46806 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46807 - atomic_read(&tcon->stats.cifs_stats.num_opens),
46808 - atomic_read(&tcon->stats.cifs_stats.num_closes),
46809 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
46810 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46811 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46812 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46813 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46814 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46815 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46816 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46817 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46818 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46819 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46820 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46821 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46822 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46823 seq_printf(m, "\nRenames: %d T2 Renames %d",
46824 - atomic_read(&tcon->stats.cifs_stats.num_renames),
46825 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46826 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46827 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46828 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46829 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46830 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
46831 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
46832 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46833 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46834 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46835 #endif
46836 }
46837
46838 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46839 index c9c7aa7..065056a 100644
46840 --- a/fs/cifs/smb2ops.c
46841 +++ b/fs/cifs/smb2ops.c
46842 @@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46843 #ifdef CONFIG_CIFS_STATS
46844 int i;
46845 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46846 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46847 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46848 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46849 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46850 }
46851 #endif
46852 }
46853 @@ -284,66 +284,66 @@ static void
46854 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46855 {
46856 #ifdef CONFIG_CIFS_STATS
46857 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46858 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46859 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46860 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46861 seq_printf(m, "\nNegotiates: %d sent %d failed",
46862 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46863 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46864 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46865 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46866 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46867 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46868 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46869 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46870 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46871 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46872 seq_printf(m, "\nLogoffs: %d sent %d failed",
46873 - atomic_read(&sent[SMB2_LOGOFF_HE]),
46874 - atomic_read(&failed[SMB2_LOGOFF_HE]));
46875 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46876 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46877 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46878 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46879 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46880 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46881 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46882 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46883 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46884 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46885 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46886 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46887 seq_printf(m, "\nCreates: %d sent %d failed",
46888 - atomic_read(&sent[SMB2_CREATE_HE]),
46889 - atomic_read(&failed[SMB2_CREATE_HE]));
46890 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46891 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46892 seq_printf(m, "\nCloses: %d sent %d failed",
46893 - atomic_read(&sent[SMB2_CLOSE_HE]),
46894 - atomic_read(&failed[SMB2_CLOSE_HE]));
46895 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46896 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46897 seq_printf(m, "\nFlushes: %d sent %d failed",
46898 - atomic_read(&sent[SMB2_FLUSH_HE]),
46899 - atomic_read(&failed[SMB2_FLUSH_HE]));
46900 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46901 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46902 seq_printf(m, "\nReads: %d sent %d failed",
46903 - atomic_read(&sent[SMB2_READ_HE]),
46904 - atomic_read(&failed[SMB2_READ_HE]));
46905 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
46906 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
46907 seq_printf(m, "\nWrites: %d sent %d failed",
46908 - atomic_read(&sent[SMB2_WRITE_HE]),
46909 - atomic_read(&failed[SMB2_WRITE_HE]));
46910 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46911 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46912 seq_printf(m, "\nLocks: %d sent %d failed",
46913 - atomic_read(&sent[SMB2_LOCK_HE]),
46914 - atomic_read(&failed[SMB2_LOCK_HE]));
46915 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46916 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46917 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46918 - atomic_read(&sent[SMB2_IOCTL_HE]),
46919 - atomic_read(&failed[SMB2_IOCTL_HE]));
46920 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46921 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46922 seq_printf(m, "\nCancels: %d sent %d failed",
46923 - atomic_read(&sent[SMB2_CANCEL_HE]),
46924 - atomic_read(&failed[SMB2_CANCEL_HE]));
46925 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46926 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46927 seq_printf(m, "\nEchos: %d sent %d failed",
46928 - atomic_read(&sent[SMB2_ECHO_HE]),
46929 - atomic_read(&failed[SMB2_ECHO_HE]));
46930 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46931 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46932 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46933 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46934 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46935 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46936 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46937 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46938 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46939 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46940 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46941 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46942 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46943 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46944 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46945 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46946 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46947 seq_printf(m, "\nSetInfos: %d sent %d failed",
46948 - atomic_read(&sent[SMB2_SET_INFO_HE]),
46949 - atomic_read(&failed[SMB2_SET_INFO_HE]));
46950 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46951 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46952 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46953 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46954 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46955 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46956 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46957 #endif
46958 }
46959
46960 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
46961 index 41d9d07..dbb4772 100644
46962 --- a/fs/cifs/smb2pdu.c
46963 +++ b/fs/cifs/smb2pdu.c
46964 @@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
46965 default:
46966 cERROR(1, "info level %u isn't supported",
46967 srch_inf->info_level);
46968 - rc = -EINVAL;
46969 - goto qdir_exit;
46970 + return -EINVAL;
46971 }
46972
46973 req->FileIndex = cpu_to_le32(index);
46974 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46975 index 958ae0e..505c9d0 100644
46976 --- a/fs/coda/cache.c
46977 +++ b/fs/coda/cache.c
46978 @@ -24,7 +24,7 @@
46979 #include "coda_linux.h"
46980 #include "coda_cache.h"
46981
46982 -static atomic_t permission_epoch = ATOMIC_INIT(0);
46983 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46984
46985 /* replace or extend an acl cache hit */
46986 void coda_cache_enter(struct inode *inode, int mask)
46987 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46988 struct coda_inode_info *cii = ITOC(inode);
46989
46990 spin_lock(&cii->c_lock);
46991 - cii->c_cached_epoch = atomic_read(&permission_epoch);
46992 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46993 if (cii->c_uid != current_fsuid()) {
46994 cii->c_uid = current_fsuid();
46995 cii->c_cached_perm = mask;
46996 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46997 {
46998 struct coda_inode_info *cii = ITOC(inode);
46999 spin_lock(&cii->c_lock);
47000 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47001 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47002 spin_unlock(&cii->c_lock);
47003 }
47004
47005 /* remove all acl caches */
47006 void coda_cache_clear_all(struct super_block *sb)
47007 {
47008 - atomic_inc(&permission_epoch);
47009 + atomic_inc_unchecked(&permission_epoch);
47010 }
47011
47012
47013 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
47014 spin_lock(&cii->c_lock);
47015 hit = (mask & cii->c_cached_perm) == mask &&
47016 cii->c_uid == current_fsuid() &&
47017 - cii->c_cached_epoch == atomic_read(&permission_epoch);
47018 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47019 spin_unlock(&cii->c_lock);
47020
47021 return hit;
47022 diff --git a/fs/compat.c b/fs/compat.c
47023 index 015e1e1..5ce8e54 100644
47024 --- a/fs/compat.c
47025 +++ b/fs/compat.c
47026 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47027
47028 set_fs(KERNEL_DS);
47029 /* The __user pointer cast is valid because of the set_fs() */
47030 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47031 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47032 set_fs(oldfs);
47033 /* truncating is ok because it's a user address */
47034 if (!ret)
47035 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
47036 goto out;
47037
47038 ret = -EINVAL;
47039 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
47040 + if (nr_segs > UIO_MAXIOV)
47041 goto out;
47042 if (nr_segs > fast_segs) {
47043 ret = -ENOMEM;
47044 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
47045
47046 struct compat_readdir_callback {
47047 struct compat_old_linux_dirent __user *dirent;
47048 + struct file * file;
47049 int result;
47050 };
47051
47052 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47053 buf->result = -EOVERFLOW;
47054 return -EOVERFLOW;
47055 }
47056 +
47057 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47058 + return 0;
47059 +
47060 buf->result++;
47061 dirent = buf->dirent;
47062 if (!access_ok(VERIFY_WRITE, dirent,
47063 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47064
47065 buf.result = 0;
47066 buf.dirent = dirent;
47067 + buf.file = f.file;
47068
47069 error = vfs_readdir(f.file, compat_fillonedir, &buf);
47070 if (buf.result)
47071 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
47072 struct compat_getdents_callback {
47073 struct compat_linux_dirent __user *current_dir;
47074 struct compat_linux_dirent __user *previous;
47075 + struct file * file;
47076 int count;
47077 int error;
47078 };
47079 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47080 buf->error = -EOVERFLOW;
47081 return -EOVERFLOW;
47082 }
47083 +
47084 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47085 + return 0;
47086 +
47087 dirent = buf->previous;
47088 if (dirent) {
47089 if (__put_user(offset, &dirent->d_off))
47090 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47091 buf.previous = NULL;
47092 buf.count = count;
47093 buf.error = 0;
47094 + buf.file = f.file;
47095
47096 error = vfs_readdir(f.file, compat_filldir, &buf);
47097 if (error >= 0)
47098 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47099 struct compat_getdents_callback64 {
47100 struct linux_dirent64 __user *current_dir;
47101 struct linux_dirent64 __user *previous;
47102 + struct file * file;
47103 int count;
47104 int error;
47105 };
47106 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47107 buf->error = -EINVAL; /* only used if we fail.. */
47108 if (reclen > buf->count)
47109 return -EINVAL;
47110 +
47111 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47112 + return 0;
47113 +
47114 dirent = buf->previous;
47115
47116 if (dirent) {
47117 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47118 buf.previous = NULL;
47119 buf.count = count;
47120 buf.error = 0;
47121 + buf.file = f.file;
47122
47123 error = vfs_readdir(f.file, compat_filldir64, &buf);
47124 if (error >= 0)
47125 error = buf.error;
47126 lastdirent = buf.previous;
47127 if (lastdirent) {
47128 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
47129 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
47130 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47131 error = -EFAULT;
47132 else
47133 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47134 index a81147e..20bf2b5 100644
47135 --- a/fs/compat_binfmt_elf.c
47136 +++ b/fs/compat_binfmt_elf.c
47137 @@ -30,11 +30,13 @@
47138 #undef elf_phdr
47139 #undef elf_shdr
47140 #undef elf_note
47141 +#undef elf_dyn
47142 #undef elf_addr_t
47143 #define elfhdr elf32_hdr
47144 #define elf_phdr elf32_phdr
47145 #define elf_shdr elf32_shdr
47146 #define elf_note elf32_note
47147 +#define elf_dyn Elf32_Dyn
47148 #define elf_addr_t Elf32_Addr
47149
47150 /*
47151 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47152 index e2f57a0..3c78771 100644
47153 --- a/fs/compat_ioctl.c
47154 +++ b/fs/compat_ioctl.c
47155 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
47156 return -EFAULT;
47157 if (__get_user(udata, &ss32->iomem_base))
47158 return -EFAULT;
47159 - ss.iomem_base = compat_ptr(udata);
47160 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47161 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47162 __get_user(ss.port_high, &ss32->port_high))
47163 return -EFAULT;
47164 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
47165 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47166 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47167 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47168 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47169 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47170 return -EFAULT;
47171
47172 return ioctl_preallocate(file, p);
47173 @@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
47174 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
47175 {
47176 unsigned int a, b;
47177 - a = *(unsigned int *)p;
47178 - b = *(unsigned int *)q;
47179 + a = *(const unsigned int *)p;
47180 + b = *(const unsigned int *)q;
47181 if (a > b)
47182 return 1;
47183 if (a < b)
47184 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47185 index 712b10f..6b54d7b 100644
47186 --- a/fs/configfs/dir.c
47187 +++ b/fs/configfs/dir.c
47188 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47189 }
47190 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47191 struct configfs_dirent *next;
47192 - const char * name;
47193 + const unsigned char * name;
47194 + char d_name[sizeof(next->s_dentry->d_iname)];
47195 int len;
47196 struct inode *inode = NULL;
47197
47198 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47199 continue;
47200
47201 name = configfs_get_name(next);
47202 - len = strlen(name);
47203 + if (next->s_dentry && name == next->s_dentry->d_iname) {
47204 + len = next->s_dentry->d_name.len;
47205 + memcpy(d_name, name, len);
47206 + name = d_name;
47207 + } else
47208 + len = strlen(name);
47209
47210 /*
47211 * We'll have a dentry and an inode for
47212 diff --git a/fs/coredump.c b/fs/coredump.c
47213 index 1774932..5812106 100644
47214 --- a/fs/coredump.c
47215 +++ b/fs/coredump.c
47216 @@ -52,7 +52,7 @@ struct core_name {
47217 char *corename;
47218 int used, size;
47219 };
47220 -static atomic_t call_count = ATOMIC_INIT(1);
47221 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
47222
47223 /* The maximal length of core_pattern is also specified in sysctl.c */
47224
47225 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
47226 {
47227 char *old_corename = cn->corename;
47228
47229 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
47230 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
47231 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
47232
47233 if (!cn->corename) {
47234 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
47235 int pid_in_pattern = 0;
47236 int err = 0;
47237
47238 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
47239 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
47240 cn->corename = kmalloc(cn->size, GFP_KERNEL);
47241 cn->used = 0;
47242
47243 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
47244 pipe = file->f_path.dentry->d_inode->i_pipe;
47245
47246 pipe_lock(pipe);
47247 - pipe->readers++;
47248 - pipe->writers--;
47249 + atomic_inc(&pipe->readers);
47250 + atomic_dec(&pipe->writers);
47251
47252 - while ((pipe->readers > 1) && (!signal_pending(current))) {
47253 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
47254 wake_up_interruptible_sync(&pipe->wait);
47255 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47256 pipe_wait(pipe);
47257 }
47258
47259 - pipe->readers--;
47260 - pipe->writers++;
47261 + atomic_dec(&pipe->readers);
47262 + atomic_inc(&pipe->writers);
47263 pipe_unlock(pipe);
47264
47265 }
47266 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
47267 int ispipe;
47268 struct files_struct *displaced;
47269 bool need_nonrelative = false;
47270 - static atomic_t core_dump_count = ATOMIC_INIT(0);
47271 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
47272 + long signr = siginfo->si_signo;
47273 struct coredump_params cprm = {
47274 .siginfo = siginfo,
47275 .regs = signal_pt_regs(),
47276 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
47277 .mm_flags = mm->flags,
47278 };
47279
47280 - audit_core_dumps(siginfo->si_signo);
47281 + audit_core_dumps(signr);
47282 +
47283 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
47284 + gr_handle_brute_attach(cprm.mm_flags);
47285
47286 binfmt = mm->binfmt;
47287 if (!binfmt || !binfmt->core_dump)
47288 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
47289 need_nonrelative = true;
47290 }
47291
47292 - retval = coredump_wait(siginfo->si_signo, &core_state);
47293 + retval = coredump_wait(signr, &core_state);
47294 if (retval < 0)
47295 goto fail_creds;
47296
47297 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
47298 }
47299 cprm.limit = RLIM_INFINITY;
47300
47301 - dump_count = atomic_inc_return(&core_dump_count);
47302 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
47303 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
47304 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
47305 task_tgid_vnr(current), current->comm);
47306 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
47307 } else {
47308 struct inode *inode;
47309
47310 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
47311 +
47312 if (cprm.limit < binfmt->min_coredump)
47313 goto fail_unlock;
47314
47315 @@ -640,7 +646,7 @@ close_fail:
47316 filp_close(cprm.file, NULL);
47317 fail_dropcount:
47318 if (ispipe)
47319 - atomic_dec(&core_dump_count);
47320 + atomic_dec_unchecked(&core_dump_count);
47321 fail_unlock:
47322 kfree(cn.corename);
47323 fail_corename:
47324 @@ -659,7 +665,7 @@ fail:
47325 */
47326 int dump_write(struct file *file, const void *addr, int nr)
47327 {
47328 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
47329 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
47330 }
47331 EXPORT_SYMBOL(dump_write);
47332
47333 diff --git a/fs/dcache.c b/fs/dcache.c
47334 index 19153a0..428c2f5 100644
47335 --- a/fs/dcache.c
47336 +++ b/fs/dcache.c
47337 @@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
47338 mempages -= reserve;
47339
47340 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47341 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47342 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47343
47344 dcache_init();
47345 inode_init();
47346 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
47347 index a5f12b7..4ee8a6f 100644
47348 --- a/fs/debugfs/inode.c
47349 +++ b/fs/debugfs/inode.c
47350 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
47351 */
47352 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
47353 {
47354 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47355 + return __create_file(name, S_IFDIR | S_IRWXU,
47356 +#else
47357 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
47358 +#endif
47359 parent, NULL, NULL);
47360 }
47361 EXPORT_SYMBOL_GPL(debugfs_create_dir);
47362 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47363 index cc7709e..7e7211f 100644
47364 --- a/fs/ecryptfs/inode.c
47365 +++ b/fs/ecryptfs/inode.c
47366 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47367 old_fs = get_fs();
47368 set_fs(get_ds());
47369 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47370 - (char __user *)lower_buf,
47371 + (char __force_user *)lower_buf,
47372 PATH_MAX);
47373 set_fs(old_fs);
47374 if (rc < 0)
47375 @@ -706,7 +706,7 @@ out:
47376 static void
47377 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
47378 {
47379 - char *buf = nd_get_link(nd);
47380 + const char *buf = nd_get_link(nd);
47381 if (!IS_ERR(buf)) {
47382 /* Free the char* */
47383 kfree(buf);
47384 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
47385 index 412e6ed..4292d22 100644
47386 --- a/fs/ecryptfs/miscdev.c
47387 +++ b/fs/ecryptfs/miscdev.c
47388 @@ -315,7 +315,7 @@ check_list:
47389 goto out_unlock_msg_ctx;
47390 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
47391 if (msg_ctx->msg) {
47392 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
47393 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
47394 goto out_unlock_msg_ctx;
47395 i += packet_length_size;
47396 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
47397 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
47398 index b2a34a1..162fa69 100644
47399 --- a/fs/ecryptfs/read_write.c
47400 +++ b/fs/ecryptfs/read_write.c
47401 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
47402 return -EIO;
47403 fs_save = get_fs();
47404 set_fs(get_ds());
47405 - rc = vfs_write(lower_file, data, size, &offset);
47406 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
47407 set_fs(fs_save);
47408 mark_inode_dirty_sync(ecryptfs_inode);
47409 return rc;
47410 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
47411 return -EIO;
47412 fs_save = get_fs();
47413 set_fs(get_ds());
47414 - rc = vfs_read(lower_file, data, size, &offset);
47415 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
47416 set_fs(fs_save);
47417 return rc;
47418 }
47419 diff --git a/fs/exec.c b/fs/exec.c
47420 index 20df02c..1dff97d 100644
47421 --- a/fs/exec.c
47422 +++ b/fs/exec.c
47423 @@ -55,6 +55,17 @@
47424 #include <linux/pipe_fs_i.h>
47425 #include <linux/oom.h>
47426 #include <linux/compat.h>
47427 +#include <linux/random.h>
47428 +#include <linux/seq_file.h>
47429 +#include <linux/coredump.h>
47430 +#include <linux/mman.h>
47431 +
47432 +#ifdef CONFIG_PAX_REFCOUNT
47433 +#include <linux/kallsyms.h>
47434 +#include <linux/kdebug.h>
47435 +#endif
47436 +
47437 +#include <trace/events/fs.h>
47438
47439 #include <asm/uaccess.h>
47440 #include <asm/mmu_context.h>
47441 @@ -66,6 +77,18 @@
47442
47443 #include <trace/events/sched.h>
47444
47445 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47446 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
47447 +{
47448 + 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");
47449 +}
47450 +#endif
47451 +
47452 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
47453 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
47454 +EXPORT_SYMBOL(pax_set_initial_flags_func);
47455 +#endif
47456 +
47457 int suid_dumpable = 0;
47458
47459 static LIST_HEAD(formats);
47460 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47461 int write)
47462 {
47463 struct page *page;
47464 - int ret;
47465
47466 -#ifdef CONFIG_STACK_GROWSUP
47467 - if (write) {
47468 - ret = expand_downwards(bprm->vma, pos);
47469 - if (ret < 0)
47470 - return NULL;
47471 - }
47472 -#endif
47473 - ret = get_user_pages(current, bprm->mm, pos,
47474 - 1, write, 1, &page, NULL);
47475 - if (ret <= 0)
47476 + if (0 > expand_downwards(bprm->vma, pos))
47477 + return NULL;
47478 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
47479 return NULL;
47480
47481 if (write) {
47482 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47483 if (size <= ARG_MAX)
47484 return page;
47485
47486 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47487 + // only allow 512KB for argv+env on suid/sgid binaries
47488 + // to prevent easy ASLR exhaustion
47489 + if (((bprm->cred->euid != current_euid()) ||
47490 + (bprm->cred->egid != current_egid())) &&
47491 + (size > (512 * 1024))) {
47492 + put_page(page);
47493 + return NULL;
47494 + }
47495 +#endif
47496 +
47497 /*
47498 * Limit to 1/4-th the stack size for the argv+env strings.
47499 * This ensures that:
47500 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47501 vma->vm_end = STACK_TOP_MAX;
47502 vma->vm_start = vma->vm_end - PAGE_SIZE;
47503 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
47504 +
47505 +#ifdef CONFIG_PAX_SEGMEXEC
47506 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
47507 +#endif
47508 +
47509 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
47510 INIT_LIST_HEAD(&vma->anon_vma_chain);
47511
47512 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47513 mm->stack_vm = mm->total_vm = 1;
47514 up_write(&mm->mmap_sem);
47515 bprm->p = vma->vm_end - sizeof(void *);
47516 +
47517 +#ifdef CONFIG_PAX_RANDUSTACK
47518 + if (randomize_va_space)
47519 + bprm->p ^= random32() & ~PAGE_MASK;
47520 +#endif
47521 +
47522 return 0;
47523 err:
47524 up_write(&mm->mmap_sem);
47525 @@ -384,19 +421,7 @@ err:
47526 return err;
47527 }
47528
47529 -struct user_arg_ptr {
47530 -#ifdef CONFIG_COMPAT
47531 - bool is_compat;
47532 -#endif
47533 - union {
47534 - const char __user *const __user *native;
47535 -#ifdef CONFIG_COMPAT
47536 - const compat_uptr_t __user *compat;
47537 -#endif
47538 - } ptr;
47539 -};
47540 -
47541 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47542 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47543 {
47544 const char __user *native;
47545
47546 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47547 compat_uptr_t compat;
47548
47549 if (get_user(compat, argv.ptr.compat + nr))
47550 - return ERR_PTR(-EFAULT);
47551 + return (const char __force_user *)ERR_PTR(-EFAULT);
47552
47553 return compat_ptr(compat);
47554 }
47555 #endif
47556
47557 if (get_user(native, argv.ptr.native + nr))
47558 - return ERR_PTR(-EFAULT);
47559 + return (const char __force_user *)ERR_PTR(-EFAULT);
47560
47561 return native;
47562 }
47563 @@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
47564 if (!p)
47565 break;
47566
47567 - if (IS_ERR(p))
47568 + if (IS_ERR((const char __force_kernel *)p))
47569 return -EFAULT;
47570
47571 if (i >= max)
47572 @@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
47573
47574 ret = -EFAULT;
47575 str = get_user_arg_ptr(argv, argc);
47576 - if (IS_ERR(str))
47577 + if (IS_ERR((const char __force_kernel *)str))
47578 goto out;
47579
47580 len = strnlen_user(str, MAX_ARG_STRLEN);
47581 @@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
47582 int r;
47583 mm_segment_t oldfs = get_fs();
47584 struct user_arg_ptr argv = {
47585 - .ptr.native = (const char __user *const __user *)__argv,
47586 + .ptr.native = (const char __force_user *const __force_user *)__argv,
47587 };
47588
47589 set_fs(KERNEL_DS);
47590 @@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47591 unsigned long new_end = old_end - shift;
47592 struct mmu_gather tlb;
47593
47594 - BUG_ON(new_start > new_end);
47595 + if (new_start >= new_end || new_start < mmap_min_addr)
47596 + return -ENOMEM;
47597
47598 /*
47599 * ensure there are no vmas between where we want to go
47600 @@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47601 if (vma != find_vma(mm, new_start))
47602 return -EFAULT;
47603
47604 +#ifdef CONFIG_PAX_SEGMEXEC
47605 + BUG_ON(pax_find_mirror_vma(vma));
47606 +#endif
47607 +
47608 /*
47609 * cover the whole range: [new_start, old_end)
47610 */
47611 @@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47612 stack_top = arch_align_stack(stack_top);
47613 stack_top = PAGE_ALIGN(stack_top);
47614
47615 - if (unlikely(stack_top < mmap_min_addr) ||
47616 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
47617 - return -ENOMEM;
47618 -
47619 stack_shift = vma->vm_end - stack_top;
47620
47621 bprm->p -= stack_shift;
47622 @@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
47623 bprm->exec -= stack_shift;
47624
47625 down_write(&mm->mmap_sem);
47626 +
47627 + /* Move stack pages down in memory. */
47628 + if (stack_shift) {
47629 + ret = shift_arg_pages(vma, stack_shift);
47630 + if (ret)
47631 + goto out_unlock;
47632 + }
47633 +
47634 vm_flags = VM_STACK_FLAGS;
47635
47636 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47637 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47638 + vm_flags &= ~VM_EXEC;
47639 +
47640 +#ifdef CONFIG_PAX_MPROTECT
47641 + if (mm->pax_flags & MF_PAX_MPROTECT)
47642 + vm_flags &= ~VM_MAYEXEC;
47643 +#endif
47644 +
47645 + }
47646 +#endif
47647 +
47648 /*
47649 * Adjust stack execute permissions; explicitly enable for
47650 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
47651 @@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47652 goto out_unlock;
47653 BUG_ON(prev != vma);
47654
47655 - /* Move stack pages down in memory. */
47656 - if (stack_shift) {
47657 - ret = shift_arg_pages(vma, stack_shift);
47658 - if (ret)
47659 - goto out_unlock;
47660 - }
47661 -
47662 /* mprotect_fixup is overkill to remove the temporary stack flags */
47663 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
47664
47665 @@ -737,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
47666 #endif
47667 current->mm->start_stack = bprm->p;
47668 ret = expand_stack(vma, stack_base);
47669 +
47670 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
47671 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
47672 + unsigned long size, flags, vm_flags;
47673 +
47674 + size = STACK_TOP - vma->vm_end;
47675 + flags = MAP_FIXED | MAP_PRIVATE;
47676 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
47677 +
47678 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
47679 +
47680 +#ifdef CONFIG_X86
47681 + if (!ret) {
47682 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
47683 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
47684 + }
47685 +#endif
47686 +
47687 + }
47688 +#endif
47689 +
47690 if (ret)
47691 ret = -EFAULT;
47692
47693 @@ -772,6 +832,8 @@ struct file *open_exec(const char *name)
47694
47695 fsnotify_open(file);
47696
47697 + trace_open_exec(name);
47698 +
47699 err = deny_write_access(file);
47700 if (err)
47701 goto exit;
47702 @@ -795,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
47703 old_fs = get_fs();
47704 set_fs(get_ds());
47705 /* The cast to a user pointer is valid due to the set_fs() */
47706 - result = vfs_read(file, (void __user *)addr, count, &pos);
47707 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
47708 set_fs(old_fs);
47709 return result;
47710 }
47711 @@ -1247,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
47712 }
47713 rcu_read_unlock();
47714
47715 - if (p->fs->users > n_fs) {
47716 + if (atomic_read(&p->fs->users) > n_fs) {
47717 bprm->unsafe |= LSM_UNSAFE_SHARE;
47718 } else {
47719 res = -EAGAIN;
47720 @@ -1447,6 +1509,28 @@ int search_binary_handler(struct linux_binprm *bprm)
47721
47722 EXPORT_SYMBOL(search_binary_handler);
47723
47724 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47725 +static DEFINE_PER_CPU(u64, exec_counter);
47726 +static int __init init_exec_counters(void)
47727 +{
47728 + unsigned int cpu;
47729 +
47730 + for_each_possible_cpu(cpu) {
47731 + per_cpu(exec_counter, cpu) = (u64)cpu;
47732 + }
47733 +
47734 + return 0;
47735 +}
47736 +early_initcall(init_exec_counters);
47737 +static inline void increment_exec_counter(void)
47738 +{
47739 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
47740 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47741 +}
47742 +#else
47743 +static inline void increment_exec_counter(void) {}
47744 +#endif
47745 +
47746 /*
47747 * sys_execve() executes a new program.
47748 */
47749 @@ -1454,6 +1538,11 @@ static int do_execve_common(const char *filename,
47750 struct user_arg_ptr argv,
47751 struct user_arg_ptr envp)
47752 {
47753 +#ifdef CONFIG_GRKERNSEC
47754 + struct file *old_exec_file;
47755 + struct acl_subject_label *old_acl;
47756 + struct rlimit old_rlim[RLIM_NLIMITS];
47757 +#endif
47758 struct linux_binprm *bprm;
47759 struct file *file;
47760 struct files_struct *displaced;
47761 @@ -1461,6 +1550,8 @@ static int do_execve_common(const char *filename,
47762 int retval;
47763 const struct cred *cred = current_cred();
47764
47765 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47766 +
47767 /*
47768 * We move the actual failure in case of RLIMIT_NPROC excess from
47769 * set*uid() to execve() because too many poorly written programs
47770 @@ -1501,12 +1592,27 @@ static int do_execve_common(const char *filename,
47771 if (IS_ERR(file))
47772 goto out_unmark;
47773
47774 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
47775 + retval = -EPERM;
47776 + goto out_file;
47777 + }
47778 +
47779 sched_exec();
47780
47781 bprm->file = file;
47782 bprm->filename = filename;
47783 bprm->interp = filename;
47784
47785 + if (gr_process_user_ban()) {
47786 + retval = -EPERM;
47787 + goto out_file;
47788 + }
47789 +
47790 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47791 + retval = -EACCES;
47792 + goto out_file;
47793 + }
47794 +
47795 retval = bprm_mm_init(bprm);
47796 if (retval)
47797 goto out_file;
47798 @@ -1523,24 +1629,65 @@ static int do_execve_common(const char *filename,
47799 if (retval < 0)
47800 goto out;
47801
47802 +#ifdef CONFIG_GRKERNSEC
47803 + old_acl = current->acl;
47804 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47805 + old_exec_file = current->exec_file;
47806 + get_file(file);
47807 + current->exec_file = file;
47808 +#endif
47809 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47810 + /* limit suid stack to 8MB
47811 + * we saved the old limits above and will restore them if this exec fails
47812 + */
47813 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47814 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47815 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47816 +#endif
47817 +
47818 + if (!gr_tpe_allow(file)) {
47819 + retval = -EACCES;
47820 + goto out_fail;
47821 + }
47822 +
47823 + if (gr_check_crash_exec(file)) {
47824 + retval = -EACCES;
47825 + goto out_fail;
47826 + }
47827 +
47828 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47829 + bprm->unsafe);
47830 + if (retval < 0)
47831 + goto out_fail;
47832 +
47833 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47834 if (retval < 0)
47835 - goto out;
47836 + goto out_fail;
47837
47838 bprm->exec = bprm->p;
47839 retval = copy_strings(bprm->envc, envp, bprm);
47840 if (retval < 0)
47841 - goto out;
47842 + goto out_fail;
47843
47844 retval = copy_strings(bprm->argc, argv, bprm);
47845 if (retval < 0)
47846 - goto out;
47847 + goto out_fail;
47848 +
47849 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47850 +
47851 + gr_handle_exec_args(bprm, argv);
47852
47853 retval = search_binary_handler(bprm);
47854 if (retval < 0)
47855 - goto out;
47856 + goto out_fail;
47857 +#ifdef CONFIG_GRKERNSEC
47858 + if (old_exec_file)
47859 + fput(old_exec_file);
47860 +#endif
47861
47862 /* execve succeeded */
47863 +
47864 + increment_exec_counter();
47865 current->fs->in_exec = 0;
47866 current->in_execve = 0;
47867 acct_update_integrals(current);
47868 @@ -1549,6 +1696,14 @@ static int do_execve_common(const char *filename,
47869 put_files_struct(displaced);
47870 return retval;
47871
47872 +out_fail:
47873 +#ifdef CONFIG_GRKERNSEC
47874 + current->acl = old_acl;
47875 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47876 + fput(current->exec_file);
47877 + current->exec_file = old_exec_file;
47878 +#endif
47879 +
47880 out:
47881 if (bprm->mm) {
47882 acct_arg_size(bprm, 0);
47883 @@ -1697,3 +1852,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
47884 return error;
47885 }
47886 #endif
47887 +
47888 +int pax_check_flags(unsigned long *flags)
47889 +{
47890 + int retval = 0;
47891 +
47892 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47893 + if (*flags & MF_PAX_SEGMEXEC)
47894 + {
47895 + *flags &= ~MF_PAX_SEGMEXEC;
47896 + retval = -EINVAL;
47897 + }
47898 +#endif
47899 +
47900 + if ((*flags & MF_PAX_PAGEEXEC)
47901 +
47902 +#ifdef CONFIG_PAX_PAGEEXEC
47903 + && (*flags & MF_PAX_SEGMEXEC)
47904 +#endif
47905 +
47906 + )
47907 + {
47908 + *flags &= ~MF_PAX_PAGEEXEC;
47909 + retval = -EINVAL;
47910 + }
47911 +
47912 + if ((*flags & MF_PAX_MPROTECT)
47913 +
47914 +#ifdef CONFIG_PAX_MPROTECT
47915 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47916 +#endif
47917 +
47918 + )
47919 + {
47920 + *flags &= ~MF_PAX_MPROTECT;
47921 + retval = -EINVAL;
47922 + }
47923 +
47924 + if ((*flags & MF_PAX_EMUTRAMP)
47925 +
47926 +#ifdef CONFIG_PAX_EMUTRAMP
47927 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47928 +#endif
47929 +
47930 + )
47931 + {
47932 + *flags &= ~MF_PAX_EMUTRAMP;
47933 + retval = -EINVAL;
47934 + }
47935 +
47936 + return retval;
47937 +}
47938 +
47939 +EXPORT_SYMBOL(pax_check_flags);
47940 +
47941 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47942 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47943 +{
47944 + struct task_struct *tsk = current;
47945 + struct mm_struct *mm = current->mm;
47946 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47947 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47948 + char *path_exec = NULL;
47949 + char *path_fault = NULL;
47950 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
47951 + siginfo_t info = { };
47952 +
47953 + if (buffer_exec && buffer_fault) {
47954 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47955 +
47956 + down_read(&mm->mmap_sem);
47957 + vma = mm->mmap;
47958 + while (vma && (!vma_exec || !vma_fault)) {
47959 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47960 + vma_exec = vma;
47961 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47962 + vma_fault = vma;
47963 + vma = vma->vm_next;
47964 + }
47965 + if (vma_exec) {
47966 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47967 + if (IS_ERR(path_exec))
47968 + path_exec = "<path too long>";
47969 + else {
47970 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47971 + if (path_exec) {
47972 + *path_exec = 0;
47973 + path_exec = buffer_exec;
47974 + } else
47975 + path_exec = "<path too long>";
47976 + }
47977 + }
47978 + if (vma_fault) {
47979 + start = vma_fault->vm_start;
47980 + end = vma_fault->vm_end;
47981 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47982 + if (vma_fault->vm_file) {
47983 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47984 + if (IS_ERR(path_fault))
47985 + path_fault = "<path too long>";
47986 + else {
47987 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47988 + if (path_fault) {
47989 + *path_fault = 0;
47990 + path_fault = buffer_fault;
47991 + } else
47992 + path_fault = "<path too long>";
47993 + }
47994 + } else
47995 + path_fault = "<anonymous mapping>";
47996 + }
47997 + up_read(&mm->mmap_sem);
47998 + }
47999 + if (tsk->signal->curr_ip)
48000 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48001 + else
48002 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48003 + 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),
48004 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
48005 + free_page((unsigned long)buffer_exec);
48006 + free_page((unsigned long)buffer_fault);
48007 + pax_report_insns(regs, pc, sp);
48008 + info.si_signo = SIGKILL;
48009 + info.si_errno = 0;
48010 + info.si_code = SI_KERNEL;
48011 + info.si_pid = 0;
48012 + info.si_uid = 0;
48013 + do_coredump(&info);
48014 +}
48015 +#endif
48016 +
48017 +#ifdef CONFIG_PAX_REFCOUNT
48018 +void pax_report_refcount_overflow(struct pt_regs *regs)
48019 +{
48020 + if (current->signal->curr_ip)
48021 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48022 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
48023 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48024 + else
48025 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
48026 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48027 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48028 + show_regs(regs);
48029 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
48030 +}
48031 +#endif
48032 +
48033 +#ifdef CONFIG_PAX_USERCOPY
48034 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48035 +static noinline int check_stack_object(const void *obj, unsigned long len)
48036 +{
48037 + const void * const stack = task_stack_page(current);
48038 + const void * const stackend = stack + THREAD_SIZE;
48039 +
48040 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48041 + const void *frame = NULL;
48042 + const void *oldframe;
48043 +#endif
48044 +
48045 + if (obj + len < obj)
48046 + return -1;
48047 +
48048 + if (obj + len <= stack || stackend <= obj)
48049 + return 0;
48050 +
48051 + if (obj < stack || stackend < obj + len)
48052 + return -1;
48053 +
48054 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48055 + oldframe = __builtin_frame_address(1);
48056 + if (oldframe)
48057 + frame = __builtin_frame_address(2);
48058 + /*
48059 + low ----------------------------------------------> high
48060 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
48061 + ^----------------^
48062 + allow copies only within here
48063 + */
48064 + while (stack <= frame && frame < stackend) {
48065 + /* if obj + len extends past the last frame, this
48066 + check won't pass and the next frame will be 0,
48067 + causing us to bail out and correctly report
48068 + the copy as invalid
48069 + */
48070 + if (obj + len <= frame)
48071 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48072 + oldframe = frame;
48073 + frame = *(const void * const *)frame;
48074 + }
48075 + return -1;
48076 +#else
48077 + return 1;
48078 +#endif
48079 +}
48080 +
48081 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48082 +{
48083 + if (current->signal->curr_ip)
48084 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48085 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48086 + else
48087 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48088 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48089 + dump_stack();
48090 + gr_handle_kernel_exploit();
48091 + do_group_exit(SIGKILL);
48092 +}
48093 +#endif
48094 +
48095 +void __check_object_size(const void *ptr, unsigned long n, bool to)
48096 +{
48097 +
48098 +#ifdef CONFIG_PAX_USERCOPY
48099 + const char *type;
48100 +
48101 + if (!n)
48102 + return;
48103 +
48104 + type = check_heap_object(ptr, n);
48105 + if (!type) {
48106 + if (check_stack_object(ptr, n) != -1)
48107 + return;
48108 + type = "<process stack>";
48109 + }
48110 +
48111 + pax_report_usercopy(ptr, n, to, type);
48112 +#endif
48113 +
48114 +}
48115 +EXPORT_SYMBOL(__check_object_size);
48116 +
48117 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48118 +void pax_track_stack(void)
48119 +{
48120 + unsigned long sp = (unsigned long)&sp;
48121 + if (sp < current_thread_info()->lowest_stack &&
48122 + sp > (unsigned long)task_stack_page(current))
48123 + current_thread_info()->lowest_stack = sp;
48124 +}
48125 +EXPORT_SYMBOL(pax_track_stack);
48126 +#endif
48127 +
48128 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
48129 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
48130 +{
48131 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
48132 + dump_stack();
48133 + do_group_exit(SIGKILL);
48134 +}
48135 +EXPORT_SYMBOL(report_size_overflow);
48136 +#endif
48137 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48138 index 2616d0e..2ffdec9 100644
48139 --- a/fs/ext2/balloc.c
48140 +++ b/fs/ext2/balloc.c
48141 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48142
48143 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48144 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48145 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48146 + if (free_blocks < root_blocks + 1 &&
48147 !uid_eq(sbi->s_resuid, current_fsuid()) &&
48148 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48149 - !in_group_p (sbi->s_resgid))) {
48150 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48151 return 0;
48152 }
48153 return 1;
48154 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48155 index 22548f5..41521d8 100644
48156 --- a/fs/ext3/balloc.c
48157 +++ b/fs/ext3/balloc.c
48158 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
48159
48160 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48161 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48162 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48163 + if (free_blocks < root_blocks + 1 &&
48164 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
48165 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48166 - !in_group_p (sbi->s_resgid))) {
48167 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48168 return 0;
48169 }
48170 return 1;
48171 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48172 index cf18217..8f6b9c3 100644
48173 --- a/fs/ext4/balloc.c
48174 +++ b/fs/ext4/balloc.c
48175 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
48176 /* Hm, nope. Are (enough) root reserved clusters available? */
48177 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
48178 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
48179 - capable(CAP_SYS_RESOURCE) ||
48180 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
48181 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
48182 + capable_nolog(CAP_SYS_RESOURCE)) {
48183
48184 if (free_clusters >= (nclusters + dirty_clusters))
48185 return 1;
48186 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48187 index 8462eb3..4a71af6 100644
48188 --- a/fs/ext4/ext4.h
48189 +++ b/fs/ext4/ext4.h
48190 @@ -1265,19 +1265,19 @@ struct ext4_sb_info {
48191 unsigned long s_mb_last_start;
48192
48193 /* stats for buddy allocator */
48194 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48195 - atomic_t s_bal_success; /* we found long enough chunks */
48196 - atomic_t s_bal_allocated; /* in blocks */
48197 - atomic_t s_bal_ex_scanned; /* total extents scanned */
48198 - atomic_t s_bal_goals; /* goal hits */
48199 - atomic_t s_bal_breaks; /* too long searches */
48200 - atomic_t s_bal_2orders; /* 2^order hits */
48201 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48202 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48203 + atomic_unchecked_t s_bal_allocated; /* in blocks */
48204 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48205 + atomic_unchecked_t s_bal_goals; /* goal hits */
48206 + atomic_unchecked_t s_bal_breaks; /* too long searches */
48207 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48208 spinlock_t s_bal_lock;
48209 unsigned long s_mb_buddies_generated;
48210 unsigned long long s_mb_generation_time;
48211 - atomic_t s_mb_lost_chunks;
48212 - atomic_t s_mb_preallocated;
48213 - atomic_t s_mb_discarded;
48214 + atomic_unchecked_t s_mb_lost_chunks;
48215 + atomic_unchecked_t s_mb_preallocated;
48216 + atomic_unchecked_t s_mb_discarded;
48217 atomic_t s_lock_busy;
48218
48219 /* locality groups */
48220 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48221 index 1bf6fe7..1a5bdef 100644
48222 --- a/fs/ext4/mballoc.c
48223 +++ b/fs/ext4/mballoc.c
48224 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48225 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48226
48227 if (EXT4_SB(sb)->s_mb_stats)
48228 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48229 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48230
48231 break;
48232 }
48233 @@ -2044,7 +2044,7 @@ repeat:
48234 ac->ac_status = AC_STATUS_CONTINUE;
48235 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48236 cr = 3;
48237 - atomic_inc(&sbi->s_mb_lost_chunks);
48238 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48239 goto repeat;
48240 }
48241 }
48242 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
48243 if (sbi->s_mb_stats) {
48244 ext4_msg(sb, KERN_INFO,
48245 "mballoc: %u blocks %u reqs (%u success)",
48246 - atomic_read(&sbi->s_bal_allocated),
48247 - atomic_read(&sbi->s_bal_reqs),
48248 - atomic_read(&sbi->s_bal_success));
48249 + atomic_read_unchecked(&sbi->s_bal_allocated),
48250 + atomic_read_unchecked(&sbi->s_bal_reqs),
48251 + atomic_read_unchecked(&sbi->s_bal_success));
48252 ext4_msg(sb, KERN_INFO,
48253 "mballoc: %u extents scanned, %u goal hits, "
48254 "%u 2^N hits, %u breaks, %u lost",
48255 - atomic_read(&sbi->s_bal_ex_scanned),
48256 - atomic_read(&sbi->s_bal_goals),
48257 - atomic_read(&sbi->s_bal_2orders),
48258 - atomic_read(&sbi->s_bal_breaks),
48259 - atomic_read(&sbi->s_mb_lost_chunks));
48260 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48261 + atomic_read_unchecked(&sbi->s_bal_goals),
48262 + atomic_read_unchecked(&sbi->s_bal_2orders),
48263 + atomic_read_unchecked(&sbi->s_bal_breaks),
48264 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48265 ext4_msg(sb, KERN_INFO,
48266 "mballoc: %lu generated and it took %Lu",
48267 sbi->s_mb_buddies_generated,
48268 sbi->s_mb_generation_time);
48269 ext4_msg(sb, KERN_INFO,
48270 "mballoc: %u preallocated, %u discarded",
48271 - atomic_read(&sbi->s_mb_preallocated),
48272 - atomic_read(&sbi->s_mb_discarded));
48273 + atomic_read_unchecked(&sbi->s_mb_preallocated),
48274 + atomic_read_unchecked(&sbi->s_mb_discarded));
48275 }
48276
48277 free_percpu(sbi->s_locality_groups);
48278 @@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48279 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48280
48281 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48282 - atomic_inc(&sbi->s_bal_reqs);
48283 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48284 + atomic_inc_unchecked(&sbi->s_bal_reqs);
48285 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48286 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
48287 - atomic_inc(&sbi->s_bal_success);
48288 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48289 + atomic_inc_unchecked(&sbi->s_bal_success);
48290 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48291 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48292 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48293 - atomic_inc(&sbi->s_bal_goals);
48294 + atomic_inc_unchecked(&sbi->s_bal_goals);
48295 if (ac->ac_found > sbi->s_mb_max_to_scan)
48296 - atomic_inc(&sbi->s_bal_breaks);
48297 + atomic_inc_unchecked(&sbi->s_bal_breaks);
48298 }
48299
48300 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48301 @@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48302 trace_ext4_mb_new_inode_pa(ac, pa);
48303
48304 ext4_mb_use_inode_pa(ac, pa);
48305 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
48306 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
48307
48308 ei = EXT4_I(ac->ac_inode);
48309 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48310 @@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48311 trace_ext4_mb_new_group_pa(ac, pa);
48312
48313 ext4_mb_use_group_pa(ac, pa);
48314 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48315 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48316
48317 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48318 lg = ac->ac_lg;
48319 @@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48320 * from the bitmap and continue.
48321 */
48322 }
48323 - atomic_add(free, &sbi->s_mb_discarded);
48324 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
48325
48326 return err;
48327 }
48328 @@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48329 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48330 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48331 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48332 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48333 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48334 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
48335
48336 return 0;
48337 diff --git a/fs/fcntl.c b/fs/fcntl.c
48338 index 71a600a..20d87b1 100644
48339 --- a/fs/fcntl.c
48340 +++ b/fs/fcntl.c
48341 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48342 if (err)
48343 return err;
48344
48345 + if (gr_handle_chroot_fowner(pid, type))
48346 + return -ENOENT;
48347 + if (gr_check_protected_task_fowner(pid, type))
48348 + return -EACCES;
48349 +
48350 f_modown(filp, pid, type, force);
48351 return 0;
48352 }
48353 diff --git a/fs/fhandle.c b/fs/fhandle.c
48354 index 999ff5c..41f4109 100644
48355 --- a/fs/fhandle.c
48356 +++ b/fs/fhandle.c
48357 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
48358 } else
48359 retval = 0;
48360 /* copy the mount id */
48361 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
48362 - sizeof(*mnt_id)) ||
48363 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
48364 copy_to_user(ufh, handle,
48365 sizeof(struct file_handle) + handle_bytes))
48366 retval = -EFAULT;
48367 diff --git a/fs/fifo.c b/fs/fifo.c
48368 index cf6f434..3d7942c 100644
48369 --- a/fs/fifo.c
48370 +++ b/fs/fifo.c
48371 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48372 */
48373 filp->f_op = &read_pipefifo_fops;
48374 pipe->r_counter++;
48375 - if (pipe->readers++ == 0)
48376 + if (atomic_inc_return(&pipe->readers) == 1)
48377 wake_up_partner(inode);
48378
48379 - if (!pipe->writers) {
48380 + if (!atomic_read(&pipe->writers)) {
48381 if ((filp->f_flags & O_NONBLOCK)) {
48382 /* suppress POLLHUP until we have
48383 * seen a writer */
48384 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48385 * errno=ENXIO when there is no process reading the FIFO.
48386 */
48387 ret = -ENXIO;
48388 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48389 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48390 goto err;
48391
48392 filp->f_op = &write_pipefifo_fops;
48393 pipe->w_counter++;
48394 - if (!pipe->writers++)
48395 + if (atomic_inc_return(&pipe->writers) == 1)
48396 wake_up_partner(inode);
48397
48398 - if (!pipe->readers) {
48399 + if (!atomic_read(&pipe->readers)) {
48400 if (wait_for_partner(inode, &pipe->r_counter))
48401 goto err_wr;
48402 }
48403 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48404 */
48405 filp->f_op = &rdwr_pipefifo_fops;
48406
48407 - pipe->readers++;
48408 - pipe->writers++;
48409 + atomic_inc(&pipe->readers);
48410 + atomic_inc(&pipe->writers);
48411 pipe->r_counter++;
48412 pipe->w_counter++;
48413 - if (pipe->readers == 1 || pipe->writers == 1)
48414 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48415 wake_up_partner(inode);
48416 break;
48417
48418 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48419 return 0;
48420
48421 err_rd:
48422 - if (!--pipe->readers)
48423 + if (atomic_dec_and_test(&pipe->readers))
48424 wake_up_interruptible(&pipe->wait);
48425 ret = -ERESTARTSYS;
48426 goto err;
48427
48428 err_wr:
48429 - if (!--pipe->writers)
48430 + if (atomic_dec_and_test(&pipe->writers))
48431 wake_up_interruptible(&pipe->wait);
48432 ret = -ERESTARTSYS;
48433 goto err;
48434
48435 err:
48436 - if (!pipe->readers && !pipe->writers)
48437 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48438 free_pipe_info(inode);
48439
48440 err_nocleanup:
48441 diff --git a/fs/file.c b/fs/file.c
48442 index 2b3570b..c57924b 100644
48443 --- a/fs/file.c
48444 +++ b/fs/file.c
48445 @@ -16,6 +16,7 @@
48446 #include <linux/slab.h>
48447 #include <linux/vmalloc.h>
48448 #include <linux/file.h>
48449 +#include <linux/security.h>
48450 #include <linux/fdtable.h>
48451 #include <linux/bitops.h>
48452 #include <linux/interrupt.h>
48453 @@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
48454 if (!file)
48455 return __close_fd(files, fd);
48456
48457 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
48458 if (fd >= rlimit(RLIMIT_NOFILE))
48459 return -EBADF;
48460
48461 @@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
48462 if (unlikely(oldfd == newfd))
48463 return -EINVAL;
48464
48465 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
48466 if (newfd >= rlimit(RLIMIT_NOFILE))
48467 return -EBADF;
48468
48469 @@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
48470 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
48471 {
48472 int err;
48473 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
48474 if (from >= rlimit(RLIMIT_NOFILE))
48475 return -EINVAL;
48476 err = alloc_fd(from, flags);
48477 diff --git a/fs/filesystems.c b/fs/filesystems.c
48478 index da165f6..3671bdb 100644
48479 --- a/fs/filesystems.c
48480 +++ b/fs/filesystems.c
48481 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
48482 int len = dot ? dot - name : strlen(name);
48483
48484 fs = __get_fs_type(name, len);
48485 +
48486 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
48487 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48488 +#else
48489 if (!fs && (request_module("%.*s", len, name) == 0))
48490 +#endif
48491 fs = __get_fs_type(name, len);
48492
48493 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48494 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48495 index fe6ca58..65318cf 100644
48496 --- a/fs/fs_struct.c
48497 +++ b/fs/fs_struct.c
48498 @@ -4,6 +4,7 @@
48499 #include <linux/path.h>
48500 #include <linux/slab.h>
48501 #include <linux/fs_struct.h>
48502 +#include <linux/grsecurity.h>
48503 #include "internal.h"
48504
48505 /*
48506 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48507 write_seqcount_begin(&fs->seq);
48508 old_root = fs->root;
48509 fs->root = *path;
48510 + gr_set_chroot_entries(current, path);
48511 write_seqcount_end(&fs->seq);
48512 spin_unlock(&fs->lock);
48513 if (old_root.dentry)
48514 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
48515 return 1;
48516 }
48517
48518 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
48519 +{
48520 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
48521 + return 0;
48522 + *p = *new;
48523 +
48524 + /* This function is only called from pivot_root(). Leave our
48525 + gr_chroot_dentry and is_chrooted flags as-is, so that a
48526 + pivoted root isn't treated as a chroot
48527 + */
48528 + //gr_set_chroot_entries(task, new);
48529 +
48530 + return 1;
48531 +}
48532 +
48533 void chroot_fs_refs(struct path *old_root, struct path *new_root)
48534 {
48535 struct task_struct *g, *p;
48536 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48537 int hits = 0;
48538 spin_lock(&fs->lock);
48539 write_seqcount_begin(&fs->seq);
48540 - hits += replace_path(&fs->root, old_root, new_root);
48541 + hits += replace_root_path(p, &fs->root, old_root, new_root);
48542 hits += replace_path(&fs->pwd, old_root, new_root);
48543 write_seqcount_end(&fs->seq);
48544 while (hits--) {
48545 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
48546 task_lock(tsk);
48547 spin_lock(&fs->lock);
48548 tsk->fs = NULL;
48549 - kill = !--fs->users;
48550 + gr_clear_chroot_entries(tsk);
48551 + kill = !atomic_dec_return(&fs->users);
48552 spin_unlock(&fs->lock);
48553 task_unlock(tsk);
48554 if (kill)
48555 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48556 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
48557 /* We don't need to lock fs - think why ;-) */
48558 if (fs) {
48559 - fs->users = 1;
48560 + atomic_set(&fs->users, 1);
48561 fs->in_exec = 0;
48562 spin_lock_init(&fs->lock);
48563 seqcount_init(&fs->seq);
48564 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48565 spin_lock(&old->lock);
48566 fs->root = old->root;
48567 path_get(&fs->root);
48568 + /* instead of calling gr_set_chroot_entries here,
48569 + we call it from every caller of this function
48570 + */
48571 fs->pwd = old->pwd;
48572 path_get(&fs->pwd);
48573 spin_unlock(&old->lock);
48574 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
48575
48576 task_lock(current);
48577 spin_lock(&fs->lock);
48578 - kill = !--fs->users;
48579 + kill = !atomic_dec_return(&fs->users);
48580 current->fs = new_fs;
48581 + gr_set_chroot_entries(current, &new_fs->root);
48582 spin_unlock(&fs->lock);
48583 task_unlock(current);
48584
48585 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
48586
48587 int current_umask(void)
48588 {
48589 - return current->fs->umask;
48590 + return current->fs->umask | gr_acl_umask();
48591 }
48592 EXPORT_SYMBOL(current_umask);
48593
48594 /* to be mentioned only in INIT_TASK */
48595 struct fs_struct init_fs = {
48596 - .users = 1,
48597 + .users = ATOMIC_INIT(1),
48598 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
48599 .seq = SEQCNT_ZERO,
48600 .umask = 0022,
48601 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
48602 index 8dcb114..b1072e2 100644
48603 --- a/fs/fscache/cookie.c
48604 +++ b/fs/fscache/cookie.c
48605 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
48606 parent ? (char *) parent->def->name : "<no-parent>",
48607 def->name, netfs_data);
48608
48609 - fscache_stat(&fscache_n_acquires);
48610 + fscache_stat_unchecked(&fscache_n_acquires);
48611
48612 /* if there's no parent cookie, then we don't create one here either */
48613 if (!parent) {
48614 - fscache_stat(&fscache_n_acquires_null);
48615 + fscache_stat_unchecked(&fscache_n_acquires_null);
48616 _leave(" [no parent]");
48617 return NULL;
48618 }
48619 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
48620 /* allocate and initialise a cookie */
48621 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
48622 if (!cookie) {
48623 - fscache_stat(&fscache_n_acquires_oom);
48624 + fscache_stat_unchecked(&fscache_n_acquires_oom);
48625 _leave(" [ENOMEM]");
48626 return NULL;
48627 }
48628 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48629
48630 switch (cookie->def->type) {
48631 case FSCACHE_COOKIE_TYPE_INDEX:
48632 - fscache_stat(&fscache_n_cookie_index);
48633 + fscache_stat_unchecked(&fscache_n_cookie_index);
48634 break;
48635 case FSCACHE_COOKIE_TYPE_DATAFILE:
48636 - fscache_stat(&fscache_n_cookie_data);
48637 + fscache_stat_unchecked(&fscache_n_cookie_data);
48638 break;
48639 default:
48640 - fscache_stat(&fscache_n_cookie_special);
48641 + fscache_stat_unchecked(&fscache_n_cookie_special);
48642 break;
48643 }
48644
48645 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48646 if (fscache_acquire_non_index_cookie(cookie) < 0) {
48647 atomic_dec(&parent->n_children);
48648 __fscache_cookie_put(cookie);
48649 - fscache_stat(&fscache_n_acquires_nobufs);
48650 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
48651 _leave(" = NULL");
48652 return NULL;
48653 }
48654 }
48655
48656 - fscache_stat(&fscache_n_acquires_ok);
48657 + fscache_stat_unchecked(&fscache_n_acquires_ok);
48658 _leave(" = %p", cookie);
48659 return cookie;
48660 }
48661 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
48662 cache = fscache_select_cache_for_object(cookie->parent);
48663 if (!cache) {
48664 up_read(&fscache_addremove_sem);
48665 - fscache_stat(&fscache_n_acquires_no_cache);
48666 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
48667 _leave(" = -ENOMEDIUM [no cache]");
48668 return -ENOMEDIUM;
48669 }
48670 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
48671 object = cache->ops->alloc_object(cache, cookie);
48672 fscache_stat_d(&fscache_n_cop_alloc_object);
48673 if (IS_ERR(object)) {
48674 - fscache_stat(&fscache_n_object_no_alloc);
48675 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
48676 ret = PTR_ERR(object);
48677 goto error;
48678 }
48679
48680 - fscache_stat(&fscache_n_object_alloc);
48681 + fscache_stat_unchecked(&fscache_n_object_alloc);
48682
48683 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
48684
48685 @@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
48686
48687 _enter("{%s}", cookie->def->name);
48688
48689 - fscache_stat(&fscache_n_invalidates);
48690 + fscache_stat_unchecked(&fscache_n_invalidates);
48691
48692 /* Only permit invalidation of data files. Invalidating an index will
48693 * require the caller to release all its attachments to the tree rooted
48694 @@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
48695 struct fscache_object *object;
48696 struct hlist_node *_p;
48697
48698 - fscache_stat(&fscache_n_updates);
48699 + fscache_stat_unchecked(&fscache_n_updates);
48700
48701 if (!cookie) {
48702 - fscache_stat(&fscache_n_updates_null);
48703 + fscache_stat_unchecked(&fscache_n_updates_null);
48704 _leave(" [no cookie]");
48705 return;
48706 }
48707 @@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48708 struct fscache_object *object;
48709 unsigned long event;
48710
48711 - fscache_stat(&fscache_n_relinquishes);
48712 + fscache_stat_unchecked(&fscache_n_relinquishes);
48713 if (retire)
48714 - fscache_stat(&fscache_n_relinquishes_retire);
48715 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48716
48717 if (!cookie) {
48718 - fscache_stat(&fscache_n_relinquishes_null);
48719 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
48720 _leave(" [no cookie]");
48721 return;
48722 }
48723 @@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48724
48725 /* wait for the cookie to finish being instantiated (or to fail) */
48726 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48727 - fscache_stat(&fscache_n_relinquishes_waitcrt);
48728 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48729 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48730 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48731 }
48732 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48733 index ee38fef..0a326d4 100644
48734 --- a/fs/fscache/internal.h
48735 +++ b/fs/fscache/internal.h
48736 @@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
48737 * stats.c
48738 */
48739 #ifdef CONFIG_FSCACHE_STATS
48740 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48741 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48742 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48743 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48744
48745 -extern atomic_t fscache_n_op_pend;
48746 -extern atomic_t fscache_n_op_run;
48747 -extern atomic_t fscache_n_op_enqueue;
48748 -extern atomic_t fscache_n_op_deferred_release;
48749 -extern atomic_t fscache_n_op_release;
48750 -extern atomic_t fscache_n_op_gc;
48751 -extern atomic_t fscache_n_op_cancelled;
48752 -extern atomic_t fscache_n_op_rejected;
48753 +extern atomic_unchecked_t fscache_n_op_pend;
48754 +extern atomic_unchecked_t fscache_n_op_run;
48755 +extern atomic_unchecked_t fscache_n_op_enqueue;
48756 +extern atomic_unchecked_t fscache_n_op_deferred_release;
48757 +extern atomic_unchecked_t fscache_n_op_release;
48758 +extern atomic_unchecked_t fscache_n_op_gc;
48759 +extern atomic_unchecked_t fscache_n_op_cancelled;
48760 +extern atomic_unchecked_t fscache_n_op_rejected;
48761
48762 -extern atomic_t fscache_n_attr_changed;
48763 -extern atomic_t fscache_n_attr_changed_ok;
48764 -extern atomic_t fscache_n_attr_changed_nobufs;
48765 -extern atomic_t fscache_n_attr_changed_nomem;
48766 -extern atomic_t fscache_n_attr_changed_calls;
48767 +extern atomic_unchecked_t fscache_n_attr_changed;
48768 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
48769 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48770 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48771 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
48772
48773 -extern atomic_t fscache_n_allocs;
48774 -extern atomic_t fscache_n_allocs_ok;
48775 -extern atomic_t fscache_n_allocs_wait;
48776 -extern atomic_t fscache_n_allocs_nobufs;
48777 -extern atomic_t fscache_n_allocs_intr;
48778 -extern atomic_t fscache_n_allocs_object_dead;
48779 -extern atomic_t fscache_n_alloc_ops;
48780 -extern atomic_t fscache_n_alloc_op_waits;
48781 +extern atomic_unchecked_t fscache_n_allocs;
48782 +extern atomic_unchecked_t fscache_n_allocs_ok;
48783 +extern atomic_unchecked_t fscache_n_allocs_wait;
48784 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
48785 +extern atomic_unchecked_t fscache_n_allocs_intr;
48786 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
48787 +extern atomic_unchecked_t fscache_n_alloc_ops;
48788 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
48789
48790 -extern atomic_t fscache_n_retrievals;
48791 -extern atomic_t fscache_n_retrievals_ok;
48792 -extern atomic_t fscache_n_retrievals_wait;
48793 -extern atomic_t fscache_n_retrievals_nodata;
48794 -extern atomic_t fscache_n_retrievals_nobufs;
48795 -extern atomic_t fscache_n_retrievals_intr;
48796 -extern atomic_t fscache_n_retrievals_nomem;
48797 -extern atomic_t fscache_n_retrievals_object_dead;
48798 -extern atomic_t fscache_n_retrieval_ops;
48799 -extern atomic_t fscache_n_retrieval_op_waits;
48800 +extern atomic_unchecked_t fscache_n_retrievals;
48801 +extern atomic_unchecked_t fscache_n_retrievals_ok;
48802 +extern atomic_unchecked_t fscache_n_retrievals_wait;
48803 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
48804 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48805 +extern atomic_unchecked_t fscache_n_retrievals_intr;
48806 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
48807 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48808 +extern atomic_unchecked_t fscache_n_retrieval_ops;
48809 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48810
48811 -extern atomic_t fscache_n_stores;
48812 -extern atomic_t fscache_n_stores_ok;
48813 -extern atomic_t fscache_n_stores_again;
48814 -extern atomic_t fscache_n_stores_nobufs;
48815 -extern atomic_t fscache_n_stores_oom;
48816 -extern atomic_t fscache_n_store_ops;
48817 -extern atomic_t fscache_n_store_calls;
48818 -extern atomic_t fscache_n_store_pages;
48819 -extern atomic_t fscache_n_store_radix_deletes;
48820 -extern atomic_t fscache_n_store_pages_over_limit;
48821 +extern atomic_unchecked_t fscache_n_stores;
48822 +extern atomic_unchecked_t fscache_n_stores_ok;
48823 +extern atomic_unchecked_t fscache_n_stores_again;
48824 +extern atomic_unchecked_t fscache_n_stores_nobufs;
48825 +extern atomic_unchecked_t fscache_n_stores_oom;
48826 +extern atomic_unchecked_t fscache_n_store_ops;
48827 +extern atomic_unchecked_t fscache_n_store_calls;
48828 +extern atomic_unchecked_t fscache_n_store_pages;
48829 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
48830 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48831
48832 -extern atomic_t fscache_n_store_vmscan_not_storing;
48833 -extern atomic_t fscache_n_store_vmscan_gone;
48834 -extern atomic_t fscache_n_store_vmscan_busy;
48835 -extern atomic_t fscache_n_store_vmscan_cancelled;
48836 -extern atomic_t fscache_n_store_vmscan_wait;
48837 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48838 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48839 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48840 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48841 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
48842
48843 -extern atomic_t fscache_n_marks;
48844 -extern atomic_t fscache_n_uncaches;
48845 +extern atomic_unchecked_t fscache_n_marks;
48846 +extern atomic_unchecked_t fscache_n_uncaches;
48847
48848 -extern atomic_t fscache_n_acquires;
48849 -extern atomic_t fscache_n_acquires_null;
48850 -extern atomic_t fscache_n_acquires_no_cache;
48851 -extern atomic_t fscache_n_acquires_ok;
48852 -extern atomic_t fscache_n_acquires_nobufs;
48853 -extern atomic_t fscache_n_acquires_oom;
48854 +extern atomic_unchecked_t fscache_n_acquires;
48855 +extern atomic_unchecked_t fscache_n_acquires_null;
48856 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
48857 +extern atomic_unchecked_t fscache_n_acquires_ok;
48858 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
48859 +extern atomic_unchecked_t fscache_n_acquires_oom;
48860
48861 -extern atomic_t fscache_n_invalidates;
48862 -extern atomic_t fscache_n_invalidates_run;
48863 +extern atomic_unchecked_t fscache_n_invalidates;
48864 +extern atomic_unchecked_t fscache_n_invalidates_run;
48865
48866 -extern atomic_t fscache_n_updates;
48867 -extern atomic_t fscache_n_updates_null;
48868 -extern atomic_t fscache_n_updates_run;
48869 +extern atomic_unchecked_t fscache_n_updates;
48870 +extern atomic_unchecked_t fscache_n_updates_null;
48871 +extern atomic_unchecked_t fscache_n_updates_run;
48872
48873 -extern atomic_t fscache_n_relinquishes;
48874 -extern atomic_t fscache_n_relinquishes_null;
48875 -extern atomic_t fscache_n_relinquishes_waitcrt;
48876 -extern atomic_t fscache_n_relinquishes_retire;
48877 +extern atomic_unchecked_t fscache_n_relinquishes;
48878 +extern atomic_unchecked_t fscache_n_relinquishes_null;
48879 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48880 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
48881
48882 -extern atomic_t fscache_n_cookie_index;
48883 -extern atomic_t fscache_n_cookie_data;
48884 -extern atomic_t fscache_n_cookie_special;
48885 +extern atomic_unchecked_t fscache_n_cookie_index;
48886 +extern atomic_unchecked_t fscache_n_cookie_data;
48887 +extern atomic_unchecked_t fscache_n_cookie_special;
48888
48889 -extern atomic_t fscache_n_object_alloc;
48890 -extern atomic_t fscache_n_object_no_alloc;
48891 -extern atomic_t fscache_n_object_lookups;
48892 -extern atomic_t fscache_n_object_lookups_negative;
48893 -extern atomic_t fscache_n_object_lookups_positive;
48894 -extern atomic_t fscache_n_object_lookups_timed_out;
48895 -extern atomic_t fscache_n_object_created;
48896 -extern atomic_t fscache_n_object_avail;
48897 -extern atomic_t fscache_n_object_dead;
48898 +extern atomic_unchecked_t fscache_n_object_alloc;
48899 +extern atomic_unchecked_t fscache_n_object_no_alloc;
48900 +extern atomic_unchecked_t fscache_n_object_lookups;
48901 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
48902 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
48903 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48904 +extern atomic_unchecked_t fscache_n_object_created;
48905 +extern atomic_unchecked_t fscache_n_object_avail;
48906 +extern atomic_unchecked_t fscache_n_object_dead;
48907
48908 -extern atomic_t fscache_n_checkaux_none;
48909 -extern atomic_t fscache_n_checkaux_okay;
48910 -extern atomic_t fscache_n_checkaux_update;
48911 -extern atomic_t fscache_n_checkaux_obsolete;
48912 +extern atomic_unchecked_t fscache_n_checkaux_none;
48913 +extern atomic_unchecked_t fscache_n_checkaux_okay;
48914 +extern atomic_unchecked_t fscache_n_checkaux_update;
48915 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48916
48917 extern atomic_t fscache_n_cop_alloc_object;
48918 extern atomic_t fscache_n_cop_lookup_object;
48919 @@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
48920 atomic_inc(stat);
48921 }
48922
48923 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48924 +{
48925 + atomic_inc_unchecked(stat);
48926 +}
48927 +
48928 static inline void fscache_stat_d(atomic_t *stat)
48929 {
48930 atomic_dec(stat);
48931 @@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
48932
48933 #define __fscache_stat(stat) (NULL)
48934 #define fscache_stat(stat) do {} while (0)
48935 +#define fscache_stat_unchecked(stat) do {} while (0)
48936 #define fscache_stat_d(stat) do {} while (0)
48937 #endif
48938
48939 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48940 index 50d41c1..10ee117 100644
48941 --- a/fs/fscache/object.c
48942 +++ b/fs/fscache/object.c
48943 @@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48944 /* Invalidate an object on disk */
48945 case FSCACHE_OBJECT_INVALIDATING:
48946 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
48947 - fscache_stat(&fscache_n_invalidates_run);
48948 + fscache_stat_unchecked(&fscache_n_invalidates_run);
48949 fscache_stat(&fscache_n_cop_invalidate_object);
48950 fscache_invalidate_object(object);
48951 fscache_stat_d(&fscache_n_cop_invalidate_object);
48952 @@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48953 /* update the object metadata on disk */
48954 case FSCACHE_OBJECT_UPDATING:
48955 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48956 - fscache_stat(&fscache_n_updates_run);
48957 + fscache_stat_unchecked(&fscache_n_updates_run);
48958 fscache_stat(&fscache_n_cop_update_object);
48959 object->cache->ops->update_object(object);
48960 fscache_stat_d(&fscache_n_cop_update_object);
48961 @@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48962 spin_lock(&object->lock);
48963 object->state = FSCACHE_OBJECT_DEAD;
48964 spin_unlock(&object->lock);
48965 - fscache_stat(&fscache_n_object_dead);
48966 + fscache_stat_unchecked(&fscache_n_object_dead);
48967 goto terminal_transit;
48968
48969 /* handle the parent cache of this object being withdrawn from
48970 @@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48971 spin_lock(&object->lock);
48972 object->state = FSCACHE_OBJECT_DEAD;
48973 spin_unlock(&object->lock);
48974 - fscache_stat(&fscache_n_object_dead);
48975 + fscache_stat_unchecked(&fscache_n_object_dead);
48976 goto terminal_transit;
48977
48978 /* complain about the object being woken up once it is
48979 @@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48980 parent->cookie->def->name, cookie->def->name,
48981 object->cache->tag->name);
48982
48983 - fscache_stat(&fscache_n_object_lookups);
48984 + fscache_stat_unchecked(&fscache_n_object_lookups);
48985 fscache_stat(&fscache_n_cop_lookup_object);
48986 ret = object->cache->ops->lookup_object(object);
48987 fscache_stat_d(&fscache_n_cop_lookup_object);
48988 @@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48989 if (ret == -ETIMEDOUT) {
48990 /* probably stuck behind another object, so move this one to
48991 * the back of the queue */
48992 - fscache_stat(&fscache_n_object_lookups_timed_out);
48993 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48994 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48995 }
48996
48997 @@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48998
48999 spin_lock(&object->lock);
49000 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49001 - fscache_stat(&fscache_n_object_lookups_negative);
49002 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49003
49004 /* transit here to allow write requests to begin stacking up
49005 * and read requests to begin returning ENODATA */
49006 @@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
49007 * result, in which case there may be data available */
49008 spin_lock(&object->lock);
49009 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49010 - fscache_stat(&fscache_n_object_lookups_positive);
49011 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49012
49013 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49014
49015 @@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
49016 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49017 } else {
49018 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49019 - fscache_stat(&fscache_n_object_created);
49020 + fscache_stat_unchecked(&fscache_n_object_created);
49021
49022 object->state = FSCACHE_OBJECT_AVAILABLE;
49023 spin_unlock(&object->lock);
49024 @@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
49025 fscache_enqueue_dependents(object);
49026
49027 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49028 - fscache_stat(&fscache_n_object_avail);
49029 + fscache_stat_unchecked(&fscache_n_object_avail);
49030
49031 _leave("");
49032 }
49033 @@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49034 enum fscache_checkaux result;
49035
49036 if (!object->cookie->def->check_aux) {
49037 - fscache_stat(&fscache_n_checkaux_none);
49038 + fscache_stat_unchecked(&fscache_n_checkaux_none);
49039 return FSCACHE_CHECKAUX_OKAY;
49040 }
49041
49042 @@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49043 switch (result) {
49044 /* entry okay as is */
49045 case FSCACHE_CHECKAUX_OKAY:
49046 - fscache_stat(&fscache_n_checkaux_okay);
49047 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
49048 break;
49049
49050 /* entry requires update */
49051 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49052 - fscache_stat(&fscache_n_checkaux_update);
49053 + fscache_stat_unchecked(&fscache_n_checkaux_update);
49054 break;
49055
49056 /* entry requires deletion */
49057 case FSCACHE_CHECKAUX_OBSOLETE:
49058 - fscache_stat(&fscache_n_checkaux_obsolete);
49059 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49060 break;
49061
49062 default:
49063 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49064 index 762a9ec..2023284 100644
49065 --- a/fs/fscache/operation.c
49066 +++ b/fs/fscache/operation.c
49067 @@ -17,7 +17,7 @@
49068 #include <linux/slab.h>
49069 #include "internal.h"
49070
49071 -atomic_t fscache_op_debug_id;
49072 +atomic_unchecked_t fscache_op_debug_id;
49073 EXPORT_SYMBOL(fscache_op_debug_id);
49074
49075 /**
49076 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49077 ASSERTCMP(atomic_read(&op->usage), >, 0);
49078 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
49079
49080 - fscache_stat(&fscache_n_op_enqueue);
49081 + fscache_stat_unchecked(&fscache_n_op_enqueue);
49082 switch (op->flags & FSCACHE_OP_TYPE) {
49083 case FSCACHE_OP_ASYNC:
49084 _debug("queue async");
49085 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
49086 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49087 if (op->processor)
49088 fscache_enqueue_operation(op);
49089 - fscache_stat(&fscache_n_op_run);
49090 + fscache_stat_unchecked(&fscache_n_op_run);
49091 }
49092
49093 /*
49094 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49095 if (object->n_in_progress > 0) {
49096 atomic_inc(&op->usage);
49097 list_add_tail(&op->pend_link, &object->pending_ops);
49098 - fscache_stat(&fscache_n_op_pend);
49099 + fscache_stat_unchecked(&fscache_n_op_pend);
49100 } else if (!list_empty(&object->pending_ops)) {
49101 atomic_inc(&op->usage);
49102 list_add_tail(&op->pend_link, &object->pending_ops);
49103 - fscache_stat(&fscache_n_op_pend);
49104 + fscache_stat_unchecked(&fscache_n_op_pend);
49105 fscache_start_operations(object);
49106 } else {
49107 ASSERTCMP(object->n_in_progress, ==, 0);
49108 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49109 object->n_exclusive++; /* reads and writes must wait */
49110 atomic_inc(&op->usage);
49111 list_add_tail(&op->pend_link, &object->pending_ops);
49112 - fscache_stat(&fscache_n_op_pend);
49113 + fscache_stat_unchecked(&fscache_n_op_pend);
49114 ret = 0;
49115 } else {
49116 /* If we're in any other state, there must have been an I/O
49117 @@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
49118 if (object->n_exclusive > 0) {
49119 atomic_inc(&op->usage);
49120 list_add_tail(&op->pend_link, &object->pending_ops);
49121 - fscache_stat(&fscache_n_op_pend);
49122 + fscache_stat_unchecked(&fscache_n_op_pend);
49123 } else if (!list_empty(&object->pending_ops)) {
49124 atomic_inc(&op->usage);
49125 list_add_tail(&op->pend_link, &object->pending_ops);
49126 - fscache_stat(&fscache_n_op_pend);
49127 + fscache_stat_unchecked(&fscache_n_op_pend);
49128 fscache_start_operations(object);
49129 } else {
49130 ASSERTCMP(object->n_exclusive, ==, 0);
49131 @@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
49132 object->n_ops++;
49133 atomic_inc(&op->usage);
49134 list_add_tail(&op->pend_link, &object->pending_ops);
49135 - fscache_stat(&fscache_n_op_pend);
49136 + fscache_stat_unchecked(&fscache_n_op_pend);
49137 ret = 0;
49138 } else if (object->state == FSCACHE_OBJECT_DYING ||
49139 object->state == FSCACHE_OBJECT_LC_DYING ||
49140 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49141 - fscache_stat(&fscache_n_op_rejected);
49142 + fscache_stat_unchecked(&fscache_n_op_rejected);
49143 op->state = FSCACHE_OP_ST_CANCELLED;
49144 ret = -ENOBUFS;
49145 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49146 @@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
49147 ret = -EBUSY;
49148 if (op->state == FSCACHE_OP_ST_PENDING) {
49149 ASSERT(!list_empty(&op->pend_link));
49150 - fscache_stat(&fscache_n_op_cancelled);
49151 + fscache_stat_unchecked(&fscache_n_op_cancelled);
49152 list_del_init(&op->pend_link);
49153 if (do_cancel)
49154 do_cancel(op);
49155 @@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
49156 while (!list_empty(&object->pending_ops)) {
49157 op = list_entry(object->pending_ops.next,
49158 struct fscache_operation, pend_link);
49159 - fscache_stat(&fscache_n_op_cancelled);
49160 + fscache_stat_unchecked(&fscache_n_op_cancelled);
49161 list_del_init(&op->pend_link);
49162
49163 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
49164 @@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
49165 op->state, ==, FSCACHE_OP_ST_CANCELLED);
49166 op->state = FSCACHE_OP_ST_DEAD;
49167
49168 - fscache_stat(&fscache_n_op_release);
49169 + fscache_stat_unchecked(&fscache_n_op_release);
49170
49171 if (op->release) {
49172 op->release(op);
49173 @@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
49174 * lock, and defer it otherwise */
49175 if (!spin_trylock(&object->lock)) {
49176 _debug("defer put");
49177 - fscache_stat(&fscache_n_op_deferred_release);
49178 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
49179
49180 cache = object->cache;
49181 spin_lock(&cache->op_gc_list_lock);
49182 @@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
49183
49184 _debug("GC DEFERRED REL OBJ%x OP%x",
49185 object->debug_id, op->debug_id);
49186 - fscache_stat(&fscache_n_op_gc);
49187 + fscache_stat_unchecked(&fscache_n_op_gc);
49188
49189 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49190 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
49191 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49192 index ff000e5..c44ec6d 100644
49193 --- a/fs/fscache/page.c
49194 +++ b/fs/fscache/page.c
49195 @@ -61,7 +61,7 @@ try_again:
49196 val = radix_tree_lookup(&cookie->stores, page->index);
49197 if (!val) {
49198 rcu_read_unlock();
49199 - fscache_stat(&fscache_n_store_vmscan_not_storing);
49200 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49201 __fscache_uncache_page(cookie, page);
49202 return true;
49203 }
49204 @@ -91,11 +91,11 @@ try_again:
49205 spin_unlock(&cookie->stores_lock);
49206
49207 if (xpage) {
49208 - fscache_stat(&fscache_n_store_vmscan_cancelled);
49209 - fscache_stat(&fscache_n_store_radix_deletes);
49210 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49211 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49212 ASSERTCMP(xpage, ==, page);
49213 } else {
49214 - fscache_stat(&fscache_n_store_vmscan_gone);
49215 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49216 }
49217
49218 wake_up_bit(&cookie->flags, 0);
49219 @@ -110,11 +110,11 @@ page_busy:
49220 * sleeping on memory allocation, so we may need to impose a timeout
49221 * too. */
49222 if (!(gfp & __GFP_WAIT)) {
49223 - fscache_stat(&fscache_n_store_vmscan_busy);
49224 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49225 return false;
49226 }
49227
49228 - fscache_stat(&fscache_n_store_vmscan_wait);
49229 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
49230 __fscache_wait_on_page_write(cookie, page);
49231 gfp &= ~__GFP_WAIT;
49232 goto try_again;
49233 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49234 FSCACHE_COOKIE_STORING_TAG);
49235 if (!radix_tree_tag_get(&cookie->stores, page->index,
49236 FSCACHE_COOKIE_PENDING_TAG)) {
49237 - fscache_stat(&fscache_n_store_radix_deletes);
49238 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49239 xpage = radix_tree_delete(&cookie->stores, page->index);
49240 }
49241 spin_unlock(&cookie->stores_lock);
49242 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49243
49244 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49245
49246 - fscache_stat(&fscache_n_attr_changed_calls);
49247 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49248
49249 if (fscache_object_is_active(object)) {
49250 fscache_stat(&fscache_n_cop_attr_changed);
49251 @@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49252
49253 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49254
49255 - fscache_stat(&fscache_n_attr_changed);
49256 + fscache_stat_unchecked(&fscache_n_attr_changed);
49257
49258 op = kzalloc(sizeof(*op), GFP_KERNEL);
49259 if (!op) {
49260 - fscache_stat(&fscache_n_attr_changed_nomem);
49261 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49262 _leave(" = -ENOMEM");
49263 return -ENOMEM;
49264 }
49265 @@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49266 if (fscache_submit_exclusive_op(object, op) < 0)
49267 goto nobufs;
49268 spin_unlock(&cookie->lock);
49269 - fscache_stat(&fscache_n_attr_changed_ok);
49270 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49271 fscache_put_operation(op);
49272 _leave(" = 0");
49273 return 0;
49274 @@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49275 nobufs:
49276 spin_unlock(&cookie->lock);
49277 kfree(op);
49278 - fscache_stat(&fscache_n_attr_changed_nobufs);
49279 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49280 _leave(" = %d", -ENOBUFS);
49281 return -ENOBUFS;
49282 }
49283 @@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49284 /* allocate a retrieval operation and attempt to submit it */
49285 op = kzalloc(sizeof(*op), GFP_NOIO);
49286 if (!op) {
49287 - fscache_stat(&fscache_n_retrievals_nomem);
49288 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49289 return NULL;
49290 }
49291
49292 @@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49293 return 0;
49294 }
49295
49296 - fscache_stat(&fscache_n_retrievals_wait);
49297 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
49298
49299 jif = jiffies;
49300 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49301 fscache_wait_bit_interruptible,
49302 TASK_INTERRUPTIBLE) != 0) {
49303 - fscache_stat(&fscache_n_retrievals_intr);
49304 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49305 _leave(" = -ERESTARTSYS");
49306 return -ERESTARTSYS;
49307 }
49308 @@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
49309 */
49310 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49311 struct fscache_retrieval *op,
49312 - atomic_t *stat_op_waits,
49313 - atomic_t *stat_object_dead)
49314 + atomic_unchecked_t *stat_op_waits,
49315 + atomic_unchecked_t *stat_object_dead)
49316 {
49317 int ret;
49318
49319 @@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49320 goto check_if_dead;
49321
49322 _debug(">>> WT");
49323 - fscache_stat(stat_op_waits);
49324 + fscache_stat_unchecked(stat_op_waits);
49325 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49326 fscache_wait_bit_interruptible,
49327 TASK_INTERRUPTIBLE) != 0) {
49328 @@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49329
49330 check_if_dead:
49331 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
49332 - fscache_stat(stat_object_dead);
49333 + fscache_stat_unchecked(stat_object_dead);
49334 _leave(" = -ENOBUFS [cancelled]");
49335 return -ENOBUFS;
49336 }
49337 if (unlikely(fscache_object_is_dead(object))) {
49338 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
49339 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
49340 - fscache_stat(stat_object_dead);
49341 + fscache_stat_unchecked(stat_object_dead);
49342 return -ENOBUFS;
49343 }
49344 return 0;
49345 @@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49346
49347 _enter("%p,%p,,,", cookie, page);
49348
49349 - fscache_stat(&fscache_n_retrievals);
49350 + fscache_stat_unchecked(&fscache_n_retrievals);
49351
49352 if (hlist_empty(&cookie->backing_objects))
49353 goto nobufs;
49354 @@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49355 goto nobufs_unlock_dec;
49356 spin_unlock(&cookie->lock);
49357
49358 - fscache_stat(&fscache_n_retrieval_ops);
49359 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
49360
49361 /* pin the netfs read context in case we need to do the actual netfs
49362 * read because we've encountered a cache read failure */
49363 @@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49364
49365 error:
49366 if (ret == -ENOMEM)
49367 - fscache_stat(&fscache_n_retrievals_nomem);
49368 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49369 else if (ret == -ERESTARTSYS)
49370 - fscache_stat(&fscache_n_retrievals_intr);
49371 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49372 else if (ret == -ENODATA)
49373 - fscache_stat(&fscache_n_retrievals_nodata);
49374 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49375 else if (ret < 0)
49376 - fscache_stat(&fscache_n_retrievals_nobufs);
49377 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49378 else
49379 - fscache_stat(&fscache_n_retrievals_ok);
49380 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
49381
49382 fscache_put_retrieval(op);
49383 _leave(" = %d", ret);
49384 @@ -467,7 +467,7 @@ nobufs_unlock:
49385 spin_unlock(&cookie->lock);
49386 kfree(op);
49387 nobufs:
49388 - fscache_stat(&fscache_n_retrievals_nobufs);
49389 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49390 _leave(" = -ENOBUFS");
49391 return -ENOBUFS;
49392 }
49393 @@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49394
49395 _enter("%p,,%d,,,", cookie, *nr_pages);
49396
49397 - fscache_stat(&fscache_n_retrievals);
49398 + fscache_stat_unchecked(&fscache_n_retrievals);
49399
49400 if (hlist_empty(&cookie->backing_objects))
49401 goto nobufs;
49402 @@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49403 goto nobufs_unlock_dec;
49404 spin_unlock(&cookie->lock);
49405
49406 - fscache_stat(&fscache_n_retrieval_ops);
49407 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
49408
49409 /* pin the netfs read context in case we need to do the actual netfs
49410 * read because we've encountered a cache read failure */
49411 @@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49412
49413 error:
49414 if (ret == -ENOMEM)
49415 - fscache_stat(&fscache_n_retrievals_nomem);
49416 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49417 else if (ret == -ERESTARTSYS)
49418 - fscache_stat(&fscache_n_retrievals_intr);
49419 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49420 else if (ret == -ENODATA)
49421 - fscache_stat(&fscache_n_retrievals_nodata);
49422 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49423 else if (ret < 0)
49424 - fscache_stat(&fscache_n_retrievals_nobufs);
49425 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49426 else
49427 - fscache_stat(&fscache_n_retrievals_ok);
49428 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
49429
49430 fscache_put_retrieval(op);
49431 _leave(" = %d", ret);
49432 @@ -591,7 +591,7 @@ nobufs_unlock:
49433 spin_unlock(&cookie->lock);
49434 kfree(op);
49435 nobufs:
49436 - fscache_stat(&fscache_n_retrievals_nobufs);
49437 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49438 _leave(" = -ENOBUFS");
49439 return -ENOBUFS;
49440 }
49441 @@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49442
49443 _enter("%p,%p,,,", cookie, page);
49444
49445 - fscache_stat(&fscache_n_allocs);
49446 + fscache_stat_unchecked(&fscache_n_allocs);
49447
49448 if (hlist_empty(&cookie->backing_objects))
49449 goto nobufs;
49450 @@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49451 goto nobufs_unlock;
49452 spin_unlock(&cookie->lock);
49453
49454 - fscache_stat(&fscache_n_alloc_ops);
49455 + fscache_stat_unchecked(&fscache_n_alloc_ops);
49456
49457 ret = fscache_wait_for_retrieval_activation(
49458 object, op,
49459 @@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49460
49461 error:
49462 if (ret == -ERESTARTSYS)
49463 - fscache_stat(&fscache_n_allocs_intr);
49464 + fscache_stat_unchecked(&fscache_n_allocs_intr);
49465 else if (ret < 0)
49466 - fscache_stat(&fscache_n_allocs_nobufs);
49467 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49468 else
49469 - fscache_stat(&fscache_n_allocs_ok);
49470 + fscache_stat_unchecked(&fscache_n_allocs_ok);
49471
49472 fscache_put_retrieval(op);
49473 _leave(" = %d", ret);
49474 @@ -677,7 +677,7 @@ nobufs_unlock:
49475 spin_unlock(&cookie->lock);
49476 kfree(op);
49477 nobufs:
49478 - fscache_stat(&fscache_n_allocs_nobufs);
49479 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49480 _leave(" = -ENOBUFS");
49481 return -ENOBUFS;
49482 }
49483 @@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49484
49485 spin_lock(&cookie->stores_lock);
49486
49487 - fscache_stat(&fscache_n_store_calls);
49488 + fscache_stat_unchecked(&fscache_n_store_calls);
49489
49490 /* find a page to store */
49491 page = NULL;
49492 @@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49493 page = results[0];
49494 _debug("gang %d [%lx]", n, page->index);
49495 if (page->index > op->store_limit) {
49496 - fscache_stat(&fscache_n_store_pages_over_limit);
49497 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49498 goto superseded;
49499 }
49500
49501 @@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49502 spin_unlock(&cookie->stores_lock);
49503 spin_unlock(&object->lock);
49504
49505 - fscache_stat(&fscache_n_store_pages);
49506 + fscache_stat_unchecked(&fscache_n_store_pages);
49507 fscache_stat(&fscache_n_cop_write_page);
49508 ret = object->cache->ops->write_page(op, page);
49509 fscache_stat_d(&fscache_n_cop_write_page);
49510 @@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49511 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49512 ASSERT(PageFsCache(page));
49513
49514 - fscache_stat(&fscache_n_stores);
49515 + fscache_stat_unchecked(&fscache_n_stores);
49516
49517 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
49518 _leave(" = -ENOBUFS [invalidating]");
49519 @@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49520 spin_unlock(&cookie->stores_lock);
49521 spin_unlock(&object->lock);
49522
49523 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49524 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49525 op->store_limit = object->store_limit;
49526
49527 if (fscache_submit_op(object, &op->op) < 0)
49528 @@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49529
49530 spin_unlock(&cookie->lock);
49531 radix_tree_preload_end();
49532 - fscache_stat(&fscache_n_store_ops);
49533 - fscache_stat(&fscache_n_stores_ok);
49534 + fscache_stat_unchecked(&fscache_n_store_ops);
49535 + fscache_stat_unchecked(&fscache_n_stores_ok);
49536
49537 /* the work queue now carries its own ref on the object */
49538 fscache_put_operation(&op->op);
49539 @@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49540 return 0;
49541
49542 already_queued:
49543 - fscache_stat(&fscache_n_stores_again);
49544 + fscache_stat_unchecked(&fscache_n_stores_again);
49545 already_pending:
49546 spin_unlock(&cookie->stores_lock);
49547 spin_unlock(&object->lock);
49548 spin_unlock(&cookie->lock);
49549 radix_tree_preload_end();
49550 kfree(op);
49551 - fscache_stat(&fscache_n_stores_ok);
49552 + fscache_stat_unchecked(&fscache_n_stores_ok);
49553 _leave(" = 0");
49554 return 0;
49555
49556 @@ -959,14 +959,14 @@ nobufs:
49557 spin_unlock(&cookie->lock);
49558 radix_tree_preload_end();
49559 kfree(op);
49560 - fscache_stat(&fscache_n_stores_nobufs);
49561 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
49562 _leave(" = -ENOBUFS");
49563 return -ENOBUFS;
49564
49565 nomem_free:
49566 kfree(op);
49567 nomem:
49568 - fscache_stat(&fscache_n_stores_oom);
49569 + fscache_stat_unchecked(&fscache_n_stores_oom);
49570 _leave(" = -ENOMEM");
49571 return -ENOMEM;
49572 }
49573 @@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49574 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49575 ASSERTCMP(page, !=, NULL);
49576
49577 - fscache_stat(&fscache_n_uncaches);
49578 + fscache_stat_unchecked(&fscache_n_uncaches);
49579
49580 /* cache withdrawal may beat us to it */
49581 if (!PageFsCache(page))
49582 @@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
49583 struct fscache_cookie *cookie = op->op.object->cookie;
49584
49585 #ifdef CONFIG_FSCACHE_STATS
49586 - atomic_inc(&fscache_n_marks);
49587 + atomic_inc_unchecked(&fscache_n_marks);
49588 #endif
49589
49590 _debug("- mark %p{%lx}", page, page->index);
49591 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49592 index 8179e8b..5072cc7 100644
49593 --- a/fs/fscache/stats.c
49594 +++ b/fs/fscache/stats.c
49595 @@ -18,99 +18,99 @@
49596 /*
49597 * operation counters
49598 */
49599 -atomic_t fscache_n_op_pend;
49600 -atomic_t fscache_n_op_run;
49601 -atomic_t fscache_n_op_enqueue;
49602 -atomic_t fscache_n_op_requeue;
49603 -atomic_t fscache_n_op_deferred_release;
49604 -atomic_t fscache_n_op_release;
49605 -atomic_t fscache_n_op_gc;
49606 -atomic_t fscache_n_op_cancelled;
49607 -atomic_t fscache_n_op_rejected;
49608 +atomic_unchecked_t fscache_n_op_pend;
49609 +atomic_unchecked_t fscache_n_op_run;
49610 +atomic_unchecked_t fscache_n_op_enqueue;
49611 +atomic_unchecked_t fscache_n_op_requeue;
49612 +atomic_unchecked_t fscache_n_op_deferred_release;
49613 +atomic_unchecked_t fscache_n_op_release;
49614 +atomic_unchecked_t fscache_n_op_gc;
49615 +atomic_unchecked_t fscache_n_op_cancelled;
49616 +atomic_unchecked_t fscache_n_op_rejected;
49617
49618 -atomic_t fscache_n_attr_changed;
49619 -atomic_t fscache_n_attr_changed_ok;
49620 -atomic_t fscache_n_attr_changed_nobufs;
49621 -atomic_t fscache_n_attr_changed_nomem;
49622 -atomic_t fscache_n_attr_changed_calls;
49623 +atomic_unchecked_t fscache_n_attr_changed;
49624 +atomic_unchecked_t fscache_n_attr_changed_ok;
49625 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
49626 +atomic_unchecked_t fscache_n_attr_changed_nomem;
49627 +atomic_unchecked_t fscache_n_attr_changed_calls;
49628
49629 -atomic_t fscache_n_allocs;
49630 -atomic_t fscache_n_allocs_ok;
49631 -atomic_t fscache_n_allocs_wait;
49632 -atomic_t fscache_n_allocs_nobufs;
49633 -atomic_t fscache_n_allocs_intr;
49634 -atomic_t fscache_n_allocs_object_dead;
49635 -atomic_t fscache_n_alloc_ops;
49636 -atomic_t fscache_n_alloc_op_waits;
49637 +atomic_unchecked_t fscache_n_allocs;
49638 +atomic_unchecked_t fscache_n_allocs_ok;
49639 +atomic_unchecked_t fscache_n_allocs_wait;
49640 +atomic_unchecked_t fscache_n_allocs_nobufs;
49641 +atomic_unchecked_t fscache_n_allocs_intr;
49642 +atomic_unchecked_t fscache_n_allocs_object_dead;
49643 +atomic_unchecked_t fscache_n_alloc_ops;
49644 +atomic_unchecked_t fscache_n_alloc_op_waits;
49645
49646 -atomic_t fscache_n_retrievals;
49647 -atomic_t fscache_n_retrievals_ok;
49648 -atomic_t fscache_n_retrievals_wait;
49649 -atomic_t fscache_n_retrievals_nodata;
49650 -atomic_t fscache_n_retrievals_nobufs;
49651 -atomic_t fscache_n_retrievals_intr;
49652 -atomic_t fscache_n_retrievals_nomem;
49653 -atomic_t fscache_n_retrievals_object_dead;
49654 -atomic_t fscache_n_retrieval_ops;
49655 -atomic_t fscache_n_retrieval_op_waits;
49656 +atomic_unchecked_t fscache_n_retrievals;
49657 +atomic_unchecked_t fscache_n_retrievals_ok;
49658 +atomic_unchecked_t fscache_n_retrievals_wait;
49659 +atomic_unchecked_t fscache_n_retrievals_nodata;
49660 +atomic_unchecked_t fscache_n_retrievals_nobufs;
49661 +atomic_unchecked_t fscache_n_retrievals_intr;
49662 +atomic_unchecked_t fscache_n_retrievals_nomem;
49663 +atomic_unchecked_t fscache_n_retrievals_object_dead;
49664 +atomic_unchecked_t fscache_n_retrieval_ops;
49665 +atomic_unchecked_t fscache_n_retrieval_op_waits;
49666
49667 -atomic_t fscache_n_stores;
49668 -atomic_t fscache_n_stores_ok;
49669 -atomic_t fscache_n_stores_again;
49670 -atomic_t fscache_n_stores_nobufs;
49671 -atomic_t fscache_n_stores_oom;
49672 -atomic_t fscache_n_store_ops;
49673 -atomic_t fscache_n_store_calls;
49674 -atomic_t fscache_n_store_pages;
49675 -atomic_t fscache_n_store_radix_deletes;
49676 -atomic_t fscache_n_store_pages_over_limit;
49677 +atomic_unchecked_t fscache_n_stores;
49678 +atomic_unchecked_t fscache_n_stores_ok;
49679 +atomic_unchecked_t fscache_n_stores_again;
49680 +atomic_unchecked_t fscache_n_stores_nobufs;
49681 +atomic_unchecked_t fscache_n_stores_oom;
49682 +atomic_unchecked_t fscache_n_store_ops;
49683 +atomic_unchecked_t fscache_n_store_calls;
49684 +atomic_unchecked_t fscache_n_store_pages;
49685 +atomic_unchecked_t fscache_n_store_radix_deletes;
49686 +atomic_unchecked_t fscache_n_store_pages_over_limit;
49687
49688 -atomic_t fscache_n_store_vmscan_not_storing;
49689 -atomic_t fscache_n_store_vmscan_gone;
49690 -atomic_t fscache_n_store_vmscan_busy;
49691 -atomic_t fscache_n_store_vmscan_cancelled;
49692 -atomic_t fscache_n_store_vmscan_wait;
49693 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49694 +atomic_unchecked_t fscache_n_store_vmscan_gone;
49695 +atomic_unchecked_t fscache_n_store_vmscan_busy;
49696 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49697 +atomic_unchecked_t fscache_n_store_vmscan_wait;
49698
49699 -atomic_t fscache_n_marks;
49700 -atomic_t fscache_n_uncaches;
49701 +atomic_unchecked_t fscache_n_marks;
49702 +atomic_unchecked_t fscache_n_uncaches;
49703
49704 -atomic_t fscache_n_acquires;
49705 -atomic_t fscache_n_acquires_null;
49706 -atomic_t fscache_n_acquires_no_cache;
49707 -atomic_t fscache_n_acquires_ok;
49708 -atomic_t fscache_n_acquires_nobufs;
49709 -atomic_t fscache_n_acquires_oom;
49710 +atomic_unchecked_t fscache_n_acquires;
49711 +atomic_unchecked_t fscache_n_acquires_null;
49712 +atomic_unchecked_t fscache_n_acquires_no_cache;
49713 +atomic_unchecked_t fscache_n_acquires_ok;
49714 +atomic_unchecked_t fscache_n_acquires_nobufs;
49715 +atomic_unchecked_t fscache_n_acquires_oom;
49716
49717 -atomic_t fscache_n_invalidates;
49718 -atomic_t fscache_n_invalidates_run;
49719 +atomic_unchecked_t fscache_n_invalidates;
49720 +atomic_unchecked_t fscache_n_invalidates_run;
49721
49722 -atomic_t fscache_n_updates;
49723 -atomic_t fscache_n_updates_null;
49724 -atomic_t fscache_n_updates_run;
49725 +atomic_unchecked_t fscache_n_updates;
49726 +atomic_unchecked_t fscache_n_updates_null;
49727 +atomic_unchecked_t fscache_n_updates_run;
49728
49729 -atomic_t fscache_n_relinquishes;
49730 -atomic_t fscache_n_relinquishes_null;
49731 -atomic_t fscache_n_relinquishes_waitcrt;
49732 -atomic_t fscache_n_relinquishes_retire;
49733 +atomic_unchecked_t fscache_n_relinquishes;
49734 +atomic_unchecked_t fscache_n_relinquishes_null;
49735 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49736 +atomic_unchecked_t fscache_n_relinquishes_retire;
49737
49738 -atomic_t fscache_n_cookie_index;
49739 -atomic_t fscache_n_cookie_data;
49740 -atomic_t fscache_n_cookie_special;
49741 +atomic_unchecked_t fscache_n_cookie_index;
49742 +atomic_unchecked_t fscache_n_cookie_data;
49743 +atomic_unchecked_t fscache_n_cookie_special;
49744
49745 -atomic_t fscache_n_object_alloc;
49746 -atomic_t fscache_n_object_no_alloc;
49747 -atomic_t fscache_n_object_lookups;
49748 -atomic_t fscache_n_object_lookups_negative;
49749 -atomic_t fscache_n_object_lookups_positive;
49750 -atomic_t fscache_n_object_lookups_timed_out;
49751 -atomic_t fscache_n_object_created;
49752 -atomic_t fscache_n_object_avail;
49753 -atomic_t fscache_n_object_dead;
49754 +atomic_unchecked_t fscache_n_object_alloc;
49755 +atomic_unchecked_t fscache_n_object_no_alloc;
49756 +atomic_unchecked_t fscache_n_object_lookups;
49757 +atomic_unchecked_t fscache_n_object_lookups_negative;
49758 +atomic_unchecked_t fscache_n_object_lookups_positive;
49759 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
49760 +atomic_unchecked_t fscache_n_object_created;
49761 +atomic_unchecked_t fscache_n_object_avail;
49762 +atomic_unchecked_t fscache_n_object_dead;
49763
49764 -atomic_t fscache_n_checkaux_none;
49765 -atomic_t fscache_n_checkaux_okay;
49766 -atomic_t fscache_n_checkaux_update;
49767 -atomic_t fscache_n_checkaux_obsolete;
49768 +atomic_unchecked_t fscache_n_checkaux_none;
49769 +atomic_unchecked_t fscache_n_checkaux_okay;
49770 +atomic_unchecked_t fscache_n_checkaux_update;
49771 +atomic_unchecked_t fscache_n_checkaux_obsolete;
49772
49773 atomic_t fscache_n_cop_alloc_object;
49774 atomic_t fscache_n_cop_lookup_object;
49775 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49776 seq_puts(m, "FS-Cache statistics\n");
49777
49778 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49779 - atomic_read(&fscache_n_cookie_index),
49780 - atomic_read(&fscache_n_cookie_data),
49781 - atomic_read(&fscache_n_cookie_special));
49782 + atomic_read_unchecked(&fscache_n_cookie_index),
49783 + atomic_read_unchecked(&fscache_n_cookie_data),
49784 + atomic_read_unchecked(&fscache_n_cookie_special));
49785
49786 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49787 - atomic_read(&fscache_n_object_alloc),
49788 - atomic_read(&fscache_n_object_no_alloc),
49789 - atomic_read(&fscache_n_object_avail),
49790 - atomic_read(&fscache_n_object_dead));
49791 + atomic_read_unchecked(&fscache_n_object_alloc),
49792 + atomic_read_unchecked(&fscache_n_object_no_alloc),
49793 + atomic_read_unchecked(&fscache_n_object_avail),
49794 + atomic_read_unchecked(&fscache_n_object_dead));
49795 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49796 - atomic_read(&fscache_n_checkaux_none),
49797 - atomic_read(&fscache_n_checkaux_okay),
49798 - atomic_read(&fscache_n_checkaux_update),
49799 - atomic_read(&fscache_n_checkaux_obsolete));
49800 + atomic_read_unchecked(&fscache_n_checkaux_none),
49801 + atomic_read_unchecked(&fscache_n_checkaux_okay),
49802 + atomic_read_unchecked(&fscache_n_checkaux_update),
49803 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49804
49805 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49806 - atomic_read(&fscache_n_marks),
49807 - atomic_read(&fscache_n_uncaches));
49808 + atomic_read_unchecked(&fscache_n_marks),
49809 + atomic_read_unchecked(&fscache_n_uncaches));
49810
49811 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49812 " oom=%u\n",
49813 - atomic_read(&fscache_n_acquires),
49814 - atomic_read(&fscache_n_acquires_null),
49815 - atomic_read(&fscache_n_acquires_no_cache),
49816 - atomic_read(&fscache_n_acquires_ok),
49817 - atomic_read(&fscache_n_acquires_nobufs),
49818 - atomic_read(&fscache_n_acquires_oom));
49819 + atomic_read_unchecked(&fscache_n_acquires),
49820 + atomic_read_unchecked(&fscache_n_acquires_null),
49821 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
49822 + atomic_read_unchecked(&fscache_n_acquires_ok),
49823 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
49824 + atomic_read_unchecked(&fscache_n_acquires_oom));
49825
49826 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49827 - atomic_read(&fscache_n_object_lookups),
49828 - atomic_read(&fscache_n_object_lookups_negative),
49829 - atomic_read(&fscache_n_object_lookups_positive),
49830 - atomic_read(&fscache_n_object_created),
49831 - atomic_read(&fscache_n_object_lookups_timed_out));
49832 + atomic_read_unchecked(&fscache_n_object_lookups),
49833 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
49834 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
49835 + atomic_read_unchecked(&fscache_n_object_created),
49836 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49837
49838 seq_printf(m, "Invals : n=%u run=%u\n",
49839 - atomic_read(&fscache_n_invalidates),
49840 - atomic_read(&fscache_n_invalidates_run));
49841 + atomic_read_unchecked(&fscache_n_invalidates),
49842 + atomic_read_unchecked(&fscache_n_invalidates_run));
49843
49844 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49845 - atomic_read(&fscache_n_updates),
49846 - atomic_read(&fscache_n_updates_null),
49847 - atomic_read(&fscache_n_updates_run));
49848 + atomic_read_unchecked(&fscache_n_updates),
49849 + atomic_read_unchecked(&fscache_n_updates_null),
49850 + atomic_read_unchecked(&fscache_n_updates_run));
49851
49852 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49853 - atomic_read(&fscache_n_relinquishes),
49854 - atomic_read(&fscache_n_relinquishes_null),
49855 - atomic_read(&fscache_n_relinquishes_waitcrt),
49856 - atomic_read(&fscache_n_relinquishes_retire));
49857 + atomic_read_unchecked(&fscache_n_relinquishes),
49858 + atomic_read_unchecked(&fscache_n_relinquishes_null),
49859 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49860 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
49861
49862 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49863 - atomic_read(&fscache_n_attr_changed),
49864 - atomic_read(&fscache_n_attr_changed_ok),
49865 - atomic_read(&fscache_n_attr_changed_nobufs),
49866 - atomic_read(&fscache_n_attr_changed_nomem),
49867 - atomic_read(&fscache_n_attr_changed_calls));
49868 + atomic_read_unchecked(&fscache_n_attr_changed),
49869 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
49870 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49871 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49872 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
49873
49874 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49875 - atomic_read(&fscache_n_allocs),
49876 - atomic_read(&fscache_n_allocs_ok),
49877 - atomic_read(&fscache_n_allocs_wait),
49878 - atomic_read(&fscache_n_allocs_nobufs),
49879 - atomic_read(&fscache_n_allocs_intr));
49880 + atomic_read_unchecked(&fscache_n_allocs),
49881 + atomic_read_unchecked(&fscache_n_allocs_ok),
49882 + atomic_read_unchecked(&fscache_n_allocs_wait),
49883 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
49884 + atomic_read_unchecked(&fscache_n_allocs_intr));
49885 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49886 - atomic_read(&fscache_n_alloc_ops),
49887 - atomic_read(&fscache_n_alloc_op_waits),
49888 - atomic_read(&fscache_n_allocs_object_dead));
49889 + atomic_read_unchecked(&fscache_n_alloc_ops),
49890 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
49891 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
49892
49893 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49894 " int=%u oom=%u\n",
49895 - atomic_read(&fscache_n_retrievals),
49896 - atomic_read(&fscache_n_retrievals_ok),
49897 - atomic_read(&fscache_n_retrievals_wait),
49898 - atomic_read(&fscache_n_retrievals_nodata),
49899 - atomic_read(&fscache_n_retrievals_nobufs),
49900 - atomic_read(&fscache_n_retrievals_intr),
49901 - atomic_read(&fscache_n_retrievals_nomem));
49902 + atomic_read_unchecked(&fscache_n_retrievals),
49903 + atomic_read_unchecked(&fscache_n_retrievals_ok),
49904 + atomic_read_unchecked(&fscache_n_retrievals_wait),
49905 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
49906 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49907 + atomic_read_unchecked(&fscache_n_retrievals_intr),
49908 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
49909 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49910 - atomic_read(&fscache_n_retrieval_ops),
49911 - atomic_read(&fscache_n_retrieval_op_waits),
49912 - atomic_read(&fscache_n_retrievals_object_dead));
49913 + atomic_read_unchecked(&fscache_n_retrieval_ops),
49914 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49915 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49916
49917 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49918 - atomic_read(&fscache_n_stores),
49919 - atomic_read(&fscache_n_stores_ok),
49920 - atomic_read(&fscache_n_stores_again),
49921 - atomic_read(&fscache_n_stores_nobufs),
49922 - atomic_read(&fscache_n_stores_oom));
49923 + atomic_read_unchecked(&fscache_n_stores),
49924 + atomic_read_unchecked(&fscache_n_stores_ok),
49925 + atomic_read_unchecked(&fscache_n_stores_again),
49926 + atomic_read_unchecked(&fscache_n_stores_nobufs),
49927 + atomic_read_unchecked(&fscache_n_stores_oom));
49928 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49929 - atomic_read(&fscache_n_store_ops),
49930 - atomic_read(&fscache_n_store_calls),
49931 - atomic_read(&fscache_n_store_pages),
49932 - atomic_read(&fscache_n_store_radix_deletes),
49933 - atomic_read(&fscache_n_store_pages_over_limit));
49934 + atomic_read_unchecked(&fscache_n_store_ops),
49935 + atomic_read_unchecked(&fscache_n_store_calls),
49936 + atomic_read_unchecked(&fscache_n_store_pages),
49937 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
49938 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49939
49940 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
49941 - atomic_read(&fscache_n_store_vmscan_not_storing),
49942 - atomic_read(&fscache_n_store_vmscan_gone),
49943 - atomic_read(&fscache_n_store_vmscan_busy),
49944 - atomic_read(&fscache_n_store_vmscan_cancelled),
49945 - atomic_read(&fscache_n_store_vmscan_wait));
49946 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49947 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49948 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49949 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
49950 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
49951
49952 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49953 - atomic_read(&fscache_n_op_pend),
49954 - atomic_read(&fscache_n_op_run),
49955 - atomic_read(&fscache_n_op_enqueue),
49956 - atomic_read(&fscache_n_op_cancelled),
49957 - atomic_read(&fscache_n_op_rejected));
49958 + atomic_read_unchecked(&fscache_n_op_pend),
49959 + atomic_read_unchecked(&fscache_n_op_run),
49960 + atomic_read_unchecked(&fscache_n_op_enqueue),
49961 + atomic_read_unchecked(&fscache_n_op_cancelled),
49962 + atomic_read_unchecked(&fscache_n_op_rejected));
49963 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49964 - atomic_read(&fscache_n_op_deferred_release),
49965 - atomic_read(&fscache_n_op_release),
49966 - atomic_read(&fscache_n_op_gc));
49967 + atomic_read_unchecked(&fscache_n_op_deferred_release),
49968 + atomic_read_unchecked(&fscache_n_op_release),
49969 + atomic_read_unchecked(&fscache_n_op_gc));
49970
49971 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49972 atomic_read(&fscache_n_cop_alloc_object),
49973 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49974 index e397b67..b0d8709 100644
49975 --- a/fs/fuse/cuse.c
49976 +++ b/fs/fuse/cuse.c
49977 @@ -593,10 +593,12 @@ static int __init cuse_init(void)
49978 INIT_LIST_HEAD(&cuse_conntbl[i]);
49979
49980 /* inherit and extend fuse_dev_operations */
49981 - cuse_channel_fops = fuse_dev_operations;
49982 - cuse_channel_fops.owner = THIS_MODULE;
49983 - cuse_channel_fops.open = cuse_channel_open;
49984 - cuse_channel_fops.release = cuse_channel_release;
49985 + pax_open_kernel();
49986 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
49987 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
49988 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
49989 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
49990 + pax_close_kernel();
49991
49992 cuse_class = class_create(THIS_MODULE, "cuse");
49993 if (IS_ERR(cuse_class))
49994 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
49995 index e83351a..41e3c9c 100644
49996 --- a/fs/fuse/dev.c
49997 +++ b/fs/fuse/dev.c
49998 @@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
49999 ret = 0;
50000 pipe_lock(pipe);
50001
50002 - if (!pipe->readers) {
50003 + if (!atomic_read(&pipe->readers)) {
50004 send_sig(SIGPIPE, current, 0);
50005 if (!ret)
50006 ret = -EPIPE;
50007 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50008 index b7c09f9..3eff736 100644
50009 --- a/fs/fuse/dir.c
50010 +++ b/fs/fuse/dir.c
50011 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
50012 return link;
50013 }
50014
50015 -static void free_link(char *link)
50016 +static void free_link(const char *link)
50017 {
50018 if (!IS_ERR(link))
50019 free_page((unsigned long) link);
50020 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
50021 index 2b6f569..fcb4d1f 100644
50022 --- a/fs/gfs2/inode.c
50023 +++ b/fs/gfs2/inode.c
50024 @@ -1499,7 +1499,7 @@ out:
50025
50026 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50027 {
50028 - char *s = nd_get_link(nd);
50029 + const char *s = nd_get_link(nd);
50030 if (!IS_ERR(s))
50031 kfree(s);
50032 }
50033 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50034 index 78bde32..767e906 100644
50035 --- a/fs/hugetlbfs/inode.c
50036 +++ b/fs/hugetlbfs/inode.c
50037 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50038 struct mm_struct *mm = current->mm;
50039 struct vm_area_struct *vma;
50040 struct hstate *h = hstate_file(file);
50041 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
50042 struct vm_unmapped_area_info info;
50043
50044 if (len & ~huge_page_mask(h))
50045 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50046 return addr;
50047 }
50048
50049 +#ifdef CONFIG_PAX_RANDMMAP
50050 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
50051 +#endif
50052 +
50053 if (addr) {
50054 addr = ALIGN(addr, huge_page_size(h));
50055 vma = find_vma(mm, addr);
50056 - if (TASK_SIZE - len >= addr &&
50057 - (!vma || addr + len <= vma->vm_start))
50058 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
50059 return addr;
50060 }
50061
50062 info.flags = 0;
50063 info.length = len;
50064 info.low_limit = TASK_UNMAPPED_BASE;
50065 +
50066 +#ifdef CONFIG_PAX_RANDMMAP
50067 + if (mm->pax_flags & MF_PAX_RANDMMAP)
50068 + info.low_limit += mm->delta_mmap;
50069 +#endif
50070 +
50071 info.high_limit = TASK_SIZE;
50072 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
50073 info.align_offset = 0;
50074 @@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50075 .kill_sb = kill_litter_super,
50076 };
50077
50078 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50079 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50080
50081 static int can_do_hugetlb_shm(void)
50082 {
50083 diff --git a/fs/inode.c b/fs/inode.c
50084 index 14084b7..29af1d9 100644
50085 --- a/fs/inode.c
50086 +++ b/fs/inode.c
50087 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
50088
50089 #ifdef CONFIG_SMP
50090 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
50091 - static atomic_t shared_last_ino;
50092 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
50093 + static atomic_unchecked_t shared_last_ino;
50094 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
50095
50096 res = next - LAST_INO_BATCH;
50097 }
50098 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50099 index 4a6cf28..d3a29d3 100644
50100 --- a/fs/jffs2/erase.c
50101 +++ b/fs/jffs2/erase.c
50102 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50103 struct jffs2_unknown_node marker = {
50104 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50105 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50106 - .totlen = cpu_to_je32(c->cleanmarker_size)
50107 + .totlen = cpu_to_je32(c->cleanmarker_size),
50108 + .hdr_crc = cpu_to_je32(0)
50109 };
50110
50111 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50112 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50113 index a6597d6..41b30ec 100644
50114 --- a/fs/jffs2/wbuf.c
50115 +++ b/fs/jffs2/wbuf.c
50116 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50117 {
50118 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50119 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50120 - .totlen = constant_cpu_to_je32(8)
50121 + .totlen = constant_cpu_to_je32(8),
50122 + .hdr_crc = constant_cpu_to_je32(0)
50123 };
50124
50125 /*
50126 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50127 index 1a543be..d803c40 100644
50128 --- a/fs/jfs/super.c
50129 +++ b/fs/jfs/super.c
50130 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
50131
50132 jfs_inode_cachep =
50133 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50134 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50135 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50136 init_once);
50137 if (jfs_inode_cachep == NULL)
50138 return -ENOMEM;
50139 diff --git a/fs/libfs.c b/fs/libfs.c
50140 index 916da8c..1588998 100644
50141 --- a/fs/libfs.c
50142 +++ b/fs/libfs.c
50143 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50144
50145 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50146 struct dentry *next;
50147 + char d_name[sizeof(next->d_iname)];
50148 + const unsigned char *name;
50149 +
50150 next = list_entry(p, struct dentry, d_u.d_child);
50151 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
50152 if (!simple_positive(next)) {
50153 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50154
50155 spin_unlock(&next->d_lock);
50156 spin_unlock(&dentry->d_lock);
50157 - if (filldir(dirent, next->d_name.name,
50158 + name = next->d_name.name;
50159 + if (name == next->d_iname) {
50160 + memcpy(d_name, name, next->d_name.len);
50161 + name = d_name;
50162 + }
50163 + if (filldir(dirent, name,
50164 next->d_name.len, filp->f_pos,
50165 next->d_inode->i_ino,
50166 dt_type(next->d_inode)) < 0)
50167 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50168 index 54f9e6c..9ed908c 100644
50169 --- a/fs/lockd/clntproc.c
50170 +++ b/fs/lockd/clntproc.c
50171 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50172 /*
50173 * Cookie counter for NLM requests
50174 */
50175 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50176 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50177
50178 void nlmclnt_next_cookie(struct nlm_cookie *c)
50179 {
50180 - u32 cookie = atomic_inc_return(&nlm_cookie);
50181 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50182
50183 memcpy(c->data, &cookie, 4);
50184 c->len=4;
50185 diff --git a/fs/locks.c b/fs/locks.c
50186 index a94e331..060bce3 100644
50187 --- a/fs/locks.c
50188 +++ b/fs/locks.c
50189 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
50190 return;
50191
50192 if (filp->f_op && filp->f_op->flock) {
50193 - struct file_lock fl = {
50194 + struct file_lock flock = {
50195 .fl_pid = current->tgid,
50196 .fl_file = filp,
50197 .fl_flags = FL_FLOCK,
50198 .fl_type = F_UNLCK,
50199 .fl_end = OFFSET_MAX,
50200 };
50201 - filp->f_op->flock(filp, F_SETLKW, &fl);
50202 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
50203 - fl.fl_ops->fl_release_private(&fl);
50204 + filp->f_op->flock(filp, F_SETLKW, &flock);
50205 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
50206 + flock.fl_ops->fl_release_private(&flock);
50207 }
50208
50209 lock_flocks();
50210 diff --git a/fs/namei.c b/fs/namei.c
50211 index 43a97ee..ff3f601 100644
50212 --- a/fs/namei.c
50213 +++ b/fs/namei.c
50214 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
50215 if (ret != -EACCES)
50216 return ret;
50217
50218 +#ifdef CONFIG_GRKERNSEC
50219 + /* we'll block if we have to log due to a denied capability use */
50220 + if (mask & MAY_NOT_BLOCK)
50221 + return -ECHILD;
50222 +#endif
50223 +
50224 if (S_ISDIR(inode->i_mode)) {
50225 /* DACs are overridable for directories */
50226 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
50227 - return 0;
50228 if (!(mask & MAY_WRITE))
50229 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50230 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50231 + inode_capable(inode, CAP_DAC_READ_SEARCH))
50232 return 0;
50233 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
50234 + return 0;
50235 return -EACCES;
50236 }
50237 /*
50238 + * Searching includes executable on directories, else just read.
50239 + */
50240 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50241 + if (mask == MAY_READ)
50242 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50243 + inode_capable(inode, CAP_DAC_READ_SEARCH))
50244 + return 0;
50245 +
50246 + /*
50247 * Read/write DACs are always overridable.
50248 * Executable DACs are overridable when there is
50249 * at least one exec bit set.
50250 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
50251 if (inode_capable(inode, CAP_DAC_OVERRIDE))
50252 return 0;
50253
50254 - /*
50255 - * Searching includes executable on directories, else just read.
50256 - */
50257 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50258 - if (mask == MAY_READ)
50259 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50260 - return 0;
50261 -
50262 return -EACCES;
50263 }
50264
50265 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50266 {
50267 struct dentry *dentry = link->dentry;
50268 int error;
50269 - char *s;
50270 + const char *s;
50271
50272 BUG_ON(nd->flags & LOOKUP_RCU);
50273
50274 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50275 if (error)
50276 goto out_put_nd_path;
50277
50278 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
50279 + dentry->d_inode, dentry, nd->path.mnt)) {
50280 + error = -EACCES;
50281 + goto out_put_nd_path;
50282 + }
50283 +
50284 nd->last_type = LAST_BIND;
50285 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
50286 error = PTR_ERR(*p);
50287 @@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
50288 break;
50289 res = walk_component(nd, path, &nd->last,
50290 nd->last_type, LOOKUP_FOLLOW);
50291 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
50292 + res = -EACCES;
50293 put_link(nd, &link, cookie);
50294 } while (res > 0);
50295
50296 @@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
50297 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
50298 {
50299 unsigned long a, b, adata, bdata, mask, hash, len;
50300 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50301 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50302
50303 hash = a = 0;
50304 len = -sizeof(unsigned long);
50305 @@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
50306 if (err)
50307 break;
50308 err = lookup_last(nd, &path);
50309 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
50310 + err = -EACCES;
50311 put_link(nd, &link, cookie);
50312 }
50313 }
50314 @@ -1986,6 +2004,21 @@ static int path_lookupat(int dfd, const char *name,
50315 if (!err)
50316 err = complete_walk(nd);
50317
50318 + if (!(nd->flags & LOOKUP_PARENT)) {
50319 +#ifdef CONFIG_GRKERNSEC
50320 + if (flags & LOOKUP_RCU) {
50321 + if (!err)
50322 + path_put(&nd->path);
50323 + err = -ECHILD;
50324 + } else
50325 +#endif
50326 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50327 + if (!err)
50328 + path_put(&nd->path);
50329 + err = -ENOENT;
50330 + }
50331 + }
50332 +
50333 if (!err && nd->flags & LOOKUP_DIRECTORY) {
50334 if (!nd->inode->i_op->lookup) {
50335 path_put(&nd->path);
50336 @@ -2013,8 +2046,17 @@ static int filename_lookup(int dfd, struct filename *name,
50337 retval = path_lookupat(dfd, name->name,
50338 flags | LOOKUP_REVAL, nd);
50339
50340 - if (likely(!retval))
50341 + if (likely(!retval)) {
50342 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
50343 +#ifdef CONFIG_GRKERNSEC
50344 + if (flags & LOOKUP_RCU)
50345 + return -ECHILD;
50346 +#endif
50347 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
50348 + return -ENOENT;
50349 + }
50350 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
50351 + }
50352 return retval;
50353 }
50354
50355 @@ -2392,6 +2434,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
50356 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
50357 return -EPERM;
50358
50359 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
50360 + return -EPERM;
50361 + if (gr_handle_rawio(inode))
50362 + return -EPERM;
50363 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
50364 + return -EACCES;
50365 +
50366 return 0;
50367 }
50368
50369 @@ -2613,7 +2662,7 @@ looked_up:
50370 * cleared otherwise prior to returning.
50371 */
50372 static int lookup_open(struct nameidata *nd, struct path *path,
50373 - struct file *file,
50374 + struct path *link, struct file *file,
50375 const struct open_flags *op,
50376 bool got_write, int *opened)
50377 {
50378 @@ -2648,6 +2697,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50379 /* Negative dentry, just create the file */
50380 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
50381 umode_t mode = op->mode;
50382 +
50383 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
50384 + error = -EACCES;
50385 + goto out_dput;
50386 + }
50387 +
50388 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
50389 + error = -EACCES;
50390 + goto out_dput;
50391 + }
50392 +
50393 if (!IS_POSIXACL(dir->d_inode))
50394 mode &= ~current_umask();
50395 /*
50396 @@ -2669,6 +2729,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50397 nd->flags & LOOKUP_EXCL);
50398 if (error)
50399 goto out_dput;
50400 + else
50401 + gr_handle_create(dentry, nd->path.mnt);
50402 }
50403 out_no_open:
50404 path->dentry = dentry;
50405 @@ -2683,7 +2745,7 @@ out_dput:
50406 /*
50407 * Handle the last step of open()
50408 */
50409 -static int do_last(struct nameidata *nd, struct path *path,
50410 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
50411 struct file *file, const struct open_flags *op,
50412 int *opened, struct filename *name)
50413 {
50414 @@ -2712,16 +2774,44 @@ static int do_last(struct nameidata *nd, struct path *path,
50415 error = complete_walk(nd);
50416 if (error)
50417 return error;
50418 +#ifdef CONFIG_GRKERNSEC
50419 + if (nd->flags & LOOKUP_RCU) {
50420 + error = -ECHILD;
50421 + goto out;
50422 + }
50423 +#endif
50424 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50425 + error = -ENOENT;
50426 + goto out;
50427 + }
50428 audit_inode(name, nd->path.dentry, 0);
50429 if (open_flag & O_CREAT) {
50430 error = -EISDIR;
50431 goto out;
50432 }
50433 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
50434 + error = -EACCES;
50435 + goto out;
50436 + }
50437 goto finish_open;
50438 case LAST_BIND:
50439 error = complete_walk(nd);
50440 if (error)
50441 return error;
50442 +#ifdef CONFIG_GRKERNSEC
50443 + if (nd->flags & LOOKUP_RCU) {
50444 + error = -ECHILD;
50445 + goto out;
50446 + }
50447 +#endif
50448 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
50449 + error = -ENOENT;
50450 + goto out;
50451 + }
50452 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
50453 + error = -EACCES;
50454 + goto out;
50455 + }
50456 audit_inode(name, dir, 0);
50457 goto finish_open;
50458 }
50459 @@ -2770,7 +2860,7 @@ retry_lookup:
50460 */
50461 }
50462 mutex_lock(&dir->d_inode->i_mutex);
50463 - error = lookup_open(nd, path, file, op, got_write, opened);
50464 + error = lookup_open(nd, path, link, file, op, got_write, opened);
50465 mutex_unlock(&dir->d_inode->i_mutex);
50466
50467 if (error <= 0) {
50468 @@ -2794,11 +2884,28 @@ retry_lookup:
50469 goto finish_open_created;
50470 }
50471
50472 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
50473 + error = -ENOENT;
50474 + goto exit_dput;
50475 + }
50476 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
50477 + error = -EACCES;
50478 + goto exit_dput;
50479 + }
50480 +
50481 /*
50482 * create/update audit record if it already exists.
50483 */
50484 - if (path->dentry->d_inode)
50485 + if (path->dentry->d_inode) {
50486 + /* only check if O_CREAT is specified, all other checks need to go
50487 + into may_open */
50488 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
50489 + error = -EACCES;
50490 + goto exit_dput;
50491 + }
50492 +
50493 audit_inode(name, path->dentry, 0);
50494 + }
50495
50496 /*
50497 * If atomic_open() acquired write access it is dropped now due to
50498 @@ -2839,6 +2946,11 @@ finish_lookup:
50499 }
50500 }
50501 BUG_ON(inode != path->dentry->d_inode);
50502 + /* if we're resolving a symlink to another symlink */
50503 + if (link && gr_handle_symlink_owner(link, inode)) {
50504 + error = -EACCES;
50505 + goto out;
50506 + }
50507 return 1;
50508 }
50509
50510 @@ -2848,7 +2960,6 @@ finish_lookup:
50511 save_parent.dentry = nd->path.dentry;
50512 save_parent.mnt = mntget(path->mnt);
50513 nd->path.dentry = path->dentry;
50514 -
50515 }
50516 nd->inode = inode;
50517 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
50518 @@ -2857,6 +2968,22 @@ finish_lookup:
50519 path_put(&save_parent);
50520 return error;
50521 }
50522 +
50523 +#ifdef CONFIG_GRKERNSEC
50524 + if (nd->flags & LOOKUP_RCU) {
50525 + error = -ECHILD;
50526 + goto out;
50527 + }
50528 +#endif
50529 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50530 + error = -ENOENT;
50531 + goto out;
50532 + }
50533 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
50534 + error = -EACCES;
50535 + goto out;
50536 + }
50537 +
50538 error = -EISDIR;
50539 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
50540 goto out;
50541 @@ -2955,7 +3082,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50542 if (unlikely(error))
50543 goto out;
50544
50545 - error = do_last(nd, &path, file, op, &opened, pathname);
50546 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
50547 while (unlikely(error > 0)) { /* trailing symlink */
50548 struct path link = path;
50549 void *cookie;
50550 @@ -2973,7 +3100,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50551 error = follow_link(&link, nd, &cookie);
50552 if (unlikely(error))
50553 break;
50554 - error = do_last(nd, &path, file, op, &opened, pathname);
50555 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
50556 put_link(nd, &link, cookie);
50557 }
50558 out:
50559 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
50560 goto unlock;
50561
50562 error = -EEXIST;
50563 - if (dentry->d_inode)
50564 + if (dentry->d_inode) {
50565 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
50566 + error = -ENOENT;
50567 + }
50568 goto fail;
50569 + }
50570 /*
50571 * Special case - lookup gave negative, but... we had foo/bar/
50572 * From the vfs_mknod() POV we just have a negative dentry -
50573 @@ -3126,6 +3257,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
50574 }
50575 EXPORT_SYMBOL(user_path_create);
50576
50577 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
50578 +{
50579 + struct filename *tmp = getname(pathname);
50580 + struct dentry *res;
50581 + if (IS_ERR(tmp))
50582 + return ERR_CAST(tmp);
50583 + res = kern_path_create(dfd, tmp->name, path, is_dir);
50584 + if (IS_ERR(res))
50585 + putname(tmp);
50586 + else
50587 + *to = tmp;
50588 + return res;
50589 +}
50590 +
50591 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
50592 {
50593 int error = may_create(dir, dentry);
50594 @@ -3188,6 +3333,17 @@ retry:
50595
50596 if (!IS_POSIXACL(path.dentry->d_inode))
50597 mode &= ~current_umask();
50598 +
50599 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
50600 + error = -EPERM;
50601 + goto out;
50602 + }
50603 +
50604 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
50605 + error = -EACCES;
50606 + goto out;
50607 + }
50608 +
50609 error = security_path_mknod(&path, dentry, mode, dev);
50610 if (error)
50611 goto out;
50612 @@ -3204,6 +3360,8 @@ retry:
50613 break;
50614 }
50615 out:
50616 + if (!error)
50617 + gr_handle_create(dentry, path.mnt);
50618 done_path_create(&path, dentry);
50619 if (retry_estale(error, lookup_flags)) {
50620 lookup_flags |= LOOKUP_REVAL;
50621 @@ -3256,9 +3414,16 @@ retry:
50622
50623 if (!IS_POSIXACL(path.dentry->d_inode))
50624 mode &= ~current_umask();
50625 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
50626 + error = -EACCES;
50627 + goto out;
50628 + }
50629 error = security_path_mkdir(&path, dentry, mode);
50630 if (!error)
50631 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
50632 + if (!error)
50633 + gr_handle_create(dentry, path.mnt);
50634 +out:
50635 done_path_create(&path, dentry);
50636 if (retry_estale(error, lookup_flags)) {
50637 lookup_flags |= LOOKUP_REVAL;
50638 @@ -3339,6 +3504,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
50639 struct filename *name;
50640 struct dentry *dentry;
50641 struct nameidata nd;
50642 + ino_t saved_ino = 0;
50643 + dev_t saved_dev = 0;
50644 unsigned int lookup_flags = 0;
50645 retry:
50646 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50647 @@ -3371,10 +3538,21 @@ retry:
50648 error = -ENOENT;
50649 goto exit3;
50650 }
50651 +
50652 + saved_ino = dentry->d_inode->i_ino;
50653 + saved_dev = gr_get_dev_from_dentry(dentry);
50654 +
50655 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
50656 + error = -EACCES;
50657 + goto exit3;
50658 + }
50659 +
50660 error = security_path_rmdir(&nd.path, dentry);
50661 if (error)
50662 goto exit3;
50663 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
50664 + if (!error && (saved_dev || saved_ino))
50665 + gr_handle_delete(saved_ino, saved_dev);
50666 exit3:
50667 dput(dentry);
50668 exit2:
50669 @@ -3440,6 +3618,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
50670 struct dentry *dentry;
50671 struct nameidata nd;
50672 struct inode *inode = NULL;
50673 + ino_t saved_ino = 0;
50674 + dev_t saved_dev = 0;
50675 unsigned int lookup_flags = 0;
50676 retry:
50677 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50678 @@ -3466,10 +3646,22 @@ retry:
50679 if (!inode)
50680 goto slashes;
50681 ihold(inode);
50682 +
50683 + if (inode->i_nlink <= 1) {
50684 + saved_ino = inode->i_ino;
50685 + saved_dev = gr_get_dev_from_dentry(dentry);
50686 + }
50687 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
50688 + error = -EACCES;
50689 + goto exit2;
50690 + }
50691 +
50692 error = security_path_unlink(&nd.path, dentry);
50693 if (error)
50694 goto exit2;
50695 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
50696 + if (!error && (saved_ino || saved_dev))
50697 + gr_handle_delete(saved_ino, saved_dev);
50698 exit2:
50699 dput(dentry);
50700 }
50701 @@ -3547,9 +3739,17 @@ retry:
50702 if (IS_ERR(dentry))
50703 goto out_putname;
50704
50705 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
50706 + error = -EACCES;
50707 + goto out;
50708 + }
50709 +
50710 error = security_path_symlink(&path, dentry, from->name);
50711 if (!error)
50712 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
50713 + if (!error)
50714 + gr_handle_create(dentry, path.mnt);
50715 +out:
50716 done_path_create(&path, dentry);
50717 if (retry_estale(error, lookup_flags)) {
50718 lookup_flags |= LOOKUP_REVAL;
50719 @@ -3623,6 +3823,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50720 {
50721 struct dentry *new_dentry;
50722 struct path old_path, new_path;
50723 + struct filename *to = NULL;
50724 int how = 0;
50725 int error;
50726
50727 @@ -3646,7 +3847,7 @@ retry:
50728 if (error)
50729 return error;
50730
50731 - new_dentry = user_path_create(newdfd, newname, &new_path,
50732 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
50733 (how & LOOKUP_REVAL));
50734 error = PTR_ERR(new_dentry);
50735 if (IS_ERR(new_dentry))
50736 @@ -3658,11 +3859,28 @@ retry:
50737 error = may_linkat(&old_path);
50738 if (unlikely(error))
50739 goto out_dput;
50740 +
50741 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50742 + old_path.dentry->d_inode,
50743 + old_path.dentry->d_inode->i_mode, to)) {
50744 + error = -EACCES;
50745 + goto out_dput;
50746 + }
50747 +
50748 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50749 + old_path.dentry, old_path.mnt, to)) {
50750 + error = -EACCES;
50751 + goto out_dput;
50752 + }
50753 +
50754 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50755 if (error)
50756 goto out_dput;
50757 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50758 + if (!error)
50759 + gr_handle_create(new_dentry, new_path.mnt);
50760 out_dput:
50761 + putname(to);
50762 done_path_create(&new_path, new_dentry);
50763 if (retry_estale(error, how)) {
50764 how |= LOOKUP_REVAL;
50765 @@ -3908,12 +4126,21 @@ retry:
50766 if (new_dentry == trap)
50767 goto exit5;
50768
50769 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50770 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
50771 + to);
50772 + if (error)
50773 + goto exit5;
50774 +
50775 error = security_path_rename(&oldnd.path, old_dentry,
50776 &newnd.path, new_dentry);
50777 if (error)
50778 goto exit5;
50779 error = vfs_rename(old_dir->d_inode, old_dentry,
50780 new_dir->d_inode, new_dentry);
50781 + if (!error)
50782 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50783 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50784 exit5:
50785 dput(new_dentry);
50786 exit4:
50787 @@ -3945,6 +4172,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50788
50789 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50790 {
50791 + char tmpbuf[64];
50792 + const char *newlink;
50793 int len;
50794
50795 len = PTR_ERR(link);
50796 @@ -3954,7 +4183,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50797 len = strlen(link);
50798 if (len > (unsigned) buflen)
50799 len = buflen;
50800 - if (copy_to_user(buffer, link, len))
50801 +
50802 + if (len < sizeof(tmpbuf)) {
50803 + memcpy(tmpbuf, link, len);
50804 + newlink = tmpbuf;
50805 + } else
50806 + newlink = link;
50807 +
50808 + if (copy_to_user(buffer, newlink, len))
50809 len = -EFAULT;
50810 out:
50811 return len;
50812 diff --git a/fs/namespace.c b/fs/namespace.c
50813 index 55605c5..f2908c8 100644
50814 --- a/fs/namespace.c
50815 +++ b/fs/namespace.c
50816 @@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
50817 if (!(sb->s_flags & MS_RDONLY))
50818 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50819 up_write(&sb->s_umount);
50820 +
50821 + gr_log_remount(mnt->mnt_devname, retval);
50822 +
50823 return retval;
50824 }
50825
50826 @@ -1234,9 +1237,20 @@ static int do_umount(struct mount *mnt, int flags)
50827 br_write_unlock(&vfsmount_lock);
50828 up_write(&namespace_sem);
50829 release_mounts(&umount_list);
50830 +
50831 + gr_log_unmount(mnt->mnt_devname, retval);
50832 +
50833 return retval;
50834 }
50835
50836 +/*
50837 + * Is the caller allowed to modify his namespace?
50838 + */
50839 +static inline bool may_mount(void)
50840 +{
50841 + return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
50842 +}
50843 +
50844 /*
50845 * Now umount can handle mount points as well as block devices.
50846 * This is important for filesystems which use unnamed block devices.
50847 @@ -1255,6 +1269,9 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
50848 if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
50849 return -EINVAL;
50850
50851 + if (!may_mount())
50852 + return -EPERM;
50853 +
50854 if (!(flags & UMOUNT_NOFOLLOW))
50855 lookup_flags |= LOOKUP_FOLLOW;
50856
50857 @@ -1268,10 +1285,6 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
50858 if (!check_mnt(mnt))
50859 goto dput_and_out;
50860
50861 - retval = -EPERM;
50862 - if (!ns_capable(mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
50863 - goto dput_and_out;
50864 -
50865 retval = do_umount(mnt, flags);
50866 dput_and_out:
50867 /* we mustn't call path_put() as that would clear mnt_expiry_mark */
50868 @@ -1295,7 +1308,7 @@ SYSCALL_DEFINE1(oldumount, char __user *, name)
50869
50870 static int mount_is_safe(struct path *path)
50871 {
50872 - if (ns_capable(real_mount(path->mnt)->mnt_ns->user_ns, CAP_SYS_ADMIN))
50873 + if (may_mount())
50874 return 0;
50875 return -EPERM;
50876 #ifdef notyet
50877 @@ -1633,7 +1646,7 @@ static int do_change_type(struct path *path, int flag)
50878 int type;
50879 int err = 0;
50880
50881 - if (!ns_capable(mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
50882 + if (!may_mount())
50883 return -EPERM;
50884
50885 if (path->dentry != path->mnt->mnt_root)
50886 @@ -1797,7 +1810,7 @@ static int do_move_mount(struct path *path, const char *old_name)
50887 struct mount *p;
50888 struct mount *old;
50889 int err = 0;
50890 - if (!ns_capable(real_mount(path->mnt)->mnt_ns->user_ns, CAP_SYS_ADMIN))
50891 + if (!may_mount())
50892 return -EPERM;
50893 if (!old_name || !*old_name)
50894 return -EINVAL;
50895 @@ -1933,16 +1946,14 @@ static int do_new_mount(struct path *path, const char *fstype, int flags,
50896 int mnt_flags, const char *name, void *data)
50897 {
50898 struct file_system_type *type;
50899 - struct user_namespace *user_ns;
50900 + struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
50901 struct vfsmount *mnt;
50902 int err;
50903
50904 if (!fstype)
50905 return -EINVAL;
50906
50907 - /* we need capabilities... */
50908 - user_ns = real_mount(path->mnt)->mnt_ns->user_ns;
50909 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
50910 + if (!may_mount())
50911 return -EPERM;
50912
50913 type = get_fs_type(fstype);
50914 @@ -2282,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50915 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50916 MS_STRICTATIME);
50917
50918 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50919 + retval = -EPERM;
50920 + goto dput_out;
50921 + }
50922 +
50923 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50924 + retval = -EPERM;
50925 + goto dput_out;
50926 + }
50927 +
50928 if (flags & MS_REMOUNT)
50929 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50930 data_page);
50931 @@ -2296,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50932 dev_name, data_page);
50933 dput_out:
50934 path_put(&path);
50935 +
50936 + gr_log_mount(dev_name, dir_name, retval);
50937 +
50938 return retval;
50939 }
50940
50941 @@ -2567,7 +2591,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50942 struct mount *new_mnt, *root_mnt;
50943 int error;
50944
50945 - if (!ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN))
50946 + if (!may_mount())
50947 return -EPERM;
50948
50949 error = user_path_dir(new_root, &new);
50950 @@ -2582,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50951 if (error)
50952 goto out2;
50953
50954 + if (gr_handle_chroot_pivot()) {
50955 + error = -EPERM;
50956 + goto out2;
50957 + }
50958 +
50959 get_fs_root(current->fs, &root);
50960 error = lock_mount(&old);
50961 if (error)
50962 @@ -2785,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
50963 !nsown_capable(CAP_SYS_ADMIN))
50964 return -EPERM;
50965
50966 - if (fs->users != 1)
50967 + if (atomic_read(&fs->users) != 1)
50968 return -EINVAL;
50969
50970 get_mnt_ns(mnt_ns);
50971 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50972 index ebeb94c..ff35337 100644
50973 --- a/fs/nfs/inode.c
50974 +++ b/fs/nfs/inode.c
50975 @@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50976 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50977 }
50978
50979 -static atomic_long_t nfs_attr_generation_counter;
50980 +static atomic_long_unchecked_t nfs_attr_generation_counter;
50981
50982 static unsigned long nfs_read_attr_generation_counter(void)
50983 {
50984 - return atomic_long_read(&nfs_attr_generation_counter);
50985 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50986 }
50987
50988 unsigned long nfs_inc_attr_generation_counter(void)
50989 {
50990 - return atomic_long_inc_return(&nfs_attr_generation_counter);
50991 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50992 }
50993
50994 void nfs_fattr_init(struct nfs_fattr *fattr)
50995 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50996 index d586117..143d568 100644
50997 --- a/fs/nfsd/vfs.c
50998 +++ b/fs/nfsd/vfs.c
50999 @@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51000 } else {
51001 oldfs = get_fs();
51002 set_fs(KERNEL_DS);
51003 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51004 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51005 set_fs(oldfs);
51006 }
51007
51008 @@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51009
51010 /* Write the data. */
51011 oldfs = get_fs(); set_fs(KERNEL_DS);
51012 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51013 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51014 set_fs(oldfs);
51015 if (host_err < 0)
51016 goto out_nfserr;
51017 @@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51018 */
51019
51020 oldfs = get_fs(); set_fs(KERNEL_DS);
51021 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
51022 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
51023 set_fs(oldfs);
51024
51025 if (host_err < 0)
51026 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
51027 index 9ff4a5e..deb1f0f 100644
51028 --- a/fs/notify/fanotify/fanotify_user.c
51029 +++ b/fs/notify/fanotify/fanotify_user.c
51030 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
51031
51032 fd = fanotify_event_metadata.fd;
51033 ret = -EFAULT;
51034 - if (copy_to_user(buf, &fanotify_event_metadata,
51035 - fanotify_event_metadata.event_len))
51036 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
51037 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
51038 goto out_close_fd;
51039
51040 ret = prepare_for_access_response(group, event, fd);
51041 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51042 index 7b51b05..5ea5ef6 100644
51043 --- a/fs/notify/notification.c
51044 +++ b/fs/notify/notification.c
51045 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51046 * get set to 0 so it will never get 'freed'
51047 */
51048 static struct fsnotify_event *q_overflow_event;
51049 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51050 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51051
51052 /**
51053 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51054 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51055 */
51056 u32 fsnotify_get_cookie(void)
51057 {
51058 - return atomic_inc_return(&fsnotify_sync_cookie);
51059 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51060 }
51061 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51062
51063 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51064 index 99e3610..02c1068 100644
51065 --- a/fs/ntfs/dir.c
51066 +++ b/fs/ntfs/dir.c
51067 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
51068 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51069 ~(s64)(ndir->itype.index.block_size - 1)));
51070 /* Bounds checks. */
51071 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51072 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51073 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51074 "inode 0x%lx or driver bug.", vdir->i_ino);
51075 goto err_out;
51076 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51077 index 5b2d4f0..c6de396 100644
51078 --- a/fs/ntfs/file.c
51079 +++ b/fs/ntfs/file.c
51080 @@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51081 #endif /* NTFS_RW */
51082 };
51083
51084 -const struct file_operations ntfs_empty_file_ops = {};
51085 +const struct file_operations ntfs_empty_file_ops __read_only;
51086
51087 -const struct inode_operations ntfs_empty_inode_ops = {};
51088 +const struct inode_operations ntfs_empty_inode_ops __read_only;
51089 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51090 index a9f78c7..ed8a381 100644
51091 --- a/fs/ocfs2/localalloc.c
51092 +++ b/fs/ocfs2/localalloc.c
51093 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51094 goto bail;
51095 }
51096
51097 - atomic_inc(&osb->alloc_stats.moves);
51098 + atomic_inc_unchecked(&osb->alloc_stats.moves);
51099
51100 bail:
51101 if (handle)
51102 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51103 index d355e6e..578d905 100644
51104 --- a/fs/ocfs2/ocfs2.h
51105 +++ b/fs/ocfs2/ocfs2.h
51106 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
51107
51108 struct ocfs2_alloc_stats
51109 {
51110 - atomic_t moves;
51111 - atomic_t local_data;
51112 - atomic_t bitmap_data;
51113 - atomic_t bg_allocs;
51114 - atomic_t bg_extends;
51115 + atomic_unchecked_t moves;
51116 + atomic_unchecked_t local_data;
51117 + atomic_unchecked_t bitmap_data;
51118 + atomic_unchecked_t bg_allocs;
51119 + atomic_unchecked_t bg_extends;
51120 };
51121
51122 enum ocfs2_local_alloc_state
51123 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51124 index f169da4..9112253 100644
51125 --- a/fs/ocfs2/suballoc.c
51126 +++ b/fs/ocfs2/suballoc.c
51127 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51128 mlog_errno(status);
51129 goto bail;
51130 }
51131 - atomic_inc(&osb->alloc_stats.bg_extends);
51132 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51133
51134 /* You should never ask for this much metadata */
51135 BUG_ON(bits_wanted >
51136 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
51137 mlog_errno(status);
51138 goto bail;
51139 }
51140 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51141 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51142
51143 *suballoc_loc = res.sr_bg_blkno;
51144 *suballoc_bit_start = res.sr_bit_offset;
51145 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
51146 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
51147 res->sr_bits);
51148
51149 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51150 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51151
51152 BUG_ON(res->sr_bits != 1);
51153
51154 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
51155 mlog_errno(status);
51156 goto bail;
51157 }
51158 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51159 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51160
51161 BUG_ON(res.sr_bits != 1);
51162
51163 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51164 cluster_start,
51165 num_clusters);
51166 if (!status)
51167 - atomic_inc(&osb->alloc_stats.local_data);
51168 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
51169 } else {
51170 if (min_clusters > (osb->bitmap_cpg - 1)) {
51171 /* The only paths asking for contiguousness
51172 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51173 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51174 res.sr_bg_blkno,
51175 res.sr_bit_offset);
51176 - atomic_inc(&osb->alloc_stats.bitmap_data);
51177 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51178 *num_clusters = res.sr_bits;
51179 }
51180 }
51181 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51182 index 0e91ec2..f4b3fc6 100644
51183 --- a/fs/ocfs2/super.c
51184 +++ b/fs/ocfs2/super.c
51185 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51186 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51187 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51188 "Stats",
51189 - atomic_read(&osb->alloc_stats.bitmap_data),
51190 - atomic_read(&osb->alloc_stats.local_data),
51191 - atomic_read(&osb->alloc_stats.bg_allocs),
51192 - atomic_read(&osb->alloc_stats.moves),
51193 - atomic_read(&osb->alloc_stats.bg_extends));
51194 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51195 + atomic_read_unchecked(&osb->alloc_stats.local_data),
51196 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51197 + atomic_read_unchecked(&osb->alloc_stats.moves),
51198 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51199
51200 out += snprintf(buf + out, len - out,
51201 "%10s => State: %u Descriptor: %llu Size: %u bits "
51202 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51203 spin_lock_init(&osb->osb_xattr_lock);
51204 ocfs2_init_steal_slots(osb);
51205
51206 - atomic_set(&osb->alloc_stats.moves, 0);
51207 - atomic_set(&osb->alloc_stats.local_data, 0);
51208 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
51209 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
51210 - atomic_set(&osb->alloc_stats.bg_extends, 0);
51211 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51212 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51213 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51214 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51215 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51216
51217 /* Copy the blockcheck stats from the superblock probe */
51218 osb->osb_ecc_stats = *stats;
51219 diff --git a/fs/open.c b/fs/open.c
51220 index 9b33c0c..2ffcca2 100644
51221 --- a/fs/open.c
51222 +++ b/fs/open.c
51223 @@ -31,6 +31,8 @@
51224 #include <linux/ima.h>
51225 #include <linux/dnotify.h>
51226
51227 +#define CREATE_TRACE_POINTS
51228 +#include <trace/events/fs.h>
51229 #include "internal.h"
51230
51231 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
51232 @@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
51233 error = locks_verify_truncate(inode, NULL, length);
51234 if (!error)
51235 error = security_path_truncate(path);
51236 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
51237 + error = -EACCES;
51238 if (!error)
51239 error = do_truncate(path->dentry, length, 0, NULL);
51240
51241 @@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
51242 error = locks_verify_truncate(inode, f.file, length);
51243 if (!error)
51244 error = security_path_truncate(&f.file->f_path);
51245 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
51246 + error = -EACCES;
51247 if (!error)
51248 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
51249 sb_end_write(inode->i_sb);
51250 @@ -373,6 +379,9 @@ retry:
51251 if (__mnt_is_readonly(path.mnt))
51252 res = -EROFS;
51253
51254 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51255 + res = -EACCES;
51256 +
51257 out_path_release:
51258 path_put(&path);
51259 if (retry_estale(res, lookup_flags)) {
51260 @@ -404,6 +413,8 @@ retry:
51261 if (error)
51262 goto dput_and_out;
51263
51264 + gr_log_chdir(path.dentry, path.mnt);
51265 +
51266 set_fs_pwd(current->fs, &path);
51267
51268 dput_and_out:
51269 @@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51270 goto out_putf;
51271
51272 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
51273 +
51274 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
51275 + error = -EPERM;
51276 +
51277 + if (!error)
51278 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
51279 +
51280 if (!error)
51281 set_fs_pwd(current->fs, &f.file->f_path);
51282 out_putf:
51283 @@ -462,7 +480,13 @@ retry:
51284 if (error)
51285 goto dput_and_out;
51286
51287 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51288 + goto dput_and_out;
51289 +
51290 set_fs_root(current->fs, &path);
51291 +
51292 + gr_handle_chroot_chdir(&path);
51293 +
51294 error = 0;
51295 dput_and_out:
51296 path_put(&path);
51297 @@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
51298 if (error)
51299 return error;
51300 mutex_lock(&inode->i_mutex);
51301 +
51302 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
51303 + error = -EACCES;
51304 + goto out_unlock;
51305 + }
51306 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
51307 + error = -EACCES;
51308 + goto out_unlock;
51309 + }
51310 +
51311 error = security_path_chmod(path, mode);
51312 if (error)
51313 goto out_unlock;
51314 @@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
51315 uid = make_kuid(current_user_ns(), user);
51316 gid = make_kgid(current_user_ns(), group);
51317
51318 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
51319 + return -EACCES;
51320 +
51321 newattrs.ia_valid = ATTR_CTIME;
51322 if (user != (uid_t) -1) {
51323 if (!uid_valid(uid))
51324 @@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
51325 } else {
51326 fsnotify_open(f);
51327 fd_install(fd, f);
51328 + trace_do_sys_open(tmp->name, flags, mode);
51329 }
51330 }
51331 putname(tmp);
51332 diff --git a/fs/pipe.c b/fs/pipe.c
51333 index bd3479d..fb92c4d 100644
51334 --- a/fs/pipe.c
51335 +++ b/fs/pipe.c
51336 @@ -438,9 +438,9 @@ redo:
51337 }
51338 if (bufs) /* More to do? */
51339 continue;
51340 - if (!pipe->writers)
51341 + if (!atomic_read(&pipe->writers))
51342 break;
51343 - if (!pipe->waiting_writers) {
51344 + if (!atomic_read(&pipe->waiting_writers)) {
51345 /* syscall merging: Usually we must not sleep
51346 * if O_NONBLOCK is set, or if we got some data.
51347 * But if a writer sleeps in kernel space, then
51348 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
51349 mutex_lock(&inode->i_mutex);
51350 pipe = inode->i_pipe;
51351
51352 - if (!pipe->readers) {
51353 + if (!atomic_read(&pipe->readers)) {
51354 send_sig(SIGPIPE, current, 0);
51355 ret = -EPIPE;
51356 goto out;
51357 @@ -553,7 +553,7 @@ redo1:
51358 for (;;) {
51359 int bufs;
51360
51361 - if (!pipe->readers) {
51362 + if (!atomic_read(&pipe->readers)) {
51363 send_sig(SIGPIPE, current, 0);
51364 if (!ret)
51365 ret = -EPIPE;
51366 @@ -644,9 +644,9 @@ redo2:
51367 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
51368 do_wakeup = 0;
51369 }
51370 - pipe->waiting_writers++;
51371 + atomic_inc(&pipe->waiting_writers);
51372 pipe_wait(pipe);
51373 - pipe->waiting_writers--;
51374 + atomic_dec(&pipe->waiting_writers);
51375 }
51376 out:
51377 mutex_unlock(&inode->i_mutex);
51378 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51379 mask = 0;
51380 if (filp->f_mode & FMODE_READ) {
51381 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
51382 - if (!pipe->writers && filp->f_version != pipe->w_counter)
51383 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
51384 mask |= POLLHUP;
51385 }
51386
51387 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51388 * Most Unices do not set POLLERR for FIFOs but on Linux they
51389 * behave exactly like pipes for poll().
51390 */
51391 - if (!pipe->readers)
51392 + if (!atomic_read(&pipe->readers))
51393 mask |= POLLERR;
51394 }
51395
51396 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
51397
51398 mutex_lock(&inode->i_mutex);
51399 pipe = inode->i_pipe;
51400 - pipe->readers -= decr;
51401 - pipe->writers -= decw;
51402 + atomic_sub(decr, &pipe->readers);
51403 + atomic_sub(decw, &pipe->writers);
51404
51405 - if (!pipe->readers && !pipe->writers) {
51406 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
51407 free_pipe_info(inode);
51408 } else {
51409 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
51410 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
51411
51412 if (inode->i_pipe) {
51413 ret = 0;
51414 - inode->i_pipe->readers++;
51415 + atomic_inc(&inode->i_pipe->readers);
51416 }
51417
51418 mutex_unlock(&inode->i_mutex);
51419 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
51420
51421 if (inode->i_pipe) {
51422 ret = 0;
51423 - inode->i_pipe->writers++;
51424 + atomic_inc(&inode->i_pipe->writers);
51425 }
51426
51427 mutex_unlock(&inode->i_mutex);
51428 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
51429 if (inode->i_pipe) {
51430 ret = 0;
51431 if (filp->f_mode & FMODE_READ)
51432 - inode->i_pipe->readers++;
51433 + atomic_inc(&inode->i_pipe->readers);
51434 if (filp->f_mode & FMODE_WRITE)
51435 - inode->i_pipe->writers++;
51436 + atomic_inc(&inode->i_pipe->writers);
51437 }
51438
51439 mutex_unlock(&inode->i_mutex);
51440 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
51441 inode->i_pipe = NULL;
51442 }
51443
51444 -static struct vfsmount *pipe_mnt __read_mostly;
51445 +struct vfsmount *pipe_mnt __read_mostly;
51446
51447 /*
51448 * pipefs_dname() is called from d_path().
51449 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
51450 goto fail_iput;
51451 inode->i_pipe = pipe;
51452
51453 - pipe->readers = pipe->writers = 1;
51454 + atomic_set(&pipe->readers, 1);
51455 + atomic_set(&pipe->writers, 1);
51456 inode->i_fop = &rdwr_pipefifo_fops;
51457
51458 /*
51459 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
51460 index 15af622..0e9f4467 100644
51461 --- a/fs/proc/Kconfig
51462 +++ b/fs/proc/Kconfig
51463 @@ -30,12 +30,12 @@ config PROC_FS
51464
51465 config PROC_KCORE
51466 bool "/proc/kcore support" if !ARM
51467 - depends on PROC_FS && MMU
51468 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
51469
51470 config PROC_VMCORE
51471 bool "/proc/vmcore support"
51472 - depends on PROC_FS && CRASH_DUMP
51473 - default y
51474 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
51475 + default n
51476 help
51477 Exports the dump image of crashed kernel in ELF format.
51478
51479 @@ -59,8 +59,8 @@ config PROC_SYSCTL
51480 limited in memory.
51481
51482 config PROC_PAGE_MONITOR
51483 - default y
51484 - depends on PROC_FS && MMU
51485 + default n
51486 + depends on PROC_FS && MMU && !GRKERNSEC
51487 bool "Enable /proc page monitoring" if EXPERT
51488 help
51489 Various /proc files exist to monitor process memory utilization:
51490 diff --git a/fs/proc/array.c b/fs/proc/array.c
51491 index 6a91e6f..e54dbc14 100644
51492 --- a/fs/proc/array.c
51493 +++ b/fs/proc/array.c
51494 @@ -60,6 +60,7 @@
51495 #include <linux/tty.h>
51496 #include <linux/string.h>
51497 #include <linux/mman.h>
51498 +#include <linux/grsecurity.h>
51499 #include <linux/proc_fs.h>
51500 #include <linux/ioport.h>
51501 #include <linux/uaccess.h>
51502 @@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
51503 seq_putc(m, '\n');
51504 }
51505
51506 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51507 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
51508 +{
51509 + if (p->mm)
51510 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
51511 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
51512 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
51513 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
51514 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
51515 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
51516 + else
51517 + seq_printf(m, "PaX:\t-----\n");
51518 +}
51519 +#endif
51520 +
51521 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51522 struct pid *pid, struct task_struct *task)
51523 {
51524 @@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51525 task_cpus_allowed(m, task);
51526 cpuset_task_status_allowed(m, task);
51527 task_context_switch_counts(m, task);
51528 +
51529 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51530 + task_pax(m, task);
51531 +#endif
51532 +
51533 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
51534 + task_grsec_rbac(m, task);
51535 +#endif
51536 +
51537 return 0;
51538 }
51539
51540 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51541 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51542 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51543 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51544 +#endif
51545 +
51546 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51547 struct pid *pid, struct task_struct *task, int whole)
51548 {
51549 @@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51550 char tcomm[sizeof(task->comm)];
51551 unsigned long flags;
51552
51553 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51554 + if (current->exec_id != m->exec_id) {
51555 + gr_log_badprocpid("stat");
51556 + return 0;
51557 + }
51558 +#endif
51559 +
51560 state = *get_task_state(task);
51561 vsize = eip = esp = 0;
51562 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51563 @@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51564 gtime = task->gtime;
51565 }
51566
51567 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51568 + if (PAX_RAND_FLAGS(mm)) {
51569 + eip = 0;
51570 + esp = 0;
51571 + wchan = 0;
51572 + }
51573 +#endif
51574 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51575 + wchan = 0;
51576 + eip =0;
51577 + esp =0;
51578 +#endif
51579 +
51580 /* scale priority and nice values from timeslices to -20..20 */
51581 /* to make it look like a "normal" Unix priority/nice value */
51582 priority = task_prio(task);
51583 @@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51584 seq_put_decimal_ull(m, ' ', vsize);
51585 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
51586 seq_put_decimal_ull(m, ' ', rsslim);
51587 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51588 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
51589 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
51590 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
51591 +#else
51592 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
51593 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
51594 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
51595 +#endif
51596 seq_put_decimal_ull(m, ' ', esp);
51597 seq_put_decimal_ull(m, ' ', eip);
51598 /* The signal information here is obsolete.
51599 @@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51600 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
51601 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
51602
51603 - if (mm && permitted) {
51604 + if (mm && permitted
51605 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51606 + && !PAX_RAND_FLAGS(mm)
51607 +#endif
51608 + ) {
51609 seq_put_decimal_ull(m, ' ', mm->start_data);
51610 seq_put_decimal_ull(m, ' ', mm->end_data);
51611 seq_put_decimal_ull(m, ' ', mm->start_brk);
51612 @@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51613 struct pid *pid, struct task_struct *task)
51614 {
51615 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
51616 - struct mm_struct *mm = get_task_mm(task);
51617 + struct mm_struct *mm;
51618
51619 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51620 + if (current->exec_id != m->exec_id) {
51621 + gr_log_badprocpid("statm");
51622 + return 0;
51623 + }
51624 +#endif
51625 + mm = get_task_mm(task);
51626 if (mm) {
51627 size = task_statm(mm, &shared, &text, &data, &resident);
51628 mmput(mm);
51629 @@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51630 return 0;
51631 }
51632
51633 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51634 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
51635 +{
51636 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
51637 +}
51638 +#endif
51639 +
51640 #ifdef CONFIG_CHECKPOINT_RESTORE
51641 static struct pid *
51642 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
51643 diff --git a/fs/proc/base.c b/fs/proc/base.c
51644 index 9b43ff77..3d6a99f 100644
51645 --- a/fs/proc/base.c
51646 +++ b/fs/proc/base.c
51647 @@ -111,6 +111,14 @@ struct pid_entry {
51648 union proc_op op;
51649 };
51650
51651 +struct getdents_callback {
51652 + struct linux_dirent __user * current_dir;
51653 + struct linux_dirent __user * previous;
51654 + struct file * file;
51655 + int count;
51656 + int error;
51657 +};
51658 +
51659 #define NOD(NAME, MODE, IOP, FOP, OP) { \
51660 .name = (NAME), \
51661 .len = sizeof(NAME) - 1, \
51662 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
51663 if (!mm->arg_end)
51664 goto out_mm; /* Shh! No looking before we're done */
51665
51666 + if (gr_acl_handle_procpidmem(task))
51667 + goto out_mm;
51668 +
51669 len = mm->arg_end - mm->arg_start;
51670
51671 if (len > PAGE_SIZE)
51672 @@ -235,12 +246,28 @@ out:
51673 return res;
51674 }
51675
51676 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51677 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51678 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51679 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51680 +#endif
51681 +
51682 static int proc_pid_auxv(struct task_struct *task, char *buffer)
51683 {
51684 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
51685 int res = PTR_ERR(mm);
51686 if (mm && !IS_ERR(mm)) {
51687 unsigned int nwords = 0;
51688 +
51689 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51690 + /* allow if we're currently ptracing this task */
51691 + if (PAX_RAND_FLAGS(mm) &&
51692 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
51693 + mmput(mm);
51694 + return 0;
51695 + }
51696 +#endif
51697 +
51698 do {
51699 nwords += 2;
51700 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
51701 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
51702 }
51703
51704
51705 -#ifdef CONFIG_KALLSYMS
51706 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51707 /*
51708 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
51709 * Returns the resolved symbol. If that fails, simply return the address.
51710 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
51711 mutex_unlock(&task->signal->cred_guard_mutex);
51712 }
51713
51714 -#ifdef CONFIG_STACKTRACE
51715 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51716
51717 #define MAX_STACK_TRACE_DEPTH 64
51718
51719 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
51720 return count;
51721 }
51722
51723 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51724 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51725 static int proc_pid_syscall(struct task_struct *task, char *buffer)
51726 {
51727 long nr;
51728 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
51729 /************************************************************************/
51730
51731 /* permission checks */
51732 -static int proc_fd_access_allowed(struct inode *inode)
51733 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
51734 {
51735 struct task_struct *task;
51736 int allowed = 0;
51737 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
51738 */
51739 task = get_proc_task(inode);
51740 if (task) {
51741 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51742 + if (log)
51743 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51744 + else
51745 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51746 put_task_struct(task);
51747 }
51748 return allowed;
51749 @@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
51750 struct task_struct *task,
51751 int hide_pid_min)
51752 {
51753 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51754 + return false;
51755 +
51756 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51757 + rcu_read_lock();
51758 + {
51759 + const struct cred *tmpcred = current_cred();
51760 + const struct cred *cred = __task_cred(task);
51761 +
51762 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
51763 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51764 + || in_group_p(grsec_proc_gid)
51765 +#endif
51766 + ) {
51767 + rcu_read_unlock();
51768 + return true;
51769 + }
51770 + }
51771 + rcu_read_unlock();
51772 +
51773 + if (!pid->hide_pid)
51774 + return false;
51775 +#endif
51776 +
51777 if (pid->hide_pid < hide_pid_min)
51778 return true;
51779 if (in_group_p(pid->pid_gid))
51780 return true;
51781 +
51782 return ptrace_may_access(task, PTRACE_MODE_READ);
51783 }
51784
51785 @@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51786 put_task_struct(task);
51787
51788 if (!has_perms) {
51789 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51790 + {
51791 +#else
51792 if (pid->hide_pid == 2) {
51793 +#endif
51794 /*
51795 * Let's make getdents(), stat(), and open()
51796 * consistent with each other. If a process
51797 @@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51798 if (!task)
51799 return -ESRCH;
51800
51801 + if (gr_acl_handle_procpidmem(task)) {
51802 + put_task_struct(task);
51803 + return -EPERM;
51804 + }
51805 +
51806 mm = mm_access(task, mode);
51807 put_task_struct(task);
51808
51809 @@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51810
51811 file->private_data = mm;
51812
51813 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51814 + file->f_version = current->exec_id;
51815 +#endif
51816 +
51817 return 0;
51818 }
51819
51820 @@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51821 ssize_t copied;
51822 char *page;
51823
51824 +#ifdef CONFIG_GRKERNSEC
51825 + if (write)
51826 + return -EPERM;
51827 +#endif
51828 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51829 + if (file->f_version != current->exec_id) {
51830 + gr_log_badprocpid("mem");
51831 + return 0;
51832 + }
51833 +#endif
51834 +
51835 if (!mm)
51836 return 0;
51837
51838 @@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51839 if (!mm)
51840 return 0;
51841
51842 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51843 + if (file->f_version != current->exec_id) {
51844 + gr_log_badprocpid("environ");
51845 + return 0;
51846 + }
51847 +#endif
51848 +
51849 page = (char *)__get_free_page(GFP_TEMPORARY);
51850 if (!page)
51851 return -ENOMEM;
51852 @@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51853 int error = -EACCES;
51854
51855 /* Are we allowed to snoop on the tasks file descriptors? */
51856 - if (!proc_fd_access_allowed(inode))
51857 + if (!proc_fd_access_allowed(inode, 0))
51858 goto out;
51859
51860 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51861 @@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51862 struct path path;
51863
51864 /* Are we allowed to snoop on the tasks file descriptors? */
51865 - if (!proc_fd_access_allowed(inode))
51866 - goto out;
51867 + /* logging this is needed for learning on chromium to work properly,
51868 + but we don't want to flood the logs from 'ps' which does a readlink
51869 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51870 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
51871 + */
51872 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51873 + if (!proc_fd_access_allowed(inode,0))
51874 + goto out;
51875 + } else {
51876 + if (!proc_fd_access_allowed(inode,1))
51877 + goto out;
51878 + }
51879
51880 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51881 if (error)
51882 @@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51883 rcu_read_lock();
51884 cred = __task_cred(task);
51885 inode->i_uid = cred->euid;
51886 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51887 + inode->i_gid = grsec_proc_gid;
51888 +#else
51889 inode->i_gid = cred->egid;
51890 +#endif
51891 rcu_read_unlock();
51892 }
51893 security_task_to_inode(task, inode);
51894 @@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51895 return -ENOENT;
51896 }
51897 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51898 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51899 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51900 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51901 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51902 +#endif
51903 task_dumpable(task)) {
51904 cred = __task_cred(task);
51905 stat->uid = cred->euid;
51906 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51907 + stat->gid = grsec_proc_gid;
51908 +#else
51909 stat->gid = cred->egid;
51910 +#endif
51911 }
51912 }
51913 rcu_read_unlock();
51914 @@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51915
51916 if (task) {
51917 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51918 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51919 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51920 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51921 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51922 +#endif
51923 task_dumpable(task)) {
51924 rcu_read_lock();
51925 cred = __task_cred(task);
51926 inode->i_uid = cred->euid;
51927 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51928 + inode->i_gid = grsec_proc_gid;
51929 +#else
51930 inode->i_gid = cred->egid;
51931 +#endif
51932 rcu_read_unlock();
51933 } else {
51934 inode->i_uid = GLOBAL_ROOT_UID;
51935 @@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51936 if (!task)
51937 goto out_no_task;
51938
51939 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51940 + goto out;
51941 +
51942 /*
51943 * Yes, it does not scale. And it should not. Don't add
51944 * new entries into /proc/<tgid>/ without very good reasons.
51945 @@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
51946 if (!task)
51947 goto out_no_task;
51948
51949 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51950 + goto out;
51951 +
51952 ret = 0;
51953 i = filp->f_pos;
51954 switch (i) {
51955 @@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51956 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51957 #endif
51958 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51959 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51960 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51961 INF("syscall", S_IRUGO, proc_pid_syscall),
51962 #endif
51963 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51964 @@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51965 #ifdef CONFIG_SECURITY
51966 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51967 #endif
51968 -#ifdef CONFIG_KALLSYMS
51969 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51970 INF("wchan", S_IRUGO, proc_pid_wchan),
51971 #endif
51972 -#ifdef CONFIG_STACKTRACE
51973 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51974 ONE("stack", S_IRUGO, proc_pid_stack),
51975 #endif
51976 #ifdef CONFIG_SCHEDSTATS
51977 @@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51978 #ifdef CONFIG_HARDWALL
51979 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51980 #endif
51981 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51982 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51983 +#endif
51984 #ifdef CONFIG_USER_NS
51985 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51986 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51987 @@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51988 if (!inode)
51989 goto out;
51990
51991 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51992 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51993 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51994 + inode->i_gid = grsec_proc_gid;
51995 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51996 +#else
51997 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51998 +#endif
51999 inode->i_op = &proc_tgid_base_inode_operations;
52000 inode->i_fop = &proc_tgid_base_operations;
52001 inode->i_flags|=S_IMMUTABLE;
52002 @@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
52003 if (!task)
52004 goto out;
52005
52006 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52007 + goto out_put_task;
52008 +
52009 result = proc_pid_instantiate(dir, dentry, task, NULL);
52010 +out_put_task:
52011 put_task_struct(task);
52012 out:
52013 return result;
52014 @@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
52015 static int fake_filldir(void *buf, const char *name, int namelen,
52016 loff_t offset, u64 ino, unsigned d_type)
52017 {
52018 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
52019 + __buf->error = -EINVAL;
52020 return 0;
52021 }
52022
52023 @@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
52024 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52025 #endif
52026 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
52027 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52028 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52029 INF("syscall", S_IRUGO, proc_pid_syscall),
52030 #endif
52031 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52032 @@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
52033 #ifdef CONFIG_SECURITY
52034 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52035 #endif
52036 -#ifdef CONFIG_KALLSYMS
52037 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52038 INF("wchan", S_IRUGO, proc_pid_wchan),
52039 #endif
52040 -#ifdef CONFIG_STACKTRACE
52041 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52042 ONE("stack", S_IRUGO, proc_pid_stack),
52043 #endif
52044 #ifdef CONFIG_SCHEDSTATS
52045 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
52046 index 82676e3..5f8518a 100644
52047 --- a/fs/proc/cmdline.c
52048 +++ b/fs/proc/cmdline.c
52049 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
52050
52051 static int __init proc_cmdline_init(void)
52052 {
52053 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52054 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
52055 +#else
52056 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
52057 +#endif
52058 return 0;
52059 }
52060 module_init(proc_cmdline_init);
52061 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
52062 index b143471..bb105e5 100644
52063 --- a/fs/proc/devices.c
52064 +++ b/fs/proc/devices.c
52065 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
52066
52067 static int __init proc_devices_init(void)
52068 {
52069 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52070 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
52071 +#else
52072 proc_create("devices", 0, NULL, &proc_devinfo_operations);
52073 +#endif
52074 return 0;
52075 }
52076 module_init(proc_devices_init);
52077 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
52078 index d7a4a28..0201742 100644
52079 --- a/fs/proc/fd.c
52080 +++ b/fs/proc/fd.c
52081 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
52082 if (!task)
52083 return -ENOENT;
52084
52085 - files = get_files_struct(task);
52086 + if (!gr_acl_handle_procpidmem(task))
52087 + files = get_files_struct(task);
52088 put_task_struct(task);
52089
52090 if (files) {
52091 @@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
52092 */
52093 int proc_fd_permission(struct inode *inode, int mask)
52094 {
52095 + struct task_struct *task;
52096 int rv = generic_permission(inode, mask);
52097 - if (rv == 0)
52098 - return 0;
52099 +
52100 if (task_pid(current) == proc_pid(inode))
52101 rv = 0;
52102 +
52103 + task = get_proc_task(inode);
52104 + if (task == NULL)
52105 + return rv;
52106 +
52107 + if (gr_acl_handle_procpidmem(task))
52108 + rv = -EACCES;
52109 +
52110 + put_task_struct(task);
52111 +
52112 return rv;
52113 }
52114
52115 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52116 index 439ae688..c21ac36 100644
52117 --- a/fs/proc/inode.c
52118 +++ b/fs/proc/inode.c
52119 @@ -21,11 +21,17 @@
52120 #include <linux/seq_file.h>
52121 #include <linux/slab.h>
52122 #include <linux/mount.h>
52123 +#include <linux/grsecurity.h>
52124
52125 #include <asm/uaccess.h>
52126
52127 #include "internal.h"
52128
52129 +#ifdef CONFIG_PROC_SYSCTL
52130 +extern const struct inode_operations proc_sys_inode_operations;
52131 +extern const struct inode_operations proc_sys_dir_operations;
52132 +#endif
52133 +
52134 static void proc_evict_inode(struct inode *inode)
52135 {
52136 struct proc_dir_entry *de;
52137 @@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
52138 ns = PROC_I(inode)->ns;
52139 if (ns_ops && ns)
52140 ns_ops->put(ns);
52141 +
52142 +#ifdef CONFIG_PROC_SYSCTL
52143 + if (inode->i_op == &proc_sys_inode_operations ||
52144 + inode->i_op == &proc_sys_dir_operations)
52145 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52146 +#endif
52147 +
52148 }
52149
52150 static struct kmem_cache * proc_inode_cachep;
52151 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
52152 if (de->mode) {
52153 inode->i_mode = de->mode;
52154 inode->i_uid = de->uid;
52155 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52156 + inode->i_gid = grsec_proc_gid;
52157 +#else
52158 inode->i_gid = de->gid;
52159 +#endif
52160 }
52161 if (de->size)
52162 inode->i_size = de->size;
52163 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52164 index 252544c..04395b9 100644
52165 --- a/fs/proc/internal.h
52166 +++ b/fs/proc/internal.h
52167 @@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52168 struct pid *pid, struct task_struct *task);
52169 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52170 struct pid *pid, struct task_struct *task);
52171 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52172 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52173 +#endif
52174 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52175
52176 extern const struct file_operations proc_tid_children_operations;
52177 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52178 index e96d4f1..8b116ed 100644
52179 --- a/fs/proc/kcore.c
52180 +++ b/fs/proc/kcore.c
52181 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52182 * the addresses in the elf_phdr on our list.
52183 */
52184 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52185 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52186 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52187 + if (tsz > buflen)
52188 tsz = buflen;
52189 -
52190 +
52191 while (buflen) {
52192 struct kcore_list *m;
52193
52194 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52195 kfree(elf_buf);
52196 } else {
52197 if (kern_addr_valid(start)) {
52198 - unsigned long n;
52199 + char *elf_buf;
52200 + mm_segment_t oldfs;
52201
52202 - n = copy_to_user(buffer, (char *)start, tsz);
52203 - /*
52204 - * We cannot distinguish between fault on source
52205 - * and fault on destination. When this happens
52206 - * we clear too and hope it will trigger the
52207 - * EFAULT again.
52208 - */
52209 - if (n) {
52210 - if (clear_user(buffer + tsz - n,
52211 - n))
52212 + elf_buf = kmalloc(tsz, GFP_KERNEL);
52213 + if (!elf_buf)
52214 + return -ENOMEM;
52215 + oldfs = get_fs();
52216 + set_fs(KERNEL_DS);
52217 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52218 + set_fs(oldfs);
52219 + if (copy_to_user(buffer, elf_buf, tsz)) {
52220 + kfree(elf_buf);
52221 return -EFAULT;
52222 + }
52223 }
52224 + set_fs(oldfs);
52225 + kfree(elf_buf);
52226 } else {
52227 if (clear_user(buffer, tsz))
52228 return -EFAULT;
52229 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52230
52231 static int open_kcore(struct inode *inode, struct file *filp)
52232 {
52233 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52234 + return -EPERM;
52235 +#endif
52236 if (!capable(CAP_SYS_RAWIO))
52237 return -EPERM;
52238 if (kcore_need_update)
52239 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52240 index 80e4645..53e5fcf 100644
52241 --- a/fs/proc/meminfo.c
52242 +++ b/fs/proc/meminfo.c
52243 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52244 vmi.used >> 10,
52245 vmi.largest_chunk >> 10
52246 #ifdef CONFIG_MEMORY_FAILURE
52247 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52248 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52249 #endif
52250 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
52251 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
52252 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52253 index b1822dd..df622cb 100644
52254 --- a/fs/proc/nommu.c
52255 +++ b/fs/proc/nommu.c
52256 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
52257 if (len < 1)
52258 len = 1;
52259 seq_printf(m, "%*c", len, ' ');
52260 - seq_path(m, &file->f_path, "");
52261 + seq_path(m, &file->f_path, "\n\\");
52262 }
52263
52264 seq_putc(m, '\n');
52265 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
52266 index fe72cd0..cb9b67d 100644
52267 --- a/fs/proc/proc_net.c
52268 +++ b/fs/proc/proc_net.c
52269 @@ -23,6 +23,7 @@
52270 #include <linux/nsproxy.h>
52271 #include <net/net_namespace.h>
52272 #include <linux/seq_file.h>
52273 +#include <linux/grsecurity.h>
52274
52275 #include "internal.h"
52276
52277 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
52278 struct task_struct *task;
52279 struct nsproxy *ns;
52280 struct net *net = NULL;
52281 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52282 + const struct cred *cred = current_cred();
52283 +#endif
52284 +
52285 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52286 + if (cred->fsuid)
52287 + return net;
52288 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52289 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
52290 + return net;
52291 +#endif
52292
52293 rcu_read_lock();
52294 task = pid_task(proc_pid(dir), PIDTYPE_PID);
52295 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
52296 index 1827d88..9a60b01 100644
52297 --- a/fs/proc/proc_sysctl.c
52298 +++ b/fs/proc/proc_sysctl.c
52299 @@ -12,11 +12,15 @@
52300 #include <linux/module.h>
52301 #include "internal.h"
52302
52303 +extern int gr_handle_chroot_sysctl(const int op);
52304 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
52305 + const int op);
52306 +
52307 static const struct dentry_operations proc_sys_dentry_operations;
52308 static const struct file_operations proc_sys_file_operations;
52309 -static const struct inode_operations proc_sys_inode_operations;
52310 +const struct inode_operations proc_sys_inode_operations;
52311 static const struct file_operations proc_sys_dir_file_operations;
52312 -static const struct inode_operations proc_sys_dir_operations;
52313 +const struct inode_operations proc_sys_dir_operations;
52314
52315 void proc_sys_poll_notify(struct ctl_table_poll *poll)
52316 {
52317 @@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
52318
52319 err = NULL;
52320 d_set_d_op(dentry, &proc_sys_dentry_operations);
52321 +
52322 + gr_handle_proc_create(dentry, inode);
52323 +
52324 d_add(dentry, inode);
52325
52326 out:
52327 @@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52328 struct inode *inode = filp->f_path.dentry->d_inode;
52329 struct ctl_table_header *head = grab_header(inode);
52330 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
52331 + int op = write ? MAY_WRITE : MAY_READ;
52332 ssize_t error;
52333 size_t res;
52334
52335 @@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52336 * and won't be until we finish.
52337 */
52338 error = -EPERM;
52339 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
52340 + if (sysctl_perm(head, table, op))
52341 goto out;
52342
52343 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
52344 @@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52345 if (!table->proc_handler)
52346 goto out;
52347
52348 +#ifdef CONFIG_GRKERNSEC
52349 + error = -EPERM;
52350 + if (gr_handle_chroot_sysctl(op))
52351 + goto out;
52352 + dget(filp->f_path.dentry);
52353 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
52354 + dput(filp->f_path.dentry);
52355 + goto out;
52356 + }
52357 + dput(filp->f_path.dentry);
52358 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
52359 + goto out;
52360 + if (write && !capable(CAP_SYS_ADMIN))
52361 + goto out;
52362 +#endif
52363 +
52364 /* careful: calling conventions are nasty here */
52365 res = count;
52366 error = table->proc_handler(table, write, buf, &res, ppos);
52367 @@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
52368 return -ENOMEM;
52369 } else {
52370 d_set_d_op(child, &proc_sys_dentry_operations);
52371 +
52372 + gr_handle_proc_create(child, inode);
52373 +
52374 d_add(child, inode);
52375 }
52376 } else {
52377 @@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
52378 if ((*pos)++ < file->f_pos)
52379 return 0;
52380
52381 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
52382 + return 0;
52383 +
52384 if (unlikely(S_ISLNK(table->mode)))
52385 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
52386 else
52387 @@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
52388 if (IS_ERR(head))
52389 return PTR_ERR(head);
52390
52391 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
52392 + return -ENOENT;
52393 +
52394 generic_fillattr(inode, stat);
52395 if (table)
52396 stat->mode = (stat->mode & S_IFMT) | table->mode;
52397 @@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
52398 .llseek = generic_file_llseek,
52399 };
52400
52401 -static const struct inode_operations proc_sys_inode_operations = {
52402 +const struct inode_operations proc_sys_inode_operations = {
52403 .permission = proc_sys_permission,
52404 .setattr = proc_sys_setattr,
52405 .getattr = proc_sys_getattr,
52406 };
52407
52408 -static const struct inode_operations proc_sys_dir_operations = {
52409 +const struct inode_operations proc_sys_dir_operations = {
52410 .lookup = proc_sys_lookup,
52411 .permission = proc_sys_permission,
52412 .setattr = proc_sys_setattr,
52413 diff --git a/fs/proc/root.c b/fs/proc/root.c
52414 index c6e9fac..a740964 100644
52415 --- a/fs/proc/root.c
52416 +++ b/fs/proc/root.c
52417 @@ -176,7 +176,15 @@ void __init proc_root_init(void)
52418 #ifdef CONFIG_PROC_DEVICETREE
52419 proc_device_tree_init();
52420 #endif
52421 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52422 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52423 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
52424 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52425 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
52426 +#endif
52427 +#else
52428 proc_mkdir("bus", NULL);
52429 +#endif
52430 proc_sys_init();
52431 }
52432
52433 diff --git a/fs/proc/self.c b/fs/proc/self.c
52434 index aa5cc3b..c91a5d0 100644
52435 --- a/fs/proc/self.c
52436 +++ b/fs/proc/self.c
52437 @@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52438 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52439 void *cookie)
52440 {
52441 - char *s = nd_get_link(nd);
52442 + const char *s = nd_get_link(nd);
52443 if (!IS_ERR(s))
52444 kfree(s);
52445 }
52446 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
52447 index ca5ce7f..02c1cf0 100644
52448 --- a/fs/proc/task_mmu.c
52449 +++ b/fs/proc/task_mmu.c
52450 @@ -11,12 +11,19 @@
52451 #include <linux/rmap.h>
52452 #include <linux/swap.h>
52453 #include <linux/swapops.h>
52454 +#include <linux/grsecurity.h>
52455
52456 #include <asm/elf.h>
52457 #include <asm/uaccess.h>
52458 #include <asm/tlbflush.h>
52459 #include "internal.h"
52460
52461 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52462 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52463 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
52464 + _mm->pax_flags & MF_PAX_SEGMEXEC))
52465 +#endif
52466 +
52467 void task_mem(struct seq_file *m, struct mm_struct *mm)
52468 {
52469 unsigned long data, text, lib, swap;
52470 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52471 "VmExe:\t%8lu kB\n"
52472 "VmLib:\t%8lu kB\n"
52473 "VmPTE:\t%8lu kB\n"
52474 - "VmSwap:\t%8lu kB\n",
52475 - hiwater_vm << (PAGE_SHIFT-10),
52476 + "VmSwap:\t%8lu kB\n"
52477 +
52478 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52479 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
52480 +#endif
52481 +
52482 + ,hiwater_vm << (PAGE_SHIFT-10),
52483 total_vm << (PAGE_SHIFT-10),
52484 mm->locked_vm << (PAGE_SHIFT-10),
52485 mm->pinned_vm << (PAGE_SHIFT-10),
52486 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52487 data << (PAGE_SHIFT-10),
52488 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
52489 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
52490 - swap << (PAGE_SHIFT-10));
52491 + swap << (PAGE_SHIFT-10)
52492 +
52493 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52494 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52495 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
52496 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
52497 +#else
52498 + , mm->context.user_cs_base
52499 + , mm->context.user_cs_limit
52500 +#endif
52501 +#endif
52502 +
52503 + );
52504 }
52505
52506 unsigned long task_vsize(struct mm_struct *mm)
52507 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52508 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
52509 }
52510
52511 - /* We don't show the stack guard page in /proc/maps */
52512 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52513 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
52514 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
52515 +#else
52516 start = vma->vm_start;
52517 - if (stack_guard_page_start(vma, start))
52518 - start += PAGE_SIZE;
52519 end = vma->vm_end;
52520 - if (stack_guard_page_end(vma, end))
52521 - end -= PAGE_SIZE;
52522 +#endif
52523
52524 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
52525 start,
52526 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52527 flags & VM_WRITE ? 'w' : '-',
52528 flags & VM_EXEC ? 'x' : '-',
52529 flags & VM_MAYSHARE ? 's' : 'p',
52530 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52531 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
52532 +#else
52533 pgoff,
52534 +#endif
52535 MAJOR(dev), MINOR(dev), ino, &len);
52536
52537 /*
52538 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52539 */
52540 if (file) {
52541 pad_len_spaces(m, len);
52542 - seq_path(m, &file->f_path, "\n");
52543 + seq_path(m, &file->f_path, "\n\\");
52544 goto done;
52545 }
52546
52547 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52548 * Thread stack in /proc/PID/task/TID/maps or
52549 * the main process stack.
52550 */
52551 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
52552 - vma->vm_end >= mm->start_stack)) {
52553 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
52554 + (vma->vm_start <= mm->start_stack &&
52555 + vma->vm_end >= mm->start_stack)) {
52556 name = "[stack]";
52557 } else {
52558 /* Thread stack in /proc/PID/maps */
52559 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
52560 struct proc_maps_private *priv = m->private;
52561 struct task_struct *task = priv->task;
52562
52563 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52564 + if (current->exec_id != m->exec_id) {
52565 + gr_log_badprocpid("maps");
52566 + return 0;
52567 + }
52568 +#endif
52569 +
52570 show_map_vma(m, vma, is_pid);
52571
52572 if (m->count < m->size) /* vma is copied successfully */
52573 @@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52574 .private = &mss,
52575 };
52576
52577 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52578 + if (current->exec_id != m->exec_id) {
52579 + gr_log_badprocpid("smaps");
52580 + return 0;
52581 + }
52582 +#endif
52583 memset(&mss, 0, sizeof mss);
52584 - mss.vma = vma;
52585 - /* mmap_sem is held in m_start */
52586 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52587 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52588 -
52589 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52590 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
52591 +#endif
52592 + mss.vma = vma;
52593 + /* mmap_sem is held in m_start */
52594 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52595 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52596 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52597 + }
52598 +#endif
52599 show_map_vma(m, vma, is_pid);
52600
52601 seq_printf(m,
52602 @@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52603 "KernelPageSize: %8lu kB\n"
52604 "MMUPageSize: %8lu kB\n"
52605 "Locked: %8lu kB\n",
52606 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52607 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
52608 +#else
52609 (vma->vm_end - vma->vm_start) >> 10,
52610 +#endif
52611 mss.resident >> 10,
52612 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
52613 mss.shared_clean >> 10,
52614 @@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52615 int n;
52616 char buffer[50];
52617
52618 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52619 + if (current->exec_id != m->exec_id) {
52620 + gr_log_badprocpid("numa_maps");
52621 + return 0;
52622 + }
52623 +#endif
52624 +
52625 if (!mm)
52626 return 0;
52627
52628 @@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52629 mpol_to_str(buffer, sizeof(buffer), pol);
52630 mpol_cond_put(pol);
52631
52632 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52633 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
52634 +#else
52635 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
52636 +#endif
52637
52638 if (file) {
52639 seq_printf(m, " file=");
52640 - seq_path(m, &file->f_path, "\n\t= ");
52641 + seq_path(m, &file->f_path, "\n\t\\= ");
52642 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52643 seq_printf(m, " heap");
52644 } else {
52645 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
52646 index 1ccfa53..0848f95 100644
52647 --- a/fs/proc/task_nommu.c
52648 +++ b/fs/proc/task_nommu.c
52649 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52650 else
52651 bytes += kobjsize(mm);
52652
52653 - if (current->fs && current->fs->users > 1)
52654 + if (current->fs && atomic_read(&current->fs->users) > 1)
52655 sbytes += kobjsize(current->fs);
52656 else
52657 bytes += kobjsize(current->fs);
52658 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
52659
52660 if (file) {
52661 pad_len_spaces(m, len);
52662 - seq_path(m, &file->f_path, "");
52663 + seq_path(m, &file->f_path, "\n\\");
52664 } else if (mm) {
52665 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
52666
52667 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
52668 index 16e8abb..2dcf914 100644
52669 --- a/fs/quota/netlink.c
52670 +++ b/fs/quota/netlink.c
52671 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
52672 void quota_send_warning(struct kqid qid, dev_t dev,
52673 const char warntype)
52674 {
52675 - static atomic_t seq;
52676 + static atomic_unchecked_t seq;
52677 struct sk_buff *skb;
52678 void *msg_head;
52679 int ret;
52680 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
52681 "VFS: Not enough memory to send quota warning.\n");
52682 return;
52683 }
52684 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
52685 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
52686 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
52687 if (!msg_head) {
52688 printk(KERN_ERR
52689 diff --git a/fs/readdir.c b/fs/readdir.c
52690 index 5e69ef5..e5d9099 100644
52691 --- a/fs/readdir.c
52692 +++ b/fs/readdir.c
52693 @@ -17,6 +17,7 @@
52694 #include <linux/security.h>
52695 #include <linux/syscalls.h>
52696 #include <linux/unistd.h>
52697 +#include <linux/namei.h>
52698
52699 #include <asm/uaccess.h>
52700
52701 @@ -67,6 +68,7 @@ struct old_linux_dirent {
52702
52703 struct readdir_callback {
52704 struct old_linux_dirent __user * dirent;
52705 + struct file * file;
52706 int result;
52707 };
52708
52709 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
52710 buf->result = -EOVERFLOW;
52711 return -EOVERFLOW;
52712 }
52713 +
52714 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52715 + return 0;
52716 +
52717 buf->result++;
52718 dirent = buf->dirent;
52719 if (!access_ok(VERIFY_WRITE, dirent,
52720 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
52721
52722 buf.result = 0;
52723 buf.dirent = dirent;
52724 + buf.file = f.file;
52725
52726 error = vfs_readdir(f.file, fillonedir, &buf);
52727 if (buf.result)
52728 @@ -139,6 +146,7 @@ struct linux_dirent {
52729 struct getdents_callback {
52730 struct linux_dirent __user * current_dir;
52731 struct linux_dirent __user * previous;
52732 + struct file * file;
52733 int count;
52734 int error;
52735 };
52736 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
52737 buf->error = -EOVERFLOW;
52738 return -EOVERFLOW;
52739 }
52740 +
52741 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52742 + return 0;
52743 +
52744 dirent = buf->previous;
52745 if (dirent) {
52746 if (__put_user(offset, &dirent->d_off))
52747 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52748 buf.previous = NULL;
52749 buf.count = count;
52750 buf.error = 0;
52751 + buf.file = f.file;
52752
52753 error = vfs_readdir(f.file, filldir, &buf);
52754 if (error >= 0)
52755 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52756 struct getdents_callback64 {
52757 struct linux_dirent64 __user * current_dir;
52758 struct linux_dirent64 __user * previous;
52759 + struct file *file;
52760 int count;
52761 int error;
52762 };
52763 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52764 buf->error = -EINVAL; /* only used if we fail.. */
52765 if (reclen > buf->count)
52766 return -EINVAL;
52767 +
52768 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52769 + return 0;
52770 +
52771 dirent = buf->previous;
52772 if (dirent) {
52773 if (__put_user(offset, &dirent->d_off))
52774 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52775
52776 buf.current_dir = dirent;
52777 buf.previous = NULL;
52778 + buf.file = f.file;
52779 buf.count = count;
52780 buf.error = 0;
52781
52782 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52783 error = buf.error;
52784 lastdirent = buf.previous;
52785 if (lastdirent) {
52786 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
52787 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52788 if (__put_user(d_off, &lastdirent->d_off))
52789 error = -EFAULT;
52790 else
52791 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52792 index 2b7882b..1c5ef48 100644
52793 --- a/fs/reiserfs/do_balan.c
52794 +++ b/fs/reiserfs/do_balan.c
52795 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52796 return;
52797 }
52798
52799 - atomic_inc(&(fs_generation(tb->tb_sb)));
52800 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52801 do_balance_starts(tb);
52802
52803 /* balance leaf returns 0 except if combining L R and S into
52804 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52805 index e60e870..f40ac16 100644
52806 --- a/fs/reiserfs/procfs.c
52807 +++ b/fs/reiserfs/procfs.c
52808 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52809 "SMALL_TAILS " : "NO_TAILS ",
52810 replay_only(sb) ? "REPLAY_ONLY " : "",
52811 convert_reiserfs(sb) ? "CONV " : "",
52812 - atomic_read(&r->s_generation_counter),
52813 + atomic_read_unchecked(&r->s_generation_counter),
52814 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52815 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52816 SF(s_good_search_by_key_reada), SF(s_bmaps),
52817 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52818 index 157e474..65a6114 100644
52819 --- a/fs/reiserfs/reiserfs.h
52820 +++ b/fs/reiserfs/reiserfs.h
52821 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52822 /* Comment? -Hans */
52823 wait_queue_head_t s_wait;
52824 /* To be obsoleted soon by per buffer seals.. -Hans */
52825 - atomic_t s_generation_counter; // increased by one every time the
52826 + atomic_unchecked_t s_generation_counter; // increased by one every time the
52827 // tree gets re-balanced
52828 unsigned long s_properties; /* File system properties. Currently holds
52829 on-disk FS format */
52830 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52831 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52832
52833 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52834 -#define get_generation(s) atomic_read (&fs_generation(s))
52835 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52836 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52837 #define __fs_changed(gen,s) (gen != get_generation (s))
52838 #define fs_changed(gen,s) \
52839 diff --git a/fs/select.c b/fs/select.c
52840 index 2ef72d9..f213b17 100644
52841 --- a/fs/select.c
52842 +++ b/fs/select.c
52843 @@ -20,6 +20,7 @@
52844 #include <linux/export.h>
52845 #include <linux/slab.h>
52846 #include <linux/poll.h>
52847 +#include <linux/security.h>
52848 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52849 #include <linux/file.h>
52850 #include <linux/fdtable.h>
52851 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52852 struct poll_list *walk = head;
52853 unsigned long todo = nfds;
52854
52855 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52856 if (nfds > rlimit(RLIMIT_NOFILE))
52857 return -EINVAL;
52858
52859 diff --git a/fs/seq_file.c b/fs/seq_file.c
52860 index f2bc3df..239d4f6 100644
52861 --- a/fs/seq_file.c
52862 +++ b/fs/seq_file.c
52863 @@ -10,6 +10,7 @@
52864 #include <linux/seq_file.h>
52865 #include <linux/slab.h>
52866 #include <linux/cred.h>
52867 +#include <linux/sched.h>
52868
52869 #include <asm/uaccess.h>
52870 #include <asm/page.h>
52871 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52872 #ifdef CONFIG_USER_NS
52873 p->user_ns = file->f_cred->user_ns;
52874 #endif
52875 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52876 + p->exec_id = current->exec_id;
52877 +#endif
52878
52879 /*
52880 * Wrappers around seq_open(e.g. swaps_open) need to be
52881 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52882 return 0;
52883 }
52884 if (!m->buf) {
52885 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52886 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52887 if (!m->buf)
52888 return -ENOMEM;
52889 }
52890 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52891 Eoverflow:
52892 m->op->stop(m, p);
52893 kfree(m->buf);
52894 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52895 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52896 return !m->buf ? -ENOMEM : -EAGAIN;
52897 }
52898
52899 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52900
52901 /* grab buffer if we didn't have one */
52902 if (!m->buf) {
52903 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52904 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52905 if (!m->buf)
52906 goto Enomem;
52907 }
52908 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52909 goto Fill;
52910 m->op->stop(m, p);
52911 kfree(m->buf);
52912 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52913 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52914 if (!m->buf)
52915 goto Enomem;
52916 m->count = 0;
52917 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52918 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52919 void *data)
52920 {
52921 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52922 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52923 int res = -ENOMEM;
52924
52925 if (op) {
52926 diff --git a/fs/splice.c b/fs/splice.c
52927 index 6909d89..5b2e8f9 100644
52928 --- a/fs/splice.c
52929 +++ b/fs/splice.c
52930 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52931 pipe_lock(pipe);
52932
52933 for (;;) {
52934 - if (!pipe->readers) {
52935 + if (!atomic_read(&pipe->readers)) {
52936 send_sig(SIGPIPE, current, 0);
52937 if (!ret)
52938 ret = -EPIPE;
52939 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52940 do_wakeup = 0;
52941 }
52942
52943 - pipe->waiting_writers++;
52944 + atomic_inc(&pipe->waiting_writers);
52945 pipe_wait(pipe);
52946 - pipe->waiting_writers--;
52947 + atomic_dec(&pipe->waiting_writers);
52948 }
52949
52950 pipe_unlock(pipe);
52951 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52952 old_fs = get_fs();
52953 set_fs(get_ds());
52954 /* The cast to a user pointer is valid due to the set_fs() */
52955 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52956 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52957 set_fs(old_fs);
52958
52959 return res;
52960 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52961 old_fs = get_fs();
52962 set_fs(get_ds());
52963 /* The cast to a user pointer is valid due to the set_fs() */
52964 - res = vfs_write(file, (const char __user *)buf, count, &pos);
52965 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52966 set_fs(old_fs);
52967
52968 return res;
52969 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52970 goto err;
52971
52972 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52973 - vec[i].iov_base = (void __user *) page_address(page);
52974 + vec[i].iov_base = (void __force_user *) page_address(page);
52975 vec[i].iov_len = this_len;
52976 spd.pages[i] = page;
52977 spd.nr_pages++;
52978 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52979 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52980 {
52981 while (!pipe->nrbufs) {
52982 - if (!pipe->writers)
52983 + if (!atomic_read(&pipe->writers))
52984 return 0;
52985
52986 - if (!pipe->waiting_writers && sd->num_spliced)
52987 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52988 return 0;
52989
52990 if (sd->flags & SPLICE_F_NONBLOCK)
52991 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52992 * out of the pipe right after the splice_to_pipe(). So set
52993 * PIPE_READERS appropriately.
52994 */
52995 - pipe->readers = 1;
52996 + atomic_set(&pipe->readers, 1);
52997
52998 current->splice_pipe = pipe;
52999 }
53000 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53001 ret = -ERESTARTSYS;
53002 break;
53003 }
53004 - if (!pipe->writers)
53005 + if (!atomic_read(&pipe->writers))
53006 break;
53007 - if (!pipe->waiting_writers) {
53008 + if (!atomic_read(&pipe->waiting_writers)) {
53009 if (flags & SPLICE_F_NONBLOCK) {
53010 ret = -EAGAIN;
53011 break;
53012 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53013 pipe_lock(pipe);
53014
53015 while (pipe->nrbufs >= pipe->buffers) {
53016 - if (!pipe->readers) {
53017 + if (!atomic_read(&pipe->readers)) {
53018 send_sig(SIGPIPE, current, 0);
53019 ret = -EPIPE;
53020 break;
53021 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53022 ret = -ERESTARTSYS;
53023 break;
53024 }
53025 - pipe->waiting_writers++;
53026 + atomic_inc(&pipe->waiting_writers);
53027 pipe_wait(pipe);
53028 - pipe->waiting_writers--;
53029 + atomic_dec(&pipe->waiting_writers);
53030 }
53031
53032 pipe_unlock(pipe);
53033 @@ -1823,14 +1823,14 @@ retry:
53034 pipe_double_lock(ipipe, opipe);
53035
53036 do {
53037 - if (!opipe->readers) {
53038 + if (!atomic_read(&opipe->readers)) {
53039 send_sig(SIGPIPE, current, 0);
53040 if (!ret)
53041 ret = -EPIPE;
53042 break;
53043 }
53044
53045 - if (!ipipe->nrbufs && !ipipe->writers)
53046 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
53047 break;
53048
53049 /*
53050 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53051 pipe_double_lock(ipipe, opipe);
53052
53053 do {
53054 - if (!opipe->readers) {
53055 + if (!atomic_read(&opipe->readers)) {
53056 send_sig(SIGPIPE, current, 0);
53057 if (!ret)
53058 ret = -EPIPE;
53059 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53060 * return EAGAIN if we have the potential of some data in the
53061 * future, otherwise just return 0
53062 */
53063 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
53064 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
53065 ret = -EAGAIN;
53066
53067 pipe_unlock(ipipe);
53068 diff --git a/fs/stat.c b/fs/stat.c
53069 index 14f4545..9b7f55b 100644
53070 --- a/fs/stat.c
53071 +++ b/fs/stat.c
53072 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
53073 stat->gid = inode->i_gid;
53074 stat->rdev = inode->i_rdev;
53075 stat->size = i_size_read(inode);
53076 - stat->atime = inode->i_atime;
53077 - stat->mtime = inode->i_mtime;
53078 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53079 + stat->atime = inode->i_ctime;
53080 + stat->mtime = inode->i_ctime;
53081 + } else {
53082 + stat->atime = inode->i_atime;
53083 + stat->mtime = inode->i_mtime;
53084 + }
53085 stat->ctime = inode->i_ctime;
53086 stat->blksize = (1 << inode->i_blkbits);
53087 stat->blocks = inode->i_blocks;
53088 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
53089 if (retval)
53090 return retval;
53091
53092 - if (inode->i_op->getattr)
53093 - return inode->i_op->getattr(mnt, dentry, stat);
53094 + if (inode->i_op->getattr) {
53095 + retval = inode->i_op->getattr(mnt, dentry, stat);
53096 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53097 + stat->atime = stat->ctime;
53098 + stat->mtime = stat->ctime;
53099 + }
53100 + return retval;
53101 + }
53102
53103 generic_fillattr(inode, stat);
53104 return 0;
53105 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
53106 index 2fbdff6..5530a61 100644
53107 --- a/fs/sysfs/dir.c
53108 +++ b/fs/sysfs/dir.c
53109 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
53110 struct sysfs_dirent *sd;
53111 int rc;
53112
53113 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
53114 + const char *parent_name = parent_sd->s_name;
53115 +
53116 + mode = S_IFDIR | S_IRWXU;
53117 +
53118 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
53119 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
53120 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
53121 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
53122 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
53123 +#endif
53124 +
53125 /* allocate */
53126 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
53127 if (!sd)
53128 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53129 index 602f56d..6853db8 100644
53130 --- a/fs/sysfs/file.c
53131 +++ b/fs/sysfs/file.c
53132 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53133
53134 struct sysfs_open_dirent {
53135 atomic_t refcnt;
53136 - atomic_t event;
53137 + atomic_unchecked_t event;
53138 wait_queue_head_t poll;
53139 struct list_head buffers; /* goes through sysfs_buffer.list */
53140 };
53141 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53142 if (!sysfs_get_active(attr_sd))
53143 return -ENODEV;
53144
53145 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53146 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53147 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53148
53149 sysfs_put_active(attr_sd);
53150 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53151 return -ENOMEM;
53152
53153 atomic_set(&new_od->refcnt, 0);
53154 - atomic_set(&new_od->event, 1);
53155 + atomic_set_unchecked(&new_od->event, 1);
53156 init_waitqueue_head(&new_od->poll);
53157 INIT_LIST_HEAD(&new_od->buffers);
53158 goto retry;
53159 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53160
53161 sysfs_put_active(attr_sd);
53162
53163 - if (buffer->event != atomic_read(&od->event))
53164 + if (buffer->event != atomic_read_unchecked(&od->event))
53165 goto trigger;
53166
53167 return DEFAULT_POLLMASK;
53168 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53169
53170 od = sd->s_attr.open;
53171 if (od) {
53172 - atomic_inc(&od->event);
53173 + atomic_inc_unchecked(&od->event);
53174 wake_up_interruptible(&od->poll);
53175 }
53176
53177 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
53178 index 3c9eb56..9dea5be 100644
53179 --- a/fs/sysfs/symlink.c
53180 +++ b/fs/sysfs/symlink.c
53181 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53182
53183 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
53184 {
53185 - char *page = nd_get_link(nd);
53186 + const char *page = nd_get_link(nd);
53187 if (!IS_ERR(page))
53188 free_page((unsigned long)page);
53189 }
53190 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
53191 index c175b4d..8f36a16 100644
53192 --- a/fs/udf/misc.c
53193 +++ b/fs/udf/misc.c
53194 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
53195
53196 u8 udf_tag_checksum(const struct tag *t)
53197 {
53198 - u8 *data = (u8 *)t;
53199 + const u8 *data = (const u8 *)t;
53200 u8 checksum = 0;
53201 int i;
53202 for (i = 0; i < sizeof(struct tag); ++i)
53203 diff --git a/fs/utimes.c b/fs/utimes.c
53204 index f4fb7ec..3fe03c0 100644
53205 --- a/fs/utimes.c
53206 +++ b/fs/utimes.c
53207 @@ -1,6 +1,7 @@
53208 #include <linux/compiler.h>
53209 #include <linux/file.h>
53210 #include <linux/fs.h>
53211 +#include <linux/security.h>
53212 #include <linux/linkage.h>
53213 #include <linux/mount.h>
53214 #include <linux/namei.h>
53215 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
53216 goto mnt_drop_write_and_out;
53217 }
53218 }
53219 +
53220 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
53221 + error = -EACCES;
53222 + goto mnt_drop_write_and_out;
53223 + }
53224 +
53225 mutex_lock(&inode->i_mutex);
53226 error = notify_change(path->dentry, &newattrs);
53227 mutex_unlock(&inode->i_mutex);
53228 diff --git a/fs/xattr.c b/fs/xattr.c
53229 index 3377dff..4feded6 100644
53230 --- a/fs/xattr.c
53231 +++ b/fs/xattr.c
53232 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
53233 * Extended attribute SET operations
53234 */
53235 static long
53236 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
53237 +setxattr(struct path *path, const char __user *name, const void __user *value,
53238 size_t size, int flags)
53239 {
53240 int error;
53241 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
53242 posix_acl_fix_xattr_from_user(kvalue, size);
53243 }
53244
53245 - error = vfs_setxattr(d, kname, kvalue, size, flags);
53246 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
53247 + error = -EACCES;
53248 + goto out;
53249 + }
53250 +
53251 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
53252 out:
53253 if (vvalue)
53254 vfree(vvalue);
53255 @@ -377,7 +382,7 @@ retry:
53256 return error;
53257 error = mnt_want_write(path.mnt);
53258 if (!error) {
53259 - error = setxattr(path.dentry, name, value, size, flags);
53260 + error = setxattr(&path, name, value, size, flags);
53261 mnt_drop_write(path.mnt);
53262 }
53263 path_put(&path);
53264 @@ -401,7 +406,7 @@ retry:
53265 return error;
53266 error = mnt_want_write(path.mnt);
53267 if (!error) {
53268 - error = setxattr(path.dentry, name, value, size, flags);
53269 + error = setxattr(&path, name, value, size, flags);
53270 mnt_drop_write(path.mnt);
53271 }
53272 path_put(&path);
53273 @@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
53274 const void __user *,value, size_t, size, int, flags)
53275 {
53276 struct fd f = fdget(fd);
53277 - struct dentry *dentry;
53278 int error = -EBADF;
53279
53280 if (!f.file)
53281 return error;
53282 - dentry = f.file->f_path.dentry;
53283 - audit_inode(NULL, dentry, 0);
53284 + audit_inode(NULL, f.file->f_path.dentry, 0);
53285 error = mnt_want_write_file(f.file);
53286 if (!error) {
53287 - error = setxattr(dentry, name, value, size, flags);
53288 + error = setxattr(&f.file->f_path, name, value, size, flags);
53289 mnt_drop_write_file(f.file);
53290 }
53291 fdput(f);
53292 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
53293 index 9fbea87..6b19972 100644
53294 --- a/fs/xattr_acl.c
53295 +++ b/fs/xattr_acl.c
53296 @@ -76,8 +76,8 @@ struct posix_acl *
53297 posix_acl_from_xattr(struct user_namespace *user_ns,
53298 const void *value, size_t size)
53299 {
53300 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
53301 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
53302 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
53303 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
53304 int count;
53305 struct posix_acl *acl;
53306 struct posix_acl_entry *acl_e;
53307 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
53308 index cdb2d33..704ce7f 100644
53309 --- a/fs/xfs/xfs_bmap.c
53310 +++ b/fs/xfs/xfs_bmap.c
53311 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
53312 int nmap,
53313 int ret_nmap);
53314 #else
53315 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
53316 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
53317 #endif /* DEBUG */
53318
53319 STATIC int
53320 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
53321 index 1b9fc3e..e1bdde0 100644
53322 --- a/fs/xfs/xfs_dir2_sf.c
53323 +++ b/fs/xfs/xfs_dir2_sf.c
53324 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
53325 }
53326
53327 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
53328 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53329 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
53330 + char name[sfep->namelen];
53331 + memcpy(name, sfep->name, sfep->namelen);
53332 + if (filldir(dirent, name, sfep->namelen,
53333 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
53334 + *offset = off & 0x7fffffff;
53335 + return 0;
53336 + }
53337 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53338 off & 0x7fffffff, ino, DT_UNKNOWN)) {
53339 *offset = off & 0x7fffffff;
53340 return 0;
53341 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
53342 index c1c3ef8..0952438 100644
53343 --- a/fs/xfs/xfs_ioctl.c
53344 +++ b/fs/xfs/xfs_ioctl.c
53345 @@ -127,7 +127,7 @@ xfs_find_handle(
53346 }
53347
53348 error = -EFAULT;
53349 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
53350 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
53351 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
53352 goto out_put;
53353
53354 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
53355 index d82efaa..0904a8e 100644
53356 --- a/fs/xfs/xfs_iops.c
53357 +++ b/fs/xfs/xfs_iops.c
53358 @@ -395,7 +395,7 @@ xfs_vn_put_link(
53359 struct nameidata *nd,
53360 void *p)
53361 {
53362 - char *s = nd_get_link(nd);
53363 + const char *s = nd_get_link(nd);
53364
53365 if (!IS_ERR(s))
53366 kfree(s);
53367 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
53368 new file mode 100644
53369 index 0000000..92247e4
53370 --- /dev/null
53371 +++ b/grsecurity/Kconfig
53372 @@ -0,0 +1,1021 @@
53373 +#
53374 +# grecurity configuration
53375 +#
53376 +menu "Memory Protections"
53377 +depends on GRKERNSEC
53378 +
53379 +config GRKERNSEC_KMEM
53380 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
53381 + default y if GRKERNSEC_CONFIG_AUTO
53382 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
53383 + help
53384 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
53385 + be written to or read from to modify or leak the contents of the running
53386 + kernel. /dev/port will also not be allowed to be opened and support
53387 + for /dev/cpu/*/msr will be removed. If you have module
53388 + support disabled, enabling this will close up five ways that are
53389 + currently used to insert malicious code into the running kernel.
53390 +
53391 + Even with all these features enabled, we still highly recommend that
53392 + you use the RBAC system, as it is still possible for an attacker to
53393 + modify the running kernel through privileged I/O granted by ioperm/iopl.
53394 +
53395 + If you are not using XFree86, you may be able to stop this additional
53396 + case by enabling the 'Disable privileged I/O' option. Though nothing
53397 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
53398 + but only to video memory, which is the only writing we allow in this
53399 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
53400 + not be allowed to mprotect it with PROT_WRITE later.
53401 + Enabling this feature will prevent the "cpupower" and "powertop" tools
53402 + from working.
53403 +
53404 + It is highly recommended that you say Y here if you meet all the
53405 + conditions above.
53406 +
53407 +config GRKERNSEC_VM86
53408 + bool "Restrict VM86 mode"
53409 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53410 + depends on X86_32
53411 +
53412 + help
53413 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
53414 + make use of a special execution mode on 32bit x86 processors called
53415 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
53416 + video cards and will still work with this option enabled. The purpose
53417 + of the option is to prevent exploitation of emulation errors in
53418 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
53419 + Nearly all users should be able to enable this option.
53420 +
53421 +config GRKERNSEC_IO
53422 + bool "Disable privileged I/O"
53423 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53424 + depends on X86
53425 + select RTC_CLASS
53426 + select RTC_INTF_DEV
53427 + select RTC_DRV_CMOS
53428 +
53429 + help
53430 + If you say Y here, all ioperm and iopl calls will return an error.
53431 + Ioperm and iopl can be used to modify the running kernel.
53432 + Unfortunately, some programs need this access to operate properly,
53433 + the most notable of which are XFree86 and hwclock. hwclock can be
53434 + remedied by having RTC support in the kernel, so real-time
53435 + clock support is enabled if this option is enabled, to ensure
53436 + that hwclock operates correctly. XFree86 still will not
53437 + operate correctly with this option enabled, so DO NOT CHOOSE Y
53438 + IF YOU USE XFree86. If you use XFree86 and you still want to
53439 + protect your kernel against modification, use the RBAC system.
53440 +
53441 +config GRKERNSEC_JIT_HARDEN
53442 + bool "Harden BPF JIT against spray attacks"
53443 + default y if GRKERNSEC_CONFIG_AUTO
53444 + depends on BPF_JIT
53445 + help
53446 + If you say Y here, the native code generated by the kernel's Berkeley
53447 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
53448 + attacks that attempt to fit attacker-beneficial instructions in
53449 + 32bit immediate fields of JIT-generated native instructions. The
53450 + attacker will generally aim to cause an unintended instruction sequence
53451 + of JIT-generated native code to execute by jumping into the middle of
53452 + a generated instruction. This feature effectively randomizes the 32bit
53453 + immediate constants present in the generated code to thwart such attacks.
53454 +
53455 + If you're using KERNEXEC, it's recommended that you enable this option
53456 + to supplement the hardening of the kernel.
53457 +
53458 +config GRKERNSEC_RAND_THREADSTACK
53459 + bool "Insert random gaps between thread stacks"
53460 + default y if GRKERNSEC_CONFIG_AUTO
53461 + depends on PAX_RANDMMAP && !PPC
53462 + help
53463 + If you say Y here, a random-sized gap will be enforced between allocated
53464 + thread stacks. Glibc's NPTL and other threading libraries that
53465 + pass MAP_STACK to the kernel for thread stack allocation are supported.
53466 + The implementation currently provides 8 bits of entropy for the gap.
53467 +
53468 + Many distributions do not compile threaded remote services with the
53469 + -fstack-check argument to GCC, causing the variable-sized stack-based
53470 + allocator, alloca(), to not probe the stack on allocation. This
53471 + permits an unbounded alloca() to skip over any guard page and potentially
53472 + modify another thread's stack reliably. An enforced random gap
53473 + reduces the reliability of such an attack and increases the chance
53474 + that such a read/write to another thread's stack instead lands in
53475 + an unmapped area, causing a crash and triggering grsecurity's
53476 + anti-bruteforcing logic.
53477 +
53478 +config GRKERNSEC_PROC_MEMMAP
53479 + bool "Harden ASLR against information leaks and entropy reduction"
53480 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
53481 + depends on PAX_NOEXEC || PAX_ASLR
53482 + help
53483 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
53484 + give no information about the addresses of its mappings if
53485 + PaX features that rely on random addresses are enabled on the task.
53486 + In addition to sanitizing this information and disabling other
53487 + dangerous sources of information, this option causes reads of sensitive
53488 + /proc/<pid> entries where the file descriptor was opened in a different
53489 + task than the one performing the read. Such attempts are logged.
53490 + This option also limits argv/env strings for suid/sgid binaries
53491 + to 512KB to prevent a complete exhaustion of the stack entropy provided
53492 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
53493 + binaries to prevent alternative mmap layouts from being abused.
53494 +
53495 + If you use PaX it is essential that you say Y here as it closes up
53496 + several holes that make full ASLR useless locally.
53497 +
53498 +config GRKERNSEC_BRUTE
53499 + bool "Deter exploit bruteforcing"
53500 + default y if GRKERNSEC_CONFIG_AUTO
53501 + help
53502 + If you say Y here, attempts to bruteforce exploits against forking
53503 + daemons such as apache or sshd, as well as against suid/sgid binaries
53504 + will be deterred. When a child of a forking daemon is killed by PaX
53505 + or crashes due to an illegal instruction or other suspicious signal,
53506 + the parent process will be delayed 30 seconds upon every subsequent
53507 + fork until the administrator is able to assess the situation and
53508 + restart the daemon.
53509 + In the suid/sgid case, the attempt is logged, the user has all their
53510 + processes terminated, and they are prevented from executing any further
53511 + processes for 15 minutes.
53512 + It is recommended that you also enable signal logging in the auditing
53513 + section so that logs are generated when a process triggers a suspicious
53514 + signal.
53515 + If the sysctl option is enabled, a sysctl option with name
53516 + "deter_bruteforce" is created.
53517 +
53518 +
53519 +config GRKERNSEC_MODHARDEN
53520 + bool "Harden module auto-loading"
53521 + default y if GRKERNSEC_CONFIG_AUTO
53522 + depends on MODULES
53523 + help
53524 + If you say Y here, module auto-loading in response to use of some
53525 + feature implemented by an unloaded module will be restricted to
53526 + root users. Enabling this option helps defend against attacks
53527 + by unprivileged users who abuse the auto-loading behavior to
53528 + cause a vulnerable module to load that is then exploited.
53529 +
53530 + If this option prevents a legitimate use of auto-loading for a
53531 + non-root user, the administrator can execute modprobe manually
53532 + with the exact name of the module mentioned in the alert log.
53533 + Alternatively, the administrator can add the module to the list
53534 + of modules loaded at boot by modifying init scripts.
53535 +
53536 + Modification of init scripts will most likely be needed on
53537 + Ubuntu servers with encrypted home directory support enabled,
53538 + as the first non-root user logging in will cause the ecb(aes),
53539 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
53540 +
53541 +config GRKERNSEC_HIDESYM
53542 + bool "Hide kernel symbols"
53543 + default y if GRKERNSEC_CONFIG_AUTO
53544 + select PAX_USERCOPY_SLABS
53545 + help
53546 + If you say Y here, getting information on loaded modules, and
53547 + displaying all kernel symbols through a syscall will be restricted
53548 + to users with CAP_SYS_MODULE. For software compatibility reasons,
53549 + /proc/kallsyms will be restricted to the root user. The RBAC
53550 + system can hide that entry even from root.
53551 +
53552 + This option also prevents leaking of kernel addresses through
53553 + several /proc entries.
53554 +
53555 + Note that this option is only effective provided the following
53556 + conditions are met:
53557 + 1) The kernel using grsecurity is not precompiled by some distribution
53558 + 2) You have also enabled GRKERNSEC_DMESG
53559 + 3) You are using the RBAC system and hiding other files such as your
53560 + kernel image and System.map. Alternatively, enabling this option
53561 + causes the permissions on /boot, /lib/modules, and the kernel
53562 + source directory to change at compile time to prevent
53563 + reading by non-root users.
53564 + If the above conditions are met, this option will aid in providing a
53565 + useful protection against local kernel exploitation of overflows
53566 + and arbitrary read/write vulnerabilities.
53567 +
53568 +config GRKERNSEC_KERN_LOCKOUT
53569 + bool "Active kernel exploit response"
53570 + default y if GRKERNSEC_CONFIG_AUTO
53571 + depends on X86 || ARM || PPC || SPARC
53572 + help
53573 + If you say Y here, when a PaX alert is triggered due to suspicious
53574 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
53575 + or an OOPS occurs due to bad memory accesses, instead of just
53576 + terminating the offending process (and potentially allowing
53577 + a subsequent exploit from the same user), we will take one of two
53578 + actions:
53579 + If the user was root, we will panic the system
53580 + If the user was non-root, we will log the attempt, terminate
53581 + all processes owned by the user, then prevent them from creating
53582 + any new processes until the system is restarted
53583 + This deters repeated kernel exploitation/bruteforcing attempts
53584 + and is useful for later forensics.
53585 +
53586 +endmenu
53587 +menu "Role Based Access Control Options"
53588 +depends on GRKERNSEC
53589 +
53590 +config GRKERNSEC_RBAC_DEBUG
53591 + bool
53592 +
53593 +config GRKERNSEC_NO_RBAC
53594 + bool "Disable RBAC system"
53595 + help
53596 + If you say Y here, the /dev/grsec device will be removed from the kernel,
53597 + preventing the RBAC system from being enabled. You should only say Y
53598 + here if you have no intention of using the RBAC system, so as to prevent
53599 + an attacker with root access from misusing the RBAC system to hide files
53600 + and processes when loadable module support and /dev/[k]mem have been
53601 + locked down.
53602 +
53603 +config GRKERNSEC_ACL_HIDEKERN
53604 + bool "Hide kernel processes"
53605 + help
53606 + If you say Y here, all kernel threads will be hidden to all
53607 + processes but those whose subject has the "view hidden processes"
53608 + flag.
53609 +
53610 +config GRKERNSEC_ACL_MAXTRIES
53611 + int "Maximum tries before password lockout"
53612 + default 3
53613 + help
53614 + This option enforces the maximum number of times a user can attempt
53615 + to authorize themselves with the grsecurity RBAC system before being
53616 + denied the ability to attempt authorization again for a specified time.
53617 + The lower the number, the harder it will be to brute-force a password.
53618 +
53619 +config GRKERNSEC_ACL_TIMEOUT
53620 + int "Time to wait after max password tries, in seconds"
53621 + default 30
53622 + help
53623 + This option specifies the time the user must wait after attempting to
53624 + authorize to the RBAC system with the maximum number of invalid
53625 + passwords. The higher the number, the harder it will be to brute-force
53626 + a password.
53627 +
53628 +endmenu
53629 +menu "Filesystem Protections"
53630 +depends on GRKERNSEC
53631 +
53632 +config GRKERNSEC_PROC
53633 + bool "Proc restrictions"
53634 + default y if GRKERNSEC_CONFIG_AUTO
53635 + help
53636 + If you say Y here, the permissions of the /proc filesystem
53637 + will be altered to enhance system security and privacy. You MUST
53638 + choose either a user only restriction or a user and group restriction.
53639 + Depending upon the option you choose, you can either restrict users to
53640 + see only the processes they themselves run, or choose a group that can
53641 + view all processes and files normally restricted to root if you choose
53642 + the "restrict to user only" option. NOTE: If you're running identd or
53643 + ntpd as a non-root user, you will have to run it as the group you
53644 + specify here.
53645 +
53646 +config GRKERNSEC_PROC_USER
53647 + bool "Restrict /proc to user only"
53648 + depends on GRKERNSEC_PROC
53649 + help
53650 + If you say Y here, non-root users will only be able to view their own
53651 + processes, and restricts them from viewing network-related information,
53652 + and viewing kernel symbol and module information.
53653 +
53654 +config GRKERNSEC_PROC_USERGROUP
53655 + bool "Allow special group"
53656 + default y if GRKERNSEC_CONFIG_AUTO
53657 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
53658 + help
53659 + If you say Y here, you will be able to select a group that will be
53660 + able to view all processes and network-related information. If you've
53661 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53662 + remain hidden. This option is useful if you want to run identd as
53663 + a non-root user. The group you select may also be chosen at boot time
53664 + via "grsec_proc_gid=" on the kernel commandline.
53665 +
53666 +config GRKERNSEC_PROC_GID
53667 + int "GID for special group"
53668 + depends on GRKERNSEC_PROC_USERGROUP
53669 + default 1001
53670 +
53671 +config GRKERNSEC_PROC_ADD
53672 + bool "Additional restrictions"
53673 + default y if GRKERNSEC_CONFIG_AUTO
53674 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53675 + help
53676 + If you say Y here, additional restrictions will be placed on
53677 + /proc that keep normal users from viewing device information and
53678 + slabinfo information that could be useful for exploits.
53679 +
53680 +config GRKERNSEC_LINK
53681 + bool "Linking restrictions"
53682 + default y if GRKERNSEC_CONFIG_AUTO
53683 + help
53684 + If you say Y here, /tmp race exploits will be prevented, since users
53685 + will no longer be able to follow symlinks owned by other users in
53686 + world-writable +t directories (e.g. /tmp), unless the owner of the
53687 + symlink is the owner of the directory. users will also not be
53688 + able to hardlink to files they do not own. If the sysctl option is
53689 + enabled, a sysctl option with name "linking_restrictions" is created.
53690 +
53691 +config GRKERNSEC_SYMLINKOWN
53692 + bool "Kernel-enforced SymlinksIfOwnerMatch"
53693 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53694 + help
53695 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
53696 + that prevents it from being used as a security feature. As Apache
53697 + verifies the symlink by performing a stat() against the target of
53698 + the symlink before it is followed, an attacker can setup a symlink
53699 + to point to a same-owned file, then replace the symlink with one
53700 + that targets another user's file just after Apache "validates" the
53701 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
53702 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
53703 + will be in place for the group you specify. If the sysctl option
53704 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
53705 + created.
53706 +
53707 +config GRKERNSEC_SYMLINKOWN_GID
53708 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
53709 + depends on GRKERNSEC_SYMLINKOWN
53710 + default 1006
53711 + help
53712 + Setting this GID determines what group kernel-enforced
53713 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
53714 + is enabled, a sysctl option with name "symlinkown_gid" is created.
53715 +
53716 +config GRKERNSEC_FIFO
53717 + bool "FIFO restrictions"
53718 + default y if GRKERNSEC_CONFIG_AUTO
53719 + help
53720 + If you say Y here, users will not be able to write to FIFOs they don't
53721 + own in world-writable +t directories (e.g. /tmp), unless the owner of
53722 + the FIFO is the same owner of the directory it's held in. If the sysctl
53723 + option is enabled, a sysctl option with name "fifo_restrictions" is
53724 + created.
53725 +
53726 +config GRKERNSEC_SYSFS_RESTRICT
53727 + bool "Sysfs/debugfs restriction"
53728 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53729 + depends on SYSFS
53730 + help
53731 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53732 + any filesystem normally mounted under it (e.g. debugfs) will be
53733 + mostly accessible only by root. These filesystems generally provide access
53734 + to hardware and debug information that isn't appropriate for unprivileged
53735 + users of the system. Sysfs and debugfs have also become a large source
53736 + of new vulnerabilities, ranging from infoleaks to local compromise.
53737 + There has been very little oversight with an eye toward security involved
53738 + in adding new exporters of information to these filesystems, so their
53739 + use is discouraged.
53740 + For reasons of compatibility, a few directories have been whitelisted
53741 + for access by non-root users:
53742 + /sys/fs/selinux
53743 + /sys/fs/fuse
53744 + /sys/devices/system/cpu
53745 +
53746 +config GRKERNSEC_ROFS
53747 + bool "Runtime read-only mount protection"
53748 + help
53749 + If you say Y here, a sysctl option with name "romount_protect" will
53750 + be created. By setting this option to 1 at runtime, filesystems
53751 + will be protected in the following ways:
53752 + * No new writable mounts will be allowed
53753 + * Existing read-only mounts won't be able to be remounted read/write
53754 + * Write operations will be denied on all block devices
53755 + This option acts independently of grsec_lock: once it is set to 1,
53756 + it cannot be turned off. Therefore, please be mindful of the resulting
53757 + behavior if this option is enabled in an init script on a read-only
53758 + filesystem. This feature is mainly intended for secure embedded systems.
53759 +
53760 +config GRKERNSEC_DEVICE_SIDECHANNEL
53761 + bool "Eliminate stat/notify-based device sidechannels"
53762 + default y if GRKERNSEC_CONFIG_AUTO
53763 + help
53764 + If you say Y here, timing analyses on block or character
53765 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53766 + will be thwarted for unprivileged users. If a process without
53767 + CAP_MKNOD stats such a device, the last access and last modify times
53768 + will match the device's create time. No access or modify events
53769 + will be triggered through inotify/dnotify/fanotify for such devices.
53770 + This feature will prevent attacks that may at a minimum
53771 + allow an attacker to determine the administrator's password length.
53772 +
53773 +config GRKERNSEC_CHROOT
53774 + bool "Chroot jail restrictions"
53775 + default y if GRKERNSEC_CONFIG_AUTO
53776 + help
53777 + If you say Y here, you will be able to choose several options that will
53778 + make breaking out of a chrooted jail much more difficult. If you
53779 + encounter no software incompatibilities with the following options, it
53780 + is recommended that you enable each one.
53781 +
53782 +config GRKERNSEC_CHROOT_MOUNT
53783 + bool "Deny mounts"
53784 + default y if GRKERNSEC_CONFIG_AUTO
53785 + depends on GRKERNSEC_CHROOT
53786 + help
53787 + If you say Y here, processes inside a chroot will not be able to
53788 + mount or remount filesystems. If the sysctl option is enabled, a
53789 + sysctl option with name "chroot_deny_mount" is created.
53790 +
53791 +config GRKERNSEC_CHROOT_DOUBLE
53792 + bool "Deny double-chroots"
53793 + default y if GRKERNSEC_CONFIG_AUTO
53794 + depends on GRKERNSEC_CHROOT
53795 + help
53796 + If you say Y here, processes inside a chroot will not be able to chroot
53797 + again outside the chroot. This is a widely used method of breaking
53798 + out of a chroot jail and should not be allowed. If the sysctl
53799 + option is enabled, a sysctl option with name
53800 + "chroot_deny_chroot" is created.
53801 +
53802 +config GRKERNSEC_CHROOT_PIVOT
53803 + bool "Deny pivot_root in chroot"
53804 + default y if GRKERNSEC_CONFIG_AUTO
53805 + depends on GRKERNSEC_CHROOT
53806 + help
53807 + If you say Y here, processes inside a chroot will not be able to use
53808 + a function called pivot_root() that was introduced in Linux 2.3.41. It
53809 + works similar to chroot in that it changes the root filesystem. This
53810 + function could be misused in a chrooted process to attempt to break out
53811 + of the chroot, and therefore should not be allowed. If the sysctl
53812 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
53813 + created.
53814 +
53815 +config GRKERNSEC_CHROOT_CHDIR
53816 + bool "Enforce chdir(\"/\") on all chroots"
53817 + default y if GRKERNSEC_CONFIG_AUTO
53818 + depends on GRKERNSEC_CHROOT
53819 + help
53820 + If you say Y here, the current working directory of all newly-chrooted
53821 + applications will be set to the the root directory of the chroot.
53822 + The man page on chroot(2) states:
53823 + Note that this call does not change the current working
53824 + directory, so that `.' can be outside the tree rooted at
53825 + `/'. In particular, the super-user can escape from a
53826 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53827 +
53828 + It is recommended that you say Y here, since it's not known to break
53829 + any software. If the sysctl option is enabled, a sysctl option with
53830 + name "chroot_enforce_chdir" is created.
53831 +
53832 +config GRKERNSEC_CHROOT_CHMOD
53833 + bool "Deny (f)chmod +s"
53834 + default y if GRKERNSEC_CONFIG_AUTO
53835 + depends on GRKERNSEC_CHROOT
53836 + help
53837 + If you say Y here, processes inside a chroot will not be able to chmod
53838 + or fchmod files to make them have suid or sgid bits. This protects
53839 + against another published method of breaking a chroot. If the sysctl
53840 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
53841 + created.
53842 +
53843 +config GRKERNSEC_CHROOT_FCHDIR
53844 + bool "Deny fchdir out of chroot"
53845 + default y if GRKERNSEC_CONFIG_AUTO
53846 + depends on GRKERNSEC_CHROOT
53847 + help
53848 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
53849 + to a file descriptor of the chrooting process that points to a directory
53850 + outside the filesystem will be stopped. If the sysctl option
53851 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53852 +
53853 +config GRKERNSEC_CHROOT_MKNOD
53854 + bool "Deny mknod"
53855 + default y if GRKERNSEC_CONFIG_AUTO
53856 + depends on GRKERNSEC_CHROOT
53857 + help
53858 + If you say Y here, processes inside a chroot will not be allowed to
53859 + mknod. The problem with using mknod inside a chroot is that it
53860 + would allow an attacker to create a device entry that is the same
53861 + as one on the physical root of your system, which could range from
53862 + anything from the console device to a device for your harddrive (which
53863 + they could then use to wipe the drive or steal data). It is recommended
53864 + that you say Y here, unless you run into software incompatibilities.
53865 + If the sysctl option is enabled, a sysctl option with name
53866 + "chroot_deny_mknod" is created.
53867 +
53868 +config GRKERNSEC_CHROOT_SHMAT
53869 + bool "Deny shmat() out of chroot"
53870 + default y if GRKERNSEC_CONFIG_AUTO
53871 + depends on GRKERNSEC_CHROOT
53872 + help
53873 + If you say Y here, processes inside a chroot will not be able to attach
53874 + to shared memory segments that were created outside of the chroot jail.
53875 + It is recommended that you say Y here. If the sysctl option is enabled,
53876 + a sysctl option with name "chroot_deny_shmat" is created.
53877 +
53878 +config GRKERNSEC_CHROOT_UNIX
53879 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
53880 + default y if GRKERNSEC_CONFIG_AUTO
53881 + depends on GRKERNSEC_CHROOT
53882 + help
53883 + If you say Y here, processes inside a chroot will not be able to
53884 + connect to abstract (meaning not belonging to a filesystem) Unix
53885 + domain sockets that were bound outside of a chroot. It is recommended
53886 + that you say Y here. If the sysctl option is enabled, a sysctl option
53887 + with name "chroot_deny_unix" is created.
53888 +
53889 +config GRKERNSEC_CHROOT_FINDTASK
53890 + bool "Protect outside processes"
53891 + default y if GRKERNSEC_CONFIG_AUTO
53892 + depends on GRKERNSEC_CHROOT
53893 + help
53894 + If you say Y here, processes inside a chroot will not be able to
53895 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53896 + getsid, or view any process outside of the chroot. If the sysctl
53897 + option is enabled, a sysctl option with name "chroot_findtask" is
53898 + created.
53899 +
53900 +config GRKERNSEC_CHROOT_NICE
53901 + bool "Restrict priority changes"
53902 + default y if GRKERNSEC_CONFIG_AUTO
53903 + depends on GRKERNSEC_CHROOT
53904 + help
53905 + If you say Y here, processes inside a chroot will not be able to raise
53906 + the priority of processes in the chroot, or alter the priority of
53907 + processes outside the chroot. This provides more security than simply
53908 + removing CAP_SYS_NICE from the process' capability set. If the
53909 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53910 + is created.
53911 +
53912 +config GRKERNSEC_CHROOT_SYSCTL
53913 + bool "Deny sysctl writes"
53914 + default y if GRKERNSEC_CONFIG_AUTO
53915 + depends on GRKERNSEC_CHROOT
53916 + help
53917 + If you say Y here, an attacker in a chroot will not be able to
53918 + write to sysctl entries, either by sysctl(2) or through a /proc
53919 + interface. It is strongly recommended that you say Y here. If the
53920 + sysctl option is enabled, a sysctl option with name
53921 + "chroot_deny_sysctl" is created.
53922 +
53923 +config GRKERNSEC_CHROOT_CAPS
53924 + bool "Capability restrictions"
53925 + default y if GRKERNSEC_CONFIG_AUTO
53926 + depends on GRKERNSEC_CHROOT
53927 + help
53928 + If you say Y here, the capabilities on all processes within a
53929 + chroot jail will be lowered to stop module insertion, raw i/o,
53930 + system and net admin tasks, rebooting the system, modifying immutable
53931 + files, modifying IPC owned by another, and changing the system time.
53932 + This is left an option because it can break some apps. Disable this
53933 + if your chrooted apps are having problems performing those kinds of
53934 + tasks. If the sysctl option is enabled, a sysctl option with
53935 + name "chroot_caps" is created.
53936 +
53937 +endmenu
53938 +menu "Kernel Auditing"
53939 +depends on GRKERNSEC
53940 +
53941 +config GRKERNSEC_AUDIT_GROUP
53942 + bool "Single group for auditing"
53943 + help
53944 + If you say Y here, the exec and chdir logging features will only operate
53945 + on a group you specify. This option is recommended if you only want to
53946 + watch certain users instead of having a large amount of logs from the
53947 + entire system. If the sysctl option is enabled, a sysctl option with
53948 + name "audit_group" is created.
53949 +
53950 +config GRKERNSEC_AUDIT_GID
53951 + int "GID for auditing"
53952 + depends on GRKERNSEC_AUDIT_GROUP
53953 + default 1007
53954 +
53955 +config GRKERNSEC_EXECLOG
53956 + bool "Exec logging"
53957 + help
53958 + If you say Y here, all execve() calls will be logged (since the
53959 + other exec*() calls are frontends to execve(), all execution
53960 + will be logged). Useful for shell-servers that like to keep track
53961 + of their users. If the sysctl option is enabled, a sysctl option with
53962 + name "exec_logging" is created.
53963 + WARNING: This option when enabled will produce a LOT of logs, especially
53964 + on an active system.
53965 +
53966 +config GRKERNSEC_RESLOG
53967 + bool "Resource logging"
53968 + default y if GRKERNSEC_CONFIG_AUTO
53969 + help
53970 + If you say Y here, all attempts to overstep resource limits will
53971 + be logged with the resource name, the requested size, and the current
53972 + limit. It is highly recommended that you say Y here. If the sysctl
53973 + option is enabled, a sysctl option with name "resource_logging" is
53974 + created. If the RBAC system is enabled, the sysctl value is ignored.
53975 +
53976 +config GRKERNSEC_CHROOT_EXECLOG
53977 + bool "Log execs within chroot"
53978 + help
53979 + If you say Y here, all executions inside a chroot jail will be logged
53980 + to syslog. This can cause a large amount of logs if certain
53981 + applications (eg. djb's daemontools) are installed on the system, and
53982 + is therefore left as an option. If the sysctl option is enabled, a
53983 + sysctl option with name "chroot_execlog" is created.
53984 +
53985 +config GRKERNSEC_AUDIT_PTRACE
53986 + bool "Ptrace logging"
53987 + help
53988 + If you say Y here, all attempts to attach to a process via ptrace
53989 + will be logged. If the sysctl option is enabled, a sysctl option
53990 + with name "audit_ptrace" is created.
53991 +
53992 +config GRKERNSEC_AUDIT_CHDIR
53993 + bool "Chdir logging"
53994 + help
53995 + If you say Y here, all chdir() calls will be logged. If the sysctl
53996 + option is enabled, a sysctl option with name "audit_chdir" is created.
53997 +
53998 +config GRKERNSEC_AUDIT_MOUNT
53999 + bool "(Un)Mount logging"
54000 + help
54001 + If you say Y here, all mounts and unmounts will be logged. If the
54002 + sysctl option is enabled, a sysctl option with name "audit_mount" is
54003 + created.
54004 +
54005 +config GRKERNSEC_SIGNAL
54006 + bool "Signal logging"
54007 + default y if GRKERNSEC_CONFIG_AUTO
54008 + help
54009 + If you say Y here, certain important signals will be logged, such as
54010 + SIGSEGV, which will as a result inform you of when a error in a program
54011 + occurred, which in some cases could mean a possible exploit attempt.
54012 + If the sysctl option is enabled, a sysctl option with name
54013 + "signal_logging" is created.
54014 +
54015 +config GRKERNSEC_FORKFAIL
54016 + bool "Fork failure logging"
54017 + help
54018 + If you say Y here, all failed fork() attempts will be logged.
54019 + This could suggest a fork bomb, or someone attempting to overstep
54020 + their process limit. If the sysctl option is enabled, a sysctl option
54021 + with name "forkfail_logging" is created.
54022 +
54023 +config GRKERNSEC_TIME
54024 + bool "Time change logging"
54025 + default y if GRKERNSEC_CONFIG_AUTO
54026 + help
54027 + If you say Y here, any changes of the system clock will be logged.
54028 + If the sysctl option is enabled, a sysctl option with name
54029 + "timechange_logging" is created.
54030 +
54031 +config GRKERNSEC_PROC_IPADDR
54032 + bool "/proc/<pid>/ipaddr support"
54033 + default y if GRKERNSEC_CONFIG_AUTO
54034 + help
54035 + If you say Y here, a new entry will be added to each /proc/<pid>
54036 + directory that contains the IP address of the person using the task.
54037 + The IP is carried across local TCP and AF_UNIX stream sockets.
54038 + This information can be useful for IDS/IPSes to perform remote response
54039 + to a local attack. The entry is readable by only the owner of the
54040 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
54041 + the RBAC system), and thus does not create privacy concerns.
54042 +
54043 +config GRKERNSEC_RWXMAP_LOG
54044 + bool 'Denied RWX mmap/mprotect logging'
54045 + default y if GRKERNSEC_CONFIG_AUTO
54046 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
54047 + help
54048 + If you say Y here, calls to mmap() and mprotect() with explicit
54049 + usage of PROT_WRITE and PROT_EXEC together will be logged when
54050 + denied by the PAX_MPROTECT feature. If the sysctl option is
54051 + enabled, a sysctl option with name "rwxmap_logging" is created.
54052 +
54053 +config GRKERNSEC_AUDIT_TEXTREL
54054 + bool 'ELF text relocations logging (READ HELP)'
54055 + depends on PAX_MPROTECT
54056 + help
54057 + If you say Y here, text relocations will be logged with the filename
54058 + of the offending library or binary. The purpose of the feature is
54059 + to help Linux distribution developers get rid of libraries and
54060 + binaries that need text relocations which hinder the future progress
54061 + of PaX. Only Linux distribution developers should say Y here, and
54062 + never on a production machine, as this option creates an information
54063 + leak that could aid an attacker in defeating the randomization of
54064 + a single memory region. If the sysctl option is enabled, a sysctl
54065 + option with name "audit_textrel" is created.
54066 +
54067 +endmenu
54068 +
54069 +menu "Executable Protections"
54070 +depends on GRKERNSEC
54071 +
54072 +config GRKERNSEC_DMESG
54073 + bool "Dmesg(8) restriction"
54074 + default y if GRKERNSEC_CONFIG_AUTO
54075 + help
54076 + If you say Y here, non-root users will not be able to use dmesg(8)
54077 + to view the contents of the kernel's circular log buffer.
54078 + The kernel's log buffer often contains kernel addresses and other
54079 + identifying information useful to an attacker in fingerprinting a
54080 + system for a targeted exploit.
54081 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
54082 + created.
54083 +
54084 +config GRKERNSEC_HARDEN_PTRACE
54085 + bool "Deter ptrace-based process snooping"
54086 + default y if GRKERNSEC_CONFIG_AUTO
54087 + help
54088 + If you say Y here, TTY sniffers and other malicious monitoring
54089 + programs implemented through ptrace will be defeated. If you
54090 + have been using the RBAC system, this option has already been
54091 + enabled for several years for all users, with the ability to make
54092 + fine-grained exceptions.
54093 +
54094 + This option only affects the ability of non-root users to ptrace
54095 + processes that are not a descendent of the ptracing process.
54096 + This means that strace ./binary and gdb ./binary will still work,
54097 + but attaching to arbitrary processes will not. If the sysctl
54098 + option is enabled, a sysctl option with name "harden_ptrace" is
54099 + created.
54100 +
54101 +config GRKERNSEC_PTRACE_READEXEC
54102 + bool "Require read access to ptrace sensitive binaries"
54103 + default y if GRKERNSEC_CONFIG_AUTO
54104 + help
54105 + If you say Y here, unprivileged users will not be able to ptrace unreadable
54106 + binaries. This option is useful in environments that
54107 + remove the read bits (e.g. file mode 4711) from suid binaries to
54108 + prevent infoleaking of their contents. This option adds
54109 + consistency to the use of that file mode, as the binary could normally
54110 + be read out when run without privileges while ptracing.
54111 +
54112 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
54113 + is created.
54114 +
54115 +config GRKERNSEC_SETXID
54116 + bool "Enforce consistent multithreaded privileges"
54117 + default y if GRKERNSEC_CONFIG_AUTO
54118 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
54119 + help
54120 + If you say Y here, a change from a root uid to a non-root uid
54121 + in a multithreaded application will cause the resulting uids,
54122 + gids, supplementary groups, and capabilities in that thread
54123 + to be propagated to the other threads of the process. In most
54124 + cases this is unnecessary, as glibc will emulate this behavior
54125 + on behalf of the application. Other libcs do not act in the
54126 + same way, allowing the other threads of the process to continue
54127 + running with root privileges. If the sysctl option is enabled,
54128 + a sysctl option with name "consistent_setxid" is created.
54129 +
54130 +config GRKERNSEC_TPE
54131 + bool "Trusted Path Execution (TPE)"
54132 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
54133 + help
54134 + If you say Y here, you will be able to choose a gid to add to the
54135 + supplementary groups of users you want to mark as "untrusted."
54136 + These users will not be able to execute any files that are not in
54137 + root-owned directories writable only by root. If the sysctl option
54138 + is enabled, a sysctl option with name "tpe" is created.
54139 +
54140 +config GRKERNSEC_TPE_ALL
54141 + bool "Partially restrict all non-root users"
54142 + depends on GRKERNSEC_TPE
54143 + help
54144 + If you say Y here, all non-root users will be covered under
54145 + a weaker TPE restriction. This is separate from, and in addition to,
54146 + the main TPE options that you have selected elsewhere. Thus, if a
54147 + "trusted" GID is chosen, this restriction applies to even that GID.
54148 + Under this restriction, all non-root users will only be allowed to
54149 + execute files in directories they own that are not group or
54150 + world-writable, or in directories owned by root and writable only by
54151 + root. If the sysctl option is enabled, a sysctl option with name
54152 + "tpe_restrict_all" is created.
54153 +
54154 +config GRKERNSEC_TPE_INVERT
54155 + bool "Invert GID option"
54156 + depends on GRKERNSEC_TPE
54157 + help
54158 + If you say Y here, the group you specify in the TPE configuration will
54159 + decide what group TPE restrictions will be *disabled* for. This
54160 + option is useful if you want TPE restrictions to be applied to most
54161 + users on the system. If the sysctl option is enabled, a sysctl option
54162 + with name "tpe_invert" is created. Unlike other sysctl options, this
54163 + entry will default to on for backward-compatibility.
54164 +
54165 +config GRKERNSEC_TPE_GID
54166 + int
54167 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
54168 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
54169 +
54170 +config GRKERNSEC_TPE_UNTRUSTED_GID
54171 + int "GID for TPE-untrusted users"
54172 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
54173 + default 1005
54174 + help
54175 + Setting this GID determines what group TPE restrictions will be
54176 + *enabled* for. If the sysctl option is enabled, a sysctl option
54177 + with name "tpe_gid" is created.
54178 +
54179 +config GRKERNSEC_TPE_TRUSTED_GID
54180 + int "GID for TPE-trusted users"
54181 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
54182 + default 1005
54183 + help
54184 + Setting this GID determines what group TPE restrictions will be
54185 + *disabled* for. If the sysctl option is enabled, a sysctl option
54186 + with name "tpe_gid" is created.
54187 +
54188 +endmenu
54189 +menu "Network Protections"
54190 +depends on GRKERNSEC
54191 +
54192 +config GRKERNSEC_RANDNET
54193 + bool "Larger entropy pools"
54194 + default y if GRKERNSEC_CONFIG_AUTO
54195 + help
54196 + If you say Y here, the entropy pools used for many features of Linux
54197 + and grsecurity will be doubled in size. Since several grsecurity
54198 + features use additional randomness, it is recommended that you say Y
54199 + here. Saying Y here has a similar effect as modifying
54200 + /proc/sys/kernel/random/poolsize.
54201 +
54202 +config GRKERNSEC_BLACKHOLE
54203 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
54204 + default y if GRKERNSEC_CONFIG_AUTO
54205 + depends on NET
54206 + help
54207 + If you say Y here, neither TCP resets nor ICMP
54208 + destination-unreachable packets will be sent in response to packets
54209 + sent to ports for which no associated listening process exists.
54210 + This feature supports both IPV4 and IPV6 and exempts the
54211 + loopback interface from blackholing. Enabling this feature
54212 + makes a host more resilient to DoS attacks and reduces network
54213 + visibility against scanners.
54214 +
54215 + The blackhole feature as-implemented is equivalent to the FreeBSD
54216 + blackhole feature, as it prevents RST responses to all packets, not
54217 + just SYNs. Under most application behavior this causes no
54218 + problems, but applications (like haproxy) may not close certain
54219 + connections in a way that cleanly terminates them on the remote
54220 + end, leaving the remote host in LAST_ACK state. Because of this
54221 + side-effect and to prevent intentional LAST_ACK DoSes, this
54222 + feature also adds automatic mitigation against such attacks.
54223 + The mitigation drastically reduces the amount of time a socket
54224 + can spend in LAST_ACK state. If you're using haproxy and not
54225 + all servers it connects to have this option enabled, consider
54226 + disabling this feature on the haproxy host.
54227 +
54228 + If the sysctl option is enabled, two sysctl options with names
54229 + "ip_blackhole" and "lastack_retries" will be created.
54230 + While "ip_blackhole" takes the standard zero/non-zero on/off
54231 + toggle, "lastack_retries" uses the same kinds of values as
54232 + "tcp_retries1" and "tcp_retries2". The default value of 4
54233 + prevents a socket from lasting more than 45 seconds in LAST_ACK
54234 + state.
54235 +
54236 +config GRKERNSEC_NO_SIMULT_CONNECT
54237 + bool "Disable TCP Simultaneous Connect"
54238 + default y if GRKERNSEC_CONFIG_AUTO
54239 + depends on NET
54240 + help
54241 + If you say Y here, a feature by Willy Tarreau will be enabled that
54242 + removes a weakness in Linux's strict implementation of TCP that
54243 + allows two clients to connect to each other without either entering
54244 + a listening state. The weakness allows an attacker to easily prevent
54245 + a client from connecting to a known server provided the source port
54246 + for the connection is guessed correctly.
54247 +
54248 + As the weakness could be used to prevent an antivirus or IPS from
54249 + fetching updates, or prevent an SSL gateway from fetching a CRL,
54250 + it should be eliminated by enabling this option. Though Linux is
54251 + one of few operating systems supporting simultaneous connect, it
54252 + has no legitimate use in practice and is rarely supported by firewalls.
54253 +
54254 +config GRKERNSEC_SOCKET
54255 + bool "Socket restrictions"
54256 + depends on NET
54257 + help
54258 + If you say Y here, you will be able to choose from several options.
54259 + If you assign a GID on your system and add it to the supplementary
54260 + groups of users you want to restrict socket access to, this patch
54261 + will perform up to three things, based on the option(s) you choose.
54262 +
54263 +config GRKERNSEC_SOCKET_ALL
54264 + bool "Deny any sockets to group"
54265 + depends on GRKERNSEC_SOCKET
54266 + help
54267 + If you say Y here, you will be able to choose a GID of whose users will
54268 + be unable to connect to other hosts from your machine or run server
54269 + applications from your machine. If the sysctl option is enabled, a
54270 + sysctl option with name "socket_all" is created.
54271 +
54272 +config GRKERNSEC_SOCKET_ALL_GID
54273 + int "GID to deny all sockets for"
54274 + depends on GRKERNSEC_SOCKET_ALL
54275 + default 1004
54276 + help
54277 + Here you can choose the GID to disable socket access for. Remember to
54278 + add the users you want socket access disabled for to the GID
54279 + specified here. If the sysctl option is enabled, a sysctl option
54280 + with name "socket_all_gid" is created.
54281 +
54282 +config GRKERNSEC_SOCKET_CLIENT
54283 + bool "Deny client sockets to group"
54284 + depends on GRKERNSEC_SOCKET
54285 + help
54286 + If you say Y here, you will be able to choose a GID of whose users will
54287 + be unable to connect to other hosts from your machine, but will be
54288 + able to run servers. If this option is enabled, all users in the group
54289 + you specify will have to use passive mode when initiating ftp transfers
54290 + from the shell on your machine. If the sysctl option is enabled, a
54291 + sysctl option with name "socket_client" is created.
54292 +
54293 +config GRKERNSEC_SOCKET_CLIENT_GID
54294 + int "GID to deny client sockets for"
54295 + depends on GRKERNSEC_SOCKET_CLIENT
54296 + default 1003
54297 + help
54298 + Here you can choose the GID to disable client socket access for.
54299 + Remember to add the users you want client socket access disabled for to
54300 + the GID specified here. If the sysctl option is enabled, a sysctl
54301 + option with name "socket_client_gid" is created.
54302 +
54303 +config GRKERNSEC_SOCKET_SERVER
54304 + bool "Deny server sockets to group"
54305 + depends on GRKERNSEC_SOCKET
54306 + help
54307 + If you say Y here, you will be able to choose a GID of whose users will
54308 + be unable to run server applications from your machine. If the sysctl
54309 + option is enabled, a sysctl option with name "socket_server" is created.
54310 +
54311 +config GRKERNSEC_SOCKET_SERVER_GID
54312 + int "GID to deny server sockets for"
54313 + depends on GRKERNSEC_SOCKET_SERVER
54314 + default 1002
54315 + help
54316 + Here you can choose the GID to disable server socket access for.
54317 + Remember to add the users you want server socket access disabled for to
54318 + the GID specified here. If the sysctl option is enabled, a sysctl
54319 + option with name "socket_server_gid" is created.
54320 +
54321 +endmenu
54322 +menu "Sysctl Support"
54323 +depends on GRKERNSEC && SYSCTL
54324 +
54325 +config GRKERNSEC_SYSCTL
54326 + bool "Sysctl support"
54327 + default y if GRKERNSEC_CONFIG_AUTO
54328 + help
54329 + If you say Y here, you will be able to change the options that
54330 + grsecurity runs with at bootup, without having to recompile your
54331 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
54332 + to enable (1) or disable (0) various features. All the sysctl entries
54333 + are mutable until the "grsec_lock" entry is set to a non-zero value.
54334 + All features enabled in the kernel configuration are disabled at boot
54335 + if you do not say Y to the "Turn on features by default" option.
54336 + All options should be set at startup, and the grsec_lock entry should
54337 + be set to a non-zero value after all the options are set.
54338 + *THIS IS EXTREMELY IMPORTANT*
54339 +
54340 +config GRKERNSEC_SYSCTL_DISTRO
54341 + bool "Extra sysctl support for distro makers (READ HELP)"
54342 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
54343 + help
54344 + If you say Y here, additional sysctl options will be created
54345 + for features that affect processes running as root. Therefore,
54346 + it is critical when using this option that the grsec_lock entry be
54347 + enabled after boot. Only distros with prebuilt kernel packages
54348 + with this option enabled that can ensure grsec_lock is enabled
54349 + after boot should use this option.
54350 + *Failure to set grsec_lock after boot makes all grsec features
54351 + this option covers useless*
54352 +
54353 + Currently this option creates the following sysctl entries:
54354 + "Disable Privileged I/O": "disable_priv_io"
54355 +
54356 +config GRKERNSEC_SYSCTL_ON
54357 + bool "Turn on features by default"
54358 + default y if GRKERNSEC_CONFIG_AUTO
54359 + depends on GRKERNSEC_SYSCTL
54360 + help
54361 + If you say Y here, instead of having all features enabled in the
54362 + kernel configuration disabled at boot time, the features will be
54363 + enabled at boot time. It is recommended you say Y here unless
54364 + there is some reason you would want all sysctl-tunable features to
54365 + be disabled by default. As mentioned elsewhere, it is important
54366 + to enable the grsec_lock entry once you have finished modifying
54367 + the sysctl entries.
54368 +
54369 +endmenu
54370 +menu "Logging Options"
54371 +depends on GRKERNSEC
54372 +
54373 +config GRKERNSEC_FLOODTIME
54374 + int "Seconds in between log messages (minimum)"
54375 + default 10
54376 + help
54377 + This option allows you to enforce the number of seconds between
54378 + grsecurity log messages. The default should be suitable for most
54379 + people, however, if you choose to change it, choose a value small enough
54380 + to allow informative logs to be produced, but large enough to
54381 + prevent flooding.
54382 +
54383 +config GRKERNSEC_FLOODBURST
54384 + int "Number of messages in a burst (maximum)"
54385 + default 6
54386 + help
54387 + This option allows you to choose the maximum number of messages allowed
54388 + within the flood time interval you chose in a separate option. The
54389 + default should be suitable for most people, however if you find that
54390 + many of your logs are being interpreted as flooding, you may want to
54391 + raise this value.
54392 +
54393 +endmenu
54394 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
54395 new file mode 100644
54396 index 0000000..1b9afa9
54397 --- /dev/null
54398 +++ b/grsecurity/Makefile
54399 @@ -0,0 +1,38 @@
54400 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
54401 +# during 2001-2009 it has been completely redesigned by Brad Spengler
54402 +# into an RBAC system
54403 +#
54404 +# All code in this directory and various hooks inserted throughout the kernel
54405 +# are copyright Brad Spengler - Open Source Security, Inc., and released
54406 +# under the GPL v2 or higher
54407 +
54408 +KBUILD_CFLAGS += -Werror
54409 +
54410 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
54411 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
54412 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
54413 +
54414 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
54415 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
54416 + gracl_learn.o grsec_log.o
54417 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
54418 +
54419 +ifdef CONFIG_NET
54420 +obj-y += grsec_sock.o
54421 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
54422 +endif
54423 +
54424 +ifndef CONFIG_GRKERNSEC
54425 +obj-y += grsec_disabled.o
54426 +endif
54427 +
54428 +ifdef CONFIG_GRKERNSEC_HIDESYM
54429 +extra-y := grsec_hidesym.o
54430 +$(obj)/grsec_hidesym.o:
54431 + @-chmod -f 500 /boot
54432 + @-chmod -f 500 /lib/modules
54433 + @-chmod -f 500 /lib64/modules
54434 + @-chmod -f 500 /lib32/modules
54435 + @-chmod -f 700 .
54436 + @echo ' grsec: protected kernel image paths'
54437 +endif
54438 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
54439 new file mode 100644
54440 index 0000000..69e1320
54441 --- /dev/null
54442 +++ b/grsecurity/gracl.c
54443 @@ -0,0 +1,4019 @@
54444 +#include <linux/kernel.h>
54445 +#include <linux/module.h>
54446 +#include <linux/sched.h>
54447 +#include <linux/mm.h>
54448 +#include <linux/file.h>
54449 +#include <linux/fs.h>
54450 +#include <linux/namei.h>
54451 +#include <linux/mount.h>
54452 +#include <linux/tty.h>
54453 +#include <linux/proc_fs.h>
54454 +#include <linux/lglock.h>
54455 +#include <linux/slab.h>
54456 +#include <linux/vmalloc.h>
54457 +#include <linux/types.h>
54458 +#include <linux/sysctl.h>
54459 +#include <linux/netdevice.h>
54460 +#include <linux/ptrace.h>
54461 +#include <linux/gracl.h>
54462 +#include <linux/gralloc.h>
54463 +#include <linux/security.h>
54464 +#include <linux/grinternal.h>
54465 +#include <linux/pid_namespace.h>
54466 +#include <linux/stop_machine.h>
54467 +#include <linux/fdtable.h>
54468 +#include <linux/percpu.h>
54469 +#include <linux/lglock.h>
54470 +#include <linux/hugetlb.h>
54471 +#include "../fs/mount.h"
54472 +
54473 +#include <asm/uaccess.h>
54474 +#include <asm/errno.h>
54475 +#include <asm/mman.h>
54476 +
54477 +extern struct lglock vfsmount_lock;
54478 +
54479 +static struct acl_role_db acl_role_set;
54480 +static struct name_db name_set;
54481 +static struct inodev_db inodev_set;
54482 +
54483 +/* for keeping track of userspace pointers used for subjects, so we
54484 + can share references in the kernel as well
54485 +*/
54486 +
54487 +static struct path real_root;
54488 +
54489 +static struct acl_subj_map_db subj_map_set;
54490 +
54491 +static struct acl_role_label *default_role;
54492 +
54493 +static struct acl_role_label *role_list;
54494 +
54495 +static u16 acl_sp_role_value;
54496 +
54497 +extern char *gr_shared_page[4];
54498 +static DEFINE_MUTEX(gr_dev_mutex);
54499 +DEFINE_RWLOCK(gr_inode_lock);
54500 +
54501 +struct gr_arg *gr_usermode;
54502 +
54503 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
54504 +
54505 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
54506 +extern void gr_clear_learn_entries(void);
54507 +
54508 +unsigned char *gr_system_salt;
54509 +unsigned char *gr_system_sum;
54510 +
54511 +static struct sprole_pw **acl_special_roles = NULL;
54512 +static __u16 num_sprole_pws = 0;
54513 +
54514 +static struct acl_role_label *kernel_role = NULL;
54515 +
54516 +static unsigned int gr_auth_attempts = 0;
54517 +static unsigned long gr_auth_expires = 0UL;
54518 +
54519 +#ifdef CONFIG_NET
54520 +extern struct vfsmount *sock_mnt;
54521 +#endif
54522 +
54523 +extern struct vfsmount *pipe_mnt;
54524 +extern struct vfsmount *shm_mnt;
54525 +
54526 +#ifdef CONFIG_HUGETLBFS
54527 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54528 +#endif
54529 +
54530 +static struct acl_object_label *fakefs_obj_rw;
54531 +static struct acl_object_label *fakefs_obj_rwx;
54532 +
54533 +extern int gr_init_uidset(void);
54534 +extern void gr_free_uidset(void);
54535 +extern void gr_remove_uid(uid_t uid);
54536 +extern int gr_find_uid(uid_t uid);
54537 +
54538 +__inline__ int
54539 +gr_acl_is_enabled(void)
54540 +{
54541 + return (gr_status & GR_READY);
54542 +}
54543 +
54544 +#ifdef CONFIG_BTRFS_FS
54545 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
54546 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
54547 +#endif
54548 +
54549 +static inline dev_t __get_dev(const struct dentry *dentry)
54550 +{
54551 +#ifdef CONFIG_BTRFS_FS
54552 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
54553 + return get_btrfs_dev_from_inode(dentry->d_inode);
54554 + else
54555 +#endif
54556 + return dentry->d_inode->i_sb->s_dev;
54557 +}
54558 +
54559 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54560 +{
54561 + return __get_dev(dentry);
54562 +}
54563 +
54564 +static char gr_task_roletype_to_char(struct task_struct *task)
54565 +{
54566 + switch (task->role->roletype &
54567 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
54568 + GR_ROLE_SPECIAL)) {
54569 + case GR_ROLE_DEFAULT:
54570 + return 'D';
54571 + case GR_ROLE_USER:
54572 + return 'U';
54573 + case GR_ROLE_GROUP:
54574 + return 'G';
54575 + case GR_ROLE_SPECIAL:
54576 + return 'S';
54577 + }
54578 +
54579 + return 'X';
54580 +}
54581 +
54582 +char gr_roletype_to_char(void)
54583 +{
54584 + return gr_task_roletype_to_char(current);
54585 +}
54586 +
54587 +__inline__ int
54588 +gr_acl_tpe_check(void)
54589 +{
54590 + if (unlikely(!(gr_status & GR_READY)))
54591 + return 0;
54592 + if (current->role->roletype & GR_ROLE_TPE)
54593 + return 1;
54594 + else
54595 + return 0;
54596 +}
54597 +
54598 +int
54599 +gr_handle_rawio(const struct inode *inode)
54600 +{
54601 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54602 + if (inode && S_ISBLK(inode->i_mode) &&
54603 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54604 + !capable(CAP_SYS_RAWIO))
54605 + return 1;
54606 +#endif
54607 + return 0;
54608 +}
54609 +
54610 +static int
54611 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
54612 +{
54613 + if (likely(lena != lenb))
54614 + return 0;
54615 +
54616 + return !memcmp(a, b, lena);
54617 +}
54618 +
54619 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
54620 +{
54621 + *buflen -= namelen;
54622 + if (*buflen < 0)
54623 + return -ENAMETOOLONG;
54624 + *buffer -= namelen;
54625 + memcpy(*buffer, str, namelen);
54626 + return 0;
54627 +}
54628 +
54629 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
54630 +{
54631 + return prepend(buffer, buflen, name->name, name->len);
54632 +}
54633 +
54634 +static int prepend_path(const struct path *path, struct path *root,
54635 + char **buffer, int *buflen)
54636 +{
54637 + struct dentry *dentry = path->dentry;
54638 + struct vfsmount *vfsmnt = path->mnt;
54639 + struct mount *mnt = real_mount(vfsmnt);
54640 + bool slash = false;
54641 + int error = 0;
54642 +
54643 + while (dentry != root->dentry || vfsmnt != root->mnt) {
54644 + struct dentry * parent;
54645 +
54646 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
54647 + /* Global root? */
54648 + if (!mnt_has_parent(mnt)) {
54649 + goto out;
54650 + }
54651 + dentry = mnt->mnt_mountpoint;
54652 + mnt = mnt->mnt_parent;
54653 + vfsmnt = &mnt->mnt;
54654 + continue;
54655 + }
54656 + parent = dentry->d_parent;
54657 + prefetch(parent);
54658 + spin_lock(&dentry->d_lock);
54659 + error = prepend_name(buffer, buflen, &dentry->d_name);
54660 + spin_unlock(&dentry->d_lock);
54661 + if (!error)
54662 + error = prepend(buffer, buflen, "/", 1);
54663 + if (error)
54664 + break;
54665 +
54666 + slash = true;
54667 + dentry = parent;
54668 + }
54669 +
54670 +out:
54671 + if (!error && !slash)
54672 + error = prepend(buffer, buflen, "/", 1);
54673 +
54674 + return error;
54675 +}
54676 +
54677 +/* this must be called with vfsmount_lock and rename_lock held */
54678 +
54679 +static char *__our_d_path(const struct path *path, struct path *root,
54680 + char *buf, int buflen)
54681 +{
54682 + char *res = buf + buflen;
54683 + int error;
54684 +
54685 + prepend(&res, &buflen, "\0", 1);
54686 + error = prepend_path(path, root, &res, &buflen);
54687 + if (error)
54688 + return ERR_PTR(error);
54689 +
54690 + return res;
54691 +}
54692 +
54693 +static char *
54694 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
54695 +{
54696 + char *retval;
54697 +
54698 + retval = __our_d_path(path, root, buf, buflen);
54699 + if (unlikely(IS_ERR(retval)))
54700 + retval = strcpy(buf, "<path too long>");
54701 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
54702 + retval[1] = '\0';
54703 +
54704 + return retval;
54705 +}
54706 +
54707 +static char *
54708 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54709 + char *buf, int buflen)
54710 +{
54711 + struct path path;
54712 + char *res;
54713 +
54714 + path.dentry = (struct dentry *)dentry;
54715 + path.mnt = (struct vfsmount *)vfsmnt;
54716 +
54717 + /* we can use real_root.dentry, real_root.mnt, because this is only called
54718 + by the RBAC system */
54719 + res = gen_full_path(&path, &real_root, buf, buflen);
54720 +
54721 + return res;
54722 +}
54723 +
54724 +static char *
54725 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54726 + char *buf, int buflen)
54727 +{
54728 + char *res;
54729 + struct path path;
54730 + struct path root;
54731 + struct task_struct *reaper = init_pid_ns.child_reaper;
54732 +
54733 + path.dentry = (struct dentry *)dentry;
54734 + path.mnt = (struct vfsmount *)vfsmnt;
54735 +
54736 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
54737 + get_fs_root(reaper->fs, &root);
54738 +
54739 + write_seqlock(&rename_lock);
54740 + br_read_lock(&vfsmount_lock);
54741 + res = gen_full_path(&path, &root, buf, buflen);
54742 + br_read_unlock(&vfsmount_lock);
54743 + write_sequnlock(&rename_lock);
54744 +
54745 + path_put(&root);
54746 + return res;
54747 +}
54748 +
54749 +static char *
54750 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54751 +{
54752 + char *ret;
54753 + write_seqlock(&rename_lock);
54754 + br_read_lock(&vfsmount_lock);
54755 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54756 + PAGE_SIZE);
54757 + br_read_unlock(&vfsmount_lock);
54758 + write_sequnlock(&rename_lock);
54759 + return ret;
54760 +}
54761 +
54762 +static char *
54763 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54764 +{
54765 + char *ret;
54766 + char *buf;
54767 + int buflen;
54768 +
54769 + write_seqlock(&rename_lock);
54770 + br_read_lock(&vfsmount_lock);
54771 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54772 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54773 + buflen = (int)(ret - buf);
54774 + if (buflen >= 5)
54775 + prepend(&ret, &buflen, "/proc", 5);
54776 + else
54777 + ret = strcpy(buf, "<path too long>");
54778 + br_read_unlock(&vfsmount_lock);
54779 + write_sequnlock(&rename_lock);
54780 + return ret;
54781 +}
54782 +
54783 +char *
54784 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54785 +{
54786 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54787 + PAGE_SIZE);
54788 +}
54789 +
54790 +char *
54791 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54792 +{
54793 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54794 + PAGE_SIZE);
54795 +}
54796 +
54797 +char *
54798 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54799 +{
54800 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54801 + PAGE_SIZE);
54802 +}
54803 +
54804 +char *
54805 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54806 +{
54807 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54808 + PAGE_SIZE);
54809 +}
54810 +
54811 +char *
54812 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54813 +{
54814 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54815 + PAGE_SIZE);
54816 +}
54817 +
54818 +__inline__ __u32
54819 +to_gr_audit(const __u32 reqmode)
54820 +{
54821 + /* masks off auditable permission flags, then shifts them to create
54822 + auditing flags, and adds the special case of append auditing if
54823 + we're requesting write */
54824 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54825 +}
54826 +
54827 +struct acl_subject_label *
54828 +lookup_subject_map(const struct acl_subject_label *userp)
54829 +{
54830 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
54831 + struct subject_map *match;
54832 +
54833 + match = subj_map_set.s_hash[index];
54834 +
54835 + while (match && match->user != userp)
54836 + match = match->next;
54837 +
54838 + if (match != NULL)
54839 + return match->kernel;
54840 + else
54841 + return NULL;
54842 +}
54843 +
54844 +static void
54845 +insert_subj_map_entry(struct subject_map *subjmap)
54846 +{
54847 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54848 + struct subject_map **curr;
54849 +
54850 + subjmap->prev = NULL;
54851 +
54852 + curr = &subj_map_set.s_hash[index];
54853 + if (*curr != NULL)
54854 + (*curr)->prev = subjmap;
54855 +
54856 + subjmap->next = *curr;
54857 + *curr = subjmap;
54858 +
54859 + return;
54860 +}
54861 +
54862 +static struct acl_role_label *
54863 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54864 + const gid_t gid)
54865 +{
54866 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54867 + struct acl_role_label *match;
54868 + struct role_allowed_ip *ipp;
54869 + unsigned int x;
54870 + u32 curr_ip = task->signal->curr_ip;
54871 +
54872 + task->signal->saved_ip = curr_ip;
54873 +
54874 + match = acl_role_set.r_hash[index];
54875 +
54876 + while (match) {
54877 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54878 + for (x = 0; x < match->domain_child_num; x++) {
54879 + if (match->domain_children[x] == uid)
54880 + goto found;
54881 + }
54882 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54883 + break;
54884 + match = match->next;
54885 + }
54886 +found:
54887 + if (match == NULL) {
54888 + try_group:
54889 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54890 + match = acl_role_set.r_hash[index];
54891 +
54892 + while (match) {
54893 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54894 + for (x = 0; x < match->domain_child_num; x++) {
54895 + if (match->domain_children[x] == gid)
54896 + goto found2;
54897 + }
54898 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54899 + break;
54900 + match = match->next;
54901 + }
54902 +found2:
54903 + if (match == NULL)
54904 + match = default_role;
54905 + if (match->allowed_ips == NULL)
54906 + return match;
54907 + else {
54908 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54909 + if (likely
54910 + ((ntohl(curr_ip) & ipp->netmask) ==
54911 + (ntohl(ipp->addr) & ipp->netmask)))
54912 + return match;
54913 + }
54914 + match = default_role;
54915 + }
54916 + } else if (match->allowed_ips == NULL) {
54917 + return match;
54918 + } else {
54919 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54920 + if (likely
54921 + ((ntohl(curr_ip) & ipp->netmask) ==
54922 + (ntohl(ipp->addr) & ipp->netmask)))
54923 + return match;
54924 + }
54925 + goto try_group;
54926 + }
54927 +
54928 + return match;
54929 +}
54930 +
54931 +struct acl_subject_label *
54932 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54933 + const struct acl_role_label *role)
54934 +{
54935 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54936 + struct acl_subject_label *match;
54937 +
54938 + match = role->subj_hash[index];
54939 +
54940 + while (match && (match->inode != ino || match->device != dev ||
54941 + (match->mode & GR_DELETED))) {
54942 + match = match->next;
54943 + }
54944 +
54945 + if (match && !(match->mode & GR_DELETED))
54946 + return match;
54947 + else
54948 + return NULL;
54949 +}
54950 +
54951 +struct acl_subject_label *
54952 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54953 + const struct acl_role_label *role)
54954 +{
54955 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54956 + struct acl_subject_label *match;
54957 +
54958 + match = role->subj_hash[index];
54959 +
54960 + while (match && (match->inode != ino || match->device != dev ||
54961 + !(match->mode & GR_DELETED))) {
54962 + match = match->next;
54963 + }
54964 +
54965 + if (match && (match->mode & GR_DELETED))
54966 + return match;
54967 + else
54968 + return NULL;
54969 +}
54970 +
54971 +static struct acl_object_label *
54972 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54973 + const struct acl_subject_label *subj)
54974 +{
54975 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54976 + struct acl_object_label *match;
54977 +
54978 + match = subj->obj_hash[index];
54979 +
54980 + while (match && (match->inode != ino || match->device != dev ||
54981 + (match->mode & GR_DELETED))) {
54982 + match = match->next;
54983 + }
54984 +
54985 + if (match && !(match->mode & GR_DELETED))
54986 + return match;
54987 + else
54988 + return NULL;
54989 +}
54990 +
54991 +static struct acl_object_label *
54992 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54993 + const struct acl_subject_label *subj)
54994 +{
54995 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54996 + struct acl_object_label *match;
54997 +
54998 + match = subj->obj_hash[index];
54999 +
55000 + while (match && (match->inode != ino || match->device != dev ||
55001 + !(match->mode & GR_DELETED))) {
55002 + match = match->next;
55003 + }
55004 +
55005 + if (match && (match->mode & GR_DELETED))
55006 + return match;
55007 +
55008 + match = subj->obj_hash[index];
55009 +
55010 + while (match && (match->inode != ino || match->device != dev ||
55011 + (match->mode & GR_DELETED))) {
55012 + match = match->next;
55013 + }
55014 +
55015 + if (match && !(match->mode & GR_DELETED))
55016 + return match;
55017 + else
55018 + return NULL;
55019 +}
55020 +
55021 +static struct name_entry *
55022 +lookup_name_entry(const char *name)
55023 +{
55024 + unsigned int len = strlen(name);
55025 + unsigned int key = full_name_hash(name, len);
55026 + unsigned int index = key % name_set.n_size;
55027 + struct name_entry *match;
55028 +
55029 + match = name_set.n_hash[index];
55030 +
55031 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
55032 + match = match->next;
55033 +
55034 + return match;
55035 +}
55036 +
55037 +static struct name_entry *
55038 +lookup_name_entry_create(const char *name)
55039 +{
55040 + unsigned int len = strlen(name);
55041 + unsigned int key = full_name_hash(name, len);
55042 + unsigned int index = key % name_set.n_size;
55043 + struct name_entry *match;
55044 +
55045 + match = name_set.n_hash[index];
55046 +
55047 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55048 + !match->deleted))
55049 + match = match->next;
55050 +
55051 + if (match && match->deleted)
55052 + return match;
55053 +
55054 + match = name_set.n_hash[index];
55055 +
55056 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55057 + match->deleted))
55058 + match = match->next;
55059 +
55060 + if (match && !match->deleted)
55061 + return match;
55062 + else
55063 + return NULL;
55064 +}
55065 +
55066 +static struct inodev_entry *
55067 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
55068 +{
55069 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
55070 + struct inodev_entry *match;
55071 +
55072 + match = inodev_set.i_hash[index];
55073 +
55074 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
55075 + match = match->next;
55076 +
55077 + return match;
55078 +}
55079 +
55080 +static void
55081 +insert_inodev_entry(struct inodev_entry *entry)
55082 +{
55083 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
55084 + inodev_set.i_size);
55085 + struct inodev_entry **curr;
55086 +
55087 + entry->prev = NULL;
55088 +
55089 + curr = &inodev_set.i_hash[index];
55090 + if (*curr != NULL)
55091 + (*curr)->prev = entry;
55092 +
55093 + entry->next = *curr;
55094 + *curr = entry;
55095 +
55096 + return;
55097 +}
55098 +
55099 +static void
55100 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
55101 +{
55102 + unsigned int index =
55103 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
55104 + struct acl_role_label **curr;
55105 + struct acl_role_label *tmp, *tmp2;
55106 +
55107 + curr = &acl_role_set.r_hash[index];
55108 +
55109 + /* simple case, slot is empty, just set it to our role */
55110 + if (*curr == NULL) {
55111 + *curr = role;
55112 + } else {
55113 + /* example:
55114 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
55115 + 2 -> 3
55116 + */
55117 + /* first check to see if we can already be reached via this slot */
55118 + tmp = *curr;
55119 + while (tmp && tmp != role)
55120 + tmp = tmp->next;
55121 + if (tmp == role) {
55122 + /* we don't need to add ourselves to this slot's chain */
55123 + return;
55124 + }
55125 + /* we need to add ourselves to this chain, two cases */
55126 + if (role->next == NULL) {
55127 + /* simple case, append the current chain to our role */
55128 + role->next = *curr;
55129 + *curr = role;
55130 + } else {
55131 + /* 1 -> 2 -> 3 -> 4
55132 + 2 -> 3 -> 4
55133 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
55134 + */
55135 + /* trickier case: walk our role's chain until we find
55136 + the role for the start of the current slot's chain */
55137 + tmp = role;
55138 + tmp2 = *curr;
55139 + while (tmp->next && tmp->next != tmp2)
55140 + tmp = tmp->next;
55141 + if (tmp->next == tmp2) {
55142 + /* from example above, we found 3, so just
55143 + replace this slot's chain with ours */
55144 + *curr = role;
55145 + } else {
55146 + /* we didn't find a subset of our role's chain
55147 + in the current slot's chain, so append their
55148 + chain to ours, and set us as the first role in
55149 + the slot's chain
55150 +
55151 + we could fold this case with the case above,
55152 + but making it explicit for clarity
55153 + */
55154 + tmp->next = tmp2;
55155 + *curr = role;
55156 + }
55157 + }
55158 + }
55159 +
55160 + return;
55161 +}
55162 +
55163 +static void
55164 +insert_acl_role_label(struct acl_role_label *role)
55165 +{
55166 + int i;
55167 +
55168 + if (role_list == NULL) {
55169 + role_list = role;
55170 + role->prev = NULL;
55171 + } else {
55172 + role->prev = role_list;
55173 + role_list = role;
55174 + }
55175 +
55176 + /* used for hash chains */
55177 + role->next = NULL;
55178 +
55179 + if (role->roletype & GR_ROLE_DOMAIN) {
55180 + for (i = 0; i < role->domain_child_num; i++)
55181 + __insert_acl_role_label(role, role->domain_children[i]);
55182 + } else
55183 + __insert_acl_role_label(role, role->uidgid);
55184 +}
55185 +
55186 +static int
55187 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
55188 +{
55189 + struct name_entry **curr, *nentry;
55190 + struct inodev_entry *ientry;
55191 + unsigned int len = strlen(name);
55192 + unsigned int key = full_name_hash(name, len);
55193 + unsigned int index = key % name_set.n_size;
55194 +
55195 + curr = &name_set.n_hash[index];
55196 +
55197 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
55198 + curr = &((*curr)->next);
55199 +
55200 + if (*curr != NULL)
55201 + return 1;
55202 +
55203 + nentry = acl_alloc(sizeof (struct name_entry));
55204 + if (nentry == NULL)
55205 + return 0;
55206 + ientry = acl_alloc(sizeof (struct inodev_entry));
55207 + if (ientry == NULL)
55208 + return 0;
55209 + ientry->nentry = nentry;
55210 +
55211 + nentry->key = key;
55212 + nentry->name = name;
55213 + nentry->inode = inode;
55214 + nentry->device = device;
55215 + nentry->len = len;
55216 + nentry->deleted = deleted;
55217 +
55218 + nentry->prev = NULL;
55219 + curr = &name_set.n_hash[index];
55220 + if (*curr != NULL)
55221 + (*curr)->prev = nentry;
55222 + nentry->next = *curr;
55223 + *curr = nentry;
55224 +
55225 + /* insert us into the table searchable by inode/dev */
55226 + insert_inodev_entry(ientry);
55227 +
55228 + return 1;
55229 +}
55230 +
55231 +static void
55232 +insert_acl_obj_label(struct acl_object_label *obj,
55233 + struct acl_subject_label *subj)
55234 +{
55235 + unsigned int index =
55236 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
55237 + struct acl_object_label **curr;
55238 +
55239 +
55240 + obj->prev = NULL;
55241 +
55242 + curr = &subj->obj_hash[index];
55243 + if (*curr != NULL)
55244 + (*curr)->prev = obj;
55245 +
55246 + obj->next = *curr;
55247 + *curr = obj;
55248 +
55249 + return;
55250 +}
55251 +
55252 +static void
55253 +insert_acl_subj_label(struct acl_subject_label *obj,
55254 + struct acl_role_label *role)
55255 +{
55256 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
55257 + struct acl_subject_label **curr;
55258 +
55259 + obj->prev = NULL;
55260 +
55261 + curr = &role->subj_hash[index];
55262 + if (*curr != NULL)
55263 + (*curr)->prev = obj;
55264 +
55265 + obj->next = *curr;
55266 + *curr = obj;
55267 +
55268 + return;
55269 +}
55270 +
55271 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
55272 +
55273 +static void *
55274 +create_table(__u32 * len, int elementsize)
55275 +{
55276 + unsigned int table_sizes[] = {
55277 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
55278 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
55279 + 4194301, 8388593, 16777213, 33554393, 67108859
55280 + };
55281 + void *newtable = NULL;
55282 + unsigned int pwr = 0;
55283 +
55284 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
55285 + table_sizes[pwr] <= *len)
55286 + pwr++;
55287 +
55288 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
55289 + return newtable;
55290 +
55291 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
55292 + newtable =
55293 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
55294 + else
55295 + newtable = vmalloc(table_sizes[pwr] * elementsize);
55296 +
55297 + *len = table_sizes[pwr];
55298 +
55299 + return newtable;
55300 +}
55301 +
55302 +static int
55303 +init_variables(const struct gr_arg *arg)
55304 +{
55305 + struct task_struct *reaper = init_pid_ns.child_reaper;
55306 + unsigned int stacksize;
55307 +
55308 + subj_map_set.s_size = arg->role_db.num_subjects;
55309 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
55310 + name_set.n_size = arg->role_db.num_objects;
55311 + inodev_set.i_size = arg->role_db.num_objects;
55312 +
55313 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
55314 + !name_set.n_size || !inodev_set.i_size)
55315 + return 1;
55316 +
55317 + if (!gr_init_uidset())
55318 + return 1;
55319 +
55320 + /* set up the stack that holds allocation info */
55321 +
55322 + stacksize = arg->role_db.num_pointers + 5;
55323 +
55324 + if (!acl_alloc_stack_init(stacksize))
55325 + return 1;
55326 +
55327 + /* grab reference for the real root dentry and vfsmount */
55328 + get_fs_root(reaper->fs, &real_root);
55329 +
55330 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55331 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
55332 +#endif
55333 +
55334 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
55335 + if (fakefs_obj_rw == NULL)
55336 + return 1;
55337 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
55338 +
55339 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
55340 + if (fakefs_obj_rwx == NULL)
55341 + return 1;
55342 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
55343 +
55344 + subj_map_set.s_hash =
55345 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
55346 + acl_role_set.r_hash =
55347 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
55348 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
55349 + inodev_set.i_hash =
55350 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
55351 +
55352 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
55353 + !name_set.n_hash || !inodev_set.i_hash)
55354 + return 1;
55355 +
55356 + memset(subj_map_set.s_hash, 0,
55357 + sizeof(struct subject_map *) * subj_map_set.s_size);
55358 + memset(acl_role_set.r_hash, 0,
55359 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
55360 + memset(name_set.n_hash, 0,
55361 + sizeof (struct name_entry *) * name_set.n_size);
55362 + memset(inodev_set.i_hash, 0,
55363 + sizeof (struct inodev_entry *) * inodev_set.i_size);
55364 +
55365 + return 0;
55366 +}
55367 +
55368 +/* free information not needed after startup
55369 + currently contains user->kernel pointer mappings for subjects
55370 +*/
55371 +
55372 +static void
55373 +free_init_variables(void)
55374 +{
55375 + __u32 i;
55376 +
55377 + if (subj_map_set.s_hash) {
55378 + for (i = 0; i < subj_map_set.s_size; i++) {
55379 + if (subj_map_set.s_hash[i]) {
55380 + kfree(subj_map_set.s_hash[i]);
55381 + subj_map_set.s_hash[i] = NULL;
55382 + }
55383 + }
55384 +
55385 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
55386 + PAGE_SIZE)
55387 + kfree(subj_map_set.s_hash);
55388 + else
55389 + vfree(subj_map_set.s_hash);
55390 + }
55391 +
55392 + return;
55393 +}
55394 +
55395 +static void
55396 +free_variables(void)
55397 +{
55398 + struct acl_subject_label *s;
55399 + struct acl_role_label *r;
55400 + struct task_struct *task, *task2;
55401 + unsigned int x;
55402 +
55403 + gr_clear_learn_entries();
55404 +
55405 + read_lock(&tasklist_lock);
55406 + do_each_thread(task2, task) {
55407 + task->acl_sp_role = 0;
55408 + task->acl_role_id = 0;
55409 + task->acl = NULL;
55410 + task->role = NULL;
55411 + } while_each_thread(task2, task);
55412 + read_unlock(&tasklist_lock);
55413 +
55414 + /* release the reference to the real root dentry and vfsmount */
55415 + path_put(&real_root);
55416 + memset(&real_root, 0, sizeof(real_root));
55417 +
55418 + /* free all object hash tables */
55419 +
55420 + FOR_EACH_ROLE_START(r)
55421 + if (r->subj_hash == NULL)
55422 + goto next_role;
55423 + FOR_EACH_SUBJECT_START(r, s, x)
55424 + if (s->obj_hash == NULL)
55425 + break;
55426 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55427 + kfree(s->obj_hash);
55428 + else
55429 + vfree(s->obj_hash);
55430 + FOR_EACH_SUBJECT_END(s, x)
55431 + FOR_EACH_NESTED_SUBJECT_START(r, s)
55432 + if (s->obj_hash == NULL)
55433 + break;
55434 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55435 + kfree(s->obj_hash);
55436 + else
55437 + vfree(s->obj_hash);
55438 + FOR_EACH_NESTED_SUBJECT_END(s)
55439 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
55440 + kfree(r->subj_hash);
55441 + else
55442 + vfree(r->subj_hash);
55443 + r->subj_hash = NULL;
55444 +next_role:
55445 + FOR_EACH_ROLE_END(r)
55446 +
55447 + acl_free_all();
55448 +
55449 + if (acl_role_set.r_hash) {
55450 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
55451 + PAGE_SIZE)
55452 + kfree(acl_role_set.r_hash);
55453 + else
55454 + vfree(acl_role_set.r_hash);
55455 + }
55456 + if (name_set.n_hash) {
55457 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
55458 + PAGE_SIZE)
55459 + kfree(name_set.n_hash);
55460 + else
55461 + vfree(name_set.n_hash);
55462 + }
55463 +
55464 + if (inodev_set.i_hash) {
55465 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
55466 + PAGE_SIZE)
55467 + kfree(inodev_set.i_hash);
55468 + else
55469 + vfree(inodev_set.i_hash);
55470 + }
55471 +
55472 + gr_free_uidset();
55473 +
55474 + memset(&name_set, 0, sizeof (struct name_db));
55475 + memset(&inodev_set, 0, sizeof (struct inodev_db));
55476 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
55477 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
55478 +
55479 + default_role = NULL;
55480 + kernel_role = NULL;
55481 + role_list = NULL;
55482 +
55483 + return;
55484 +}
55485 +
55486 +static __u32
55487 +count_user_objs(struct acl_object_label *userp)
55488 +{
55489 + struct acl_object_label o_tmp;
55490 + __u32 num = 0;
55491 +
55492 + while (userp) {
55493 + if (copy_from_user(&o_tmp, userp,
55494 + sizeof (struct acl_object_label)))
55495 + break;
55496 +
55497 + userp = o_tmp.prev;
55498 + num++;
55499 + }
55500 +
55501 + return num;
55502 +}
55503 +
55504 +static struct acl_subject_label *
55505 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
55506 +
55507 +static int
55508 +copy_user_glob(struct acl_object_label *obj)
55509 +{
55510 + struct acl_object_label *g_tmp, **guser;
55511 + unsigned int len;
55512 + char *tmp;
55513 +
55514 + if (obj->globbed == NULL)
55515 + return 0;
55516 +
55517 + guser = &obj->globbed;
55518 + while (*guser) {
55519 + g_tmp = (struct acl_object_label *)
55520 + acl_alloc(sizeof (struct acl_object_label));
55521 + if (g_tmp == NULL)
55522 + return -ENOMEM;
55523 +
55524 + if (copy_from_user(g_tmp, *guser,
55525 + sizeof (struct acl_object_label)))
55526 + return -EFAULT;
55527 +
55528 + len = strnlen_user(g_tmp->filename, PATH_MAX);
55529 +
55530 + if (!len || len >= PATH_MAX)
55531 + return -EINVAL;
55532 +
55533 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55534 + return -ENOMEM;
55535 +
55536 + if (copy_from_user(tmp, g_tmp->filename, len))
55537 + return -EFAULT;
55538 + tmp[len-1] = '\0';
55539 + g_tmp->filename = tmp;
55540 +
55541 + *guser = g_tmp;
55542 + guser = &(g_tmp->next);
55543 + }
55544 +
55545 + return 0;
55546 +}
55547 +
55548 +static int
55549 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
55550 + struct acl_role_label *role)
55551 +{
55552 + struct acl_object_label *o_tmp;
55553 + unsigned int len;
55554 + int ret;
55555 + char *tmp;
55556 +
55557 + while (userp) {
55558 + if ((o_tmp = (struct acl_object_label *)
55559 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
55560 + return -ENOMEM;
55561 +
55562 + if (copy_from_user(o_tmp, userp,
55563 + sizeof (struct acl_object_label)))
55564 + return -EFAULT;
55565 +
55566 + userp = o_tmp->prev;
55567 +
55568 + len = strnlen_user(o_tmp->filename, PATH_MAX);
55569 +
55570 + if (!len || len >= PATH_MAX)
55571 + return -EINVAL;
55572 +
55573 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55574 + return -ENOMEM;
55575 +
55576 + if (copy_from_user(tmp, o_tmp->filename, len))
55577 + return -EFAULT;
55578 + tmp[len-1] = '\0';
55579 + o_tmp->filename = tmp;
55580 +
55581 + insert_acl_obj_label(o_tmp, subj);
55582 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
55583 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
55584 + return -ENOMEM;
55585 +
55586 + ret = copy_user_glob(o_tmp);
55587 + if (ret)
55588 + return ret;
55589 +
55590 + if (o_tmp->nested) {
55591 + int already_copied;
55592 +
55593 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
55594 + if (IS_ERR(o_tmp->nested))
55595 + return PTR_ERR(o_tmp->nested);
55596 +
55597 + /* insert into nested subject list if we haven't copied this one yet
55598 + to prevent duplicate entries */
55599 + if (!already_copied) {
55600 + o_tmp->nested->next = role->hash->first;
55601 + role->hash->first = o_tmp->nested;
55602 + }
55603 + }
55604 + }
55605 +
55606 + return 0;
55607 +}
55608 +
55609 +static __u32
55610 +count_user_subjs(struct acl_subject_label *userp)
55611 +{
55612 + struct acl_subject_label s_tmp;
55613 + __u32 num = 0;
55614 +
55615 + while (userp) {
55616 + if (copy_from_user(&s_tmp, userp,
55617 + sizeof (struct acl_subject_label)))
55618 + break;
55619 +
55620 + userp = s_tmp.prev;
55621 + }
55622 +
55623 + return num;
55624 +}
55625 +
55626 +static int
55627 +copy_user_allowedips(struct acl_role_label *rolep)
55628 +{
55629 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
55630 +
55631 + ruserip = rolep->allowed_ips;
55632 +
55633 + while (ruserip) {
55634 + rlast = rtmp;
55635 +
55636 + if ((rtmp = (struct role_allowed_ip *)
55637 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
55638 + return -ENOMEM;
55639 +
55640 + if (copy_from_user(rtmp, ruserip,
55641 + sizeof (struct role_allowed_ip)))
55642 + return -EFAULT;
55643 +
55644 + ruserip = rtmp->prev;
55645 +
55646 + if (!rlast) {
55647 + rtmp->prev = NULL;
55648 + rolep->allowed_ips = rtmp;
55649 + } else {
55650 + rlast->next = rtmp;
55651 + rtmp->prev = rlast;
55652 + }
55653 +
55654 + if (!ruserip)
55655 + rtmp->next = NULL;
55656 + }
55657 +
55658 + return 0;
55659 +}
55660 +
55661 +static int
55662 +copy_user_transitions(struct acl_role_label *rolep)
55663 +{
55664 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
55665 +
55666 + unsigned int len;
55667 + char *tmp;
55668 +
55669 + rusertp = rolep->transitions;
55670 +
55671 + while (rusertp) {
55672 + rlast = rtmp;
55673 +
55674 + if ((rtmp = (struct role_transition *)
55675 + acl_alloc(sizeof (struct role_transition))) == NULL)
55676 + return -ENOMEM;
55677 +
55678 + if (copy_from_user(rtmp, rusertp,
55679 + sizeof (struct role_transition)))
55680 + return -EFAULT;
55681 +
55682 + rusertp = rtmp->prev;
55683 +
55684 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
55685 +
55686 + if (!len || len >= GR_SPROLE_LEN)
55687 + return -EINVAL;
55688 +
55689 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55690 + return -ENOMEM;
55691 +
55692 + if (copy_from_user(tmp, rtmp->rolename, len))
55693 + return -EFAULT;
55694 + tmp[len-1] = '\0';
55695 + rtmp->rolename = tmp;
55696 +
55697 + if (!rlast) {
55698 + rtmp->prev = NULL;
55699 + rolep->transitions = rtmp;
55700 + } else {
55701 + rlast->next = rtmp;
55702 + rtmp->prev = rlast;
55703 + }
55704 +
55705 + if (!rusertp)
55706 + rtmp->next = NULL;
55707 + }
55708 +
55709 + return 0;
55710 +}
55711 +
55712 +static struct acl_subject_label *
55713 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
55714 +{
55715 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
55716 + unsigned int len;
55717 + char *tmp;
55718 + __u32 num_objs;
55719 + struct acl_ip_label **i_tmp, *i_utmp2;
55720 + struct gr_hash_struct ghash;
55721 + struct subject_map *subjmap;
55722 + unsigned int i_num;
55723 + int err;
55724 +
55725 + if (already_copied != NULL)
55726 + *already_copied = 0;
55727 +
55728 + s_tmp = lookup_subject_map(userp);
55729 +
55730 + /* we've already copied this subject into the kernel, just return
55731 + the reference to it, and don't copy it over again
55732 + */
55733 + if (s_tmp) {
55734 + if (already_copied != NULL)
55735 + *already_copied = 1;
55736 + return(s_tmp);
55737 + }
55738 +
55739 + if ((s_tmp = (struct acl_subject_label *)
55740 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
55741 + return ERR_PTR(-ENOMEM);
55742 +
55743 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
55744 + if (subjmap == NULL)
55745 + return ERR_PTR(-ENOMEM);
55746 +
55747 + subjmap->user = userp;
55748 + subjmap->kernel = s_tmp;
55749 + insert_subj_map_entry(subjmap);
55750 +
55751 + if (copy_from_user(s_tmp, userp,
55752 + sizeof (struct acl_subject_label)))
55753 + return ERR_PTR(-EFAULT);
55754 +
55755 + len = strnlen_user(s_tmp->filename, PATH_MAX);
55756 +
55757 + if (!len || len >= PATH_MAX)
55758 + return ERR_PTR(-EINVAL);
55759 +
55760 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55761 + return ERR_PTR(-ENOMEM);
55762 +
55763 + if (copy_from_user(tmp, s_tmp->filename, len))
55764 + return ERR_PTR(-EFAULT);
55765 + tmp[len-1] = '\0';
55766 + s_tmp->filename = tmp;
55767 +
55768 + if (!strcmp(s_tmp->filename, "/"))
55769 + role->root_label = s_tmp;
55770 +
55771 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55772 + return ERR_PTR(-EFAULT);
55773 +
55774 + /* copy user and group transition tables */
55775 +
55776 + if (s_tmp->user_trans_num) {
55777 + uid_t *uidlist;
55778 +
55779 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55780 + if (uidlist == NULL)
55781 + return ERR_PTR(-ENOMEM);
55782 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55783 + return ERR_PTR(-EFAULT);
55784 +
55785 + s_tmp->user_transitions = uidlist;
55786 + }
55787 +
55788 + if (s_tmp->group_trans_num) {
55789 + gid_t *gidlist;
55790 +
55791 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55792 + if (gidlist == NULL)
55793 + return ERR_PTR(-ENOMEM);
55794 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55795 + return ERR_PTR(-EFAULT);
55796 +
55797 + s_tmp->group_transitions = gidlist;
55798 + }
55799 +
55800 + /* set up object hash table */
55801 + num_objs = count_user_objs(ghash.first);
55802 +
55803 + s_tmp->obj_hash_size = num_objs;
55804 + s_tmp->obj_hash =
55805 + (struct acl_object_label **)
55806 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55807 +
55808 + if (!s_tmp->obj_hash)
55809 + return ERR_PTR(-ENOMEM);
55810 +
55811 + memset(s_tmp->obj_hash, 0,
55812 + s_tmp->obj_hash_size *
55813 + sizeof (struct acl_object_label *));
55814 +
55815 + /* add in objects */
55816 + err = copy_user_objs(ghash.first, s_tmp, role);
55817 +
55818 + if (err)
55819 + return ERR_PTR(err);
55820 +
55821 + /* set pointer for parent subject */
55822 + if (s_tmp->parent_subject) {
55823 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55824 +
55825 + if (IS_ERR(s_tmp2))
55826 + return s_tmp2;
55827 +
55828 + s_tmp->parent_subject = s_tmp2;
55829 + }
55830 +
55831 + /* add in ip acls */
55832 +
55833 + if (!s_tmp->ip_num) {
55834 + s_tmp->ips = NULL;
55835 + goto insert;
55836 + }
55837 +
55838 + i_tmp =
55839 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55840 + sizeof (struct acl_ip_label *));
55841 +
55842 + if (!i_tmp)
55843 + return ERR_PTR(-ENOMEM);
55844 +
55845 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55846 + *(i_tmp + i_num) =
55847 + (struct acl_ip_label *)
55848 + acl_alloc(sizeof (struct acl_ip_label));
55849 + if (!*(i_tmp + i_num))
55850 + return ERR_PTR(-ENOMEM);
55851 +
55852 + if (copy_from_user
55853 + (&i_utmp2, s_tmp->ips + i_num,
55854 + sizeof (struct acl_ip_label *)))
55855 + return ERR_PTR(-EFAULT);
55856 +
55857 + if (copy_from_user
55858 + (*(i_tmp + i_num), i_utmp2,
55859 + sizeof (struct acl_ip_label)))
55860 + return ERR_PTR(-EFAULT);
55861 +
55862 + if ((*(i_tmp + i_num))->iface == NULL)
55863 + continue;
55864 +
55865 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55866 + if (!len || len >= IFNAMSIZ)
55867 + return ERR_PTR(-EINVAL);
55868 + tmp = acl_alloc(len);
55869 + if (tmp == NULL)
55870 + return ERR_PTR(-ENOMEM);
55871 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55872 + return ERR_PTR(-EFAULT);
55873 + (*(i_tmp + i_num))->iface = tmp;
55874 + }
55875 +
55876 + s_tmp->ips = i_tmp;
55877 +
55878 +insert:
55879 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55880 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55881 + return ERR_PTR(-ENOMEM);
55882 +
55883 + return s_tmp;
55884 +}
55885 +
55886 +static int
55887 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55888 +{
55889 + struct acl_subject_label s_pre;
55890 + struct acl_subject_label * ret;
55891 + int err;
55892 +
55893 + while (userp) {
55894 + if (copy_from_user(&s_pre, userp,
55895 + sizeof (struct acl_subject_label)))
55896 + return -EFAULT;
55897 +
55898 + ret = do_copy_user_subj(userp, role, NULL);
55899 +
55900 + err = PTR_ERR(ret);
55901 + if (IS_ERR(ret))
55902 + return err;
55903 +
55904 + insert_acl_subj_label(ret, role);
55905 +
55906 + userp = s_pre.prev;
55907 + }
55908 +
55909 + return 0;
55910 +}
55911 +
55912 +static int
55913 +copy_user_acl(struct gr_arg *arg)
55914 +{
55915 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55916 + struct acl_subject_label *subj_list;
55917 + struct sprole_pw *sptmp;
55918 + struct gr_hash_struct *ghash;
55919 + uid_t *domainlist;
55920 + unsigned int r_num;
55921 + unsigned int len;
55922 + char *tmp;
55923 + int err = 0;
55924 + __u16 i;
55925 + __u32 num_subjs;
55926 +
55927 + /* we need a default and kernel role */
55928 + if (arg->role_db.num_roles < 2)
55929 + return -EINVAL;
55930 +
55931 + /* copy special role authentication info from userspace */
55932 +
55933 + num_sprole_pws = arg->num_sprole_pws;
55934 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55935 +
55936 + if (!acl_special_roles && num_sprole_pws)
55937 + return -ENOMEM;
55938 +
55939 + for (i = 0; i < num_sprole_pws; i++) {
55940 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55941 + if (!sptmp)
55942 + return -ENOMEM;
55943 + if (copy_from_user(sptmp, arg->sprole_pws + i,
55944 + sizeof (struct sprole_pw)))
55945 + return -EFAULT;
55946 +
55947 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55948 +
55949 + if (!len || len >= GR_SPROLE_LEN)
55950 + return -EINVAL;
55951 +
55952 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55953 + return -ENOMEM;
55954 +
55955 + if (copy_from_user(tmp, sptmp->rolename, len))
55956 + return -EFAULT;
55957 +
55958 + tmp[len-1] = '\0';
55959 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55960 + printk(KERN_ALERT "Copying special role %s\n", tmp);
55961 +#endif
55962 + sptmp->rolename = tmp;
55963 + acl_special_roles[i] = sptmp;
55964 + }
55965 +
55966 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55967 +
55968 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55969 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
55970 +
55971 + if (!r_tmp)
55972 + return -ENOMEM;
55973 +
55974 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
55975 + sizeof (struct acl_role_label *)))
55976 + return -EFAULT;
55977 +
55978 + if (copy_from_user(r_tmp, r_utmp2,
55979 + sizeof (struct acl_role_label)))
55980 + return -EFAULT;
55981 +
55982 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55983 +
55984 + if (!len || len >= PATH_MAX)
55985 + return -EINVAL;
55986 +
55987 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55988 + return -ENOMEM;
55989 +
55990 + if (copy_from_user(tmp, r_tmp->rolename, len))
55991 + return -EFAULT;
55992 +
55993 + tmp[len-1] = '\0';
55994 + r_tmp->rolename = tmp;
55995 +
55996 + if (!strcmp(r_tmp->rolename, "default")
55997 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55998 + default_role = r_tmp;
55999 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
56000 + kernel_role = r_tmp;
56001 + }
56002 +
56003 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
56004 + return -ENOMEM;
56005 +
56006 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
56007 + return -EFAULT;
56008 +
56009 + r_tmp->hash = ghash;
56010 +
56011 + num_subjs = count_user_subjs(r_tmp->hash->first);
56012 +
56013 + r_tmp->subj_hash_size = num_subjs;
56014 + r_tmp->subj_hash =
56015 + (struct acl_subject_label **)
56016 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
56017 +
56018 + if (!r_tmp->subj_hash)
56019 + return -ENOMEM;
56020 +
56021 + err = copy_user_allowedips(r_tmp);
56022 + if (err)
56023 + return err;
56024 +
56025 + /* copy domain info */
56026 + if (r_tmp->domain_children != NULL) {
56027 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
56028 + if (domainlist == NULL)
56029 + return -ENOMEM;
56030 +
56031 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
56032 + return -EFAULT;
56033 +
56034 + r_tmp->domain_children = domainlist;
56035 + }
56036 +
56037 + err = copy_user_transitions(r_tmp);
56038 + if (err)
56039 + return err;
56040 +
56041 + memset(r_tmp->subj_hash, 0,
56042 + r_tmp->subj_hash_size *
56043 + sizeof (struct acl_subject_label *));
56044 +
56045 + /* acquire the list of subjects, then NULL out
56046 + the list prior to parsing the subjects for this role,
56047 + as during this parsing the list is replaced with a list
56048 + of *nested* subjects for the role
56049 + */
56050 + subj_list = r_tmp->hash->first;
56051 +
56052 + /* set nested subject list to null */
56053 + r_tmp->hash->first = NULL;
56054 +
56055 + err = copy_user_subjs(subj_list, r_tmp);
56056 +
56057 + if (err)
56058 + return err;
56059 +
56060 + insert_acl_role_label(r_tmp);
56061 + }
56062 +
56063 + if (default_role == NULL || kernel_role == NULL)
56064 + return -EINVAL;
56065 +
56066 + return err;
56067 +}
56068 +
56069 +static int
56070 +gracl_init(struct gr_arg *args)
56071 +{
56072 + int error = 0;
56073 +
56074 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
56075 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
56076 +
56077 + if (init_variables(args)) {
56078 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
56079 + error = -ENOMEM;
56080 + free_variables();
56081 + goto out;
56082 + }
56083 +
56084 + error = copy_user_acl(args);
56085 + free_init_variables();
56086 + if (error) {
56087 + free_variables();
56088 + goto out;
56089 + }
56090 +
56091 + if ((error = gr_set_acls(0))) {
56092 + free_variables();
56093 + goto out;
56094 + }
56095 +
56096 + pax_open_kernel();
56097 + gr_status |= GR_READY;
56098 + pax_close_kernel();
56099 +
56100 + out:
56101 + return error;
56102 +}
56103 +
56104 +/* derived from glibc fnmatch() 0: match, 1: no match*/
56105 +
56106 +static int
56107 +glob_match(const char *p, const char *n)
56108 +{
56109 + char c;
56110 +
56111 + while ((c = *p++) != '\0') {
56112 + switch (c) {
56113 + case '?':
56114 + if (*n == '\0')
56115 + return 1;
56116 + else if (*n == '/')
56117 + return 1;
56118 + break;
56119 + case '\\':
56120 + if (*n != c)
56121 + return 1;
56122 + break;
56123 + case '*':
56124 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
56125 + if (*n == '/')
56126 + return 1;
56127 + else if (c == '?') {
56128 + if (*n == '\0')
56129 + return 1;
56130 + else
56131 + ++n;
56132 + }
56133 + }
56134 + if (c == '\0') {
56135 + return 0;
56136 + } else {
56137 + const char *endp;
56138 +
56139 + if ((endp = strchr(n, '/')) == NULL)
56140 + endp = n + strlen(n);
56141 +
56142 + if (c == '[') {
56143 + for (--p; n < endp; ++n)
56144 + if (!glob_match(p, n))
56145 + return 0;
56146 + } else if (c == '/') {
56147 + while (*n != '\0' && *n != '/')
56148 + ++n;
56149 + if (*n == '/' && !glob_match(p, n + 1))
56150 + return 0;
56151 + } else {
56152 + for (--p; n < endp; ++n)
56153 + if (*n == c && !glob_match(p, n))
56154 + return 0;
56155 + }
56156 +
56157 + return 1;
56158 + }
56159 + case '[':
56160 + {
56161 + int not;
56162 + char cold;
56163 +
56164 + if (*n == '\0' || *n == '/')
56165 + return 1;
56166 +
56167 + not = (*p == '!' || *p == '^');
56168 + if (not)
56169 + ++p;
56170 +
56171 + c = *p++;
56172 + for (;;) {
56173 + unsigned char fn = (unsigned char)*n;
56174 +
56175 + if (c == '\0')
56176 + return 1;
56177 + else {
56178 + if (c == fn)
56179 + goto matched;
56180 + cold = c;
56181 + c = *p++;
56182 +
56183 + if (c == '-' && *p != ']') {
56184 + unsigned char cend = *p++;
56185 +
56186 + if (cend == '\0')
56187 + return 1;
56188 +
56189 + if (cold <= fn && fn <= cend)
56190 + goto matched;
56191 +
56192 + c = *p++;
56193 + }
56194 + }
56195 +
56196 + if (c == ']')
56197 + break;
56198 + }
56199 + if (!not)
56200 + return 1;
56201 + break;
56202 + matched:
56203 + while (c != ']') {
56204 + if (c == '\0')
56205 + return 1;
56206 +
56207 + c = *p++;
56208 + }
56209 + if (not)
56210 + return 1;
56211 + }
56212 + break;
56213 + default:
56214 + if (c != *n)
56215 + return 1;
56216 + }
56217 +
56218 + ++n;
56219 + }
56220 +
56221 + if (*n == '\0')
56222 + return 0;
56223 +
56224 + if (*n == '/')
56225 + return 0;
56226 +
56227 + return 1;
56228 +}
56229 +
56230 +static struct acl_object_label *
56231 +chk_glob_label(struct acl_object_label *globbed,
56232 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
56233 +{
56234 + struct acl_object_label *tmp;
56235 +
56236 + if (*path == NULL)
56237 + *path = gr_to_filename_nolock(dentry, mnt);
56238 +
56239 + tmp = globbed;
56240 +
56241 + while (tmp) {
56242 + if (!glob_match(tmp->filename, *path))
56243 + return tmp;
56244 + tmp = tmp->next;
56245 + }
56246 +
56247 + return NULL;
56248 +}
56249 +
56250 +static struct acl_object_label *
56251 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56252 + const ino_t curr_ino, const dev_t curr_dev,
56253 + const struct acl_subject_label *subj, char **path, const int checkglob)
56254 +{
56255 + struct acl_subject_label *tmpsubj;
56256 + struct acl_object_label *retval;
56257 + struct acl_object_label *retval2;
56258 +
56259 + tmpsubj = (struct acl_subject_label *) subj;
56260 + read_lock(&gr_inode_lock);
56261 + do {
56262 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
56263 + if (retval) {
56264 + if (checkglob && retval->globbed) {
56265 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
56266 + if (retval2)
56267 + retval = retval2;
56268 + }
56269 + break;
56270 + }
56271 + } while ((tmpsubj = tmpsubj->parent_subject));
56272 + read_unlock(&gr_inode_lock);
56273 +
56274 + return retval;
56275 +}
56276 +
56277 +static __inline__ struct acl_object_label *
56278 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56279 + struct dentry *curr_dentry,
56280 + const struct acl_subject_label *subj, char **path, const int checkglob)
56281 +{
56282 + int newglob = checkglob;
56283 + ino_t inode;
56284 + dev_t device;
56285 +
56286 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
56287 + as we don't want a / * rule to match instead of the / object
56288 + don't do this for create lookups that call this function though, since they're looking up
56289 + on the parent and thus need globbing checks on all paths
56290 + */
56291 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
56292 + newglob = GR_NO_GLOB;
56293 +
56294 + spin_lock(&curr_dentry->d_lock);
56295 + inode = curr_dentry->d_inode->i_ino;
56296 + device = __get_dev(curr_dentry);
56297 + spin_unlock(&curr_dentry->d_lock);
56298 +
56299 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
56300 +}
56301 +
56302 +#ifdef CONFIG_HUGETLBFS
56303 +static inline bool
56304 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
56305 +{
56306 + int i;
56307 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
56308 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
56309 + return true;
56310 + }
56311 +
56312 + return false;
56313 +}
56314 +#endif
56315 +
56316 +static struct acl_object_label *
56317 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56318 + const struct acl_subject_label *subj, char *path, const int checkglob)
56319 +{
56320 + struct dentry *dentry = (struct dentry *) l_dentry;
56321 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56322 + struct mount *real_mnt = real_mount(mnt);
56323 + struct acl_object_label *retval;
56324 + struct dentry *parent;
56325 +
56326 + write_seqlock(&rename_lock);
56327 + br_read_lock(&vfsmount_lock);
56328 +
56329 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
56330 +#ifdef CONFIG_NET
56331 + mnt == sock_mnt ||
56332 +#endif
56333 +#ifdef CONFIG_HUGETLBFS
56334 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
56335 +#endif
56336 + /* ignore Eric Biederman */
56337 + IS_PRIVATE(l_dentry->d_inode))) {
56338 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
56339 + goto out;
56340 + }
56341 +
56342 + for (;;) {
56343 + if (dentry == real_root.dentry && mnt == real_root.mnt)
56344 + break;
56345 +
56346 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56347 + if (!mnt_has_parent(real_mnt))
56348 + break;
56349 +
56350 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56351 + if (retval != NULL)
56352 + goto out;
56353 +
56354 + dentry = real_mnt->mnt_mountpoint;
56355 + real_mnt = real_mnt->mnt_parent;
56356 + mnt = &real_mnt->mnt;
56357 + continue;
56358 + }
56359 +
56360 + parent = dentry->d_parent;
56361 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56362 + if (retval != NULL)
56363 + goto out;
56364 +
56365 + dentry = parent;
56366 + }
56367 +
56368 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56369 +
56370 + /* real_root is pinned so we don't have to hold a reference */
56371 + if (retval == NULL)
56372 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
56373 +out:
56374 + br_read_unlock(&vfsmount_lock);
56375 + write_sequnlock(&rename_lock);
56376 +
56377 + BUG_ON(retval == NULL);
56378 +
56379 + return retval;
56380 +}
56381 +
56382 +static __inline__ struct acl_object_label *
56383 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56384 + const struct acl_subject_label *subj)
56385 +{
56386 + char *path = NULL;
56387 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
56388 +}
56389 +
56390 +static __inline__ struct acl_object_label *
56391 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56392 + const struct acl_subject_label *subj)
56393 +{
56394 + char *path = NULL;
56395 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
56396 +}
56397 +
56398 +static __inline__ struct acl_object_label *
56399 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56400 + const struct acl_subject_label *subj, char *path)
56401 +{
56402 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
56403 +}
56404 +
56405 +static struct acl_subject_label *
56406 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56407 + const struct acl_role_label *role)
56408 +{
56409 + struct dentry *dentry = (struct dentry *) l_dentry;
56410 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56411 + struct mount *real_mnt = real_mount(mnt);
56412 + struct acl_subject_label *retval;
56413 + struct dentry *parent;
56414 +
56415 + write_seqlock(&rename_lock);
56416 + br_read_lock(&vfsmount_lock);
56417 +
56418 + for (;;) {
56419 + if (dentry == real_root.dentry && mnt == real_root.mnt)
56420 + break;
56421 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56422 + if (!mnt_has_parent(real_mnt))
56423 + break;
56424 +
56425 + spin_lock(&dentry->d_lock);
56426 + read_lock(&gr_inode_lock);
56427 + retval =
56428 + lookup_acl_subj_label(dentry->d_inode->i_ino,
56429 + __get_dev(dentry), role);
56430 + read_unlock(&gr_inode_lock);
56431 + spin_unlock(&dentry->d_lock);
56432 + if (retval != NULL)
56433 + goto out;
56434 +
56435 + dentry = real_mnt->mnt_mountpoint;
56436 + real_mnt = real_mnt->mnt_parent;
56437 + mnt = &real_mnt->mnt;
56438 + continue;
56439 + }
56440 +
56441 + spin_lock(&dentry->d_lock);
56442 + read_lock(&gr_inode_lock);
56443 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56444 + __get_dev(dentry), role);
56445 + read_unlock(&gr_inode_lock);
56446 + parent = dentry->d_parent;
56447 + spin_unlock(&dentry->d_lock);
56448 +
56449 + if (retval != NULL)
56450 + goto out;
56451 +
56452 + dentry = parent;
56453 + }
56454 +
56455 + spin_lock(&dentry->d_lock);
56456 + read_lock(&gr_inode_lock);
56457 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56458 + __get_dev(dentry), role);
56459 + read_unlock(&gr_inode_lock);
56460 + spin_unlock(&dentry->d_lock);
56461 +
56462 + if (unlikely(retval == NULL)) {
56463 + /* real_root is pinned, we don't need to hold a reference */
56464 + read_lock(&gr_inode_lock);
56465 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
56466 + __get_dev(real_root.dentry), role);
56467 + read_unlock(&gr_inode_lock);
56468 + }
56469 +out:
56470 + br_read_unlock(&vfsmount_lock);
56471 + write_sequnlock(&rename_lock);
56472 +
56473 + BUG_ON(retval == NULL);
56474 +
56475 + return retval;
56476 +}
56477 +
56478 +static void
56479 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
56480 +{
56481 + struct task_struct *task = current;
56482 + const struct cred *cred = current_cred();
56483 +
56484 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
56485 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56486 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56487 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
56488 +
56489 + return;
56490 +}
56491 +
56492 +static void
56493 +gr_log_learn_id_change(const char type, const unsigned int real,
56494 + const unsigned int effective, const unsigned int fs)
56495 +{
56496 + struct task_struct *task = current;
56497 + const struct cred *cred = current_cred();
56498 +
56499 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
56500 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56501 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56502 + type, real, effective, fs, &task->signal->saved_ip);
56503 +
56504 + return;
56505 +}
56506 +
56507 +__u32
56508 +gr_search_file(const struct dentry * dentry, const __u32 mode,
56509 + const struct vfsmount * mnt)
56510 +{
56511 + __u32 retval = mode;
56512 + struct acl_subject_label *curracl;
56513 + struct acl_object_label *currobj;
56514 +
56515 + if (unlikely(!(gr_status & GR_READY)))
56516 + return (mode & ~GR_AUDITS);
56517 +
56518 + curracl = current->acl;
56519 +
56520 + currobj = chk_obj_label(dentry, mnt, curracl);
56521 + retval = currobj->mode & mode;
56522 +
56523 + /* if we're opening a specified transfer file for writing
56524 + (e.g. /dev/initctl), then transfer our role to init
56525 + */
56526 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
56527 + current->role->roletype & GR_ROLE_PERSIST)) {
56528 + struct task_struct *task = init_pid_ns.child_reaper;
56529 +
56530 + if (task->role != current->role) {
56531 + task->acl_sp_role = 0;
56532 + task->acl_role_id = current->acl_role_id;
56533 + task->role = current->role;
56534 + rcu_read_lock();
56535 + read_lock(&grsec_exec_file_lock);
56536 + gr_apply_subject_to_task(task);
56537 + read_unlock(&grsec_exec_file_lock);
56538 + rcu_read_unlock();
56539 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
56540 + }
56541 + }
56542 +
56543 + if (unlikely
56544 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
56545 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
56546 + __u32 new_mode = mode;
56547 +
56548 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56549 +
56550 + retval = new_mode;
56551 +
56552 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
56553 + new_mode |= GR_INHERIT;
56554 +
56555 + if (!(mode & GR_NOLEARN))
56556 + gr_log_learn(dentry, mnt, new_mode);
56557 + }
56558 +
56559 + return retval;
56560 +}
56561 +
56562 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
56563 + const struct dentry *parent,
56564 + const struct vfsmount *mnt)
56565 +{
56566 + struct name_entry *match;
56567 + struct acl_object_label *matchpo;
56568 + struct acl_subject_label *curracl;
56569 + char *path;
56570 +
56571 + if (unlikely(!(gr_status & GR_READY)))
56572 + return NULL;
56573 +
56574 + preempt_disable();
56575 + path = gr_to_filename_rbac(new_dentry, mnt);
56576 + match = lookup_name_entry_create(path);
56577 +
56578 + curracl = current->acl;
56579 +
56580 + if (match) {
56581 + read_lock(&gr_inode_lock);
56582 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
56583 + read_unlock(&gr_inode_lock);
56584 +
56585 + if (matchpo) {
56586 + preempt_enable();
56587 + return matchpo;
56588 + }
56589 + }
56590 +
56591 + // lookup parent
56592 +
56593 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
56594 +
56595 + preempt_enable();
56596 + return matchpo;
56597 +}
56598 +
56599 +__u32
56600 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
56601 + const struct vfsmount * mnt, const __u32 mode)
56602 +{
56603 + struct acl_object_label *matchpo;
56604 + __u32 retval;
56605 +
56606 + if (unlikely(!(gr_status & GR_READY)))
56607 + return (mode & ~GR_AUDITS);
56608 +
56609 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
56610 +
56611 + retval = matchpo->mode & mode;
56612 +
56613 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
56614 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56615 + __u32 new_mode = mode;
56616 +
56617 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56618 +
56619 + gr_log_learn(new_dentry, mnt, new_mode);
56620 + return new_mode;
56621 + }
56622 +
56623 + return retval;
56624 +}
56625 +
56626 +__u32
56627 +gr_check_link(const struct dentry * new_dentry,
56628 + const struct dentry * parent_dentry,
56629 + const struct vfsmount * parent_mnt,
56630 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
56631 +{
56632 + struct acl_object_label *obj;
56633 + __u32 oldmode, newmode;
56634 + __u32 needmode;
56635 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
56636 + GR_DELETE | GR_INHERIT;
56637 +
56638 + if (unlikely(!(gr_status & GR_READY)))
56639 + return (GR_CREATE | GR_LINK);
56640 +
56641 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
56642 + oldmode = obj->mode;
56643 +
56644 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
56645 + newmode = obj->mode;
56646 +
56647 + needmode = newmode & checkmodes;
56648 +
56649 + // old name for hardlink must have at least the permissions of the new name
56650 + if ((oldmode & needmode) != needmode)
56651 + goto bad;
56652 +
56653 + // if old name had restrictions/auditing, make sure the new name does as well
56654 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
56655 +
56656 + // don't allow hardlinking of suid/sgid/fcapped files without permission
56657 + if (is_privileged_binary(old_dentry))
56658 + needmode |= GR_SETID;
56659 +
56660 + if ((newmode & needmode) != needmode)
56661 + goto bad;
56662 +
56663 + // enforce minimum permissions
56664 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
56665 + return newmode;
56666 +bad:
56667 + needmode = oldmode;
56668 + if (is_privileged_binary(old_dentry))
56669 + needmode |= GR_SETID;
56670 +
56671 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
56672 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
56673 + return (GR_CREATE | GR_LINK);
56674 + } else if (newmode & GR_SUPPRESS)
56675 + return GR_SUPPRESS;
56676 + else
56677 + return 0;
56678 +}
56679 +
56680 +int
56681 +gr_check_hidden_task(const struct task_struct *task)
56682 +{
56683 + if (unlikely(!(gr_status & GR_READY)))
56684 + return 0;
56685 +
56686 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
56687 + return 1;
56688 +
56689 + return 0;
56690 +}
56691 +
56692 +int
56693 +gr_check_protected_task(const struct task_struct *task)
56694 +{
56695 + if (unlikely(!(gr_status & GR_READY) || !task))
56696 + return 0;
56697 +
56698 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56699 + task->acl != current->acl)
56700 + return 1;
56701 +
56702 + return 0;
56703 +}
56704 +
56705 +int
56706 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56707 +{
56708 + struct task_struct *p;
56709 + int ret = 0;
56710 +
56711 + if (unlikely(!(gr_status & GR_READY) || !pid))
56712 + return ret;
56713 +
56714 + read_lock(&tasklist_lock);
56715 + do_each_pid_task(pid, type, p) {
56716 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56717 + p->acl != current->acl) {
56718 + ret = 1;
56719 + goto out;
56720 + }
56721 + } while_each_pid_task(pid, type, p);
56722 +out:
56723 + read_unlock(&tasklist_lock);
56724 +
56725 + return ret;
56726 +}
56727 +
56728 +void
56729 +gr_copy_label(struct task_struct *tsk)
56730 +{
56731 + tsk->signal->used_accept = 0;
56732 + tsk->acl_sp_role = 0;
56733 + tsk->acl_role_id = current->acl_role_id;
56734 + tsk->acl = current->acl;
56735 + tsk->role = current->role;
56736 + tsk->signal->curr_ip = current->signal->curr_ip;
56737 + tsk->signal->saved_ip = current->signal->saved_ip;
56738 + if (current->exec_file)
56739 + get_file(current->exec_file);
56740 + tsk->exec_file = current->exec_file;
56741 + tsk->is_writable = current->is_writable;
56742 + if (unlikely(current->signal->used_accept)) {
56743 + current->signal->curr_ip = 0;
56744 + current->signal->saved_ip = 0;
56745 + }
56746 +
56747 + return;
56748 +}
56749 +
56750 +static void
56751 +gr_set_proc_res(struct task_struct *task)
56752 +{
56753 + struct acl_subject_label *proc;
56754 + unsigned short i;
56755 +
56756 + proc = task->acl;
56757 +
56758 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
56759 + return;
56760 +
56761 + for (i = 0; i < RLIM_NLIMITS; i++) {
56762 + if (!(proc->resmask & (1 << i)))
56763 + continue;
56764 +
56765 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
56766 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
56767 + }
56768 +
56769 + return;
56770 +}
56771 +
56772 +extern int __gr_process_user_ban(struct user_struct *user);
56773 +
56774 +int
56775 +gr_check_user_change(int real, int effective, int fs)
56776 +{
56777 + unsigned int i;
56778 + __u16 num;
56779 + uid_t *uidlist;
56780 + int curuid;
56781 + int realok = 0;
56782 + int effectiveok = 0;
56783 + int fsok = 0;
56784 +
56785 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56786 + struct user_struct *user;
56787 +
56788 + if (real == -1)
56789 + goto skipit;
56790 +
56791 + user = find_user(real);
56792 + if (user == NULL)
56793 + goto skipit;
56794 +
56795 + if (__gr_process_user_ban(user)) {
56796 + /* for find_user */
56797 + free_uid(user);
56798 + return 1;
56799 + }
56800 +
56801 + /* for find_user */
56802 + free_uid(user);
56803 +
56804 +skipit:
56805 +#endif
56806 +
56807 + if (unlikely(!(gr_status & GR_READY)))
56808 + return 0;
56809 +
56810 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56811 + gr_log_learn_id_change('u', real, effective, fs);
56812 +
56813 + num = current->acl->user_trans_num;
56814 + uidlist = current->acl->user_transitions;
56815 +
56816 + if (uidlist == NULL)
56817 + return 0;
56818 +
56819 + if (real == -1)
56820 + realok = 1;
56821 + if (effective == -1)
56822 + effectiveok = 1;
56823 + if (fs == -1)
56824 + fsok = 1;
56825 +
56826 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
56827 + for (i = 0; i < num; i++) {
56828 + curuid = (int)uidlist[i];
56829 + if (real == curuid)
56830 + realok = 1;
56831 + if (effective == curuid)
56832 + effectiveok = 1;
56833 + if (fs == curuid)
56834 + fsok = 1;
56835 + }
56836 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
56837 + for (i = 0; i < num; i++) {
56838 + curuid = (int)uidlist[i];
56839 + if (real == curuid)
56840 + break;
56841 + if (effective == curuid)
56842 + break;
56843 + if (fs == curuid)
56844 + break;
56845 + }
56846 + /* not in deny list */
56847 + if (i == num) {
56848 + realok = 1;
56849 + effectiveok = 1;
56850 + fsok = 1;
56851 + }
56852 + }
56853 +
56854 + if (realok && effectiveok && fsok)
56855 + return 0;
56856 + else {
56857 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56858 + return 1;
56859 + }
56860 +}
56861 +
56862 +int
56863 +gr_check_group_change(int real, int effective, int fs)
56864 +{
56865 + unsigned int i;
56866 + __u16 num;
56867 + gid_t *gidlist;
56868 + int curgid;
56869 + int realok = 0;
56870 + int effectiveok = 0;
56871 + int fsok = 0;
56872 +
56873 + if (unlikely(!(gr_status & GR_READY)))
56874 + return 0;
56875 +
56876 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56877 + gr_log_learn_id_change('g', real, effective, fs);
56878 +
56879 + num = current->acl->group_trans_num;
56880 + gidlist = current->acl->group_transitions;
56881 +
56882 + if (gidlist == NULL)
56883 + return 0;
56884 +
56885 + if (real == -1)
56886 + realok = 1;
56887 + if (effective == -1)
56888 + effectiveok = 1;
56889 + if (fs == -1)
56890 + fsok = 1;
56891 +
56892 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
56893 + for (i = 0; i < num; i++) {
56894 + curgid = (int)gidlist[i];
56895 + if (real == curgid)
56896 + realok = 1;
56897 + if (effective == curgid)
56898 + effectiveok = 1;
56899 + if (fs == curgid)
56900 + fsok = 1;
56901 + }
56902 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
56903 + for (i = 0; i < num; i++) {
56904 + curgid = (int)gidlist[i];
56905 + if (real == curgid)
56906 + break;
56907 + if (effective == curgid)
56908 + break;
56909 + if (fs == curgid)
56910 + break;
56911 + }
56912 + /* not in deny list */
56913 + if (i == num) {
56914 + realok = 1;
56915 + effectiveok = 1;
56916 + fsok = 1;
56917 + }
56918 + }
56919 +
56920 + if (realok && effectiveok && fsok)
56921 + return 0;
56922 + else {
56923 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56924 + return 1;
56925 + }
56926 +}
56927 +
56928 +extern int gr_acl_is_capable(const int cap);
56929 +
56930 +void
56931 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56932 +{
56933 + struct acl_role_label *role = task->role;
56934 + struct acl_subject_label *subj = NULL;
56935 + struct acl_object_label *obj;
56936 + struct file *filp;
56937 +
56938 + if (unlikely(!(gr_status & GR_READY)))
56939 + return;
56940 +
56941 + filp = task->exec_file;
56942 +
56943 + /* kernel process, we'll give them the kernel role */
56944 + if (unlikely(!filp)) {
56945 + task->role = kernel_role;
56946 + task->acl = kernel_role->root_label;
56947 + return;
56948 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56949 + role = lookup_acl_role_label(task, uid, gid);
56950 +
56951 + /* don't change the role if we're not a privileged process */
56952 + if (role && task->role != role &&
56953 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56954 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56955 + return;
56956 +
56957 + /* perform subject lookup in possibly new role
56958 + we can use this result below in the case where role == task->role
56959 + */
56960 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56961 +
56962 + /* if we changed uid/gid, but result in the same role
56963 + and are using inheritance, don't lose the inherited subject
56964 + if current subject is other than what normal lookup
56965 + would result in, we arrived via inheritance, don't
56966 + lose subject
56967 + */
56968 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56969 + (subj == task->acl)))
56970 + task->acl = subj;
56971 +
56972 + task->role = role;
56973 +
56974 + task->is_writable = 0;
56975 +
56976 + /* ignore additional mmap checks for processes that are writable
56977 + by the default ACL */
56978 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56979 + if (unlikely(obj->mode & GR_WRITE))
56980 + task->is_writable = 1;
56981 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56982 + if (unlikely(obj->mode & GR_WRITE))
56983 + task->is_writable = 1;
56984 +
56985 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56986 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56987 +#endif
56988 +
56989 + gr_set_proc_res(task);
56990 +
56991 + return;
56992 +}
56993 +
56994 +int
56995 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56996 + const int unsafe_flags)
56997 +{
56998 + struct task_struct *task = current;
56999 + struct acl_subject_label *newacl;
57000 + struct acl_object_label *obj;
57001 + __u32 retmode;
57002 +
57003 + if (unlikely(!(gr_status & GR_READY)))
57004 + return 0;
57005 +
57006 + newacl = chk_subj_label(dentry, mnt, task->role);
57007 +
57008 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
57009 + did an exec
57010 + */
57011 + rcu_read_lock();
57012 + read_lock(&tasklist_lock);
57013 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
57014 + (task->parent->acl->mode & GR_POVERRIDE))) {
57015 + read_unlock(&tasklist_lock);
57016 + rcu_read_unlock();
57017 + goto skip_check;
57018 + }
57019 + read_unlock(&tasklist_lock);
57020 + rcu_read_unlock();
57021 +
57022 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
57023 + !(task->role->roletype & GR_ROLE_GOD) &&
57024 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
57025 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57026 + if (unsafe_flags & LSM_UNSAFE_SHARE)
57027 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
57028 + else
57029 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
57030 + return -EACCES;
57031 + }
57032 +
57033 +skip_check:
57034 +
57035 + obj = chk_obj_label(dentry, mnt, task->acl);
57036 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
57037 +
57038 + if (!(task->acl->mode & GR_INHERITLEARN) &&
57039 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
57040 + if (obj->nested)
57041 + task->acl = obj->nested;
57042 + else
57043 + task->acl = newacl;
57044 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
57045 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
57046 +
57047 + task->is_writable = 0;
57048 +
57049 + /* ignore additional mmap checks for processes that are writable
57050 + by the default ACL */
57051 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
57052 + if (unlikely(obj->mode & GR_WRITE))
57053 + task->is_writable = 1;
57054 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
57055 + if (unlikely(obj->mode & GR_WRITE))
57056 + task->is_writable = 1;
57057 +
57058 + gr_set_proc_res(task);
57059 +
57060 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57061 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57062 +#endif
57063 + return 0;
57064 +}
57065 +
57066 +/* always called with valid inodev ptr */
57067 +static void
57068 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
57069 +{
57070 + struct acl_object_label *matchpo;
57071 + struct acl_subject_label *matchps;
57072 + struct acl_subject_label *subj;
57073 + struct acl_role_label *role;
57074 + unsigned int x;
57075 +
57076 + FOR_EACH_ROLE_START(role)
57077 + FOR_EACH_SUBJECT_START(role, subj, x)
57078 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57079 + matchpo->mode |= GR_DELETED;
57080 + FOR_EACH_SUBJECT_END(subj,x)
57081 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
57082 + /* nested subjects aren't in the role's subj_hash table */
57083 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57084 + matchpo->mode |= GR_DELETED;
57085 + FOR_EACH_NESTED_SUBJECT_END(subj)
57086 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57087 + matchps->mode |= GR_DELETED;
57088 + FOR_EACH_ROLE_END(role)
57089 +
57090 + inodev->nentry->deleted = 1;
57091 +
57092 + return;
57093 +}
57094 +
57095 +void
57096 +gr_handle_delete(const ino_t ino, const dev_t dev)
57097 +{
57098 + struct inodev_entry *inodev;
57099 +
57100 + if (unlikely(!(gr_status & GR_READY)))
57101 + return;
57102 +
57103 + write_lock(&gr_inode_lock);
57104 + inodev = lookup_inodev_entry(ino, dev);
57105 + if (inodev != NULL)
57106 + do_handle_delete(inodev, ino, dev);
57107 + write_unlock(&gr_inode_lock);
57108 +
57109 + return;
57110 +}
57111 +
57112 +static void
57113 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
57114 + const ino_t newinode, const dev_t newdevice,
57115 + struct acl_subject_label *subj)
57116 +{
57117 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
57118 + struct acl_object_label *match;
57119 +
57120 + match = subj->obj_hash[index];
57121 +
57122 + while (match && (match->inode != oldinode ||
57123 + match->device != olddevice ||
57124 + !(match->mode & GR_DELETED)))
57125 + match = match->next;
57126 +
57127 + if (match && (match->inode == oldinode)
57128 + && (match->device == olddevice)
57129 + && (match->mode & GR_DELETED)) {
57130 + if (match->prev == NULL) {
57131 + subj->obj_hash[index] = match->next;
57132 + if (match->next != NULL)
57133 + match->next->prev = NULL;
57134 + } else {
57135 + match->prev->next = match->next;
57136 + if (match->next != NULL)
57137 + match->next->prev = match->prev;
57138 + }
57139 + match->prev = NULL;
57140 + match->next = NULL;
57141 + match->inode = newinode;
57142 + match->device = newdevice;
57143 + match->mode &= ~GR_DELETED;
57144 +
57145 + insert_acl_obj_label(match, subj);
57146 + }
57147 +
57148 + return;
57149 +}
57150 +
57151 +static void
57152 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
57153 + const ino_t newinode, const dev_t newdevice,
57154 + struct acl_role_label *role)
57155 +{
57156 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
57157 + struct acl_subject_label *match;
57158 +
57159 + match = role->subj_hash[index];
57160 +
57161 + while (match && (match->inode != oldinode ||
57162 + match->device != olddevice ||
57163 + !(match->mode & GR_DELETED)))
57164 + match = match->next;
57165 +
57166 + if (match && (match->inode == oldinode)
57167 + && (match->device == olddevice)
57168 + && (match->mode & GR_DELETED)) {
57169 + if (match->prev == NULL) {
57170 + role->subj_hash[index] = match->next;
57171 + if (match->next != NULL)
57172 + match->next->prev = NULL;
57173 + } else {
57174 + match->prev->next = match->next;
57175 + if (match->next != NULL)
57176 + match->next->prev = match->prev;
57177 + }
57178 + match->prev = NULL;
57179 + match->next = NULL;
57180 + match->inode = newinode;
57181 + match->device = newdevice;
57182 + match->mode &= ~GR_DELETED;
57183 +
57184 + insert_acl_subj_label(match, role);
57185 + }
57186 +
57187 + return;
57188 +}
57189 +
57190 +static void
57191 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
57192 + const ino_t newinode, const dev_t newdevice)
57193 +{
57194 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
57195 + struct inodev_entry *match;
57196 +
57197 + match = inodev_set.i_hash[index];
57198 +
57199 + while (match && (match->nentry->inode != oldinode ||
57200 + match->nentry->device != olddevice || !match->nentry->deleted))
57201 + match = match->next;
57202 +
57203 + if (match && (match->nentry->inode == oldinode)
57204 + && (match->nentry->device == olddevice) &&
57205 + match->nentry->deleted) {
57206 + if (match->prev == NULL) {
57207 + inodev_set.i_hash[index] = match->next;
57208 + if (match->next != NULL)
57209 + match->next->prev = NULL;
57210 + } else {
57211 + match->prev->next = match->next;
57212 + if (match->next != NULL)
57213 + match->next->prev = match->prev;
57214 + }
57215 + match->prev = NULL;
57216 + match->next = NULL;
57217 + match->nentry->inode = newinode;
57218 + match->nentry->device = newdevice;
57219 + match->nentry->deleted = 0;
57220 +
57221 + insert_inodev_entry(match);
57222 + }
57223 +
57224 + return;
57225 +}
57226 +
57227 +static void
57228 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
57229 +{
57230 + struct acl_subject_label *subj;
57231 + struct acl_role_label *role;
57232 + unsigned int x;
57233 +
57234 + FOR_EACH_ROLE_START(role)
57235 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
57236 +
57237 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
57238 + if ((subj->inode == ino) && (subj->device == dev)) {
57239 + subj->inode = ino;
57240 + subj->device = dev;
57241 + }
57242 + /* nested subjects aren't in the role's subj_hash table */
57243 + update_acl_obj_label(matchn->inode, matchn->device,
57244 + ino, dev, subj);
57245 + FOR_EACH_NESTED_SUBJECT_END(subj)
57246 + FOR_EACH_SUBJECT_START(role, subj, x)
57247 + update_acl_obj_label(matchn->inode, matchn->device,
57248 + ino, dev, subj);
57249 + FOR_EACH_SUBJECT_END(subj,x)
57250 + FOR_EACH_ROLE_END(role)
57251 +
57252 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
57253 +
57254 + return;
57255 +}
57256 +
57257 +static void
57258 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
57259 + const struct vfsmount *mnt)
57260 +{
57261 + ino_t ino = dentry->d_inode->i_ino;
57262 + dev_t dev = __get_dev(dentry);
57263 +
57264 + __do_handle_create(matchn, ino, dev);
57265 +
57266 + return;
57267 +}
57268 +
57269 +void
57270 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57271 +{
57272 + struct name_entry *matchn;
57273 +
57274 + if (unlikely(!(gr_status & GR_READY)))
57275 + return;
57276 +
57277 + preempt_disable();
57278 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
57279 +
57280 + if (unlikely((unsigned long)matchn)) {
57281 + write_lock(&gr_inode_lock);
57282 + do_handle_create(matchn, dentry, mnt);
57283 + write_unlock(&gr_inode_lock);
57284 + }
57285 + preempt_enable();
57286 +
57287 + return;
57288 +}
57289 +
57290 +void
57291 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57292 +{
57293 + struct name_entry *matchn;
57294 +
57295 + if (unlikely(!(gr_status & GR_READY)))
57296 + return;
57297 +
57298 + preempt_disable();
57299 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
57300 +
57301 + if (unlikely((unsigned long)matchn)) {
57302 + write_lock(&gr_inode_lock);
57303 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
57304 + write_unlock(&gr_inode_lock);
57305 + }
57306 + preempt_enable();
57307 +
57308 + return;
57309 +}
57310 +
57311 +void
57312 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57313 + struct dentry *old_dentry,
57314 + struct dentry *new_dentry,
57315 + struct vfsmount *mnt, const __u8 replace)
57316 +{
57317 + struct name_entry *matchn;
57318 + struct inodev_entry *inodev;
57319 + struct inode *inode = new_dentry->d_inode;
57320 + ino_t old_ino = old_dentry->d_inode->i_ino;
57321 + dev_t old_dev = __get_dev(old_dentry);
57322 +
57323 + /* vfs_rename swaps the name and parent link for old_dentry and
57324 + new_dentry
57325 + at this point, old_dentry has the new name, parent link, and inode
57326 + for the renamed file
57327 + if a file is being replaced by a rename, new_dentry has the inode
57328 + and name for the replaced file
57329 + */
57330 +
57331 + if (unlikely(!(gr_status & GR_READY)))
57332 + return;
57333 +
57334 + preempt_disable();
57335 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
57336 +
57337 + /* we wouldn't have to check d_inode if it weren't for
57338 + NFS silly-renaming
57339 + */
57340 +
57341 + write_lock(&gr_inode_lock);
57342 + if (unlikely(replace && inode)) {
57343 + ino_t new_ino = inode->i_ino;
57344 + dev_t new_dev = __get_dev(new_dentry);
57345 +
57346 + inodev = lookup_inodev_entry(new_ino, new_dev);
57347 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
57348 + do_handle_delete(inodev, new_ino, new_dev);
57349 + }
57350 +
57351 + inodev = lookup_inodev_entry(old_ino, old_dev);
57352 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
57353 + do_handle_delete(inodev, old_ino, old_dev);
57354 +
57355 + if (unlikely((unsigned long)matchn))
57356 + do_handle_create(matchn, old_dentry, mnt);
57357 +
57358 + write_unlock(&gr_inode_lock);
57359 + preempt_enable();
57360 +
57361 + return;
57362 +}
57363 +
57364 +static int
57365 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
57366 + unsigned char **sum)
57367 +{
57368 + struct acl_role_label *r;
57369 + struct role_allowed_ip *ipp;
57370 + struct role_transition *trans;
57371 + unsigned int i;
57372 + int found = 0;
57373 + u32 curr_ip = current->signal->curr_ip;
57374 +
57375 + current->signal->saved_ip = curr_ip;
57376 +
57377 + /* check transition table */
57378 +
57379 + for (trans = current->role->transitions; trans; trans = trans->next) {
57380 + if (!strcmp(rolename, trans->rolename)) {
57381 + found = 1;
57382 + break;
57383 + }
57384 + }
57385 +
57386 + if (!found)
57387 + return 0;
57388 +
57389 + /* handle special roles that do not require authentication
57390 + and check ip */
57391 +
57392 + FOR_EACH_ROLE_START(r)
57393 + if (!strcmp(rolename, r->rolename) &&
57394 + (r->roletype & GR_ROLE_SPECIAL)) {
57395 + found = 0;
57396 + if (r->allowed_ips != NULL) {
57397 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
57398 + if ((ntohl(curr_ip) & ipp->netmask) ==
57399 + (ntohl(ipp->addr) & ipp->netmask))
57400 + found = 1;
57401 + }
57402 + } else
57403 + found = 2;
57404 + if (!found)
57405 + return 0;
57406 +
57407 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
57408 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
57409 + *salt = NULL;
57410 + *sum = NULL;
57411 + return 1;
57412 + }
57413 + }
57414 + FOR_EACH_ROLE_END(r)
57415 +
57416 + for (i = 0; i < num_sprole_pws; i++) {
57417 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
57418 + *salt = acl_special_roles[i]->salt;
57419 + *sum = acl_special_roles[i]->sum;
57420 + return 1;
57421 + }
57422 + }
57423 +
57424 + return 0;
57425 +}
57426 +
57427 +static void
57428 +assign_special_role(char *rolename)
57429 +{
57430 + struct acl_object_label *obj;
57431 + struct acl_role_label *r;
57432 + struct acl_role_label *assigned = NULL;
57433 + struct task_struct *tsk;
57434 + struct file *filp;
57435 +
57436 + FOR_EACH_ROLE_START(r)
57437 + if (!strcmp(rolename, r->rolename) &&
57438 + (r->roletype & GR_ROLE_SPECIAL)) {
57439 + assigned = r;
57440 + break;
57441 + }
57442 + FOR_EACH_ROLE_END(r)
57443 +
57444 + if (!assigned)
57445 + return;
57446 +
57447 + read_lock(&tasklist_lock);
57448 + read_lock(&grsec_exec_file_lock);
57449 +
57450 + tsk = current->real_parent;
57451 + if (tsk == NULL)
57452 + goto out_unlock;
57453 +
57454 + filp = tsk->exec_file;
57455 + if (filp == NULL)
57456 + goto out_unlock;
57457 +
57458 + tsk->is_writable = 0;
57459 +
57460 + tsk->acl_sp_role = 1;
57461 + tsk->acl_role_id = ++acl_sp_role_value;
57462 + tsk->role = assigned;
57463 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
57464 +
57465 + /* ignore additional mmap checks for processes that are writable
57466 + by the default ACL */
57467 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57468 + if (unlikely(obj->mode & GR_WRITE))
57469 + tsk->is_writable = 1;
57470 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
57471 + if (unlikely(obj->mode & GR_WRITE))
57472 + tsk->is_writable = 1;
57473 +
57474 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57475 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
57476 +#endif
57477 +
57478 +out_unlock:
57479 + read_unlock(&grsec_exec_file_lock);
57480 + read_unlock(&tasklist_lock);
57481 + return;
57482 +}
57483 +
57484 +int gr_check_secure_terminal(struct task_struct *task)
57485 +{
57486 + struct task_struct *p, *p2, *p3;
57487 + struct files_struct *files;
57488 + struct fdtable *fdt;
57489 + struct file *our_file = NULL, *file;
57490 + int i;
57491 +
57492 + if (task->signal->tty == NULL)
57493 + return 1;
57494 +
57495 + files = get_files_struct(task);
57496 + if (files != NULL) {
57497 + rcu_read_lock();
57498 + fdt = files_fdtable(files);
57499 + for (i=0; i < fdt->max_fds; i++) {
57500 + file = fcheck_files(files, i);
57501 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
57502 + get_file(file);
57503 + our_file = file;
57504 + }
57505 + }
57506 + rcu_read_unlock();
57507 + put_files_struct(files);
57508 + }
57509 +
57510 + if (our_file == NULL)
57511 + return 1;
57512 +
57513 + read_lock(&tasklist_lock);
57514 + do_each_thread(p2, p) {
57515 + files = get_files_struct(p);
57516 + if (files == NULL ||
57517 + (p->signal && p->signal->tty == task->signal->tty)) {
57518 + if (files != NULL)
57519 + put_files_struct(files);
57520 + continue;
57521 + }
57522 + rcu_read_lock();
57523 + fdt = files_fdtable(files);
57524 + for (i=0; i < fdt->max_fds; i++) {
57525 + file = fcheck_files(files, i);
57526 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
57527 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
57528 + p3 = task;
57529 + while (p3->pid > 0) {
57530 + if (p3 == p)
57531 + break;
57532 + p3 = p3->real_parent;
57533 + }
57534 + if (p3 == p)
57535 + break;
57536 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
57537 + gr_handle_alertkill(p);
57538 + rcu_read_unlock();
57539 + put_files_struct(files);
57540 + read_unlock(&tasklist_lock);
57541 + fput(our_file);
57542 + return 0;
57543 + }
57544 + }
57545 + rcu_read_unlock();
57546 + put_files_struct(files);
57547 + } while_each_thread(p2, p);
57548 + read_unlock(&tasklist_lock);
57549 +
57550 + fput(our_file);
57551 + return 1;
57552 +}
57553 +
57554 +static int gr_rbac_disable(void *unused)
57555 +{
57556 + pax_open_kernel();
57557 + gr_status &= ~GR_READY;
57558 + pax_close_kernel();
57559 +
57560 + return 0;
57561 +}
57562 +
57563 +ssize_t
57564 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
57565 +{
57566 + struct gr_arg_wrapper uwrap;
57567 + unsigned char *sprole_salt = NULL;
57568 + unsigned char *sprole_sum = NULL;
57569 + int error = sizeof (struct gr_arg_wrapper);
57570 + int error2 = 0;
57571 +
57572 + mutex_lock(&gr_dev_mutex);
57573 +
57574 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
57575 + error = -EPERM;
57576 + goto out;
57577 + }
57578 +
57579 + if (count != sizeof (struct gr_arg_wrapper)) {
57580 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
57581 + error = -EINVAL;
57582 + goto out;
57583 + }
57584 +
57585 +
57586 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
57587 + gr_auth_expires = 0;
57588 + gr_auth_attempts = 0;
57589 + }
57590 +
57591 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
57592 + error = -EFAULT;
57593 + goto out;
57594 + }
57595 +
57596 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
57597 + error = -EINVAL;
57598 + goto out;
57599 + }
57600 +
57601 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
57602 + error = -EFAULT;
57603 + goto out;
57604 + }
57605 +
57606 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57607 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57608 + time_after(gr_auth_expires, get_seconds())) {
57609 + error = -EBUSY;
57610 + goto out;
57611 + }
57612 +
57613 + /* if non-root trying to do anything other than use a special role,
57614 + do not attempt authentication, do not count towards authentication
57615 + locking
57616 + */
57617 +
57618 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
57619 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57620 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
57621 + error = -EPERM;
57622 + goto out;
57623 + }
57624 +
57625 + /* ensure pw and special role name are null terminated */
57626 +
57627 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
57628 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
57629 +
57630 + /* Okay.
57631 + * We have our enough of the argument structure..(we have yet
57632 + * to copy_from_user the tables themselves) . Copy the tables
57633 + * only if we need them, i.e. for loading operations. */
57634 +
57635 + switch (gr_usermode->mode) {
57636 + case GR_STATUS:
57637 + if (gr_status & GR_READY) {
57638 + error = 1;
57639 + if (!gr_check_secure_terminal(current))
57640 + error = 3;
57641 + } else
57642 + error = 2;
57643 + goto out;
57644 + case GR_SHUTDOWN:
57645 + if ((gr_status & GR_READY)
57646 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57647 + stop_machine(gr_rbac_disable, NULL, NULL);
57648 + free_variables();
57649 + memset(gr_usermode, 0, sizeof (struct gr_arg));
57650 + memset(gr_system_salt, 0, GR_SALT_LEN);
57651 + memset(gr_system_sum, 0, GR_SHA_LEN);
57652 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
57653 + } else if (gr_status & GR_READY) {
57654 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
57655 + error = -EPERM;
57656 + } else {
57657 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
57658 + error = -EAGAIN;
57659 + }
57660 + break;
57661 + case GR_ENABLE:
57662 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
57663 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
57664 + else {
57665 + if (gr_status & GR_READY)
57666 + error = -EAGAIN;
57667 + else
57668 + error = error2;
57669 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
57670 + }
57671 + break;
57672 + case GR_RELOAD:
57673 + if (!(gr_status & GR_READY)) {
57674 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
57675 + error = -EAGAIN;
57676 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57677 + stop_machine(gr_rbac_disable, NULL, NULL);
57678 + free_variables();
57679 + error2 = gracl_init(gr_usermode);
57680 + if (!error2)
57681 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
57682 + else {
57683 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57684 + error = error2;
57685 + }
57686 + } else {
57687 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57688 + error = -EPERM;
57689 + }
57690 + break;
57691 + case GR_SEGVMOD:
57692 + if (unlikely(!(gr_status & GR_READY))) {
57693 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
57694 + error = -EAGAIN;
57695 + break;
57696 + }
57697 +
57698 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57699 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
57700 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
57701 + struct acl_subject_label *segvacl;
57702 + segvacl =
57703 + lookup_acl_subj_label(gr_usermode->segv_inode,
57704 + gr_usermode->segv_device,
57705 + current->role);
57706 + if (segvacl) {
57707 + segvacl->crashes = 0;
57708 + segvacl->expires = 0;
57709 + }
57710 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
57711 + gr_remove_uid(gr_usermode->segv_uid);
57712 + }
57713 + } else {
57714 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
57715 + error = -EPERM;
57716 + }
57717 + break;
57718 + case GR_SPROLE:
57719 + case GR_SPROLEPAM:
57720 + if (unlikely(!(gr_status & GR_READY))) {
57721 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
57722 + error = -EAGAIN;
57723 + break;
57724 + }
57725 +
57726 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
57727 + current->role->expires = 0;
57728 + current->role->auth_attempts = 0;
57729 + }
57730 +
57731 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57732 + time_after(current->role->expires, get_seconds())) {
57733 + error = -EBUSY;
57734 + goto out;
57735 + }
57736 +
57737 + if (lookup_special_role_auth
57738 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
57739 + && ((!sprole_salt && !sprole_sum)
57740 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
57741 + char *p = "";
57742 + assign_special_role(gr_usermode->sp_role);
57743 + read_lock(&tasklist_lock);
57744 + if (current->real_parent)
57745 + p = current->real_parent->role->rolename;
57746 + read_unlock(&tasklist_lock);
57747 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
57748 + p, acl_sp_role_value);
57749 + } else {
57750 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
57751 + error = -EPERM;
57752 + if(!(current->role->auth_attempts++))
57753 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57754 +
57755 + goto out;
57756 + }
57757 + break;
57758 + case GR_UNSPROLE:
57759 + if (unlikely(!(gr_status & GR_READY))) {
57760 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
57761 + error = -EAGAIN;
57762 + break;
57763 + }
57764 +
57765 + if (current->role->roletype & GR_ROLE_SPECIAL) {
57766 + char *p = "";
57767 + int i = 0;
57768 +
57769 + read_lock(&tasklist_lock);
57770 + if (current->real_parent) {
57771 + p = current->real_parent->role->rolename;
57772 + i = current->real_parent->acl_role_id;
57773 + }
57774 + read_unlock(&tasklist_lock);
57775 +
57776 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57777 + gr_set_acls(1);
57778 + } else {
57779 + error = -EPERM;
57780 + goto out;
57781 + }
57782 + break;
57783 + default:
57784 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57785 + error = -EINVAL;
57786 + break;
57787 + }
57788 +
57789 + if (error != -EPERM)
57790 + goto out;
57791 +
57792 + if(!(gr_auth_attempts++))
57793 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57794 +
57795 + out:
57796 + mutex_unlock(&gr_dev_mutex);
57797 + return error;
57798 +}
57799 +
57800 +/* must be called with
57801 + rcu_read_lock();
57802 + read_lock(&tasklist_lock);
57803 + read_lock(&grsec_exec_file_lock);
57804 +*/
57805 +int gr_apply_subject_to_task(struct task_struct *task)
57806 +{
57807 + struct acl_object_label *obj;
57808 + char *tmpname;
57809 + struct acl_subject_label *tmpsubj;
57810 + struct file *filp;
57811 + struct name_entry *nmatch;
57812 +
57813 + filp = task->exec_file;
57814 + if (filp == NULL)
57815 + return 0;
57816 +
57817 + /* the following is to apply the correct subject
57818 + on binaries running when the RBAC system
57819 + is enabled, when the binaries have been
57820 + replaced or deleted since their execution
57821 + -----
57822 + when the RBAC system starts, the inode/dev
57823 + from exec_file will be one the RBAC system
57824 + is unaware of. It only knows the inode/dev
57825 + of the present file on disk, or the absence
57826 + of it.
57827 + */
57828 + preempt_disable();
57829 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57830 +
57831 + nmatch = lookup_name_entry(tmpname);
57832 + preempt_enable();
57833 + tmpsubj = NULL;
57834 + if (nmatch) {
57835 + if (nmatch->deleted)
57836 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57837 + else
57838 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57839 + if (tmpsubj != NULL)
57840 + task->acl = tmpsubj;
57841 + }
57842 + if (tmpsubj == NULL)
57843 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57844 + task->role);
57845 + if (task->acl) {
57846 + task->is_writable = 0;
57847 + /* ignore additional mmap checks for processes that are writable
57848 + by the default ACL */
57849 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57850 + if (unlikely(obj->mode & GR_WRITE))
57851 + task->is_writable = 1;
57852 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57853 + if (unlikely(obj->mode & GR_WRITE))
57854 + task->is_writable = 1;
57855 +
57856 + gr_set_proc_res(task);
57857 +
57858 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57859 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57860 +#endif
57861 + } else {
57862 + return 1;
57863 + }
57864 +
57865 + return 0;
57866 +}
57867 +
57868 +int
57869 +gr_set_acls(const int type)
57870 +{
57871 + struct task_struct *task, *task2;
57872 + struct acl_role_label *role = current->role;
57873 + __u16 acl_role_id = current->acl_role_id;
57874 + const struct cred *cred;
57875 + int ret;
57876 +
57877 + rcu_read_lock();
57878 + read_lock(&tasklist_lock);
57879 + read_lock(&grsec_exec_file_lock);
57880 + do_each_thread(task2, task) {
57881 + /* check to see if we're called from the exit handler,
57882 + if so, only replace ACLs that have inherited the admin
57883 + ACL */
57884 +
57885 + if (type && (task->role != role ||
57886 + task->acl_role_id != acl_role_id))
57887 + continue;
57888 +
57889 + task->acl_role_id = 0;
57890 + task->acl_sp_role = 0;
57891 +
57892 + if (task->exec_file) {
57893 + cred = __task_cred(task);
57894 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57895 + ret = gr_apply_subject_to_task(task);
57896 + if (ret) {
57897 + read_unlock(&grsec_exec_file_lock);
57898 + read_unlock(&tasklist_lock);
57899 + rcu_read_unlock();
57900 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57901 + return ret;
57902 + }
57903 + } else {
57904 + // it's a kernel process
57905 + task->role = kernel_role;
57906 + task->acl = kernel_role->root_label;
57907 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57908 + task->acl->mode &= ~GR_PROCFIND;
57909 +#endif
57910 + }
57911 + } while_each_thread(task2, task);
57912 + read_unlock(&grsec_exec_file_lock);
57913 + read_unlock(&tasklist_lock);
57914 + rcu_read_unlock();
57915 +
57916 + return 0;
57917 +}
57918 +
57919 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57920 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57921 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57922 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57923 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57924 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57925 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57926 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57927 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57928 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57929 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57930 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57931 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57932 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57933 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57934 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57935 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57936 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57937 +};
57938 +
57939 +void
57940 +gr_learn_resource(const struct task_struct *task,
57941 + const int res, const unsigned long wanted, const int gt)
57942 +{
57943 + struct acl_subject_label *acl;
57944 + const struct cred *cred;
57945 +
57946 + if (unlikely((gr_status & GR_READY) &&
57947 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57948 + goto skip_reslog;
57949 +
57950 + gr_log_resource(task, res, wanted, gt);
57951 +skip_reslog:
57952 +
57953 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57954 + return;
57955 +
57956 + acl = task->acl;
57957 +
57958 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57959 + !(acl->resmask & (1 << (unsigned short) res))))
57960 + return;
57961 +
57962 + if (wanted >= acl->res[res].rlim_cur) {
57963 + unsigned long res_add;
57964 +
57965 + res_add = wanted + res_learn_bumps[res];
57966 +
57967 + acl->res[res].rlim_cur = res_add;
57968 +
57969 + if (wanted > acl->res[res].rlim_max)
57970 + acl->res[res].rlim_max = res_add;
57971 +
57972 + /* only log the subject filename, since resource logging is supported for
57973 + single-subject learning only */
57974 + rcu_read_lock();
57975 + cred = __task_cred(task);
57976 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57977 + task->role->roletype, cred->uid, cred->gid, acl->filename,
57978 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57979 + "", (unsigned long) res, &task->signal->saved_ip);
57980 + rcu_read_unlock();
57981 + }
57982 +
57983 + return;
57984 +}
57985 +EXPORT_SYMBOL(gr_learn_resource);
57986 +#endif
57987 +
57988 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57989 +void
57990 +pax_set_initial_flags(struct linux_binprm *bprm)
57991 +{
57992 + struct task_struct *task = current;
57993 + struct acl_subject_label *proc;
57994 + unsigned long flags;
57995 +
57996 + if (unlikely(!(gr_status & GR_READY)))
57997 + return;
57998 +
57999 + flags = pax_get_flags(task);
58000 +
58001 + proc = task->acl;
58002 +
58003 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
58004 + flags &= ~MF_PAX_PAGEEXEC;
58005 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
58006 + flags &= ~MF_PAX_SEGMEXEC;
58007 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
58008 + flags &= ~MF_PAX_RANDMMAP;
58009 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
58010 + flags &= ~MF_PAX_EMUTRAMP;
58011 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
58012 + flags &= ~MF_PAX_MPROTECT;
58013 +
58014 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
58015 + flags |= MF_PAX_PAGEEXEC;
58016 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
58017 + flags |= MF_PAX_SEGMEXEC;
58018 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
58019 + flags |= MF_PAX_RANDMMAP;
58020 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
58021 + flags |= MF_PAX_EMUTRAMP;
58022 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
58023 + flags |= MF_PAX_MPROTECT;
58024 +
58025 + pax_set_flags(task, flags);
58026 +
58027 + return;
58028 +}
58029 +#endif
58030 +
58031 +int
58032 +gr_handle_proc_ptrace(struct task_struct *task)
58033 +{
58034 + struct file *filp;
58035 + struct task_struct *tmp = task;
58036 + struct task_struct *curtemp = current;
58037 + __u32 retmode;
58038 +
58039 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58040 + if (unlikely(!(gr_status & GR_READY)))
58041 + return 0;
58042 +#endif
58043 +
58044 + read_lock(&tasklist_lock);
58045 + read_lock(&grsec_exec_file_lock);
58046 + filp = task->exec_file;
58047 +
58048 + while (tmp->pid > 0) {
58049 + if (tmp == curtemp)
58050 + break;
58051 + tmp = tmp->real_parent;
58052 + }
58053 +
58054 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58055 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
58056 + read_unlock(&grsec_exec_file_lock);
58057 + read_unlock(&tasklist_lock);
58058 + return 1;
58059 + }
58060 +
58061 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58062 + if (!(gr_status & GR_READY)) {
58063 + read_unlock(&grsec_exec_file_lock);
58064 + read_unlock(&tasklist_lock);
58065 + return 0;
58066 + }
58067 +#endif
58068 +
58069 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
58070 + read_unlock(&grsec_exec_file_lock);
58071 + read_unlock(&tasklist_lock);
58072 +
58073 + if (retmode & GR_NOPTRACE)
58074 + return 1;
58075 +
58076 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
58077 + && (current->acl != task->acl || (current->acl != current->role->root_label
58078 + && current->pid != task->pid)))
58079 + return 1;
58080 +
58081 + return 0;
58082 +}
58083 +
58084 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
58085 +{
58086 + if (unlikely(!(gr_status & GR_READY)))
58087 + return;
58088 +
58089 + if (!(current->role->roletype & GR_ROLE_GOD))
58090 + return;
58091 +
58092 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
58093 + p->role->rolename, gr_task_roletype_to_char(p),
58094 + p->acl->filename);
58095 +}
58096 +
58097 +int
58098 +gr_handle_ptrace(struct task_struct *task, const long request)
58099 +{
58100 + struct task_struct *tmp = task;
58101 + struct task_struct *curtemp = current;
58102 + __u32 retmode;
58103 +
58104 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58105 + if (unlikely(!(gr_status & GR_READY)))
58106 + return 0;
58107 +#endif
58108 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
58109 + read_lock(&tasklist_lock);
58110 + while (tmp->pid > 0) {
58111 + if (tmp == curtemp)
58112 + break;
58113 + tmp = tmp->real_parent;
58114 + }
58115 +
58116 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58117 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
58118 + read_unlock(&tasklist_lock);
58119 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58120 + return 1;
58121 + }
58122 + read_unlock(&tasklist_lock);
58123 + }
58124 +
58125 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58126 + if (!(gr_status & GR_READY))
58127 + return 0;
58128 +#endif
58129 +
58130 + read_lock(&grsec_exec_file_lock);
58131 + if (unlikely(!task->exec_file)) {
58132 + read_unlock(&grsec_exec_file_lock);
58133 + return 0;
58134 + }
58135 +
58136 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
58137 + read_unlock(&grsec_exec_file_lock);
58138 +
58139 + if (retmode & GR_NOPTRACE) {
58140 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58141 + return 1;
58142 + }
58143 +
58144 + if (retmode & GR_PTRACERD) {
58145 + switch (request) {
58146 + case PTRACE_SEIZE:
58147 + case PTRACE_POKETEXT:
58148 + case PTRACE_POKEDATA:
58149 + case PTRACE_POKEUSR:
58150 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
58151 + case PTRACE_SETREGS:
58152 + case PTRACE_SETFPREGS:
58153 +#endif
58154 +#ifdef CONFIG_X86
58155 + case PTRACE_SETFPXREGS:
58156 +#endif
58157 +#ifdef CONFIG_ALTIVEC
58158 + case PTRACE_SETVRREGS:
58159 +#endif
58160 + return 1;
58161 + default:
58162 + return 0;
58163 + }
58164 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
58165 + !(current->role->roletype & GR_ROLE_GOD) &&
58166 + (current->acl != task->acl)) {
58167 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58168 + return 1;
58169 + }
58170 +
58171 + return 0;
58172 +}
58173 +
58174 +static int is_writable_mmap(const struct file *filp)
58175 +{
58176 + struct task_struct *task = current;
58177 + struct acl_object_label *obj, *obj2;
58178 +
58179 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
58180 + !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))) {
58181 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58182 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
58183 + task->role->root_label);
58184 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
58185 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
58186 + return 1;
58187 + }
58188 + }
58189 + return 0;
58190 +}
58191 +
58192 +int
58193 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
58194 +{
58195 + __u32 mode;
58196 +
58197 + if (unlikely(!file || !(prot & PROT_EXEC)))
58198 + return 1;
58199 +
58200 + if (is_writable_mmap(file))
58201 + return 0;
58202 +
58203 + mode =
58204 + gr_search_file(file->f_path.dentry,
58205 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58206 + file->f_path.mnt);
58207 +
58208 + if (!gr_tpe_allow(file))
58209 + return 0;
58210 +
58211 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58212 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58213 + return 0;
58214 + } else if (unlikely(!(mode & GR_EXEC))) {
58215 + return 0;
58216 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58217 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58218 + return 1;
58219 + }
58220 +
58221 + return 1;
58222 +}
58223 +
58224 +int
58225 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58226 +{
58227 + __u32 mode;
58228 +
58229 + if (unlikely(!file || !(prot & PROT_EXEC)))
58230 + return 1;
58231 +
58232 + if (is_writable_mmap(file))
58233 + return 0;
58234 +
58235 + mode =
58236 + gr_search_file(file->f_path.dentry,
58237 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58238 + file->f_path.mnt);
58239 +
58240 + if (!gr_tpe_allow(file))
58241 + return 0;
58242 +
58243 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58244 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58245 + return 0;
58246 + } else if (unlikely(!(mode & GR_EXEC))) {
58247 + return 0;
58248 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58249 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58250 + return 1;
58251 + }
58252 +
58253 + return 1;
58254 +}
58255 +
58256 +void
58257 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58258 +{
58259 + unsigned long runtime;
58260 + unsigned long cputime;
58261 + unsigned int wday, cday;
58262 + __u8 whr, chr;
58263 + __u8 wmin, cmin;
58264 + __u8 wsec, csec;
58265 + struct timespec timeval;
58266 +
58267 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
58268 + !(task->acl->mode & GR_PROCACCT)))
58269 + return;
58270 +
58271 + do_posix_clock_monotonic_gettime(&timeval);
58272 + runtime = timeval.tv_sec - task->start_time.tv_sec;
58273 + wday = runtime / (3600 * 24);
58274 + runtime -= wday * (3600 * 24);
58275 + whr = runtime / 3600;
58276 + runtime -= whr * 3600;
58277 + wmin = runtime / 60;
58278 + runtime -= wmin * 60;
58279 + wsec = runtime;
58280 +
58281 + cputime = (task->utime + task->stime) / HZ;
58282 + cday = cputime / (3600 * 24);
58283 + cputime -= cday * (3600 * 24);
58284 + chr = cputime / 3600;
58285 + cputime -= chr * 3600;
58286 + cmin = cputime / 60;
58287 + cputime -= cmin * 60;
58288 + csec = cputime;
58289 +
58290 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
58291 +
58292 + return;
58293 +}
58294 +
58295 +void gr_set_kernel_label(struct task_struct *task)
58296 +{
58297 + if (gr_status & GR_READY) {
58298 + task->role = kernel_role;
58299 + task->acl = kernel_role->root_label;
58300 + }
58301 + return;
58302 +}
58303 +
58304 +#ifdef CONFIG_TASKSTATS
58305 +int gr_is_taskstats_denied(int pid)
58306 +{
58307 + struct task_struct *task;
58308 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58309 + const struct cred *cred;
58310 +#endif
58311 + int ret = 0;
58312 +
58313 + /* restrict taskstats viewing to un-chrooted root users
58314 + who have the 'view' subject flag if the RBAC system is enabled
58315 + */
58316 +
58317 + rcu_read_lock();
58318 + read_lock(&tasklist_lock);
58319 + task = find_task_by_vpid(pid);
58320 + if (task) {
58321 +#ifdef CONFIG_GRKERNSEC_CHROOT
58322 + if (proc_is_chrooted(task))
58323 + ret = -EACCES;
58324 +#endif
58325 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58326 + cred = __task_cred(task);
58327 +#ifdef CONFIG_GRKERNSEC_PROC_USER
58328 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
58329 + ret = -EACCES;
58330 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58331 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
58332 + ret = -EACCES;
58333 +#endif
58334 +#endif
58335 + if (gr_status & GR_READY) {
58336 + if (!(task->acl->mode & GR_VIEW))
58337 + ret = -EACCES;
58338 + }
58339 + } else
58340 + ret = -ENOENT;
58341 +
58342 + read_unlock(&tasklist_lock);
58343 + rcu_read_unlock();
58344 +
58345 + return ret;
58346 +}
58347 +#endif
58348 +
58349 +/* AUXV entries are filled via a descendant of search_binary_handler
58350 + after we've already applied the subject for the target
58351 +*/
58352 +int gr_acl_enable_at_secure(void)
58353 +{
58354 + if (unlikely(!(gr_status & GR_READY)))
58355 + return 0;
58356 +
58357 + if (current->acl->mode & GR_ATSECURE)
58358 + return 1;
58359 +
58360 + return 0;
58361 +}
58362 +
58363 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
58364 +{
58365 + struct task_struct *task = current;
58366 + struct dentry *dentry = file->f_path.dentry;
58367 + struct vfsmount *mnt = file->f_path.mnt;
58368 + struct acl_object_label *obj, *tmp;
58369 + struct acl_subject_label *subj;
58370 + unsigned int bufsize;
58371 + int is_not_root;
58372 + char *path;
58373 + dev_t dev = __get_dev(dentry);
58374 +
58375 + if (unlikely(!(gr_status & GR_READY)))
58376 + return 1;
58377 +
58378 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58379 + return 1;
58380 +
58381 + /* ignore Eric Biederman */
58382 + if (IS_PRIVATE(dentry->d_inode))
58383 + return 1;
58384 +
58385 + subj = task->acl;
58386 + read_lock(&gr_inode_lock);
58387 + do {
58388 + obj = lookup_acl_obj_label(ino, dev, subj);
58389 + if (obj != NULL) {
58390 + read_unlock(&gr_inode_lock);
58391 + return (obj->mode & GR_FIND) ? 1 : 0;
58392 + }
58393 + } while ((subj = subj->parent_subject));
58394 + read_unlock(&gr_inode_lock);
58395 +
58396 + /* this is purely an optimization since we're looking for an object
58397 + for the directory we're doing a readdir on
58398 + if it's possible for any globbed object to match the entry we're
58399 + filling into the directory, then the object we find here will be
58400 + an anchor point with attached globbed objects
58401 + */
58402 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
58403 + if (obj->globbed == NULL)
58404 + return (obj->mode & GR_FIND) ? 1 : 0;
58405 +
58406 + is_not_root = ((obj->filename[0] == '/') &&
58407 + (obj->filename[1] == '\0')) ? 0 : 1;
58408 + bufsize = PAGE_SIZE - namelen - is_not_root;
58409 +
58410 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
58411 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
58412 + return 1;
58413 +
58414 + preempt_disable();
58415 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58416 + bufsize);
58417 +
58418 + bufsize = strlen(path);
58419 +
58420 + /* if base is "/", don't append an additional slash */
58421 + if (is_not_root)
58422 + *(path + bufsize) = '/';
58423 + memcpy(path + bufsize + is_not_root, name, namelen);
58424 + *(path + bufsize + namelen + is_not_root) = '\0';
58425 +
58426 + tmp = obj->globbed;
58427 + while (tmp) {
58428 + if (!glob_match(tmp->filename, path)) {
58429 + preempt_enable();
58430 + return (tmp->mode & GR_FIND) ? 1 : 0;
58431 + }
58432 + tmp = tmp->next;
58433 + }
58434 + preempt_enable();
58435 + return (obj->mode & GR_FIND) ? 1 : 0;
58436 +}
58437 +
58438 +void gr_put_exec_file(struct task_struct *task)
58439 +{
58440 + struct file *filp;
58441 +
58442 + write_lock(&grsec_exec_file_lock);
58443 + filp = task->exec_file;
58444 + task->exec_file = NULL;
58445 + write_unlock(&grsec_exec_file_lock);
58446 +
58447 + if (filp)
58448 + fput(filp);
58449 +
58450 + return;
58451 +}
58452 +
58453 +
58454 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
58455 +EXPORT_SYMBOL(gr_acl_is_enabled);
58456 +#endif
58457 +EXPORT_SYMBOL(gr_set_kernel_label);
58458 +#ifdef CONFIG_SECURITY
58459 +EXPORT_SYMBOL(gr_check_user_change);
58460 +EXPORT_SYMBOL(gr_check_group_change);
58461 +#endif
58462 +
58463 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
58464 new file mode 100644
58465 index 0000000..34fefda
58466 --- /dev/null
58467 +++ b/grsecurity/gracl_alloc.c
58468 @@ -0,0 +1,105 @@
58469 +#include <linux/kernel.h>
58470 +#include <linux/mm.h>
58471 +#include <linux/slab.h>
58472 +#include <linux/vmalloc.h>
58473 +#include <linux/gracl.h>
58474 +#include <linux/grsecurity.h>
58475 +
58476 +static unsigned long alloc_stack_next = 1;
58477 +static unsigned long alloc_stack_size = 1;
58478 +static void **alloc_stack;
58479 +
58480 +static __inline__ int
58481 +alloc_pop(void)
58482 +{
58483 + if (alloc_stack_next == 1)
58484 + return 0;
58485 +
58486 + kfree(alloc_stack[alloc_stack_next - 2]);
58487 +
58488 + alloc_stack_next--;
58489 +
58490 + return 1;
58491 +}
58492 +
58493 +static __inline__ int
58494 +alloc_push(void *buf)
58495 +{
58496 + if (alloc_stack_next >= alloc_stack_size)
58497 + return 1;
58498 +
58499 + alloc_stack[alloc_stack_next - 1] = buf;
58500 +
58501 + alloc_stack_next++;
58502 +
58503 + return 0;
58504 +}
58505 +
58506 +void *
58507 +acl_alloc(unsigned long len)
58508 +{
58509 + void *ret = NULL;
58510 +
58511 + if (!len || len > PAGE_SIZE)
58512 + goto out;
58513 +
58514 + ret = kmalloc(len, GFP_KERNEL);
58515 +
58516 + if (ret) {
58517 + if (alloc_push(ret)) {
58518 + kfree(ret);
58519 + ret = NULL;
58520 + }
58521 + }
58522 +
58523 +out:
58524 + return ret;
58525 +}
58526 +
58527 +void *
58528 +acl_alloc_num(unsigned long num, unsigned long len)
58529 +{
58530 + if (!len || (num > (PAGE_SIZE / len)))
58531 + return NULL;
58532 +
58533 + return acl_alloc(num * len);
58534 +}
58535 +
58536 +void
58537 +acl_free_all(void)
58538 +{
58539 + if (gr_acl_is_enabled() || !alloc_stack)
58540 + return;
58541 +
58542 + while (alloc_pop()) ;
58543 +
58544 + if (alloc_stack) {
58545 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
58546 + kfree(alloc_stack);
58547 + else
58548 + vfree(alloc_stack);
58549 + }
58550 +
58551 + alloc_stack = NULL;
58552 + alloc_stack_size = 1;
58553 + alloc_stack_next = 1;
58554 +
58555 + return;
58556 +}
58557 +
58558 +int
58559 +acl_alloc_stack_init(unsigned long size)
58560 +{
58561 + if ((size * sizeof (void *)) <= PAGE_SIZE)
58562 + alloc_stack =
58563 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
58564 + else
58565 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
58566 +
58567 + alloc_stack_size = size;
58568 +
58569 + if (!alloc_stack)
58570 + return 0;
58571 + else
58572 + return 1;
58573 +}
58574 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
58575 new file mode 100644
58576 index 0000000..6d21049
58577 --- /dev/null
58578 +++ b/grsecurity/gracl_cap.c
58579 @@ -0,0 +1,110 @@
58580 +#include <linux/kernel.h>
58581 +#include <linux/module.h>
58582 +#include <linux/sched.h>
58583 +#include <linux/gracl.h>
58584 +#include <linux/grsecurity.h>
58585 +#include <linux/grinternal.h>
58586 +
58587 +extern const char *captab_log[];
58588 +extern int captab_log_entries;
58589 +
58590 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58591 +{
58592 + struct acl_subject_label *curracl;
58593 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58594 + kernel_cap_t cap_audit = __cap_empty_set;
58595 +
58596 + if (!gr_acl_is_enabled())
58597 + return 1;
58598 +
58599 + curracl = task->acl;
58600 +
58601 + cap_drop = curracl->cap_lower;
58602 + cap_mask = curracl->cap_mask;
58603 + cap_audit = curracl->cap_invert_audit;
58604 +
58605 + while ((curracl = curracl->parent_subject)) {
58606 + /* if the cap isn't specified in the current computed mask but is specified in the
58607 + current level subject, and is lowered in the current level subject, then add
58608 + it to the set of dropped capabilities
58609 + otherwise, add the current level subject's mask to the current computed mask
58610 + */
58611 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58612 + cap_raise(cap_mask, cap);
58613 + if (cap_raised(curracl->cap_lower, cap))
58614 + cap_raise(cap_drop, cap);
58615 + if (cap_raised(curracl->cap_invert_audit, cap))
58616 + cap_raise(cap_audit, cap);
58617 + }
58618 + }
58619 +
58620 + if (!cap_raised(cap_drop, cap)) {
58621 + if (cap_raised(cap_audit, cap))
58622 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
58623 + return 1;
58624 + }
58625 +
58626 + curracl = task->acl;
58627 +
58628 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
58629 + && cap_raised(cred->cap_effective, cap)) {
58630 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58631 + task->role->roletype, cred->uid,
58632 + cred->gid, task->exec_file ?
58633 + gr_to_filename(task->exec_file->f_path.dentry,
58634 + task->exec_file->f_path.mnt) : curracl->filename,
58635 + curracl->filename, 0UL,
58636 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
58637 + return 1;
58638 + }
58639 +
58640 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
58641 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
58642 +
58643 + return 0;
58644 +}
58645 +
58646 +int
58647 +gr_acl_is_capable(const int cap)
58648 +{
58649 + return gr_task_acl_is_capable(current, current_cred(), cap);
58650 +}
58651 +
58652 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
58653 +{
58654 + struct acl_subject_label *curracl;
58655 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58656 +
58657 + if (!gr_acl_is_enabled())
58658 + return 1;
58659 +
58660 + curracl = task->acl;
58661 +
58662 + cap_drop = curracl->cap_lower;
58663 + cap_mask = curracl->cap_mask;
58664 +
58665 + while ((curracl = curracl->parent_subject)) {
58666 + /* if the cap isn't specified in the current computed mask but is specified in the
58667 + current level subject, and is lowered in the current level subject, then add
58668 + it to the set of dropped capabilities
58669 + otherwise, add the current level subject's mask to the current computed mask
58670 + */
58671 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58672 + cap_raise(cap_mask, cap);
58673 + if (cap_raised(curracl->cap_lower, cap))
58674 + cap_raise(cap_drop, cap);
58675 + }
58676 + }
58677 +
58678 + if (!cap_raised(cap_drop, cap))
58679 + return 1;
58680 +
58681 + return 0;
58682 +}
58683 +
58684 +int
58685 +gr_acl_is_capable_nolog(const int cap)
58686 +{
58687 + return gr_task_acl_is_capable_nolog(current, cap);
58688 +}
58689 +
58690 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
58691 new file mode 100644
58692 index 0000000..a340c17
58693 --- /dev/null
58694 +++ b/grsecurity/gracl_fs.c
58695 @@ -0,0 +1,431 @@
58696 +#include <linux/kernel.h>
58697 +#include <linux/sched.h>
58698 +#include <linux/types.h>
58699 +#include <linux/fs.h>
58700 +#include <linux/file.h>
58701 +#include <linux/stat.h>
58702 +#include <linux/grsecurity.h>
58703 +#include <linux/grinternal.h>
58704 +#include <linux/gracl.h>
58705 +
58706 +umode_t
58707 +gr_acl_umask(void)
58708 +{
58709 + if (unlikely(!gr_acl_is_enabled()))
58710 + return 0;
58711 +
58712 + return current->role->umask;
58713 +}
58714 +
58715 +__u32
58716 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58717 + const struct vfsmount * mnt)
58718 +{
58719 + __u32 mode;
58720 +
58721 + if (unlikely(!dentry->d_inode))
58722 + return GR_FIND;
58723 +
58724 + mode =
58725 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
58726 +
58727 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
58728 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58729 + return mode;
58730 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
58731 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58732 + return 0;
58733 + } else if (unlikely(!(mode & GR_FIND)))
58734 + return 0;
58735 +
58736 + return GR_FIND;
58737 +}
58738 +
58739 +__u32
58740 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58741 + int acc_mode)
58742 +{
58743 + __u32 reqmode = GR_FIND;
58744 + __u32 mode;
58745 +
58746 + if (unlikely(!dentry->d_inode))
58747 + return reqmode;
58748 +
58749 + if (acc_mode & MAY_APPEND)
58750 + reqmode |= GR_APPEND;
58751 + else if (acc_mode & MAY_WRITE)
58752 + reqmode |= GR_WRITE;
58753 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
58754 + reqmode |= GR_READ;
58755 +
58756 + mode =
58757 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58758 + mnt);
58759 +
58760 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58761 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58762 + reqmode & GR_READ ? " reading" : "",
58763 + reqmode & GR_WRITE ? " writing" : reqmode &
58764 + GR_APPEND ? " appending" : "");
58765 + return reqmode;
58766 + } else
58767 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58768 + {
58769 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58770 + reqmode & GR_READ ? " reading" : "",
58771 + reqmode & GR_WRITE ? " writing" : reqmode &
58772 + GR_APPEND ? " appending" : "");
58773 + return 0;
58774 + } else if (unlikely((mode & reqmode) != reqmode))
58775 + return 0;
58776 +
58777 + return reqmode;
58778 +}
58779 +
58780 +__u32
58781 +gr_acl_handle_creat(const struct dentry * dentry,
58782 + const struct dentry * p_dentry,
58783 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58784 + const int imode)
58785 +{
58786 + __u32 reqmode = GR_WRITE | GR_CREATE;
58787 + __u32 mode;
58788 +
58789 + if (acc_mode & MAY_APPEND)
58790 + reqmode |= GR_APPEND;
58791 + // if a directory was required or the directory already exists, then
58792 + // don't count this open as a read
58793 + if ((acc_mode & MAY_READ) &&
58794 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58795 + reqmode |= GR_READ;
58796 + if ((open_flags & O_CREAT) &&
58797 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58798 + reqmode |= GR_SETID;
58799 +
58800 + mode =
58801 + gr_check_create(dentry, p_dentry, p_mnt,
58802 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58803 +
58804 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58805 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58806 + reqmode & GR_READ ? " reading" : "",
58807 + reqmode & GR_WRITE ? " writing" : reqmode &
58808 + GR_APPEND ? " appending" : "");
58809 + return reqmode;
58810 + } else
58811 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58812 + {
58813 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58814 + reqmode & GR_READ ? " reading" : "",
58815 + reqmode & GR_WRITE ? " writing" : reqmode &
58816 + GR_APPEND ? " appending" : "");
58817 + return 0;
58818 + } else if (unlikely((mode & reqmode) != reqmode))
58819 + return 0;
58820 +
58821 + return reqmode;
58822 +}
58823 +
58824 +__u32
58825 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58826 + const int fmode)
58827 +{
58828 + __u32 mode, reqmode = GR_FIND;
58829 +
58830 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58831 + reqmode |= GR_EXEC;
58832 + if (fmode & S_IWOTH)
58833 + reqmode |= GR_WRITE;
58834 + if (fmode & S_IROTH)
58835 + reqmode |= GR_READ;
58836 +
58837 + mode =
58838 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58839 + mnt);
58840 +
58841 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58842 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58843 + reqmode & GR_READ ? " reading" : "",
58844 + reqmode & GR_WRITE ? " writing" : "",
58845 + reqmode & GR_EXEC ? " executing" : "");
58846 + return reqmode;
58847 + } else
58848 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58849 + {
58850 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58851 + reqmode & GR_READ ? " reading" : "",
58852 + reqmode & GR_WRITE ? " writing" : "",
58853 + reqmode & GR_EXEC ? " executing" : "");
58854 + return 0;
58855 + } else if (unlikely((mode & reqmode) != reqmode))
58856 + return 0;
58857 +
58858 + return reqmode;
58859 +}
58860 +
58861 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58862 +{
58863 + __u32 mode;
58864 +
58865 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58866 +
58867 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58868 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58869 + return mode;
58870 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58871 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58872 + return 0;
58873 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58874 + return 0;
58875 +
58876 + return (reqmode);
58877 +}
58878 +
58879 +__u32
58880 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58881 +{
58882 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58883 +}
58884 +
58885 +__u32
58886 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58887 +{
58888 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58889 +}
58890 +
58891 +__u32
58892 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58893 +{
58894 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58895 +}
58896 +
58897 +__u32
58898 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58899 +{
58900 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58901 +}
58902 +
58903 +__u32
58904 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58905 + umode_t *modeptr)
58906 +{
58907 + umode_t mode;
58908 +
58909 + *modeptr &= ~gr_acl_umask();
58910 + mode = *modeptr;
58911 +
58912 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58913 + return 1;
58914 +
58915 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58916 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58917 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58918 + GR_CHMOD_ACL_MSG);
58919 + } else {
58920 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58921 + }
58922 +}
58923 +
58924 +__u32
58925 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58926 +{
58927 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58928 +}
58929 +
58930 +__u32
58931 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58932 +{
58933 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58934 +}
58935 +
58936 +__u32
58937 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58938 +{
58939 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58940 +}
58941 +
58942 +__u32
58943 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58944 +{
58945 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58946 + GR_UNIXCONNECT_ACL_MSG);
58947 +}
58948 +
58949 +/* hardlinks require at minimum create and link permission,
58950 + any additional privilege required is based on the
58951 + privilege of the file being linked to
58952 +*/
58953 +__u32
58954 +gr_acl_handle_link(const struct dentry * new_dentry,
58955 + const struct dentry * parent_dentry,
58956 + const struct vfsmount * parent_mnt,
58957 + const struct dentry * old_dentry,
58958 + const struct vfsmount * old_mnt, const struct filename *to)
58959 +{
58960 + __u32 mode;
58961 + __u32 needmode = GR_CREATE | GR_LINK;
58962 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58963 +
58964 + mode =
58965 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58966 + old_mnt);
58967 +
58968 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58969 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58970 + return mode;
58971 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58972 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58973 + return 0;
58974 + } else if (unlikely((mode & needmode) != needmode))
58975 + return 0;
58976 +
58977 + return 1;
58978 +}
58979 +
58980 +__u32
58981 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58982 + const struct dentry * parent_dentry,
58983 + const struct vfsmount * parent_mnt, const struct filename *from)
58984 +{
58985 + __u32 needmode = GR_WRITE | GR_CREATE;
58986 + __u32 mode;
58987 +
58988 + mode =
58989 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
58990 + GR_CREATE | GR_AUDIT_CREATE |
58991 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58992 +
58993 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58994 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58995 + return mode;
58996 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58997 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58998 + return 0;
58999 + } else if (unlikely((mode & needmode) != needmode))
59000 + return 0;
59001 +
59002 + return (GR_WRITE | GR_CREATE);
59003 +}
59004 +
59005 +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)
59006 +{
59007 + __u32 mode;
59008 +
59009 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
59010 +
59011 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
59012 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
59013 + return mode;
59014 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
59015 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
59016 + return 0;
59017 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
59018 + return 0;
59019 +
59020 + return (reqmode);
59021 +}
59022 +
59023 +__u32
59024 +gr_acl_handle_mknod(const struct dentry * new_dentry,
59025 + const struct dentry * parent_dentry,
59026 + const struct vfsmount * parent_mnt,
59027 + const int mode)
59028 +{
59029 + __u32 reqmode = GR_WRITE | GR_CREATE;
59030 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
59031 + reqmode |= GR_SETID;
59032 +
59033 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
59034 + reqmode, GR_MKNOD_ACL_MSG);
59035 +}
59036 +
59037 +__u32
59038 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
59039 + const struct dentry *parent_dentry,
59040 + const struct vfsmount *parent_mnt)
59041 +{
59042 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
59043 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
59044 +}
59045 +
59046 +#define RENAME_CHECK_SUCCESS(old, new) \
59047 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
59048 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
59049 +
59050 +int
59051 +gr_acl_handle_rename(struct dentry *new_dentry,
59052 + struct dentry *parent_dentry,
59053 + const struct vfsmount *parent_mnt,
59054 + struct dentry *old_dentry,
59055 + struct inode *old_parent_inode,
59056 + struct vfsmount *old_mnt, const struct filename *newname)
59057 +{
59058 + __u32 comp1, comp2;
59059 + int error = 0;
59060 +
59061 + if (unlikely(!gr_acl_is_enabled()))
59062 + return 0;
59063 +
59064 + if (!new_dentry->d_inode) {
59065 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
59066 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
59067 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
59068 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
59069 + GR_DELETE | GR_AUDIT_DELETE |
59070 + GR_AUDIT_READ | GR_AUDIT_WRITE |
59071 + GR_SUPPRESS, old_mnt);
59072 + } else {
59073 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
59074 + GR_CREATE | GR_DELETE |
59075 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
59076 + GR_AUDIT_READ | GR_AUDIT_WRITE |
59077 + GR_SUPPRESS, parent_mnt);
59078 + comp2 =
59079 + gr_search_file(old_dentry,
59080 + GR_READ | GR_WRITE | GR_AUDIT_READ |
59081 + GR_DELETE | GR_AUDIT_DELETE |
59082 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
59083 + }
59084 +
59085 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
59086 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
59087 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59088 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
59089 + && !(comp2 & GR_SUPPRESS)) {
59090 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59091 + error = -EACCES;
59092 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
59093 + error = -EACCES;
59094 +
59095 + return error;
59096 +}
59097 +
59098 +void
59099 +gr_acl_handle_exit(void)
59100 +{
59101 + u16 id;
59102 + char *rolename;
59103 +
59104 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
59105 + !(current->role->roletype & GR_ROLE_PERSIST))) {
59106 + id = current->acl_role_id;
59107 + rolename = current->role->rolename;
59108 + gr_set_acls(1);
59109 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
59110 + }
59111 +
59112 + gr_put_exec_file(current);
59113 + return;
59114 +}
59115 +
59116 +int
59117 +gr_acl_handle_procpidmem(const struct task_struct *task)
59118 +{
59119 + if (unlikely(!gr_acl_is_enabled()))
59120 + return 0;
59121 +
59122 + if (task != current && task->acl->mode & GR_PROTPROCFD)
59123 + return -EACCES;
59124 +
59125 + return 0;
59126 +}
59127 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
59128 new file mode 100644
59129 index 0000000..58800a7
59130 --- /dev/null
59131 +++ b/grsecurity/gracl_ip.c
59132 @@ -0,0 +1,384 @@
59133 +#include <linux/kernel.h>
59134 +#include <asm/uaccess.h>
59135 +#include <asm/errno.h>
59136 +#include <net/sock.h>
59137 +#include <linux/file.h>
59138 +#include <linux/fs.h>
59139 +#include <linux/net.h>
59140 +#include <linux/in.h>
59141 +#include <linux/skbuff.h>
59142 +#include <linux/ip.h>
59143 +#include <linux/udp.h>
59144 +#include <linux/types.h>
59145 +#include <linux/sched.h>
59146 +#include <linux/netdevice.h>
59147 +#include <linux/inetdevice.h>
59148 +#include <linux/gracl.h>
59149 +#include <linux/grsecurity.h>
59150 +#include <linux/grinternal.h>
59151 +
59152 +#define GR_BIND 0x01
59153 +#define GR_CONNECT 0x02
59154 +#define GR_INVERT 0x04
59155 +#define GR_BINDOVERRIDE 0x08
59156 +#define GR_CONNECTOVERRIDE 0x10
59157 +#define GR_SOCK_FAMILY 0x20
59158 +
59159 +static const char * gr_protocols[IPPROTO_MAX] = {
59160 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
59161 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
59162 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
59163 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
59164 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
59165 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
59166 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
59167 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
59168 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
59169 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
59170 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
59171 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
59172 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
59173 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
59174 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
59175 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
59176 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
59177 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
59178 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
59179 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
59180 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
59181 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
59182 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
59183 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
59184 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
59185 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
59186 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
59187 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
59188 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
59189 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
59190 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
59191 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
59192 + };
59193 +
59194 +static const char * gr_socktypes[SOCK_MAX] = {
59195 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
59196 + "unknown:7", "unknown:8", "unknown:9", "packet"
59197 + };
59198 +
59199 +static const char * gr_sockfamilies[AF_MAX+1] = {
59200 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
59201 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
59202 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
59203 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
59204 + };
59205 +
59206 +const char *
59207 +gr_proto_to_name(unsigned char proto)
59208 +{
59209 + return gr_protocols[proto];
59210 +}
59211 +
59212 +const char *
59213 +gr_socktype_to_name(unsigned char type)
59214 +{
59215 + return gr_socktypes[type];
59216 +}
59217 +
59218 +const char *
59219 +gr_sockfamily_to_name(unsigned char family)
59220 +{
59221 + return gr_sockfamilies[family];
59222 +}
59223 +
59224 +int
59225 +gr_search_socket(const int domain, const int type, const int protocol)
59226 +{
59227 + struct acl_subject_label *curr;
59228 + const struct cred *cred = current_cred();
59229 +
59230 + if (unlikely(!gr_acl_is_enabled()))
59231 + goto exit;
59232 +
59233 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
59234 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
59235 + goto exit; // let the kernel handle it
59236 +
59237 + curr = current->acl;
59238 +
59239 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
59240 + /* the family is allowed, if this is PF_INET allow it only if
59241 + the extra sock type/protocol checks pass */
59242 + if (domain == PF_INET)
59243 + goto inet_check;
59244 + goto exit;
59245 + } else {
59246 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59247 + __u32 fakeip = 0;
59248 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59249 + current->role->roletype, cred->uid,
59250 + cred->gid, current->exec_file ?
59251 + gr_to_filename(current->exec_file->f_path.dentry,
59252 + current->exec_file->f_path.mnt) :
59253 + curr->filename, curr->filename,
59254 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
59255 + &current->signal->saved_ip);
59256 + goto exit;
59257 + }
59258 + goto exit_fail;
59259 + }
59260 +
59261 +inet_check:
59262 + /* the rest of this checking is for IPv4 only */
59263 + if (!curr->ips)
59264 + goto exit;
59265 +
59266 + if ((curr->ip_type & (1 << type)) &&
59267 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
59268 + goto exit;
59269 +
59270 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59271 + /* we don't place acls on raw sockets , and sometimes
59272 + dgram/ip sockets are opened for ioctl and not
59273 + bind/connect, so we'll fake a bind learn log */
59274 + if (type == SOCK_RAW || type == SOCK_PACKET) {
59275 + __u32 fakeip = 0;
59276 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59277 + current->role->roletype, cred->uid,
59278 + cred->gid, current->exec_file ?
59279 + gr_to_filename(current->exec_file->f_path.dentry,
59280 + current->exec_file->f_path.mnt) :
59281 + curr->filename, curr->filename,
59282 + &fakeip, 0, type,
59283 + protocol, GR_CONNECT, &current->signal->saved_ip);
59284 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
59285 + __u32 fakeip = 0;
59286 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59287 + current->role->roletype, cred->uid,
59288 + cred->gid, current->exec_file ?
59289 + gr_to_filename(current->exec_file->f_path.dentry,
59290 + current->exec_file->f_path.mnt) :
59291 + curr->filename, curr->filename,
59292 + &fakeip, 0, type,
59293 + protocol, GR_BIND, &current->signal->saved_ip);
59294 + }
59295 + /* we'll log when they use connect or bind */
59296 + goto exit;
59297 + }
59298 +
59299 +exit_fail:
59300 + if (domain == PF_INET)
59301 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
59302 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
59303 + else
59304 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
59305 + gr_socktype_to_name(type), protocol);
59306 +
59307 + return 0;
59308 +exit:
59309 + return 1;
59310 +}
59311 +
59312 +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)
59313 +{
59314 + if ((ip->mode & mode) &&
59315 + (ip_port >= ip->low) &&
59316 + (ip_port <= ip->high) &&
59317 + ((ntohl(ip_addr) & our_netmask) ==
59318 + (ntohl(our_addr) & our_netmask))
59319 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
59320 + && (ip->type & (1 << type))) {
59321 + if (ip->mode & GR_INVERT)
59322 + return 2; // specifically denied
59323 + else
59324 + return 1; // allowed
59325 + }
59326 +
59327 + return 0; // not specifically allowed, may continue parsing
59328 +}
59329 +
59330 +static int
59331 +gr_search_connectbind(const int full_mode, struct sock *sk,
59332 + struct sockaddr_in *addr, const int type)
59333 +{
59334 + char iface[IFNAMSIZ] = {0};
59335 + struct acl_subject_label *curr;
59336 + struct acl_ip_label *ip;
59337 + struct inet_sock *isk;
59338 + struct net_device *dev;
59339 + struct in_device *idev;
59340 + unsigned long i;
59341 + int ret;
59342 + int mode = full_mode & (GR_BIND | GR_CONNECT);
59343 + __u32 ip_addr = 0;
59344 + __u32 our_addr;
59345 + __u32 our_netmask;
59346 + char *p;
59347 + __u16 ip_port = 0;
59348 + const struct cred *cred = current_cred();
59349 +
59350 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
59351 + return 0;
59352 +
59353 + curr = current->acl;
59354 + isk = inet_sk(sk);
59355 +
59356 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
59357 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
59358 + addr->sin_addr.s_addr = curr->inaddr_any_override;
59359 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
59360 + struct sockaddr_in saddr;
59361 + int err;
59362 +
59363 + saddr.sin_family = AF_INET;
59364 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
59365 + saddr.sin_port = isk->inet_sport;
59366 +
59367 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59368 + if (err)
59369 + return err;
59370 +
59371 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59372 + if (err)
59373 + return err;
59374 + }
59375 +
59376 + if (!curr->ips)
59377 + return 0;
59378 +
59379 + ip_addr = addr->sin_addr.s_addr;
59380 + ip_port = ntohs(addr->sin_port);
59381 +
59382 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59383 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59384 + current->role->roletype, cred->uid,
59385 + cred->gid, current->exec_file ?
59386 + gr_to_filename(current->exec_file->f_path.dentry,
59387 + current->exec_file->f_path.mnt) :
59388 + curr->filename, curr->filename,
59389 + &ip_addr, ip_port, type,
59390 + sk->sk_protocol, mode, &current->signal->saved_ip);
59391 + return 0;
59392 + }
59393 +
59394 + for (i = 0; i < curr->ip_num; i++) {
59395 + ip = *(curr->ips + i);
59396 + if (ip->iface != NULL) {
59397 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
59398 + p = strchr(iface, ':');
59399 + if (p != NULL)
59400 + *p = '\0';
59401 + dev = dev_get_by_name(sock_net(sk), iface);
59402 + if (dev == NULL)
59403 + continue;
59404 + idev = in_dev_get(dev);
59405 + if (idev == NULL) {
59406 + dev_put(dev);
59407 + continue;
59408 + }
59409 + rcu_read_lock();
59410 + for_ifa(idev) {
59411 + if (!strcmp(ip->iface, ifa->ifa_label)) {
59412 + our_addr = ifa->ifa_address;
59413 + our_netmask = 0xffffffff;
59414 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59415 + if (ret == 1) {
59416 + rcu_read_unlock();
59417 + in_dev_put(idev);
59418 + dev_put(dev);
59419 + return 0;
59420 + } else if (ret == 2) {
59421 + rcu_read_unlock();
59422 + in_dev_put(idev);
59423 + dev_put(dev);
59424 + goto denied;
59425 + }
59426 + }
59427 + } endfor_ifa(idev);
59428 + rcu_read_unlock();
59429 + in_dev_put(idev);
59430 + dev_put(dev);
59431 + } else {
59432 + our_addr = ip->addr;
59433 + our_netmask = ip->netmask;
59434 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59435 + if (ret == 1)
59436 + return 0;
59437 + else if (ret == 2)
59438 + goto denied;
59439 + }
59440 + }
59441 +
59442 +denied:
59443 + if (mode == GR_BIND)
59444 + 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));
59445 + else if (mode == GR_CONNECT)
59446 + 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));
59447 +
59448 + return -EACCES;
59449 +}
59450 +
59451 +int
59452 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
59453 +{
59454 + /* always allow disconnection of dgram sockets with connect */
59455 + if (addr->sin_family == AF_UNSPEC)
59456 + return 0;
59457 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
59458 +}
59459 +
59460 +int
59461 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
59462 +{
59463 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
59464 +}
59465 +
59466 +int gr_search_listen(struct socket *sock)
59467 +{
59468 + struct sock *sk = sock->sk;
59469 + struct sockaddr_in addr;
59470 +
59471 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59472 + addr.sin_port = inet_sk(sk)->inet_sport;
59473 +
59474 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59475 +}
59476 +
59477 +int gr_search_accept(struct socket *sock)
59478 +{
59479 + struct sock *sk = sock->sk;
59480 + struct sockaddr_in addr;
59481 +
59482 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59483 + addr.sin_port = inet_sk(sk)->inet_sport;
59484 +
59485 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59486 +}
59487 +
59488 +int
59489 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
59490 +{
59491 + if (addr)
59492 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
59493 + else {
59494 + struct sockaddr_in sin;
59495 + const struct inet_sock *inet = inet_sk(sk);
59496 +
59497 + sin.sin_addr.s_addr = inet->inet_daddr;
59498 + sin.sin_port = inet->inet_dport;
59499 +
59500 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59501 + }
59502 +}
59503 +
59504 +int
59505 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
59506 +{
59507 + struct sockaddr_in sin;
59508 +
59509 + if (unlikely(skb->len < sizeof (struct udphdr)))
59510 + return 0; // skip this packet
59511 +
59512 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
59513 + sin.sin_port = udp_hdr(skb)->source;
59514 +
59515 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59516 +}
59517 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
59518 new file mode 100644
59519 index 0000000..25f54ef
59520 --- /dev/null
59521 +++ b/grsecurity/gracl_learn.c
59522 @@ -0,0 +1,207 @@
59523 +#include <linux/kernel.h>
59524 +#include <linux/mm.h>
59525 +#include <linux/sched.h>
59526 +#include <linux/poll.h>
59527 +#include <linux/string.h>
59528 +#include <linux/file.h>
59529 +#include <linux/types.h>
59530 +#include <linux/vmalloc.h>
59531 +#include <linux/grinternal.h>
59532 +
59533 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
59534 + size_t count, loff_t *ppos);
59535 +extern int gr_acl_is_enabled(void);
59536 +
59537 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
59538 +static int gr_learn_attached;
59539 +
59540 +/* use a 512k buffer */
59541 +#define LEARN_BUFFER_SIZE (512 * 1024)
59542 +
59543 +static DEFINE_SPINLOCK(gr_learn_lock);
59544 +static DEFINE_MUTEX(gr_learn_user_mutex);
59545 +
59546 +/* we need to maintain two buffers, so that the kernel context of grlearn
59547 + uses a semaphore around the userspace copying, and the other kernel contexts
59548 + use a spinlock when copying into the buffer, since they cannot sleep
59549 +*/
59550 +static char *learn_buffer;
59551 +static char *learn_buffer_user;
59552 +static int learn_buffer_len;
59553 +static int learn_buffer_user_len;
59554 +
59555 +static ssize_t
59556 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
59557 +{
59558 + DECLARE_WAITQUEUE(wait, current);
59559 + ssize_t retval = 0;
59560 +
59561 + add_wait_queue(&learn_wait, &wait);
59562 + set_current_state(TASK_INTERRUPTIBLE);
59563 + do {
59564 + mutex_lock(&gr_learn_user_mutex);
59565 + spin_lock(&gr_learn_lock);
59566 + if (learn_buffer_len)
59567 + break;
59568 + spin_unlock(&gr_learn_lock);
59569 + mutex_unlock(&gr_learn_user_mutex);
59570 + if (file->f_flags & O_NONBLOCK) {
59571 + retval = -EAGAIN;
59572 + goto out;
59573 + }
59574 + if (signal_pending(current)) {
59575 + retval = -ERESTARTSYS;
59576 + goto out;
59577 + }
59578 +
59579 + schedule();
59580 + } while (1);
59581 +
59582 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
59583 + learn_buffer_user_len = learn_buffer_len;
59584 + retval = learn_buffer_len;
59585 + learn_buffer_len = 0;
59586 +
59587 + spin_unlock(&gr_learn_lock);
59588 +
59589 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
59590 + retval = -EFAULT;
59591 +
59592 + mutex_unlock(&gr_learn_user_mutex);
59593 +out:
59594 + set_current_state(TASK_RUNNING);
59595 + remove_wait_queue(&learn_wait, &wait);
59596 + return retval;
59597 +}
59598 +
59599 +static unsigned int
59600 +poll_learn(struct file * file, poll_table * wait)
59601 +{
59602 + poll_wait(file, &learn_wait, wait);
59603 +
59604 + if (learn_buffer_len)
59605 + return (POLLIN | POLLRDNORM);
59606 +
59607 + return 0;
59608 +}
59609 +
59610 +void
59611 +gr_clear_learn_entries(void)
59612 +{
59613 + char *tmp;
59614 +
59615 + mutex_lock(&gr_learn_user_mutex);
59616 + spin_lock(&gr_learn_lock);
59617 + tmp = learn_buffer;
59618 + learn_buffer = NULL;
59619 + spin_unlock(&gr_learn_lock);
59620 + if (tmp)
59621 + vfree(tmp);
59622 + if (learn_buffer_user != NULL) {
59623 + vfree(learn_buffer_user);
59624 + learn_buffer_user = NULL;
59625 + }
59626 + learn_buffer_len = 0;
59627 + mutex_unlock(&gr_learn_user_mutex);
59628 +
59629 + return;
59630 +}
59631 +
59632 +void
59633 +gr_add_learn_entry(const char *fmt, ...)
59634 +{
59635 + va_list args;
59636 + unsigned int len;
59637 +
59638 + if (!gr_learn_attached)
59639 + return;
59640 +
59641 + spin_lock(&gr_learn_lock);
59642 +
59643 + /* leave a gap at the end so we know when it's "full" but don't have to
59644 + compute the exact length of the string we're trying to append
59645 + */
59646 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
59647 + spin_unlock(&gr_learn_lock);
59648 + wake_up_interruptible(&learn_wait);
59649 + return;
59650 + }
59651 + if (learn_buffer == NULL) {
59652 + spin_unlock(&gr_learn_lock);
59653 + return;
59654 + }
59655 +
59656 + va_start(args, fmt);
59657 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
59658 + va_end(args);
59659 +
59660 + learn_buffer_len += len + 1;
59661 +
59662 + spin_unlock(&gr_learn_lock);
59663 + wake_up_interruptible(&learn_wait);
59664 +
59665 + return;
59666 +}
59667 +
59668 +static int
59669 +open_learn(struct inode *inode, struct file *file)
59670 +{
59671 + if (file->f_mode & FMODE_READ && gr_learn_attached)
59672 + return -EBUSY;
59673 + if (file->f_mode & FMODE_READ) {
59674 + int retval = 0;
59675 + mutex_lock(&gr_learn_user_mutex);
59676 + if (learn_buffer == NULL)
59677 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
59678 + if (learn_buffer_user == NULL)
59679 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
59680 + if (learn_buffer == NULL) {
59681 + retval = -ENOMEM;
59682 + goto out_error;
59683 + }
59684 + if (learn_buffer_user == NULL) {
59685 + retval = -ENOMEM;
59686 + goto out_error;
59687 + }
59688 + learn_buffer_len = 0;
59689 + learn_buffer_user_len = 0;
59690 + gr_learn_attached = 1;
59691 +out_error:
59692 + mutex_unlock(&gr_learn_user_mutex);
59693 + return retval;
59694 + }
59695 + return 0;
59696 +}
59697 +
59698 +static int
59699 +close_learn(struct inode *inode, struct file *file)
59700 +{
59701 + if (file->f_mode & FMODE_READ) {
59702 + char *tmp = NULL;
59703 + mutex_lock(&gr_learn_user_mutex);
59704 + spin_lock(&gr_learn_lock);
59705 + tmp = learn_buffer;
59706 + learn_buffer = NULL;
59707 + spin_unlock(&gr_learn_lock);
59708 + if (tmp)
59709 + vfree(tmp);
59710 + if (learn_buffer_user != NULL) {
59711 + vfree(learn_buffer_user);
59712 + learn_buffer_user = NULL;
59713 + }
59714 + learn_buffer_len = 0;
59715 + learn_buffer_user_len = 0;
59716 + gr_learn_attached = 0;
59717 + mutex_unlock(&gr_learn_user_mutex);
59718 + }
59719 +
59720 + return 0;
59721 +}
59722 +
59723 +const struct file_operations grsec_fops = {
59724 + .read = read_learn,
59725 + .write = write_grsec_handler,
59726 + .open = open_learn,
59727 + .release = close_learn,
59728 + .poll = poll_learn,
59729 +};
59730 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
59731 new file mode 100644
59732 index 0000000..39645c9
59733 --- /dev/null
59734 +++ b/grsecurity/gracl_res.c
59735 @@ -0,0 +1,68 @@
59736 +#include <linux/kernel.h>
59737 +#include <linux/sched.h>
59738 +#include <linux/gracl.h>
59739 +#include <linux/grinternal.h>
59740 +
59741 +static const char *restab_log[] = {
59742 + [RLIMIT_CPU] = "RLIMIT_CPU",
59743 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
59744 + [RLIMIT_DATA] = "RLIMIT_DATA",
59745 + [RLIMIT_STACK] = "RLIMIT_STACK",
59746 + [RLIMIT_CORE] = "RLIMIT_CORE",
59747 + [RLIMIT_RSS] = "RLIMIT_RSS",
59748 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
59749 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
59750 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
59751 + [RLIMIT_AS] = "RLIMIT_AS",
59752 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
59753 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
59754 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
59755 + [RLIMIT_NICE] = "RLIMIT_NICE",
59756 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
59757 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
59758 + [GR_CRASH_RES] = "RLIMIT_CRASH"
59759 +};
59760 +
59761 +void
59762 +gr_log_resource(const struct task_struct *task,
59763 + const int res, const unsigned long wanted, const int gt)
59764 +{
59765 + const struct cred *cred;
59766 + unsigned long rlim;
59767 +
59768 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
59769 + return;
59770 +
59771 + // not yet supported resource
59772 + if (unlikely(!restab_log[res]))
59773 + return;
59774 +
59775 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59776 + rlim = task_rlimit_max(task, res);
59777 + else
59778 + rlim = task_rlimit(task, res);
59779 +
59780 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59781 + return;
59782 +
59783 + rcu_read_lock();
59784 + cred = __task_cred(task);
59785 +
59786 + if (res == RLIMIT_NPROC &&
59787 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59788 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59789 + goto out_rcu_unlock;
59790 + else if (res == RLIMIT_MEMLOCK &&
59791 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59792 + goto out_rcu_unlock;
59793 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59794 + goto out_rcu_unlock;
59795 + rcu_read_unlock();
59796 +
59797 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59798 +
59799 + return;
59800 +out_rcu_unlock:
59801 + rcu_read_unlock();
59802 + return;
59803 +}
59804 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59805 new file mode 100644
59806 index 0000000..25197e9
59807 --- /dev/null
59808 +++ b/grsecurity/gracl_segv.c
59809 @@ -0,0 +1,299 @@
59810 +#include <linux/kernel.h>
59811 +#include <linux/mm.h>
59812 +#include <asm/uaccess.h>
59813 +#include <asm/errno.h>
59814 +#include <asm/mman.h>
59815 +#include <net/sock.h>
59816 +#include <linux/file.h>
59817 +#include <linux/fs.h>
59818 +#include <linux/net.h>
59819 +#include <linux/in.h>
59820 +#include <linux/slab.h>
59821 +#include <linux/types.h>
59822 +#include <linux/sched.h>
59823 +#include <linux/timer.h>
59824 +#include <linux/gracl.h>
59825 +#include <linux/grsecurity.h>
59826 +#include <linux/grinternal.h>
59827 +
59828 +static struct crash_uid *uid_set;
59829 +static unsigned short uid_used;
59830 +static DEFINE_SPINLOCK(gr_uid_lock);
59831 +extern rwlock_t gr_inode_lock;
59832 +extern struct acl_subject_label *
59833 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59834 + struct acl_role_label *role);
59835 +
59836 +#ifdef CONFIG_BTRFS_FS
59837 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59838 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59839 +#endif
59840 +
59841 +static inline dev_t __get_dev(const struct dentry *dentry)
59842 +{
59843 +#ifdef CONFIG_BTRFS_FS
59844 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59845 + return get_btrfs_dev_from_inode(dentry->d_inode);
59846 + else
59847 +#endif
59848 + return dentry->d_inode->i_sb->s_dev;
59849 +}
59850 +
59851 +int
59852 +gr_init_uidset(void)
59853 +{
59854 + uid_set =
59855 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59856 + uid_used = 0;
59857 +
59858 + return uid_set ? 1 : 0;
59859 +}
59860 +
59861 +void
59862 +gr_free_uidset(void)
59863 +{
59864 + if (uid_set)
59865 + kfree(uid_set);
59866 +
59867 + return;
59868 +}
59869 +
59870 +int
59871 +gr_find_uid(const uid_t uid)
59872 +{
59873 + struct crash_uid *tmp = uid_set;
59874 + uid_t buid;
59875 + int low = 0, high = uid_used - 1, mid;
59876 +
59877 + while (high >= low) {
59878 + mid = (low + high) >> 1;
59879 + buid = tmp[mid].uid;
59880 + if (buid == uid)
59881 + return mid;
59882 + if (buid > uid)
59883 + high = mid - 1;
59884 + if (buid < uid)
59885 + low = mid + 1;
59886 + }
59887 +
59888 + return -1;
59889 +}
59890 +
59891 +static __inline__ void
59892 +gr_insertsort(void)
59893 +{
59894 + unsigned short i, j;
59895 + struct crash_uid index;
59896 +
59897 + for (i = 1; i < uid_used; i++) {
59898 + index = uid_set[i];
59899 + j = i;
59900 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59901 + uid_set[j] = uid_set[j - 1];
59902 + j--;
59903 + }
59904 + uid_set[j] = index;
59905 + }
59906 +
59907 + return;
59908 +}
59909 +
59910 +static __inline__ void
59911 +gr_insert_uid(const uid_t uid, const unsigned long expires)
59912 +{
59913 + int loc;
59914 +
59915 + if (uid_used == GR_UIDTABLE_MAX)
59916 + return;
59917 +
59918 + loc = gr_find_uid(uid);
59919 +
59920 + if (loc >= 0) {
59921 + uid_set[loc].expires = expires;
59922 + return;
59923 + }
59924 +
59925 + uid_set[uid_used].uid = uid;
59926 + uid_set[uid_used].expires = expires;
59927 + uid_used++;
59928 +
59929 + gr_insertsort();
59930 +
59931 + return;
59932 +}
59933 +
59934 +void
59935 +gr_remove_uid(const unsigned short loc)
59936 +{
59937 + unsigned short i;
59938 +
59939 + for (i = loc + 1; i < uid_used; i++)
59940 + uid_set[i - 1] = uid_set[i];
59941 +
59942 + uid_used--;
59943 +
59944 + return;
59945 +}
59946 +
59947 +int
59948 +gr_check_crash_uid(const uid_t uid)
59949 +{
59950 + int loc;
59951 + int ret = 0;
59952 +
59953 + if (unlikely(!gr_acl_is_enabled()))
59954 + return 0;
59955 +
59956 + spin_lock(&gr_uid_lock);
59957 + loc = gr_find_uid(uid);
59958 +
59959 + if (loc < 0)
59960 + goto out_unlock;
59961 +
59962 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
59963 + gr_remove_uid(loc);
59964 + else
59965 + ret = 1;
59966 +
59967 +out_unlock:
59968 + spin_unlock(&gr_uid_lock);
59969 + return ret;
59970 +}
59971 +
59972 +static __inline__ int
59973 +proc_is_setxid(const struct cred *cred)
59974 +{
59975 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59976 + !uid_eq(cred->uid, cred->fsuid))
59977 + return 1;
59978 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59979 + !uid_eq(cred->gid, cred->fsgid))
59980 + return 1;
59981 +
59982 + return 0;
59983 +}
59984 +
59985 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
59986 +
59987 +void
59988 +gr_handle_crash(struct task_struct *task, const int sig)
59989 +{
59990 + struct acl_subject_label *curr;
59991 + struct task_struct *tsk, *tsk2;
59992 + const struct cred *cred;
59993 + const struct cred *cred2;
59994 +
59995 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59996 + return;
59997 +
59998 + if (unlikely(!gr_acl_is_enabled()))
59999 + return;
60000 +
60001 + curr = task->acl;
60002 +
60003 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
60004 + return;
60005 +
60006 + if (time_before_eq(curr->expires, get_seconds())) {
60007 + curr->expires = 0;
60008 + curr->crashes = 0;
60009 + }
60010 +
60011 + curr->crashes++;
60012 +
60013 + if (!curr->expires)
60014 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
60015 +
60016 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60017 + time_after(curr->expires, get_seconds())) {
60018 + rcu_read_lock();
60019 + cred = __task_cred(task);
60020 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
60021 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
60022 + spin_lock(&gr_uid_lock);
60023 + gr_insert_uid(cred->uid, curr->expires);
60024 + spin_unlock(&gr_uid_lock);
60025 + curr->expires = 0;
60026 + curr->crashes = 0;
60027 + read_lock(&tasklist_lock);
60028 + do_each_thread(tsk2, tsk) {
60029 + cred2 = __task_cred(tsk);
60030 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
60031 + gr_fake_force_sig(SIGKILL, tsk);
60032 + } while_each_thread(tsk2, tsk);
60033 + read_unlock(&tasklist_lock);
60034 + } else {
60035 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
60036 + read_lock(&tasklist_lock);
60037 + read_lock(&grsec_exec_file_lock);
60038 + do_each_thread(tsk2, tsk) {
60039 + if (likely(tsk != task)) {
60040 + // if this thread has the same subject as the one that triggered
60041 + // RES_CRASH and it's the same binary, kill it
60042 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
60043 + gr_fake_force_sig(SIGKILL, tsk);
60044 + }
60045 + } while_each_thread(tsk2, tsk);
60046 + read_unlock(&grsec_exec_file_lock);
60047 + read_unlock(&tasklist_lock);
60048 + }
60049 + rcu_read_unlock();
60050 + }
60051 +
60052 + return;
60053 +}
60054 +
60055 +int
60056 +gr_check_crash_exec(const struct file *filp)
60057 +{
60058 + struct acl_subject_label *curr;
60059 +
60060 + if (unlikely(!gr_acl_is_enabled()))
60061 + return 0;
60062 +
60063 + read_lock(&gr_inode_lock);
60064 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
60065 + __get_dev(filp->f_path.dentry),
60066 + current->role);
60067 + read_unlock(&gr_inode_lock);
60068 +
60069 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
60070 + (!curr->crashes && !curr->expires))
60071 + return 0;
60072 +
60073 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60074 + time_after(curr->expires, get_seconds()))
60075 + return 1;
60076 + else if (time_before_eq(curr->expires, get_seconds())) {
60077 + curr->crashes = 0;
60078 + curr->expires = 0;
60079 + }
60080 +
60081 + return 0;
60082 +}
60083 +
60084 +void
60085 +gr_handle_alertkill(struct task_struct *task)
60086 +{
60087 + struct acl_subject_label *curracl;
60088 + __u32 curr_ip;
60089 + struct task_struct *p, *p2;
60090 +
60091 + if (unlikely(!gr_acl_is_enabled()))
60092 + return;
60093 +
60094 + curracl = task->acl;
60095 + curr_ip = task->signal->curr_ip;
60096 +
60097 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
60098 + read_lock(&tasklist_lock);
60099 + do_each_thread(p2, p) {
60100 + if (p->signal->curr_ip == curr_ip)
60101 + gr_fake_force_sig(SIGKILL, p);
60102 + } while_each_thread(p2, p);
60103 + read_unlock(&tasklist_lock);
60104 + } else if (curracl->mode & GR_KILLPROC)
60105 + gr_fake_force_sig(SIGKILL, task);
60106 +
60107 + return;
60108 +}
60109 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
60110 new file mode 100644
60111 index 0000000..9d83a69
60112 --- /dev/null
60113 +++ b/grsecurity/gracl_shm.c
60114 @@ -0,0 +1,40 @@
60115 +#include <linux/kernel.h>
60116 +#include <linux/mm.h>
60117 +#include <linux/sched.h>
60118 +#include <linux/file.h>
60119 +#include <linux/ipc.h>
60120 +#include <linux/gracl.h>
60121 +#include <linux/grsecurity.h>
60122 +#include <linux/grinternal.h>
60123 +
60124 +int
60125 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60126 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60127 +{
60128 + struct task_struct *task;
60129 +
60130 + if (!gr_acl_is_enabled())
60131 + return 1;
60132 +
60133 + rcu_read_lock();
60134 + read_lock(&tasklist_lock);
60135 +
60136 + task = find_task_by_vpid(shm_cprid);
60137 +
60138 + if (unlikely(!task))
60139 + task = find_task_by_vpid(shm_lapid);
60140 +
60141 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
60142 + (task->pid == shm_lapid)) &&
60143 + (task->acl->mode & GR_PROTSHM) &&
60144 + (task->acl != current->acl))) {
60145 + read_unlock(&tasklist_lock);
60146 + rcu_read_unlock();
60147 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
60148 + return 0;
60149 + }
60150 + read_unlock(&tasklist_lock);
60151 + rcu_read_unlock();
60152 +
60153 + return 1;
60154 +}
60155 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
60156 new file mode 100644
60157 index 0000000..bc0be01
60158 --- /dev/null
60159 +++ b/grsecurity/grsec_chdir.c
60160 @@ -0,0 +1,19 @@
60161 +#include <linux/kernel.h>
60162 +#include <linux/sched.h>
60163 +#include <linux/fs.h>
60164 +#include <linux/file.h>
60165 +#include <linux/grsecurity.h>
60166 +#include <linux/grinternal.h>
60167 +
60168 +void
60169 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
60170 +{
60171 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60172 + if ((grsec_enable_chdir && grsec_enable_group &&
60173 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
60174 + !grsec_enable_group)) {
60175 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
60176 + }
60177 +#endif
60178 + return;
60179 +}
60180 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
60181 new file mode 100644
60182 index 0000000..70fe0ae
60183 --- /dev/null
60184 +++ b/grsecurity/grsec_chroot.c
60185 @@ -0,0 +1,357 @@
60186 +#include <linux/kernel.h>
60187 +#include <linux/module.h>
60188 +#include <linux/sched.h>
60189 +#include <linux/file.h>
60190 +#include <linux/fs.h>
60191 +#include <linux/mount.h>
60192 +#include <linux/types.h>
60193 +#include "../fs/mount.h"
60194 +#include <linux/grsecurity.h>
60195 +#include <linux/grinternal.h>
60196 +
60197 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
60198 +{
60199 +#ifdef CONFIG_GRKERNSEC
60200 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
60201 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
60202 + task->gr_is_chrooted = 1;
60203 + else
60204 + task->gr_is_chrooted = 0;
60205 +
60206 + task->gr_chroot_dentry = path->dentry;
60207 +#endif
60208 + return;
60209 +}
60210 +
60211 +void gr_clear_chroot_entries(struct task_struct *task)
60212 +{
60213 +#ifdef CONFIG_GRKERNSEC
60214 + task->gr_is_chrooted = 0;
60215 + task->gr_chroot_dentry = NULL;
60216 +#endif
60217 + return;
60218 +}
60219 +
60220 +int
60221 +gr_handle_chroot_unix(const pid_t pid)
60222 +{
60223 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60224 + struct task_struct *p;
60225 +
60226 + if (unlikely(!grsec_enable_chroot_unix))
60227 + return 1;
60228 +
60229 + if (likely(!proc_is_chrooted(current)))
60230 + return 1;
60231 +
60232 + rcu_read_lock();
60233 + read_lock(&tasklist_lock);
60234 + p = find_task_by_vpid_unrestricted(pid);
60235 + if (unlikely(p && !have_same_root(current, p))) {
60236 + read_unlock(&tasklist_lock);
60237 + rcu_read_unlock();
60238 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
60239 + return 0;
60240 + }
60241 + read_unlock(&tasklist_lock);
60242 + rcu_read_unlock();
60243 +#endif
60244 + return 1;
60245 +}
60246 +
60247 +int
60248 +gr_handle_chroot_nice(void)
60249 +{
60250 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60251 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
60252 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
60253 + return -EPERM;
60254 + }
60255 +#endif
60256 + return 0;
60257 +}
60258 +
60259 +int
60260 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
60261 +{
60262 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60263 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
60264 + && proc_is_chrooted(current)) {
60265 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
60266 + return -EACCES;
60267 + }
60268 +#endif
60269 + return 0;
60270 +}
60271 +
60272 +int
60273 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
60274 +{
60275 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60276 + struct task_struct *p;
60277 + int ret = 0;
60278 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
60279 + return ret;
60280 +
60281 + read_lock(&tasklist_lock);
60282 + do_each_pid_task(pid, type, p) {
60283 + if (!have_same_root(current, p)) {
60284 + ret = 1;
60285 + goto out;
60286 + }
60287 + } while_each_pid_task(pid, type, p);
60288 +out:
60289 + read_unlock(&tasklist_lock);
60290 + return ret;
60291 +#endif
60292 + return 0;
60293 +}
60294 +
60295 +int
60296 +gr_pid_is_chrooted(struct task_struct *p)
60297 +{
60298 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60299 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
60300 + return 0;
60301 +
60302 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
60303 + !have_same_root(current, p)) {
60304 + return 1;
60305 + }
60306 +#endif
60307 + return 0;
60308 +}
60309 +
60310 +EXPORT_SYMBOL(gr_pid_is_chrooted);
60311 +
60312 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
60313 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
60314 +{
60315 + struct path path, currentroot;
60316 + int ret = 0;
60317 +
60318 + path.dentry = (struct dentry *)u_dentry;
60319 + path.mnt = (struct vfsmount *)u_mnt;
60320 + get_fs_root(current->fs, &currentroot);
60321 + if (path_is_under(&path, &currentroot))
60322 + ret = 1;
60323 + path_put(&currentroot);
60324 +
60325 + return ret;
60326 +}
60327 +#endif
60328 +
60329 +int
60330 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
60331 +{
60332 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60333 + if (!grsec_enable_chroot_fchdir)
60334 + return 1;
60335 +
60336 + if (!proc_is_chrooted(current))
60337 + return 1;
60338 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
60339 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
60340 + return 0;
60341 + }
60342 +#endif
60343 + return 1;
60344 +}
60345 +
60346 +int
60347 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60348 + const time_t shm_createtime)
60349 +{
60350 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60351 + struct task_struct *p;
60352 + time_t starttime;
60353 +
60354 + if (unlikely(!grsec_enable_chroot_shmat))
60355 + return 1;
60356 +
60357 + if (likely(!proc_is_chrooted(current)))
60358 + return 1;
60359 +
60360 + rcu_read_lock();
60361 + read_lock(&tasklist_lock);
60362 +
60363 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
60364 + starttime = p->start_time.tv_sec;
60365 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
60366 + if (have_same_root(current, p)) {
60367 + goto allow;
60368 + } else {
60369 + read_unlock(&tasklist_lock);
60370 + rcu_read_unlock();
60371 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60372 + return 0;
60373 + }
60374 + }
60375 + /* creator exited, pid reuse, fall through to next check */
60376 + }
60377 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
60378 + if (unlikely(!have_same_root(current, p))) {
60379 + read_unlock(&tasklist_lock);
60380 + rcu_read_unlock();
60381 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60382 + return 0;
60383 + }
60384 + }
60385 +
60386 +allow:
60387 + read_unlock(&tasklist_lock);
60388 + rcu_read_unlock();
60389 +#endif
60390 + return 1;
60391 +}
60392 +
60393 +void
60394 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
60395 +{
60396 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60397 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
60398 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
60399 +#endif
60400 + return;
60401 +}
60402 +
60403 +int
60404 +gr_handle_chroot_mknod(const struct dentry *dentry,
60405 + const struct vfsmount *mnt, const int mode)
60406 +{
60407 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60408 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
60409 + proc_is_chrooted(current)) {
60410 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
60411 + return -EPERM;
60412 + }
60413 +#endif
60414 + return 0;
60415 +}
60416 +
60417 +int
60418 +gr_handle_chroot_mount(const struct dentry *dentry,
60419 + const struct vfsmount *mnt, const char *dev_name)
60420 +{
60421 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60422 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
60423 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
60424 + return -EPERM;
60425 + }
60426 +#endif
60427 + return 0;
60428 +}
60429 +
60430 +int
60431 +gr_handle_chroot_pivot(void)
60432 +{
60433 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60434 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
60435 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
60436 + return -EPERM;
60437 + }
60438 +#endif
60439 + return 0;
60440 +}
60441 +
60442 +int
60443 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
60444 +{
60445 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60446 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
60447 + !gr_is_outside_chroot(dentry, mnt)) {
60448 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
60449 + return -EPERM;
60450 + }
60451 +#endif
60452 + return 0;
60453 +}
60454 +
60455 +extern const char *captab_log[];
60456 +extern int captab_log_entries;
60457 +
60458 +int
60459 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60460 +{
60461 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60462 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60463 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60464 + if (cap_raised(chroot_caps, cap)) {
60465 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
60466 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
60467 + }
60468 + return 0;
60469 + }
60470 + }
60471 +#endif
60472 + return 1;
60473 +}
60474 +
60475 +int
60476 +gr_chroot_is_capable(const int cap)
60477 +{
60478 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60479 + return gr_task_chroot_is_capable(current, current_cred(), cap);
60480 +#endif
60481 + return 1;
60482 +}
60483 +
60484 +int
60485 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
60486 +{
60487 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60488 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60489 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60490 + if (cap_raised(chroot_caps, cap)) {
60491 + return 0;
60492 + }
60493 + }
60494 +#endif
60495 + return 1;
60496 +}
60497 +
60498 +int
60499 +gr_chroot_is_capable_nolog(const int cap)
60500 +{
60501 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60502 + return gr_task_chroot_is_capable_nolog(current, cap);
60503 +#endif
60504 + return 1;
60505 +}
60506 +
60507 +int
60508 +gr_handle_chroot_sysctl(const int op)
60509 +{
60510 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60511 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
60512 + proc_is_chrooted(current))
60513 + return -EACCES;
60514 +#endif
60515 + return 0;
60516 +}
60517 +
60518 +void
60519 +gr_handle_chroot_chdir(struct path *path)
60520 +{
60521 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60522 + if (grsec_enable_chroot_chdir)
60523 + set_fs_pwd(current->fs, path);
60524 +#endif
60525 + return;
60526 +}
60527 +
60528 +int
60529 +gr_handle_chroot_chmod(const struct dentry *dentry,
60530 + const struct vfsmount *mnt, const int mode)
60531 +{
60532 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60533 + /* allow chmod +s on directories, but not files */
60534 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
60535 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
60536 + proc_is_chrooted(current)) {
60537 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
60538 + return -EPERM;
60539 + }
60540 +#endif
60541 + return 0;
60542 +}
60543 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
60544 new file mode 100644
60545 index 0000000..e6796b3
60546 --- /dev/null
60547 +++ b/grsecurity/grsec_disabled.c
60548 @@ -0,0 +1,434 @@
60549 +#include <linux/kernel.h>
60550 +#include <linux/module.h>
60551 +#include <linux/sched.h>
60552 +#include <linux/file.h>
60553 +#include <linux/fs.h>
60554 +#include <linux/kdev_t.h>
60555 +#include <linux/net.h>
60556 +#include <linux/in.h>
60557 +#include <linux/ip.h>
60558 +#include <linux/skbuff.h>
60559 +#include <linux/sysctl.h>
60560 +
60561 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60562 +void
60563 +pax_set_initial_flags(struct linux_binprm *bprm)
60564 +{
60565 + return;
60566 +}
60567 +#endif
60568 +
60569 +#ifdef CONFIG_SYSCTL
60570 +__u32
60571 +gr_handle_sysctl(const struct ctl_table * table, const int op)
60572 +{
60573 + return 0;
60574 +}
60575 +#endif
60576 +
60577 +#ifdef CONFIG_TASKSTATS
60578 +int gr_is_taskstats_denied(int pid)
60579 +{
60580 + return 0;
60581 +}
60582 +#endif
60583 +
60584 +int
60585 +gr_acl_is_enabled(void)
60586 +{
60587 + return 0;
60588 +}
60589 +
60590 +void
60591 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60592 +{
60593 + return;
60594 +}
60595 +
60596 +int
60597 +gr_handle_rawio(const struct inode *inode)
60598 +{
60599 + return 0;
60600 +}
60601 +
60602 +void
60603 +gr_acl_handle_psacct(struct task_struct *task, const long code)
60604 +{
60605 + return;
60606 +}
60607 +
60608 +int
60609 +gr_handle_ptrace(struct task_struct *task, const long request)
60610 +{
60611 + return 0;
60612 +}
60613 +
60614 +int
60615 +gr_handle_proc_ptrace(struct task_struct *task)
60616 +{
60617 + return 0;
60618 +}
60619 +
60620 +int
60621 +gr_set_acls(const int type)
60622 +{
60623 + return 0;
60624 +}
60625 +
60626 +int
60627 +gr_check_hidden_task(const struct task_struct *tsk)
60628 +{
60629 + return 0;
60630 +}
60631 +
60632 +int
60633 +gr_check_protected_task(const struct task_struct *task)
60634 +{
60635 + return 0;
60636 +}
60637 +
60638 +int
60639 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60640 +{
60641 + return 0;
60642 +}
60643 +
60644 +void
60645 +gr_copy_label(struct task_struct *tsk)
60646 +{
60647 + return;
60648 +}
60649 +
60650 +void
60651 +gr_set_pax_flags(struct task_struct *task)
60652 +{
60653 + return;
60654 +}
60655 +
60656 +int
60657 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60658 + const int unsafe_share)
60659 +{
60660 + return 0;
60661 +}
60662 +
60663 +void
60664 +gr_handle_delete(const ino_t ino, const dev_t dev)
60665 +{
60666 + return;
60667 +}
60668 +
60669 +void
60670 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60671 +{
60672 + return;
60673 +}
60674 +
60675 +void
60676 +gr_handle_crash(struct task_struct *task, const int sig)
60677 +{
60678 + return;
60679 +}
60680 +
60681 +int
60682 +gr_check_crash_exec(const struct file *filp)
60683 +{
60684 + return 0;
60685 +}
60686 +
60687 +int
60688 +gr_check_crash_uid(const uid_t uid)
60689 +{
60690 + return 0;
60691 +}
60692 +
60693 +void
60694 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60695 + struct dentry *old_dentry,
60696 + struct dentry *new_dentry,
60697 + struct vfsmount *mnt, const __u8 replace)
60698 +{
60699 + return;
60700 +}
60701 +
60702 +int
60703 +gr_search_socket(const int family, const int type, const int protocol)
60704 +{
60705 + return 1;
60706 +}
60707 +
60708 +int
60709 +gr_search_connectbind(const int mode, const struct socket *sock,
60710 + const struct sockaddr_in *addr)
60711 +{
60712 + return 0;
60713 +}
60714 +
60715 +void
60716 +gr_handle_alertkill(struct task_struct *task)
60717 +{
60718 + return;
60719 +}
60720 +
60721 +__u32
60722 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
60723 +{
60724 + return 1;
60725 +}
60726 +
60727 +__u32
60728 +gr_acl_handle_hidden_file(const struct dentry * dentry,
60729 + const struct vfsmount * mnt)
60730 +{
60731 + return 1;
60732 +}
60733 +
60734 +__u32
60735 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60736 + int acc_mode)
60737 +{
60738 + return 1;
60739 +}
60740 +
60741 +__u32
60742 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60743 +{
60744 + return 1;
60745 +}
60746 +
60747 +__u32
60748 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
60749 +{
60750 + return 1;
60751 +}
60752 +
60753 +int
60754 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
60755 + unsigned int *vm_flags)
60756 +{
60757 + return 1;
60758 +}
60759 +
60760 +__u32
60761 +gr_acl_handle_truncate(const struct dentry * dentry,
60762 + const struct vfsmount * mnt)
60763 +{
60764 + return 1;
60765 +}
60766 +
60767 +__u32
60768 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
60769 +{
60770 + return 1;
60771 +}
60772 +
60773 +__u32
60774 +gr_acl_handle_access(const struct dentry * dentry,
60775 + const struct vfsmount * mnt, const int fmode)
60776 +{
60777 + return 1;
60778 +}
60779 +
60780 +__u32
60781 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60782 + umode_t *mode)
60783 +{
60784 + return 1;
60785 +}
60786 +
60787 +__u32
60788 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60789 +{
60790 + return 1;
60791 +}
60792 +
60793 +__u32
60794 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60795 +{
60796 + return 1;
60797 +}
60798 +
60799 +void
60800 +grsecurity_init(void)
60801 +{
60802 + return;
60803 +}
60804 +
60805 +umode_t gr_acl_umask(void)
60806 +{
60807 + return 0;
60808 +}
60809 +
60810 +__u32
60811 +gr_acl_handle_mknod(const struct dentry * new_dentry,
60812 + const struct dentry * parent_dentry,
60813 + const struct vfsmount * parent_mnt,
60814 + const int mode)
60815 +{
60816 + return 1;
60817 +}
60818 +
60819 +__u32
60820 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
60821 + const struct dentry * parent_dentry,
60822 + const struct vfsmount * parent_mnt)
60823 +{
60824 + return 1;
60825 +}
60826 +
60827 +__u32
60828 +gr_acl_handle_symlink(const struct dentry * new_dentry,
60829 + const struct dentry * parent_dentry,
60830 + const struct vfsmount * parent_mnt, const struct filename *from)
60831 +{
60832 + return 1;
60833 +}
60834 +
60835 +__u32
60836 +gr_acl_handle_link(const struct dentry * new_dentry,
60837 + const struct dentry * parent_dentry,
60838 + const struct vfsmount * parent_mnt,
60839 + const struct dentry * old_dentry,
60840 + const struct vfsmount * old_mnt, const struct filename *to)
60841 +{
60842 + return 1;
60843 +}
60844 +
60845 +int
60846 +gr_acl_handle_rename(const struct dentry *new_dentry,
60847 + const struct dentry *parent_dentry,
60848 + const struct vfsmount *parent_mnt,
60849 + const struct dentry *old_dentry,
60850 + const struct inode *old_parent_inode,
60851 + const struct vfsmount *old_mnt, const struct filename *newname)
60852 +{
60853 + return 0;
60854 +}
60855 +
60856 +int
60857 +gr_acl_handle_filldir(const struct file *file, const char *name,
60858 + const int namelen, const ino_t ino)
60859 +{
60860 + return 1;
60861 +}
60862 +
60863 +int
60864 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60865 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60866 +{
60867 + return 1;
60868 +}
60869 +
60870 +int
60871 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60872 +{
60873 + return 0;
60874 +}
60875 +
60876 +int
60877 +gr_search_accept(const struct socket *sock)
60878 +{
60879 + return 0;
60880 +}
60881 +
60882 +int
60883 +gr_search_listen(const struct socket *sock)
60884 +{
60885 + return 0;
60886 +}
60887 +
60888 +int
60889 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60890 +{
60891 + return 0;
60892 +}
60893 +
60894 +__u32
60895 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60896 +{
60897 + return 1;
60898 +}
60899 +
60900 +__u32
60901 +gr_acl_handle_creat(const struct dentry * dentry,
60902 + const struct dentry * p_dentry,
60903 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60904 + const int imode)
60905 +{
60906 + return 1;
60907 +}
60908 +
60909 +void
60910 +gr_acl_handle_exit(void)
60911 +{
60912 + return;
60913 +}
60914 +
60915 +int
60916 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60917 +{
60918 + return 1;
60919 +}
60920 +
60921 +void
60922 +gr_set_role_label(const uid_t uid, const gid_t gid)
60923 +{
60924 + return;
60925 +}
60926 +
60927 +int
60928 +gr_acl_handle_procpidmem(const struct task_struct *task)
60929 +{
60930 + return 0;
60931 +}
60932 +
60933 +int
60934 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60935 +{
60936 + return 0;
60937 +}
60938 +
60939 +int
60940 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60941 +{
60942 + return 0;
60943 +}
60944 +
60945 +void
60946 +gr_set_kernel_label(struct task_struct *task)
60947 +{
60948 + return;
60949 +}
60950 +
60951 +int
60952 +gr_check_user_change(int real, int effective, int fs)
60953 +{
60954 + return 0;
60955 +}
60956 +
60957 +int
60958 +gr_check_group_change(int real, int effective, int fs)
60959 +{
60960 + return 0;
60961 +}
60962 +
60963 +int gr_acl_enable_at_secure(void)
60964 +{
60965 + return 0;
60966 +}
60967 +
60968 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60969 +{
60970 + return dentry->d_inode->i_sb->s_dev;
60971 +}
60972 +
60973 +void gr_put_exec_file(struct task_struct *task)
60974 +{
60975 + return;
60976 +}
60977 +
60978 +EXPORT_SYMBOL(gr_set_kernel_label);
60979 +#ifdef CONFIG_SECURITY
60980 +EXPORT_SYMBOL(gr_check_user_change);
60981 +EXPORT_SYMBOL(gr_check_group_change);
60982 +#endif
60983 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60984 new file mode 100644
60985 index 0000000..abfa971
60986 --- /dev/null
60987 +++ b/grsecurity/grsec_exec.c
60988 @@ -0,0 +1,174 @@
60989 +#include <linux/kernel.h>
60990 +#include <linux/sched.h>
60991 +#include <linux/file.h>
60992 +#include <linux/binfmts.h>
60993 +#include <linux/fs.h>
60994 +#include <linux/types.h>
60995 +#include <linux/grdefs.h>
60996 +#include <linux/grsecurity.h>
60997 +#include <linux/grinternal.h>
60998 +#include <linux/capability.h>
60999 +#include <linux/module.h>
61000 +
61001 +#include <asm/uaccess.h>
61002 +
61003 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61004 +static char gr_exec_arg_buf[132];
61005 +static DEFINE_MUTEX(gr_exec_arg_mutex);
61006 +#endif
61007 +
61008 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
61009 +
61010 +void
61011 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
61012 +{
61013 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61014 + char *grarg = gr_exec_arg_buf;
61015 + unsigned int i, x, execlen = 0;
61016 + char c;
61017 +
61018 + if (!((grsec_enable_execlog && grsec_enable_group &&
61019 + in_group_p(grsec_audit_gid))
61020 + || (grsec_enable_execlog && !grsec_enable_group)))
61021 + return;
61022 +
61023 + mutex_lock(&gr_exec_arg_mutex);
61024 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
61025 +
61026 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
61027 + const char __user *p;
61028 + unsigned int len;
61029 +
61030 + p = get_user_arg_ptr(argv, i);
61031 + if (IS_ERR(p))
61032 + goto log;
61033 +
61034 + len = strnlen_user(p, 128 - execlen);
61035 + if (len > 128 - execlen)
61036 + len = 128 - execlen;
61037 + else if (len > 0)
61038 + len--;
61039 + if (copy_from_user(grarg + execlen, p, len))
61040 + goto log;
61041 +
61042 + /* rewrite unprintable characters */
61043 + for (x = 0; x < len; x++) {
61044 + c = *(grarg + execlen + x);
61045 + if (c < 32 || c > 126)
61046 + *(grarg + execlen + x) = ' ';
61047 + }
61048 +
61049 + execlen += len;
61050 + *(grarg + execlen) = ' ';
61051 + *(grarg + execlen + 1) = '\0';
61052 + execlen++;
61053 + }
61054 +
61055 + log:
61056 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
61057 + bprm->file->f_path.mnt, grarg);
61058 + mutex_unlock(&gr_exec_arg_mutex);
61059 +#endif
61060 + return;
61061 +}
61062 +
61063 +#ifdef CONFIG_GRKERNSEC
61064 +extern int gr_acl_is_capable(const int cap);
61065 +extern int gr_acl_is_capable_nolog(const int cap);
61066 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61067 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
61068 +extern int gr_chroot_is_capable(const int cap);
61069 +extern int gr_chroot_is_capable_nolog(const int cap);
61070 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61071 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
61072 +#endif
61073 +
61074 +const char *captab_log[] = {
61075 + "CAP_CHOWN",
61076 + "CAP_DAC_OVERRIDE",
61077 + "CAP_DAC_READ_SEARCH",
61078 + "CAP_FOWNER",
61079 + "CAP_FSETID",
61080 + "CAP_KILL",
61081 + "CAP_SETGID",
61082 + "CAP_SETUID",
61083 + "CAP_SETPCAP",
61084 + "CAP_LINUX_IMMUTABLE",
61085 + "CAP_NET_BIND_SERVICE",
61086 + "CAP_NET_BROADCAST",
61087 + "CAP_NET_ADMIN",
61088 + "CAP_NET_RAW",
61089 + "CAP_IPC_LOCK",
61090 + "CAP_IPC_OWNER",
61091 + "CAP_SYS_MODULE",
61092 + "CAP_SYS_RAWIO",
61093 + "CAP_SYS_CHROOT",
61094 + "CAP_SYS_PTRACE",
61095 + "CAP_SYS_PACCT",
61096 + "CAP_SYS_ADMIN",
61097 + "CAP_SYS_BOOT",
61098 + "CAP_SYS_NICE",
61099 + "CAP_SYS_RESOURCE",
61100 + "CAP_SYS_TIME",
61101 + "CAP_SYS_TTY_CONFIG",
61102 + "CAP_MKNOD",
61103 + "CAP_LEASE",
61104 + "CAP_AUDIT_WRITE",
61105 + "CAP_AUDIT_CONTROL",
61106 + "CAP_SETFCAP",
61107 + "CAP_MAC_OVERRIDE",
61108 + "CAP_MAC_ADMIN",
61109 + "CAP_SYSLOG",
61110 + "CAP_WAKE_ALARM"
61111 +};
61112 +
61113 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
61114 +
61115 +int gr_is_capable(const int cap)
61116 +{
61117 +#ifdef CONFIG_GRKERNSEC
61118 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
61119 + return 1;
61120 + return 0;
61121 +#else
61122 + return 1;
61123 +#endif
61124 +}
61125 +
61126 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61127 +{
61128 +#ifdef CONFIG_GRKERNSEC
61129 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
61130 + return 1;
61131 + return 0;
61132 +#else
61133 + return 1;
61134 +#endif
61135 +}
61136 +
61137 +int gr_is_capable_nolog(const int cap)
61138 +{
61139 +#ifdef CONFIG_GRKERNSEC
61140 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
61141 + return 1;
61142 + return 0;
61143 +#else
61144 + return 1;
61145 +#endif
61146 +}
61147 +
61148 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
61149 +{
61150 +#ifdef CONFIG_GRKERNSEC
61151 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
61152 + return 1;
61153 + return 0;
61154 +#else
61155 + return 1;
61156 +#endif
61157 +}
61158 +
61159 +EXPORT_SYMBOL(gr_is_capable);
61160 +EXPORT_SYMBOL(gr_is_capable_nolog);
61161 +EXPORT_SYMBOL(gr_task_is_capable);
61162 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
61163 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
61164 new file mode 100644
61165 index 0000000..d3ee748
61166 --- /dev/null
61167 +++ b/grsecurity/grsec_fifo.c
61168 @@ -0,0 +1,24 @@
61169 +#include <linux/kernel.h>
61170 +#include <linux/sched.h>
61171 +#include <linux/fs.h>
61172 +#include <linux/file.h>
61173 +#include <linux/grinternal.h>
61174 +
61175 +int
61176 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
61177 + const struct dentry *dir, const int flag, const int acc_mode)
61178 +{
61179 +#ifdef CONFIG_GRKERNSEC_FIFO
61180 + const struct cred *cred = current_cred();
61181 +
61182 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
61183 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
61184 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
61185 + (cred->fsuid != dentry->d_inode->i_uid)) {
61186 + if (!inode_permission(dentry->d_inode, acc_mode))
61187 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
61188 + return -EACCES;
61189 + }
61190 +#endif
61191 + return 0;
61192 +}
61193 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
61194 new file mode 100644
61195 index 0000000..8ca18bf
61196 --- /dev/null
61197 +++ b/grsecurity/grsec_fork.c
61198 @@ -0,0 +1,23 @@
61199 +#include <linux/kernel.h>
61200 +#include <linux/sched.h>
61201 +#include <linux/grsecurity.h>
61202 +#include <linux/grinternal.h>
61203 +#include <linux/errno.h>
61204 +
61205 +void
61206 +gr_log_forkfail(const int retval)
61207 +{
61208 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61209 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
61210 + switch (retval) {
61211 + case -EAGAIN:
61212 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
61213 + break;
61214 + case -ENOMEM:
61215 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
61216 + break;
61217 + }
61218 + }
61219 +#endif
61220 + return;
61221 +}
61222 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
61223 new file mode 100644
61224 index 0000000..05a6015
61225 --- /dev/null
61226 +++ b/grsecurity/grsec_init.c
61227 @@ -0,0 +1,283 @@
61228 +#include <linux/kernel.h>
61229 +#include <linux/sched.h>
61230 +#include <linux/mm.h>
61231 +#include <linux/gracl.h>
61232 +#include <linux/slab.h>
61233 +#include <linux/vmalloc.h>
61234 +#include <linux/percpu.h>
61235 +#include <linux/module.h>
61236 +
61237 +int grsec_enable_ptrace_readexec;
61238 +int grsec_enable_setxid;
61239 +int grsec_enable_symlinkown;
61240 +int grsec_symlinkown_gid;
61241 +int grsec_enable_brute;
61242 +int grsec_enable_link;
61243 +int grsec_enable_dmesg;
61244 +int grsec_enable_harden_ptrace;
61245 +int grsec_enable_fifo;
61246 +int grsec_enable_execlog;
61247 +int grsec_enable_signal;
61248 +int grsec_enable_forkfail;
61249 +int grsec_enable_audit_ptrace;
61250 +int grsec_enable_time;
61251 +int grsec_enable_audit_textrel;
61252 +int grsec_enable_group;
61253 +int grsec_audit_gid;
61254 +int grsec_enable_chdir;
61255 +int grsec_enable_mount;
61256 +int grsec_enable_rofs;
61257 +int grsec_enable_chroot_findtask;
61258 +int grsec_enable_chroot_mount;
61259 +int grsec_enable_chroot_shmat;
61260 +int grsec_enable_chroot_fchdir;
61261 +int grsec_enable_chroot_double;
61262 +int grsec_enable_chroot_pivot;
61263 +int grsec_enable_chroot_chdir;
61264 +int grsec_enable_chroot_chmod;
61265 +int grsec_enable_chroot_mknod;
61266 +int grsec_enable_chroot_nice;
61267 +int grsec_enable_chroot_execlog;
61268 +int grsec_enable_chroot_caps;
61269 +int grsec_enable_chroot_sysctl;
61270 +int grsec_enable_chroot_unix;
61271 +int grsec_enable_tpe;
61272 +int grsec_tpe_gid;
61273 +int grsec_enable_blackhole;
61274 +#ifdef CONFIG_IPV6_MODULE
61275 +EXPORT_SYMBOL(grsec_enable_blackhole);
61276 +#endif
61277 +int grsec_lastack_retries;
61278 +int grsec_enable_tpe_all;
61279 +int grsec_enable_tpe_invert;
61280 +int grsec_enable_socket_all;
61281 +int grsec_socket_all_gid;
61282 +int grsec_enable_socket_client;
61283 +int grsec_socket_client_gid;
61284 +int grsec_enable_socket_server;
61285 +int grsec_socket_server_gid;
61286 +int grsec_resource_logging;
61287 +int grsec_disable_privio;
61288 +int grsec_enable_log_rwxmaps;
61289 +int grsec_lock;
61290 +
61291 +DEFINE_SPINLOCK(grsec_alert_lock);
61292 +unsigned long grsec_alert_wtime = 0;
61293 +unsigned long grsec_alert_fyet = 0;
61294 +
61295 +DEFINE_SPINLOCK(grsec_audit_lock);
61296 +
61297 +DEFINE_RWLOCK(grsec_exec_file_lock);
61298 +
61299 +char *gr_shared_page[4];
61300 +
61301 +char *gr_alert_log_fmt;
61302 +char *gr_audit_log_fmt;
61303 +char *gr_alert_log_buf;
61304 +char *gr_audit_log_buf;
61305 +
61306 +extern struct gr_arg *gr_usermode;
61307 +extern unsigned char *gr_system_salt;
61308 +extern unsigned char *gr_system_sum;
61309 +
61310 +void __init
61311 +grsecurity_init(void)
61312 +{
61313 + int j;
61314 + /* create the per-cpu shared pages */
61315 +
61316 +#ifdef CONFIG_X86
61317 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
61318 +#endif
61319 +
61320 + for (j = 0; j < 4; j++) {
61321 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
61322 + if (gr_shared_page[j] == NULL) {
61323 + panic("Unable to allocate grsecurity shared page");
61324 + return;
61325 + }
61326 + }
61327 +
61328 + /* allocate log buffers */
61329 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
61330 + if (!gr_alert_log_fmt) {
61331 + panic("Unable to allocate grsecurity alert log format buffer");
61332 + return;
61333 + }
61334 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
61335 + if (!gr_audit_log_fmt) {
61336 + panic("Unable to allocate grsecurity audit log format buffer");
61337 + return;
61338 + }
61339 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61340 + if (!gr_alert_log_buf) {
61341 + panic("Unable to allocate grsecurity alert log buffer");
61342 + return;
61343 + }
61344 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61345 + if (!gr_audit_log_buf) {
61346 + panic("Unable to allocate grsecurity audit log buffer");
61347 + return;
61348 + }
61349 +
61350 + /* allocate memory for authentication structure */
61351 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
61352 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
61353 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
61354 +
61355 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
61356 + panic("Unable to allocate grsecurity authentication structure");
61357 + return;
61358 + }
61359 +
61360 +
61361 +#ifdef CONFIG_GRKERNSEC_IO
61362 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
61363 + grsec_disable_privio = 1;
61364 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61365 + grsec_disable_privio = 1;
61366 +#else
61367 + grsec_disable_privio = 0;
61368 +#endif
61369 +#endif
61370 +
61371 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61372 + /* for backward compatibility, tpe_invert always defaults to on if
61373 + enabled in the kernel
61374 + */
61375 + grsec_enable_tpe_invert = 1;
61376 +#endif
61377 +
61378 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61379 +#ifndef CONFIG_GRKERNSEC_SYSCTL
61380 + grsec_lock = 1;
61381 +#endif
61382 +
61383 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61384 + grsec_enable_audit_textrel = 1;
61385 +#endif
61386 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61387 + grsec_enable_log_rwxmaps = 1;
61388 +#endif
61389 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61390 + grsec_enable_group = 1;
61391 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
61392 +#endif
61393 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61394 + grsec_enable_ptrace_readexec = 1;
61395 +#endif
61396 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61397 + grsec_enable_chdir = 1;
61398 +#endif
61399 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61400 + grsec_enable_harden_ptrace = 1;
61401 +#endif
61402 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61403 + grsec_enable_mount = 1;
61404 +#endif
61405 +#ifdef CONFIG_GRKERNSEC_LINK
61406 + grsec_enable_link = 1;
61407 +#endif
61408 +#ifdef CONFIG_GRKERNSEC_BRUTE
61409 + grsec_enable_brute = 1;
61410 +#endif
61411 +#ifdef CONFIG_GRKERNSEC_DMESG
61412 + grsec_enable_dmesg = 1;
61413 +#endif
61414 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61415 + grsec_enable_blackhole = 1;
61416 + grsec_lastack_retries = 4;
61417 +#endif
61418 +#ifdef CONFIG_GRKERNSEC_FIFO
61419 + grsec_enable_fifo = 1;
61420 +#endif
61421 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61422 + grsec_enable_execlog = 1;
61423 +#endif
61424 +#ifdef CONFIG_GRKERNSEC_SETXID
61425 + grsec_enable_setxid = 1;
61426 +#endif
61427 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61428 + grsec_enable_signal = 1;
61429 +#endif
61430 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61431 + grsec_enable_forkfail = 1;
61432 +#endif
61433 +#ifdef CONFIG_GRKERNSEC_TIME
61434 + grsec_enable_time = 1;
61435 +#endif
61436 +#ifdef CONFIG_GRKERNSEC_RESLOG
61437 + grsec_resource_logging = 1;
61438 +#endif
61439 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61440 + grsec_enable_chroot_findtask = 1;
61441 +#endif
61442 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61443 + grsec_enable_chroot_unix = 1;
61444 +#endif
61445 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61446 + grsec_enable_chroot_mount = 1;
61447 +#endif
61448 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61449 + grsec_enable_chroot_fchdir = 1;
61450 +#endif
61451 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61452 + grsec_enable_chroot_shmat = 1;
61453 +#endif
61454 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61455 + grsec_enable_audit_ptrace = 1;
61456 +#endif
61457 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61458 + grsec_enable_chroot_double = 1;
61459 +#endif
61460 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61461 + grsec_enable_chroot_pivot = 1;
61462 +#endif
61463 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61464 + grsec_enable_chroot_chdir = 1;
61465 +#endif
61466 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61467 + grsec_enable_chroot_chmod = 1;
61468 +#endif
61469 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61470 + grsec_enable_chroot_mknod = 1;
61471 +#endif
61472 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61473 + grsec_enable_chroot_nice = 1;
61474 +#endif
61475 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61476 + grsec_enable_chroot_execlog = 1;
61477 +#endif
61478 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61479 + grsec_enable_chroot_caps = 1;
61480 +#endif
61481 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61482 + grsec_enable_chroot_sysctl = 1;
61483 +#endif
61484 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61485 + grsec_enable_symlinkown = 1;
61486 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
61487 +#endif
61488 +#ifdef CONFIG_GRKERNSEC_TPE
61489 + grsec_enable_tpe = 1;
61490 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
61491 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
61492 + grsec_enable_tpe_all = 1;
61493 +#endif
61494 +#endif
61495 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61496 + grsec_enable_socket_all = 1;
61497 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
61498 +#endif
61499 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61500 + grsec_enable_socket_client = 1;
61501 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
61502 +#endif
61503 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61504 + grsec_enable_socket_server = 1;
61505 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
61506 +#endif
61507 +#endif
61508 +
61509 + return;
61510 +}
61511 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
61512 new file mode 100644
61513 index 0000000..6095407
61514 --- /dev/null
61515 +++ b/grsecurity/grsec_link.c
61516 @@ -0,0 +1,58 @@
61517 +#include <linux/kernel.h>
61518 +#include <linux/sched.h>
61519 +#include <linux/fs.h>
61520 +#include <linux/file.h>
61521 +#include <linux/grinternal.h>
61522 +
61523 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
61524 +{
61525 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61526 + const struct inode *link_inode = link->dentry->d_inode;
61527 +
61528 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
61529 + /* ignore root-owned links, e.g. /proc/self */
61530 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
61531 + !uid_eq(link_inode->i_uid, target->i_uid)) {
61532 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
61533 + return 1;
61534 + }
61535 +#endif
61536 + return 0;
61537 +}
61538 +
61539 +int
61540 +gr_handle_follow_link(const struct inode *parent,
61541 + const struct inode *inode,
61542 + const struct dentry *dentry, const struct vfsmount *mnt)
61543 +{
61544 +#ifdef CONFIG_GRKERNSEC_LINK
61545 + const struct cred *cred = current_cred();
61546 +
61547 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
61548 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
61549 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
61550 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
61551 + return -EACCES;
61552 + }
61553 +#endif
61554 + return 0;
61555 +}
61556 +
61557 +int
61558 +gr_handle_hardlink(const struct dentry *dentry,
61559 + const struct vfsmount *mnt,
61560 + struct inode *inode, const int mode, const struct filename *to)
61561 +{
61562 +#ifdef CONFIG_GRKERNSEC_LINK
61563 + const struct cred *cred = current_cred();
61564 +
61565 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
61566 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
61567 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
61568 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61569 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
61570 + return -EPERM;
61571 + }
61572 +#endif
61573 + return 0;
61574 +}
61575 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
61576 new file mode 100644
61577 index 0000000..7bd6c2b
61578 --- /dev/null
61579 +++ b/grsecurity/grsec_log.c
61580 @@ -0,0 +1,329 @@
61581 +#include <linux/kernel.h>
61582 +#include <linux/sched.h>
61583 +#include <linux/file.h>
61584 +#include <linux/tty.h>
61585 +#include <linux/fs.h>
61586 +#include <linux/grinternal.h>
61587 +
61588 +#ifdef CONFIG_TREE_PREEMPT_RCU
61589 +#define DISABLE_PREEMPT() preempt_disable()
61590 +#define ENABLE_PREEMPT() preempt_enable()
61591 +#else
61592 +#define DISABLE_PREEMPT()
61593 +#define ENABLE_PREEMPT()
61594 +#endif
61595 +
61596 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
61597 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
61598 +
61599 +#define BEGIN_LOCKS(x) \
61600 + DISABLE_PREEMPT(); \
61601 + rcu_read_lock(); \
61602 + read_lock(&tasklist_lock); \
61603 + read_lock(&grsec_exec_file_lock); \
61604 + if (x != GR_DO_AUDIT) \
61605 + spin_lock(&grsec_alert_lock); \
61606 + else \
61607 + spin_lock(&grsec_audit_lock)
61608 +
61609 +#define END_LOCKS(x) \
61610 + if (x != GR_DO_AUDIT) \
61611 + spin_unlock(&grsec_alert_lock); \
61612 + else \
61613 + spin_unlock(&grsec_audit_lock); \
61614 + read_unlock(&grsec_exec_file_lock); \
61615 + read_unlock(&tasklist_lock); \
61616 + rcu_read_unlock(); \
61617 + ENABLE_PREEMPT(); \
61618 + if (x == GR_DONT_AUDIT) \
61619 + gr_handle_alertkill(current)
61620 +
61621 +enum {
61622 + FLOODING,
61623 + NO_FLOODING
61624 +};
61625 +
61626 +extern char *gr_alert_log_fmt;
61627 +extern char *gr_audit_log_fmt;
61628 +extern char *gr_alert_log_buf;
61629 +extern char *gr_audit_log_buf;
61630 +
61631 +static int gr_log_start(int audit)
61632 +{
61633 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
61634 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
61635 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61636 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
61637 + unsigned long curr_secs = get_seconds();
61638 +
61639 + if (audit == GR_DO_AUDIT)
61640 + goto set_fmt;
61641 +
61642 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
61643 + grsec_alert_wtime = curr_secs;
61644 + grsec_alert_fyet = 0;
61645 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
61646 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
61647 + grsec_alert_fyet++;
61648 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
61649 + grsec_alert_wtime = curr_secs;
61650 + grsec_alert_fyet++;
61651 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
61652 + return FLOODING;
61653 + }
61654 + else return FLOODING;
61655 +
61656 +set_fmt:
61657 +#endif
61658 + memset(buf, 0, PAGE_SIZE);
61659 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
61660 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
61661 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61662 + } else if (current->signal->curr_ip) {
61663 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
61664 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
61665 + } else if (gr_acl_is_enabled()) {
61666 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
61667 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61668 + } else {
61669 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
61670 + strcpy(buf, fmt);
61671 + }
61672 +
61673 + return NO_FLOODING;
61674 +}
61675 +
61676 +static void gr_log_middle(int audit, const char *msg, va_list ap)
61677 + __attribute__ ((format (printf, 2, 0)));
61678 +
61679 +static void gr_log_middle(int audit, const char *msg, va_list ap)
61680 +{
61681 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61682 + unsigned int len = strlen(buf);
61683 +
61684 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61685 +
61686 + return;
61687 +}
61688 +
61689 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
61690 + __attribute__ ((format (printf, 2, 3)));
61691 +
61692 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
61693 +{
61694 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61695 + unsigned int len = strlen(buf);
61696 + va_list ap;
61697 +
61698 + va_start(ap, msg);
61699 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61700 + va_end(ap);
61701 +
61702 + return;
61703 +}
61704 +
61705 +static void gr_log_end(int audit, int append_default)
61706 +{
61707 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61708 + if (append_default) {
61709 + struct task_struct *task = current;
61710 + struct task_struct *parent = task->real_parent;
61711 + const struct cred *cred = __task_cred(task);
61712 + const struct cred *pcred = __task_cred(parent);
61713 + unsigned int len = strlen(buf);
61714 +
61715 + 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));
61716 + }
61717 +
61718 + printk("%s\n", buf);
61719 +
61720 + return;
61721 +}
61722 +
61723 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
61724 +{
61725 + int logtype;
61726 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
61727 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
61728 + void *voidptr = NULL;
61729 + int num1 = 0, num2 = 0;
61730 + unsigned long ulong1 = 0, ulong2 = 0;
61731 + struct dentry *dentry = NULL;
61732 + struct vfsmount *mnt = NULL;
61733 + struct file *file = NULL;
61734 + struct task_struct *task = NULL;
61735 + const struct cred *cred, *pcred;
61736 + va_list ap;
61737 +
61738 + BEGIN_LOCKS(audit);
61739 + logtype = gr_log_start(audit);
61740 + if (logtype == FLOODING) {
61741 + END_LOCKS(audit);
61742 + return;
61743 + }
61744 + va_start(ap, argtypes);
61745 + switch (argtypes) {
61746 + case GR_TTYSNIFF:
61747 + task = va_arg(ap, struct task_struct *);
61748 + 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));
61749 + break;
61750 + case GR_SYSCTL_HIDDEN:
61751 + str1 = va_arg(ap, char *);
61752 + gr_log_middle_varargs(audit, msg, result, str1);
61753 + break;
61754 + case GR_RBAC:
61755 + dentry = va_arg(ap, struct dentry *);
61756 + mnt = va_arg(ap, struct vfsmount *);
61757 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
61758 + break;
61759 + case GR_RBAC_STR:
61760 + dentry = va_arg(ap, struct dentry *);
61761 + mnt = va_arg(ap, struct vfsmount *);
61762 + str1 = va_arg(ap, char *);
61763 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
61764 + break;
61765 + case GR_STR_RBAC:
61766 + str1 = va_arg(ap, char *);
61767 + dentry = va_arg(ap, struct dentry *);
61768 + mnt = va_arg(ap, struct vfsmount *);
61769 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
61770 + break;
61771 + case GR_RBAC_MODE2:
61772 + dentry = va_arg(ap, struct dentry *);
61773 + mnt = va_arg(ap, struct vfsmount *);
61774 + str1 = va_arg(ap, char *);
61775 + str2 = va_arg(ap, char *);
61776 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61777 + break;
61778 + case GR_RBAC_MODE3:
61779 + dentry = va_arg(ap, struct dentry *);
61780 + mnt = va_arg(ap, struct vfsmount *);
61781 + str1 = va_arg(ap, char *);
61782 + str2 = va_arg(ap, char *);
61783 + str3 = va_arg(ap, char *);
61784 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61785 + break;
61786 + case GR_FILENAME:
61787 + dentry = va_arg(ap, struct dentry *);
61788 + mnt = va_arg(ap, struct vfsmount *);
61789 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61790 + break;
61791 + case GR_STR_FILENAME:
61792 + str1 = va_arg(ap, char *);
61793 + dentry = va_arg(ap, struct dentry *);
61794 + mnt = va_arg(ap, struct vfsmount *);
61795 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61796 + break;
61797 + case GR_FILENAME_STR:
61798 + dentry = va_arg(ap, struct dentry *);
61799 + mnt = va_arg(ap, struct vfsmount *);
61800 + str1 = va_arg(ap, char *);
61801 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61802 + break;
61803 + case GR_FILENAME_TWO_INT:
61804 + dentry = va_arg(ap, struct dentry *);
61805 + mnt = va_arg(ap, struct vfsmount *);
61806 + num1 = va_arg(ap, int);
61807 + num2 = va_arg(ap, int);
61808 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61809 + break;
61810 + case GR_FILENAME_TWO_INT_STR:
61811 + dentry = va_arg(ap, struct dentry *);
61812 + mnt = va_arg(ap, struct vfsmount *);
61813 + num1 = va_arg(ap, int);
61814 + num2 = va_arg(ap, int);
61815 + str1 = va_arg(ap, char *);
61816 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61817 + break;
61818 + case GR_TEXTREL:
61819 + file = va_arg(ap, struct file *);
61820 + ulong1 = va_arg(ap, unsigned long);
61821 + ulong2 = va_arg(ap, unsigned long);
61822 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61823 + break;
61824 + case GR_PTRACE:
61825 + task = va_arg(ap, struct task_struct *);
61826 + 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));
61827 + break;
61828 + case GR_RESOURCE:
61829 + task = va_arg(ap, struct task_struct *);
61830 + cred = __task_cred(task);
61831 + pcred = __task_cred(task->real_parent);
61832 + ulong1 = va_arg(ap, unsigned long);
61833 + str1 = va_arg(ap, char *);
61834 + ulong2 = va_arg(ap, unsigned long);
61835 + 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));
61836 + break;
61837 + case GR_CAP:
61838 + task = va_arg(ap, struct task_struct *);
61839 + cred = __task_cred(task);
61840 + pcred = __task_cred(task->real_parent);
61841 + str1 = va_arg(ap, char *);
61842 + 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));
61843 + break;
61844 + case GR_SIG:
61845 + str1 = va_arg(ap, char *);
61846 + voidptr = va_arg(ap, void *);
61847 + gr_log_middle_varargs(audit, msg, str1, voidptr);
61848 + break;
61849 + case GR_SIG2:
61850 + task = va_arg(ap, struct task_struct *);
61851 + cred = __task_cred(task);
61852 + pcred = __task_cred(task->real_parent);
61853 + num1 = va_arg(ap, int);
61854 + 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));
61855 + break;
61856 + case GR_CRASH1:
61857 + task = va_arg(ap, struct task_struct *);
61858 + cred = __task_cred(task);
61859 + pcred = __task_cred(task->real_parent);
61860 + ulong1 = va_arg(ap, unsigned long);
61861 + 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);
61862 + break;
61863 + case GR_CRASH2:
61864 + task = va_arg(ap, struct task_struct *);
61865 + cred = __task_cred(task);
61866 + pcred = __task_cred(task->real_parent);
61867 + ulong1 = va_arg(ap, unsigned long);
61868 + 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);
61869 + break;
61870 + case GR_RWXMAP:
61871 + file = va_arg(ap, struct file *);
61872 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61873 + break;
61874 + case GR_PSACCT:
61875 + {
61876 + unsigned int wday, cday;
61877 + __u8 whr, chr;
61878 + __u8 wmin, cmin;
61879 + __u8 wsec, csec;
61880 + char cur_tty[64] = { 0 };
61881 + char parent_tty[64] = { 0 };
61882 +
61883 + task = va_arg(ap, struct task_struct *);
61884 + wday = va_arg(ap, unsigned int);
61885 + cday = va_arg(ap, unsigned int);
61886 + whr = va_arg(ap, int);
61887 + chr = va_arg(ap, int);
61888 + wmin = va_arg(ap, int);
61889 + cmin = va_arg(ap, int);
61890 + wsec = va_arg(ap, int);
61891 + csec = va_arg(ap, int);
61892 + ulong1 = va_arg(ap, unsigned long);
61893 + cred = __task_cred(task);
61894 + pcred = __task_cred(task->real_parent);
61895 +
61896 + 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));
61897 + }
61898 + break;
61899 + default:
61900 + gr_log_middle(audit, msg, ap);
61901 + }
61902 + va_end(ap);
61903 + // these don't need DEFAULTSECARGS printed on the end
61904 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61905 + gr_log_end(audit, 0);
61906 + else
61907 + gr_log_end(audit, 1);
61908 + END_LOCKS(audit);
61909 +}
61910 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61911 new file mode 100644
61912 index 0000000..f536303
61913 --- /dev/null
61914 +++ b/grsecurity/grsec_mem.c
61915 @@ -0,0 +1,40 @@
61916 +#include <linux/kernel.h>
61917 +#include <linux/sched.h>
61918 +#include <linux/mm.h>
61919 +#include <linux/mman.h>
61920 +#include <linux/grinternal.h>
61921 +
61922 +void
61923 +gr_handle_ioperm(void)
61924 +{
61925 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61926 + return;
61927 +}
61928 +
61929 +void
61930 +gr_handle_iopl(void)
61931 +{
61932 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61933 + return;
61934 +}
61935 +
61936 +void
61937 +gr_handle_mem_readwrite(u64 from, u64 to)
61938 +{
61939 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61940 + return;
61941 +}
61942 +
61943 +void
61944 +gr_handle_vm86(void)
61945 +{
61946 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61947 + return;
61948 +}
61949 +
61950 +void
61951 +gr_log_badprocpid(const char *entry)
61952 +{
61953 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61954 + return;
61955 +}
61956 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61957 new file mode 100644
61958 index 0000000..2131422
61959 --- /dev/null
61960 +++ b/grsecurity/grsec_mount.c
61961 @@ -0,0 +1,62 @@
61962 +#include <linux/kernel.h>
61963 +#include <linux/sched.h>
61964 +#include <linux/mount.h>
61965 +#include <linux/grsecurity.h>
61966 +#include <linux/grinternal.h>
61967 +
61968 +void
61969 +gr_log_remount(const char *devname, const int retval)
61970 +{
61971 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61972 + if (grsec_enable_mount && (retval >= 0))
61973 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61974 +#endif
61975 + return;
61976 +}
61977 +
61978 +void
61979 +gr_log_unmount(const char *devname, const int retval)
61980 +{
61981 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61982 + if (grsec_enable_mount && (retval >= 0))
61983 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61984 +#endif
61985 + return;
61986 +}
61987 +
61988 +void
61989 +gr_log_mount(const char *from, const char *to, const int retval)
61990 +{
61991 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61992 + if (grsec_enable_mount && (retval >= 0))
61993 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61994 +#endif
61995 + return;
61996 +}
61997 +
61998 +int
61999 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
62000 +{
62001 +#ifdef CONFIG_GRKERNSEC_ROFS
62002 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
62003 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
62004 + return -EPERM;
62005 + } else
62006 + return 0;
62007 +#endif
62008 + return 0;
62009 +}
62010 +
62011 +int
62012 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
62013 +{
62014 +#ifdef CONFIG_GRKERNSEC_ROFS
62015 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
62016 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
62017 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
62018 + return -EPERM;
62019 + } else
62020 + return 0;
62021 +#endif
62022 + return 0;
62023 +}
62024 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
62025 new file mode 100644
62026 index 0000000..a3b12a0
62027 --- /dev/null
62028 +++ b/grsecurity/grsec_pax.c
62029 @@ -0,0 +1,36 @@
62030 +#include <linux/kernel.h>
62031 +#include <linux/sched.h>
62032 +#include <linux/mm.h>
62033 +#include <linux/file.h>
62034 +#include <linux/grinternal.h>
62035 +#include <linux/grsecurity.h>
62036 +
62037 +void
62038 +gr_log_textrel(struct vm_area_struct * vma)
62039 +{
62040 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62041 + if (grsec_enable_audit_textrel)
62042 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
62043 +#endif
62044 + return;
62045 +}
62046 +
62047 +void
62048 +gr_log_rwxmmap(struct file *file)
62049 +{
62050 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62051 + if (grsec_enable_log_rwxmaps)
62052 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
62053 +#endif
62054 + return;
62055 +}
62056 +
62057 +void
62058 +gr_log_rwxmprotect(struct file *file)
62059 +{
62060 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62061 + if (grsec_enable_log_rwxmaps)
62062 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
62063 +#endif
62064 + return;
62065 +}
62066 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
62067 new file mode 100644
62068 index 0000000..f7f29aa
62069 --- /dev/null
62070 +++ b/grsecurity/grsec_ptrace.c
62071 @@ -0,0 +1,30 @@
62072 +#include <linux/kernel.h>
62073 +#include <linux/sched.h>
62074 +#include <linux/grinternal.h>
62075 +#include <linux/security.h>
62076 +
62077 +void
62078 +gr_audit_ptrace(struct task_struct *task)
62079 +{
62080 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62081 + if (grsec_enable_audit_ptrace)
62082 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
62083 +#endif
62084 + return;
62085 +}
62086 +
62087 +int
62088 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
62089 +{
62090 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62091 + const struct dentry *dentry = file->f_path.dentry;
62092 + const struct vfsmount *mnt = file->f_path.mnt;
62093 +
62094 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
62095 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
62096 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
62097 + return -EACCES;
62098 + }
62099 +#endif
62100 + return 0;
62101 +}
62102 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
62103 new file mode 100644
62104 index 0000000..5c00416
62105 --- /dev/null
62106 +++ b/grsecurity/grsec_sig.c
62107 @@ -0,0 +1,222 @@
62108 +#include <linux/kernel.h>
62109 +#include <linux/sched.h>
62110 +#include <linux/delay.h>
62111 +#include <linux/grsecurity.h>
62112 +#include <linux/grinternal.h>
62113 +#include <linux/hardirq.h>
62114 +
62115 +char *signames[] = {
62116 + [SIGSEGV] = "Segmentation fault",
62117 + [SIGILL] = "Illegal instruction",
62118 + [SIGABRT] = "Abort",
62119 + [SIGBUS] = "Invalid alignment/Bus error"
62120 +};
62121 +
62122 +void
62123 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
62124 +{
62125 +#ifdef CONFIG_GRKERNSEC_SIGNAL
62126 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
62127 + (sig == SIGABRT) || (sig == SIGBUS))) {
62128 + if (t->pid == current->pid) {
62129 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
62130 + } else {
62131 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
62132 + }
62133 + }
62134 +#endif
62135 + return;
62136 +}
62137 +
62138 +int
62139 +gr_handle_signal(const struct task_struct *p, const int sig)
62140 +{
62141 +#ifdef CONFIG_GRKERNSEC
62142 + /* ignore the 0 signal for protected task checks */
62143 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
62144 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
62145 + return -EPERM;
62146 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
62147 + return -EPERM;
62148 + }
62149 +#endif
62150 + return 0;
62151 +}
62152 +
62153 +#ifdef CONFIG_GRKERNSEC
62154 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
62155 +
62156 +int gr_fake_force_sig(int sig, struct task_struct *t)
62157 +{
62158 + unsigned long int flags;
62159 + int ret, blocked, ignored;
62160 + struct k_sigaction *action;
62161 +
62162 + spin_lock_irqsave(&t->sighand->siglock, flags);
62163 + action = &t->sighand->action[sig-1];
62164 + ignored = action->sa.sa_handler == SIG_IGN;
62165 + blocked = sigismember(&t->blocked, sig);
62166 + if (blocked || ignored) {
62167 + action->sa.sa_handler = SIG_DFL;
62168 + if (blocked) {
62169 + sigdelset(&t->blocked, sig);
62170 + recalc_sigpending_and_wake(t);
62171 + }
62172 + }
62173 + if (action->sa.sa_handler == SIG_DFL)
62174 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
62175 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
62176 +
62177 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
62178 +
62179 + return ret;
62180 +}
62181 +#endif
62182 +
62183 +#ifdef CONFIG_GRKERNSEC_BRUTE
62184 +#define GR_USER_BAN_TIME (15 * 60)
62185 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
62186 +
62187 +static int __get_dumpable(unsigned long mm_flags)
62188 +{
62189 + int ret;
62190 +
62191 + ret = mm_flags & MMF_DUMPABLE_MASK;
62192 + return (ret >= 2) ? 2 : ret;
62193 +}
62194 +#endif
62195 +
62196 +void gr_handle_brute_attach(unsigned long mm_flags)
62197 +{
62198 +#ifdef CONFIG_GRKERNSEC_BRUTE
62199 + struct task_struct *p = current;
62200 + kuid_t uid = GLOBAL_ROOT_UID;
62201 + int daemon = 0;
62202 +
62203 + if (!grsec_enable_brute)
62204 + return;
62205 +
62206 + rcu_read_lock();
62207 + read_lock(&tasklist_lock);
62208 + read_lock(&grsec_exec_file_lock);
62209 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
62210 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
62211 + p->real_parent->brute = 1;
62212 + daemon = 1;
62213 + } else {
62214 + const struct cred *cred = __task_cred(p), *cred2;
62215 + struct task_struct *tsk, *tsk2;
62216 +
62217 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
62218 + struct user_struct *user;
62219 +
62220 + uid = cred->uid;
62221 +
62222 + /* this is put upon execution past expiration */
62223 + user = find_user(uid);
62224 + if (user == NULL)
62225 + goto unlock;
62226 + user->banned = 1;
62227 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
62228 + if (user->ban_expires == ~0UL)
62229 + user->ban_expires--;
62230 +
62231 + do_each_thread(tsk2, tsk) {
62232 + cred2 = __task_cred(tsk);
62233 + if (tsk != p && uid_eq(cred2->uid, uid))
62234 + gr_fake_force_sig(SIGKILL, tsk);
62235 + } while_each_thread(tsk2, tsk);
62236 + }
62237 + }
62238 +unlock:
62239 + read_unlock(&grsec_exec_file_lock);
62240 + read_unlock(&tasklist_lock);
62241 + rcu_read_unlock();
62242 +
62243 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
62244 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
62245 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
62246 + else if (daemon)
62247 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
62248 +
62249 +#endif
62250 + return;
62251 +}
62252 +
62253 +void gr_handle_brute_check(void)
62254 +{
62255 +#ifdef CONFIG_GRKERNSEC_BRUTE
62256 + struct task_struct *p = current;
62257 +
62258 + if (unlikely(p->brute)) {
62259 + if (!grsec_enable_brute)
62260 + p->brute = 0;
62261 + else if (time_before(get_seconds(), p->brute_expires))
62262 + msleep(30 * 1000);
62263 + }
62264 +#endif
62265 + return;
62266 +}
62267 +
62268 +void gr_handle_kernel_exploit(void)
62269 +{
62270 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
62271 + const struct cred *cred;
62272 + struct task_struct *tsk, *tsk2;
62273 + struct user_struct *user;
62274 + kuid_t uid;
62275 +
62276 + if (in_irq() || in_serving_softirq() || in_nmi())
62277 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
62278 +
62279 + uid = current_uid();
62280 +
62281 + if (uid_eq(uid, GLOBAL_ROOT_UID))
62282 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
62283 + else {
62284 + /* kill all the processes of this user, hold a reference
62285 + to their creds struct, and prevent them from creating
62286 + another process until system reset
62287 + */
62288 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
62289 + from_kuid_munged(&init_user_ns, uid));
62290 + /* we intentionally leak this ref */
62291 + user = get_uid(current->cred->user);
62292 + if (user) {
62293 + user->banned = 1;
62294 + user->ban_expires = ~0UL;
62295 + }
62296 +
62297 + read_lock(&tasklist_lock);
62298 + do_each_thread(tsk2, tsk) {
62299 + cred = __task_cred(tsk);
62300 + if (uid_eq(cred->uid, uid))
62301 + gr_fake_force_sig(SIGKILL, tsk);
62302 + } while_each_thread(tsk2, tsk);
62303 + read_unlock(&tasklist_lock);
62304 + }
62305 +#endif
62306 +}
62307 +
62308 +int __gr_process_user_ban(struct user_struct *user)
62309 +{
62310 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62311 + if (unlikely(user->banned)) {
62312 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
62313 + user->banned = 0;
62314 + user->ban_expires = 0;
62315 + free_uid(user);
62316 + } else
62317 + return -EPERM;
62318 + }
62319 +#endif
62320 + return 0;
62321 +}
62322 +
62323 +int gr_process_user_ban(void)
62324 +{
62325 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62326 + return __gr_process_user_ban(current->cred->user);
62327 +#endif
62328 + return 0;
62329 +}
62330 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
62331 new file mode 100644
62332 index 0000000..4030d57
62333 --- /dev/null
62334 +++ b/grsecurity/grsec_sock.c
62335 @@ -0,0 +1,244 @@
62336 +#include <linux/kernel.h>
62337 +#include <linux/module.h>
62338 +#include <linux/sched.h>
62339 +#include <linux/file.h>
62340 +#include <linux/net.h>
62341 +#include <linux/in.h>
62342 +#include <linux/ip.h>
62343 +#include <net/sock.h>
62344 +#include <net/inet_sock.h>
62345 +#include <linux/grsecurity.h>
62346 +#include <linux/grinternal.h>
62347 +#include <linux/gracl.h>
62348 +
62349 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
62350 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
62351 +
62352 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
62353 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
62354 +
62355 +#ifdef CONFIG_UNIX_MODULE
62356 +EXPORT_SYMBOL(gr_acl_handle_unix);
62357 +EXPORT_SYMBOL(gr_acl_handle_mknod);
62358 +EXPORT_SYMBOL(gr_handle_chroot_unix);
62359 +EXPORT_SYMBOL(gr_handle_create);
62360 +#endif
62361 +
62362 +#ifdef CONFIG_GRKERNSEC
62363 +#define gr_conn_table_size 32749
62364 +struct conn_table_entry {
62365 + struct conn_table_entry *next;
62366 + struct signal_struct *sig;
62367 +};
62368 +
62369 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
62370 +DEFINE_SPINLOCK(gr_conn_table_lock);
62371 +
62372 +extern const char * gr_socktype_to_name(unsigned char type);
62373 +extern const char * gr_proto_to_name(unsigned char proto);
62374 +extern const char * gr_sockfamily_to_name(unsigned char family);
62375 +
62376 +static __inline__ int
62377 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
62378 +{
62379 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
62380 +}
62381 +
62382 +static __inline__ int
62383 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
62384 + __u16 sport, __u16 dport)
62385 +{
62386 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
62387 + sig->gr_sport == sport && sig->gr_dport == dport))
62388 + return 1;
62389 + else
62390 + return 0;
62391 +}
62392 +
62393 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
62394 +{
62395 + struct conn_table_entry **match;
62396 + unsigned int index;
62397 +
62398 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62399 + sig->gr_sport, sig->gr_dport,
62400 + gr_conn_table_size);
62401 +
62402 + newent->sig = sig;
62403 +
62404 + match = &gr_conn_table[index];
62405 + newent->next = *match;
62406 + *match = newent;
62407 +
62408 + return;
62409 +}
62410 +
62411 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
62412 +{
62413 + struct conn_table_entry *match, *last = NULL;
62414 + unsigned int index;
62415 +
62416 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62417 + sig->gr_sport, sig->gr_dport,
62418 + gr_conn_table_size);
62419 +
62420 + match = gr_conn_table[index];
62421 + while (match && !conn_match(match->sig,
62422 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
62423 + sig->gr_dport)) {
62424 + last = match;
62425 + match = match->next;
62426 + }
62427 +
62428 + if (match) {
62429 + if (last)
62430 + last->next = match->next;
62431 + else
62432 + gr_conn_table[index] = NULL;
62433 + kfree(match);
62434 + }
62435 +
62436 + return;
62437 +}
62438 +
62439 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
62440 + __u16 sport, __u16 dport)
62441 +{
62442 + struct conn_table_entry *match;
62443 + unsigned int index;
62444 +
62445 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
62446 +
62447 + match = gr_conn_table[index];
62448 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
62449 + match = match->next;
62450 +
62451 + if (match)
62452 + return match->sig;
62453 + else
62454 + return NULL;
62455 +}
62456 +
62457 +#endif
62458 +
62459 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
62460 +{
62461 +#ifdef CONFIG_GRKERNSEC
62462 + struct signal_struct *sig = task->signal;
62463 + struct conn_table_entry *newent;
62464 +
62465 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
62466 + if (newent == NULL)
62467 + return;
62468 + /* no bh lock needed since we are called with bh disabled */
62469 + spin_lock(&gr_conn_table_lock);
62470 + gr_del_task_from_ip_table_nolock(sig);
62471 + sig->gr_saddr = inet->inet_rcv_saddr;
62472 + sig->gr_daddr = inet->inet_daddr;
62473 + sig->gr_sport = inet->inet_sport;
62474 + sig->gr_dport = inet->inet_dport;
62475 + gr_add_to_task_ip_table_nolock(sig, newent);
62476 + spin_unlock(&gr_conn_table_lock);
62477 +#endif
62478 + return;
62479 +}
62480 +
62481 +void gr_del_task_from_ip_table(struct task_struct *task)
62482 +{
62483 +#ifdef CONFIG_GRKERNSEC
62484 + spin_lock_bh(&gr_conn_table_lock);
62485 + gr_del_task_from_ip_table_nolock(task->signal);
62486 + spin_unlock_bh(&gr_conn_table_lock);
62487 +#endif
62488 + return;
62489 +}
62490 +
62491 +void
62492 +gr_attach_curr_ip(const struct sock *sk)
62493 +{
62494 +#ifdef CONFIG_GRKERNSEC
62495 + struct signal_struct *p, *set;
62496 + const struct inet_sock *inet = inet_sk(sk);
62497 +
62498 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
62499 + return;
62500 +
62501 + set = current->signal;
62502 +
62503 + spin_lock_bh(&gr_conn_table_lock);
62504 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
62505 + inet->inet_dport, inet->inet_sport);
62506 + if (unlikely(p != NULL)) {
62507 + set->curr_ip = p->curr_ip;
62508 + set->used_accept = 1;
62509 + gr_del_task_from_ip_table_nolock(p);
62510 + spin_unlock_bh(&gr_conn_table_lock);
62511 + return;
62512 + }
62513 + spin_unlock_bh(&gr_conn_table_lock);
62514 +
62515 + set->curr_ip = inet->inet_daddr;
62516 + set->used_accept = 1;
62517 +#endif
62518 + return;
62519 +}
62520 +
62521 +int
62522 +gr_handle_sock_all(const int family, const int type, const int protocol)
62523 +{
62524 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62525 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
62526 + (family != AF_UNIX)) {
62527 + if (family == AF_INET)
62528 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
62529 + else
62530 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
62531 + return -EACCES;
62532 + }
62533 +#endif
62534 + return 0;
62535 +}
62536 +
62537 +int
62538 +gr_handle_sock_server(const struct sockaddr *sck)
62539 +{
62540 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62541 + if (grsec_enable_socket_server &&
62542 + in_group_p(grsec_socket_server_gid) &&
62543 + sck && (sck->sa_family != AF_UNIX) &&
62544 + (sck->sa_family != AF_LOCAL)) {
62545 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62546 + return -EACCES;
62547 + }
62548 +#endif
62549 + return 0;
62550 +}
62551 +
62552 +int
62553 +gr_handle_sock_server_other(const struct sock *sck)
62554 +{
62555 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62556 + if (grsec_enable_socket_server &&
62557 + in_group_p(grsec_socket_server_gid) &&
62558 + sck && (sck->sk_family != AF_UNIX) &&
62559 + (sck->sk_family != AF_LOCAL)) {
62560 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62561 + return -EACCES;
62562 + }
62563 +#endif
62564 + return 0;
62565 +}
62566 +
62567 +int
62568 +gr_handle_sock_client(const struct sockaddr *sck)
62569 +{
62570 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62571 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
62572 + sck && (sck->sa_family != AF_UNIX) &&
62573 + (sck->sa_family != AF_LOCAL)) {
62574 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
62575 + return -EACCES;
62576 + }
62577 +#endif
62578 + return 0;
62579 +}
62580 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
62581 new file mode 100644
62582 index 0000000..f55ef0f
62583 --- /dev/null
62584 +++ b/grsecurity/grsec_sysctl.c
62585 @@ -0,0 +1,469 @@
62586 +#include <linux/kernel.h>
62587 +#include <linux/sched.h>
62588 +#include <linux/sysctl.h>
62589 +#include <linux/grsecurity.h>
62590 +#include <linux/grinternal.h>
62591 +
62592 +int
62593 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
62594 +{
62595 +#ifdef CONFIG_GRKERNSEC_SYSCTL
62596 + if (dirname == NULL || name == NULL)
62597 + return 0;
62598 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
62599 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
62600 + return -EACCES;
62601 + }
62602 +#endif
62603 + return 0;
62604 +}
62605 +
62606 +#ifdef CONFIG_GRKERNSEC_ROFS
62607 +static int __maybe_unused one = 1;
62608 +#endif
62609 +
62610 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62611 +struct ctl_table grsecurity_table[] = {
62612 +#ifdef CONFIG_GRKERNSEC_SYSCTL
62613 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
62614 +#ifdef CONFIG_GRKERNSEC_IO
62615 + {
62616 + .procname = "disable_priv_io",
62617 + .data = &grsec_disable_privio,
62618 + .maxlen = sizeof(int),
62619 + .mode = 0600,
62620 + .proc_handler = &proc_dointvec,
62621 + },
62622 +#endif
62623 +#endif
62624 +#ifdef CONFIG_GRKERNSEC_LINK
62625 + {
62626 + .procname = "linking_restrictions",
62627 + .data = &grsec_enable_link,
62628 + .maxlen = sizeof(int),
62629 + .mode = 0600,
62630 + .proc_handler = &proc_dointvec,
62631 + },
62632 +#endif
62633 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
62634 + {
62635 + .procname = "enforce_symlinksifowner",
62636 + .data = &grsec_enable_symlinkown,
62637 + .maxlen = sizeof(int),
62638 + .mode = 0600,
62639 + .proc_handler = &proc_dointvec,
62640 + },
62641 + {
62642 + .procname = "symlinkown_gid",
62643 + .data = &grsec_symlinkown_gid,
62644 + .maxlen = sizeof(int),
62645 + .mode = 0600,
62646 + .proc_handler = &proc_dointvec,
62647 + },
62648 +#endif
62649 +#ifdef CONFIG_GRKERNSEC_BRUTE
62650 + {
62651 + .procname = "deter_bruteforce",
62652 + .data = &grsec_enable_brute,
62653 + .maxlen = sizeof(int),
62654 + .mode = 0600,
62655 + .proc_handler = &proc_dointvec,
62656 + },
62657 +#endif
62658 +#ifdef CONFIG_GRKERNSEC_FIFO
62659 + {
62660 + .procname = "fifo_restrictions",
62661 + .data = &grsec_enable_fifo,
62662 + .maxlen = sizeof(int),
62663 + .mode = 0600,
62664 + .proc_handler = &proc_dointvec,
62665 + },
62666 +#endif
62667 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62668 + {
62669 + .procname = "ptrace_readexec",
62670 + .data = &grsec_enable_ptrace_readexec,
62671 + .maxlen = sizeof(int),
62672 + .mode = 0600,
62673 + .proc_handler = &proc_dointvec,
62674 + },
62675 +#endif
62676 +#ifdef CONFIG_GRKERNSEC_SETXID
62677 + {
62678 + .procname = "consistent_setxid",
62679 + .data = &grsec_enable_setxid,
62680 + .maxlen = sizeof(int),
62681 + .mode = 0600,
62682 + .proc_handler = &proc_dointvec,
62683 + },
62684 +#endif
62685 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62686 + {
62687 + .procname = "ip_blackhole",
62688 + .data = &grsec_enable_blackhole,
62689 + .maxlen = sizeof(int),
62690 + .mode = 0600,
62691 + .proc_handler = &proc_dointvec,
62692 + },
62693 + {
62694 + .procname = "lastack_retries",
62695 + .data = &grsec_lastack_retries,
62696 + .maxlen = sizeof(int),
62697 + .mode = 0600,
62698 + .proc_handler = &proc_dointvec,
62699 + },
62700 +#endif
62701 +#ifdef CONFIG_GRKERNSEC_EXECLOG
62702 + {
62703 + .procname = "exec_logging",
62704 + .data = &grsec_enable_execlog,
62705 + .maxlen = sizeof(int),
62706 + .mode = 0600,
62707 + .proc_handler = &proc_dointvec,
62708 + },
62709 +#endif
62710 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62711 + {
62712 + .procname = "rwxmap_logging",
62713 + .data = &grsec_enable_log_rwxmaps,
62714 + .maxlen = sizeof(int),
62715 + .mode = 0600,
62716 + .proc_handler = &proc_dointvec,
62717 + },
62718 +#endif
62719 +#ifdef CONFIG_GRKERNSEC_SIGNAL
62720 + {
62721 + .procname = "signal_logging",
62722 + .data = &grsec_enable_signal,
62723 + .maxlen = sizeof(int),
62724 + .mode = 0600,
62725 + .proc_handler = &proc_dointvec,
62726 + },
62727 +#endif
62728 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
62729 + {
62730 + .procname = "forkfail_logging",
62731 + .data = &grsec_enable_forkfail,
62732 + .maxlen = sizeof(int),
62733 + .mode = 0600,
62734 + .proc_handler = &proc_dointvec,
62735 + },
62736 +#endif
62737 +#ifdef CONFIG_GRKERNSEC_TIME
62738 + {
62739 + .procname = "timechange_logging",
62740 + .data = &grsec_enable_time,
62741 + .maxlen = sizeof(int),
62742 + .mode = 0600,
62743 + .proc_handler = &proc_dointvec,
62744 + },
62745 +#endif
62746 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62747 + {
62748 + .procname = "chroot_deny_shmat",
62749 + .data = &grsec_enable_chroot_shmat,
62750 + .maxlen = sizeof(int),
62751 + .mode = 0600,
62752 + .proc_handler = &proc_dointvec,
62753 + },
62754 +#endif
62755 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62756 + {
62757 + .procname = "chroot_deny_unix",
62758 + .data = &grsec_enable_chroot_unix,
62759 + .maxlen = sizeof(int),
62760 + .mode = 0600,
62761 + .proc_handler = &proc_dointvec,
62762 + },
62763 +#endif
62764 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62765 + {
62766 + .procname = "chroot_deny_mount",
62767 + .data = &grsec_enable_chroot_mount,
62768 + .maxlen = sizeof(int),
62769 + .mode = 0600,
62770 + .proc_handler = &proc_dointvec,
62771 + },
62772 +#endif
62773 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62774 + {
62775 + .procname = "chroot_deny_fchdir",
62776 + .data = &grsec_enable_chroot_fchdir,
62777 + .maxlen = sizeof(int),
62778 + .mode = 0600,
62779 + .proc_handler = &proc_dointvec,
62780 + },
62781 +#endif
62782 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62783 + {
62784 + .procname = "chroot_deny_chroot",
62785 + .data = &grsec_enable_chroot_double,
62786 + .maxlen = sizeof(int),
62787 + .mode = 0600,
62788 + .proc_handler = &proc_dointvec,
62789 + },
62790 +#endif
62791 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62792 + {
62793 + .procname = "chroot_deny_pivot",
62794 + .data = &grsec_enable_chroot_pivot,
62795 + .maxlen = sizeof(int),
62796 + .mode = 0600,
62797 + .proc_handler = &proc_dointvec,
62798 + },
62799 +#endif
62800 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62801 + {
62802 + .procname = "chroot_enforce_chdir",
62803 + .data = &grsec_enable_chroot_chdir,
62804 + .maxlen = sizeof(int),
62805 + .mode = 0600,
62806 + .proc_handler = &proc_dointvec,
62807 + },
62808 +#endif
62809 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62810 + {
62811 + .procname = "chroot_deny_chmod",
62812 + .data = &grsec_enable_chroot_chmod,
62813 + .maxlen = sizeof(int),
62814 + .mode = 0600,
62815 + .proc_handler = &proc_dointvec,
62816 + },
62817 +#endif
62818 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62819 + {
62820 + .procname = "chroot_deny_mknod",
62821 + .data = &grsec_enable_chroot_mknod,
62822 + .maxlen = sizeof(int),
62823 + .mode = 0600,
62824 + .proc_handler = &proc_dointvec,
62825 + },
62826 +#endif
62827 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62828 + {
62829 + .procname = "chroot_restrict_nice",
62830 + .data = &grsec_enable_chroot_nice,
62831 + .maxlen = sizeof(int),
62832 + .mode = 0600,
62833 + .proc_handler = &proc_dointvec,
62834 + },
62835 +#endif
62836 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62837 + {
62838 + .procname = "chroot_execlog",
62839 + .data = &grsec_enable_chroot_execlog,
62840 + .maxlen = sizeof(int),
62841 + .mode = 0600,
62842 + .proc_handler = &proc_dointvec,
62843 + },
62844 +#endif
62845 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62846 + {
62847 + .procname = "chroot_caps",
62848 + .data = &grsec_enable_chroot_caps,
62849 + .maxlen = sizeof(int),
62850 + .mode = 0600,
62851 + .proc_handler = &proc_dointvec,
62852 + },
62853 +#endif
62854 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62855 + {
62856 + .procname = "chroot_deny_sysctl",
62857 + .data = &grsec_enable_chroot_sysctl,
62858 + .maxlen = sizeof(int),
62859 + .mode = 0600,
62860 + .proc_handler = &proc_dointvec,
62861 + },
62862 +#endif
62863 +#ifdef CONFIG_GRKERNSEC_TPE
62864 + {
62865 + .procname = "tpe",
62866 + .data = &grsec_enable_tpe,
62867 + .maxlen = sizeof(int),
62868 + .mode = 0600,
62869 + .proc_handler = &proc_dointvec,
62870 + },
62871 + {
62872 + .procname = "tpe_gid",
62873 + .data = &grsec_tpe_gid,
62874 + .maxlen = sizeof(int),
62875 + .mode = 0600,
62876 + .proc_handler = &proc_dointvec,
62877 + },
62878 +#endif
62879 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62880 + {
62881 + .procname = "tpe_invert",
62882 + .data = &grsec_enable_tpe_invert,
62883 + .maxlen = sizeof(int),
62884 + .mode = 0600,
62885 + .proc_handler = &proc_dointvec,
62886 + },
62887 +#endif
62888 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62889 + {
62890 + .procname = "tpe_restrict_all",
62891 + .data = &grsec_enable_tpe_all,
62892 + .maxlen = sizeof(int),
62893 + .mode = 0600,
62894 + .proc_handler = &proc_dointvec,
62895 + },
62896 +#endif
62897 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62898 + {
62899 + .procname = "socket_all",
62900 + .data = &grsec_enable_socket_all,
62901 + .maxlen = sizeof(int),
62902 + .mode = 0600,
62903 + .proc_handler = &proc_dointvec,
62904 + },
62905 + {
62906 + .procname = "socket_all_gid",
62907 + .data = &grsec_socket_all_gid,
62908 + .maxlen = sizeof(int),
62909 + .mode = 0600,
62910 + .proc_handler = &proc_dointvec,
62911 + },
62912 +#endif
62913 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62914 + {
62915 + .procname = "socket_client",
62916 + .data = &grsec_enable_socket_client,
62917 + .maxlen = sizeof(int),
62918 + .mode = 0600,
62919 + .proc_handler = &proc_dointvec,
62920 + },
62921 + {
62922 + .procname = "socket_client_gid",
62923 + .data = &grsec_socket_client_gid,
62924 + .maxlen = sizeof(int),
62925 + .mode = 0600,
62926 + .proc_handler = &proc_dointvec,
62927 + },
62928 +#endif
62929 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62930 + {
62931 + .procname = "socket_server",
62932 + .data = &grsec_enable_socket_server,
62933 + .maxlen = sizeof(int),
62934 + .mode = 0600,
62935 + .proc_handler = &proc_dointvec,
62936 + },
62937 + {
62938 + .procname = "socket_server_gid",
62939 + .data = &grsec_socket_server_gid,
62940 + .maxlen = sizeof(int),
62941 + .mode = 0600,
62942 + .proc_handler = &proc_dointvec,
62943 + },
62944 +#endif
62945 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62946 + {
62947 + .procname = "audit_group",
62948 + .data = &grsec_enable_group,
62949 + .maxlen = sizeof(int),
62950 + .mode = 0600,
62951 + .proc_handler = &proc_dointvec,
62952 + },
62953 + {
62954 + .procname = "audit_gid",
62955 + .data = &grsec_audit_gid,
62956 + .maxlen = sizeof(int),
62957 + .mode = 0600,
62958 + .proc_handler = &proc_dointvec,
62959 + },
62960 +#endif
62961 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62962 + {
62963 + .procname = "audit_chdir",
62964 + .data = &grsec_enable_chdir,
62965 + .maxlen = sizeof(int),
62966 + .mode = 0600,
62967 + .proc_handler = &proc_dointvec,
62968 + },
62969 +#endif
62970 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62971 + {
62972 + .procname = "audit_mount",
62973 + .data = &grsec_enable_mount,
62974 + .maxlen = sizeof(int),
62975 + .mode = 0600,
62976 + .proc_handler = &proc_dointvec,
62977 + },
62978 +#endif
62979 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62980 + {
62981 + .procname = "audit_textrel",
62982 + .data = &grsec_enable_audit_textrel,
62983 + .maxlen = sizeof(int),
62984 + .mode = 0600,
62985 + .proc_handler = &proc_dointvec,
62986 + },
62987 +#endif
62988 +#ifdef CONFIG_GRKERNSEC_DMESG
62989 + {
62990 + .procname = "dmesg",
62991 + .data = &grsec_enable_dmesg,
62992 + .maxlen = sizeof(int),
62993 + .mode = 0600,
62994 + .proc_handler = &proc_dointvec,
62995 + },
62996 +#endif
62997 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62998 + {
62999 + .procname = "chroot_findtask",
63000 + .data = &grsec_enable_chroot_findtask,
63001 + .maxlen = sizeof(int),
63002 + .mode = 0600,
63003 + .proc_handler = &proc_dointvec,
63004 + },
63005 +#endif
63006 +#ifdef CONFIG_GRKERNSEC_RESLOG
63007 + {
63008 + .procname = "resource_logging",
63009 + .data = &grsec_resource_logging,
63010 + .maxlen = sizeof(int),
63011 + .mode = 0600,
63012 + .proc_handler = &proc_dointvec,
63013 + },
63014 +#endif
63015 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63016 + {
63017 + .procname = "audit_ptrace",
63018 + .data = &grsec_enable_audit_ptrace,
63019 + .maxlen = sizeof(int),
63020 + .mode = 0600,
63021 + .proc_handler = &proc_dointvec,
63022 + },
63023 +#endif
63024 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63025 + {
63026 + .procname = "harden_ptrace",
63027 + .data = &grsec_enable_harden_ptrace,
63028 + .maxlen = sizeof(int),
63029 + .mode = 0600,
63030 + .proc_handler = &proc_dointvec,
63031 + },
63032 +#endif
63033 + {
63034 + .procname = "grsec_lock",
63035 + .data = &grsec_lock,
63036 + .maxlen = sizeof(int),
63037 + .mode = 0600,
63038 + .proc_handler = &proc_dointvec,
63039 + },
63040 +#endif
63041 +#ifdef CONFIG_GRKERNSEC_ROFS
63042 + {
63043 + .procname = "romount_protect",
63044 + .data = &grsec_enable_rofs,
63045 + .maxlen = sizeof(int),
63046 + .mode = 0600,
63047 + .proc_handler = &proc_dointvec_minmax,
63048 + .extra1 = &one,
63049 + .extra2 = &one,
63050 + },
63051 +#endif
63052 + { }
63053 +};
63054 +#endif
63055 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
63056 new file mode 100644
63057 index 0000000..0dc13c3
63058 --- /dev/null
63059 +++ b/grsecurity/grsec_time.c
63060 @@ -0,0 +1,16 @@
63061 +#include <linux/kernel.h>
63062 +#include <linux/sched.h>
63063 +#include <linux/grinternal.h>
63064 +#include <linux/module.h>
63065 +
63066 +void
63067 +gr_log_timechange(void)
63068 +{
63069 +#ifdef CONFIG_GRKERNSEC_TIME
63070 + if (grsec_enable_time)
63071 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
63072 +#endif
63073 + return;
63074 +}
63075 +
63076 +EXPORT_SYMBOL(gr_log_timechange);
63077 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
63078 new file mode 100644
63079 index 0000000..07e0dc0
63080 --- /dev/null
63081 +++ b/grsecurity/grsec_tpe.c
63082 @@ -0,0 +1,73 @@
63083 +#include <linux/kernel.h>
63084 +#include <linux/sched.h>
63085 +#include <linux/file.h>
63086 +#include <linux/fs.h>
63087 +#include <linux/grinternal.h>
63088 +
63089 +extern int gr_acl_tpe_check(void);
63090 +
63091 +int
63092 +gr_tpe_allow(const struct file *file)
63093 +{
63094 +#ifdef CONFIG_GRKERNSEC
63095 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
63096 + const struct cred *cred = current_cred();
63097 + char *msg = NULL;
63098 + char *msg2 = NULL;
63099 +
63100 + // never restrict root
63101 + if (!cred->uid)
63102 + return 1;
63103 +
63104 + if (grsec_enable_tpe) {
63105 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63106 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
63107 + msg = "not being in trusted group";
63108 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
63109 + msg = "being in untrusted group";
63110 +#else
63111 + if (in_group_p(grsec_tpe_gid))
63112 + msg = "being in untrusted group";
63113 +#endif
63114 + }
63115 + if (!msg && gr_acl_tpe_check())
63116 + msg = "being in untrusted role";
63117 +
63118 + // not in any affected group/role
63119 + if (!msg)
63120 + goto next_check;
63121 +
63122 + if (inode->i_uid)
63123 + msg2 = "file in non-root-owned directory";
63124 + else if (inode->i_mode & S_IWOTH)
63125 + msg2 = "file in world-writable directory";
63126 + else if (inode->i_mode & S_IWGRP)
63127 + msg2 = "file in group-writable directory";
63128 +
63129 + if (msg && msg2) {
63130 + char fullmsg[70] = {0};
63131 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
63132 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
63133 + return 0;
63134 + }
63135 + msg = NULL;
63136 +next_check:
63137 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
63138 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
63139 + return 1;
63140 +
63141 + if (inode->i_uid && (inode->i_uid != cred->uid))
63142 + msg = "directory not owned by user";
63143 + else if (inode->i_mode & S_IWOTH)
63144 + msg = "file in world-writable directory";
63145 + else if (inode->i_mode & S_IWGRP)
63146 + msg = "file in group-writable directory";
63147 +
63148 + if (msg) {
63149 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
63150 + return 0;
63151 + }
63152 +#endif
63153 +#endif
63154 + return 1;
63155 +}
63156 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
63157 new file mode 100644
63158 index 0000000..9f7b1ac
63159 --- /dev/null
63160 +++ b/grsecurity/grsum.c
63161 @@ -0,0 +1,61 @@
63162 +#include <linux/err.h>
63163 +#include <linux/kernel.h>
63164 +#include <linux/sched.h>
63165 +#include <linux/mm.h>
63166 +#include <linux/scatterlist.h>
63167 +#include <linux/crypto.h>
63168 +#include <linux/gracl.h>
63169 +
63170 +
63171 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
63172 +#error "crypto and sha256 must be built into the kernel"
63173 +#endif
63174 +
63175 +int
63176 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
63177 +{
63178 + char *p;
63179 + struct crypto_hash *tfm;
63180 + struct hash_desc desc;
63181 + struct scatterlist sg;
63182 + unsigned char temp_sum[GR_SHA_LEN];
63183 + volatile int retval = 0;
63184 + volatile int dummy = 0;
63185 + unsigned int i;
63186 +
63187 + sg_init_table(&sg, 1);
63188 +
63189 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
63190 + if (IS_ERR(tfm)) {
63191 + /* should never happen, since sha256 should be built in */
63192 + return 1;
63193 + }
63194 +
63195 + desc.tfm = tfm;
63196 + desc.flags = 0;
63197 +
63198 + crypto_hash_init(&desc);
63199 +
63200 + p = salt;
63201 + sg_set_buf(&sg, p, GR_SALT_LEN);
63202 + crypto_hash_update(&desc, &sg, sg.length);
63203 +
63204 + p = entry->pw;
63205 + sg_set_buf(&sg, p, strlen(p));
63206 +
63207 + crypto_hash_update(&desc, &sg, sg.length);
63208 +
63209 + crypto_hash_final(&desc, temp_sum);
63210 +
63211 + memset(entry->pw, 0, GR_PW_LEN);
63212 +
63213 + for (i = 0; i < GR_SHA_LEN; i++)
63214 + if (sum[i] != temp_sum[i])
63215 + retval = 1;
63216 + else
63217 + dummy = 1; // waste a cycle
63218 +
63219 + crypto_free_hash(tfm);
63220 +
63221 + return retval;
63222 +}
63223 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
63224 index 77ff547..181834f 100644
63225 --- a/include/asm-generic/4level-fixup.h
63226 +++ b/include/asm-generic/4level-fixup.h
63227 @@ -13,8 +13,10 @@
63228 #define pmd_alloc(mm, pud, address) \
63229 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
63230 NULL: pmd_offset(pud, address))
63231 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
63232
63233 #define pud_alloc(mm, pgd, address) (pgd)
63234 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
63235 #define pud_offset(pgd, start) (pgd)
63236 #define pud_none(pud) 0
63237 #define pud_bad(pud) 0
63238 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
63239 index b7babf0..04ad282 100644
63240 --- a/include/asm-generic/atomic-long.h
63241 +++ b/include/asm-generic/atomic-long.h
63242 @@ -22,6 +22,12 @@
63243
63244 typedef atomic64_t atomic_long_t;
63245
63246 +#ifdef CONFIG_PAX_REFCOUNT
63247 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
63248 +#else
63249 +typedef atomic64_t atomic_long_unchecked_t;
63250 +#endif
63251 +
63252 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
63253
63254 static inline long atomic_long_read(atomic_long_t *l)
63255 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63256 return (long)atomic64_read(v);
63257 }
63258
63259 +#ifdef CONFIG_PAX_REFCOUNT
63260 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63261 +{
63262 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63263 +
63264 + return (long)atomic64_read_unchecked(v);
63265 +}
63266 +#endif
63267 +
63268 static inline void atomic_long_set(atomic_long_t *l, long i)
63269 {
63270 atomic64_t *v = (atomic64_t *)l;
63271 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63272 atomic64_set(v, i);
63273 }
63274
63275 +#ifdef CONFIG_PAX_REFCOUNT
63276 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63277 +{
63278 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63279 +
63280 + atomic64_set_unchecked(v, i);
63281 +}
63282 +#endif
63283 +
63284 static inline void atomic_long_inc(atomic_long_t *l)
63285 {
63286 atomic64_t *v = (atomic64_t *)l;
63287 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63288 atomic64_inc(v);
63289 }
63290
63291 +#ifdef CONFIG_PAX_REFCOUNT
63292 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63293 +{
63294 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63295 +
63296 + atomic64_inc_unchecked(v);
63297 +}
63298 +#endif
63299 +
63300 static inline void atomic_long_dec(atomic_long_t *l)
63301 {
63302 atomic64_t *v = (atomic64_t *)l;
63303 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63304 atomic64_dec(v);
63305 }
63306
63307 +#ifdef CONFIG_PAX_REFCOUNT
63308 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63309 +{
63310 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63311 +
63312 + atomic64_dec_unchecked(v);
63313 +}
63314 +#endif
63315 +
63316 static inline void atomic_long_add(long i, atomic_long_t *l)
63317 {
63318 atomic64_t *v = (atomic64_t *)l;
63319 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63320 atomic64_add(i, v);
63321 }
63322
63323 +#ifdef CONFIG_PAX_REFCOUNT
63324 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63325 +{
63326 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63327 +
63328 + atomic64_add_unchecked(i, v);
63329 +}
63330 +#endif
63331 +
63332 static inline void atomic_long_sub(long i, atomic_long_t *l)
63333 {
63334 atomic64_t *v = (atomic64_t *)l;
63335 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63336 atomic64_sub(i, v);
63337 }
63338
63339 +#ifdef CONFIG_PAX_REFCOUNT
63340 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63341 +{
63342 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63343 +
63344 + atomic64_sub_unchecked(i, v);
63345 +}
63346 +#endif
63347 +
63348 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63349 {
63350 atomic64_t *v = (atomic64_t *)l;
63351 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63352 return (long)atomic64_add_return(i, v);
63353 }
63354
63355 +#ifdef CONFIG_PAX_REFCOUNT
63356 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63357 +{
63358 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63359 +
63360 + return (long)atomic64_add_return_unchecked(i, v);
63361 +}
63362 +#endif
63363 +
63364 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63365 {
63366 atomic64_t *v = (atomic64_t *)l;
63367 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63368 return (long)atomic64_inc_return(v);
63369 }
63370
63371 +#ifdef CONFIG_PAX_REFCOUNT
63372 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63373 +{
63374 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63375 +
63376 + return (long)atomic64_inc_return_unchecked(v);
63377 +}
63378 +#endif
63379 +
63380 static inline long atomic_long_dec_return(atomic_long_t *l)
63381 {
63382 atomic64_t *v = (atomic64_t *)l;
63383 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63384
63385 typedef atomic_t atomic_long_t;
63386
63387 +#ifdef CONFIG_PAX_REFCOUNT
63388 +typedef atomic_unchecked_t atomic_long_unchecked_t;
63389 +#else
63390 +typedef atomic_t atomic_long_unchecked_t;
63391 +#endif
63392 +
63393 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
63394 static inline long atomic_long_read(atomic_long_t *l)
63395 {
63396 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63397 return (long)atomic_read(v);
63398 }
63399
63400 +#ifdef CONFIG_PAX_REFCOUNT
63401 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63402 +{
63403 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63404 +
63405 + return (long)atomic_read_unchecked(v);
63406 +}
63407 +#endif
63408 +
63409 static inline void atomic_long_set(atomic_long_t *l, long i)
63410 {
63411 atomic_t *v = (atomic_t *)l;
63412 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63413 atomic_set(v, i);
63414 }
63415
63416 +#ifdef CONFIG_PAX_REFCOUNT
63417 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63418 +{
63419 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63420 +
63421 + atomic_set_unchecked(v, i);
63422 +}
63423 +#endif
63424 +
63425 static inline void atomic_long_inc(atomic_long_t *l)
63426 {
63427 atomic_t *v = (atomic_t *)l;
63428 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63429 atomic_inc(v);
63430 }
63431
63432 +#ifdef CONFIG_PAX_REFCOUNT
63433 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63434 +{
63435 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63436 +
63437 + atomic_inc_unchecked(v);
63438 +}
63439 +#endif
63440 +
63441 static inline void atomic_long_dec(atomic_long_t *l)
63442 {
63443 atomic_t *v = (atomic_t *)l;
63444 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63445 atomic_dec(v);
63446 }
63447
63448 +#ifdef CONFIG_PAX_REFCOUNT
63449 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63450 +{
63451 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63452 +
63453 + atomic_dec_unchecked(v);
63454 +}
63455 +#endif
63456 +
63457 static inline void atomic_long_add(long i, atomic_long_t *l)
63458 {
63459 atomic_t *v = (atomic_t *)l;
63460 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63461 atomic_add(i, v);
63462 }
63463
63464 +#ifdef CONFIG_PAX_REFCOUNT
63465 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63466 +{
63467 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63468 +
63469 + atomic_add_unchecked(i, v);
63470 +}
63471 +#endif
63472 +
63473 static inline void atomic_long_sub(long i, atomic_long_t *l)
63474 {
63475 atomic_t *v = (atomic_t *)l;
63476 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63477 atomic_sub(i, v);
63478 }
63479
63480 +#ifdef CONFIG_PAX_REFCOUNT
63481 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63482 +{
63483 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63484 +
63485 + atomic_sub_unchecked(i, v);
63486 +}
63487 +#endif
63488 +
63489 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63490 {
63491 atomic_t *v = (atomic_t *)l;
63492 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63493 return (long)atomic_add_return(i, v);
63494 }
63495
63496 +#ifdef CONFIG_PAX_REFCOUNT
63497 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63498 +{
63499 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63500 +
63501 + return (long)atomic_add_return_unchecked(i, v);
63502 +}
63503 +
63504 +#endif
63505 +
63506 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63507 {
63508 atomic_t *v = (atomic_t *)l;
63509 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63510 return (long)atomic_inc_return(v);
63511 }
63512
63513 +#ifdef CONFIG_PAX_REFCOUNT
63514 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63515 +{
63516 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63517 +
63518 + return (long)atomic_inc_return_unchecked(v);
63519 +}
63520 +#endif
63521 +
63522 static inline long atomic_long_dec_return(atomic_long_t *l)
63523 {
63524 atomic_t *v = (atomic_t *)l;
63525 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63526
63527 #endif /* BITS_PER_LONG == 64 */
63528
63529 +#ifdef CONFIG_PAX_REFCOUNT
63530 +static inline void pax_refcount_needs_these_functions(void)
63531 +{
63532 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
63533 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
63534 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
63535 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
63536 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
63537 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
63538 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
63539 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
63540 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
63541 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
63542 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
63543 +#ifdef CONFIG_X86
63544 + atomic_clear_mask_unchecked(0, NULL);
63545 + atomic_set_mask_unchecked(0, NULL);
63546 +#endif
63547 +
63548 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
63549 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
63550 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
63551 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
63552 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
63553 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
63554 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
63555 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
63556 +}
63557 +#else
63558 +#define atomic_read_unchecked(v) atomic_read(v)
63559 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
63560 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
63561 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
63562 +#define atomic_inc_unchecked(v) atomic_inc(v)
63563 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
63564 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
63565 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
63566 +#define atomic_dec_unchecked(v) atomic_dec(v)
63567 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
63568 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
63569 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
63570 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
63571 +
63572 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
63573 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
63574 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
63575 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
63576 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
63577 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
63578 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
63579 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
63580 +#endif
63581 +
63582 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
63583 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
63584 index 1ced641..c896ee8 100644
63585 --- a/include/asm-generic/atomic.h
63586 +++ b/include/asm-generic/atomic.h
63587 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
63588 * Atomically clears the bits set in @mask from @v
63589 */
63590 #ifndef atomic_clear_mask
63591 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
63592 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
63593 {
63594 unsigned long flags;
63595
63596 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
63597 index b18ce4f..2ee2843 100644
63598 --- a/include/asm-generic/atomic64.h
63599 +++ b/include/asm-generic/atomic64.h
63600 @@ -16,6 +16,8 @@ typedef struct {
63601 long long counter;
63602 } atomic64_t;
63603
63604 +typedef atomic64_t atomic64_unchecked_t;
63605 +
63606 #define ATOMIC64_INIT(i) { (i) }
63607
63608 extern long long atomic64_read(const atomic64_t *v);
63609 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
63610 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
63611 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
63612
63613 +#define atomic64_read_unchecked(v) atomic64_read(v)
63614 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
63615 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
63616 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
63617 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
63618 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
63619 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
63620 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
63621 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
63622 +
63623 #endif /* _ASM_GENERIC_ATOMIC64_H */
63624 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
63625 index 1bfcfe5..e04c5c9 100644
63626 --- a/include/asm-generic/cache.h
63627 +++ b/include/asm-generic/cache.h
63628 @@ -6,7 +6,7 @@
63629 * cache lines need to provide their own cache.h.
63630 */
63631
63632 -#define L1_CACHE_SHIFT 5
63633 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
63634 +#define L1_CACHE_SHIFT 5UL
63635 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
63636
63637 #endif /* __ASM_GENERIC_CACHE_H */
63638 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
63639 index 0d68a1e..b74a761 100644
63640 --- a/include/asm-generic/emergency-restart.h
63641 +++ b/include/asm-generic/emergency-restart.h
63642 @@ -1,7 +1,7 @@
63643 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
63644 #define _ASM_GENERIC_EMERGENCY_RESTART_H
63645
63646 -static inline void machine_emergency_restart(void)
63647 +static inline __noreturn void machine_emergency_restart(void)
63648 {
63649 machine_restart(NULL);
63650 }
63651 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
63652 index 90f99c7..00ce236 100644
63653 --- a/include/asm-generic/kmap_types.h
63654 +++ b/include/asm-generic/kmap_types.h
63655 @@ -2,9 +2,9 @@
63656 #define _ASM_GENERIC_KMAP_TYPES_H
63657
63658 #ifdef __WITH_KM_FENCE
63659 -# define KM_TYPE_NR 41
63660 +# define KM_TYPE_NR 42
63661 #else
63662 -# define KM_TYPE_NR 20
63663 +# define KM_TYPE_NR 21
63664 #endif
63665
63666 #endif
63667 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
63668 index 9ceb03b..62b0b8f 100644
63669 --- a/include/asm-generic/local.h
63670 +++ b/include/asm-generic/local.h
63671 @@ -23,24 +23,37 @@ typedef struct
63672 atomic_long_t a;
63673 } local_t;
63674
63675 +typedef struct {
63676 + atomic_long_unchecked_t a;
63677 +} local_unchecked_t;
63678 +
63679 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
63680
63681 #define local_read(l) atomic_long_read(&(l)->a)
63682 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
63683 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
63684 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
63685 #define local_inc(l) atomic_long_inc(&(l)->a)
63686 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
63687 #define local_dec(l) atomic_long_dec(&(l)->a)
63688 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
63689 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
63690 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
63691 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
63692 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
63693
63694 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
63695 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
63696 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
63697 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
63698 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
63699 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
63700 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
63701 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
63702 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
63703
63704 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63705 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63706 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
63707 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
63708 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
63709 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
63710 index 725612b..9cc513a 100644
63711 --- a/include/asm-generic/pgtable-nopmd.h
63712 +++ b/include/asm-generic/pgtable-nopmd.h
63713 @@ -1,14 +1,19 @@
63714 #ifndef _PGTABLE_NOPMD_H
63715 #define _PGTABLE_NOPMD_H
63716
63717 -#ifndef __ASSEMBLY__
63718 -
63719 #include <asm-generic/pgtable-nopud.h>
63720
63721 -struct mm_struct;
63722 -
63723 #define __PAGETABLE_PMD_FOLDED
63724
63725 +#define PMD_SHIFT PUD_SHIFT
63726 +#define PTRS_PER_PMD 1
63727 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
63728 +#define PMD_MASK (~(PMD_SIZE-1))
63729 +
63730 +#ifndef __ASSEMBLY__
63731 +
63732 +struct mm_struct;
63733 +
63734 /*
63735 * Having the pmd type consist of a pud gets the size right, and allows
63736 * us to conceptually access the pud entry that this pmd is folded into
63737 @@ -16,11 +21,6 @@ struct mm_struct;
63738 */
63739 typedef struct { pud_t pud; } pmd_t;
63740
63741 -#define PMD_SHIFT PUD_SHIFT
63742 -#define PTRS_PER_PMD 1
63743 -#define PMD_SIZE (1UL << PMD_SHIFT)
63744 -#define PMD_MASK (~(PMD_SIZE-1))
63745 -
63746 /*
63747 * The "pud_xxx()" functions here are trivial for a folded two-level
63748 * setup: the pmd is never bad, and a pmd always exists (as it's folded
63749 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
63750 index 810431d..0ec4804f 100644
63751 --- a/include/asm-generic/pgtable-nopud.h
63752 +++ b/include/asm-generic/pgtable-nopud.h
63753 @@ -1,10 +1,15 @@
63754 #ifndef _PGTABLE_NOPUD_H
63755 #define _PGTABLE_NOPUD_H
63756
63757 -#ifndef __ASSEMBLY__
63758 -
63759 #define __PAGETABLE_PUD_FOLDED
63760
63761 +#define PUD_SHIFT PGDIR_SHIFT
63762 +#define PTRS_PER_PUD 1
63763 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
63764 +#define PUD_MASK (~(PUD_SIZE-1))
63765 +
63766 +#ifndef __ASSEMBLY__
63767 +
63768 /*
63769 * Having the pud type consist of a pgd gets the size right, and allows
63770 * us to conceptually access the pgd entry that this pud is folded into
63771 @@ -12,11 +17,6 @@
63772 */
63773 typedef struct { pgd_t pgd; } pud_t;
63774
63775 -#define PUD_SHIFT PGDIR_SHIFT
63776 -#define PTRS_PER_PUD 1
63777 -#define PUD_SIZE (1UL << PUD_SHIFT)
63778 -#define PUD_MASK (~(PUD_SIZE-1))
63779 -
63780 /*
63781 * The "pgd_xxx()" functions here are trivial for a folded two-level
63782 * setup: the pud is never bad, and a pud always exists (as it's folded
63783 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63784 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63785
63786 #define pgd_populate(mm, pgd, pud) do { } while (0)
63787 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63788 /*
63789 * (puds are folded into pgds so this doesn't get actually called,
63790 * but the define is needed for a generic inline function.)
63791 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63792 index 5cf680a..4b74d62 100644
63793 --- a/include/asm-generic/pgtable.h
63794 +++ b/include/asm-generic/pgtable.h
63795 @@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
63796 }
63797 #endif /* CONFIG_NUMA_BALANCING */
63798
63799 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63800 +static inline unsigned long pax_open_kernel(void) { return 0; }
63801 +#endif
63802 +
63803 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63804 +static inline unsigned long pax_close_kernel(void) { return 0; }
63805 +#endif
63806 +
63807 #endif /* CONFIG_MMU */
63808
63809 #endif /* !__ASSEMBLY__ */
63810 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63811 index d1ea7ce..b1ebf2a 100644
63812 --- a/include/asm-generic/vmlinux.lds.h
63813 +++ b/include/asm-generic/vmlinux.lds.h
63814 @@ -218,6 +218,7 @@
63815 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63816 VMLINUX_SYMBOL(__start_rodata) = .; \
63817 *(.rodata) *(.rodata.*) \
63818 + *(.data..read_only) \
63819 *(__vermagic) /* Kernel version magic */ \
63820 . = ALIGN(8); \
63821 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63822 @@ -725,17 +726,18 @@
63823 * section in the linker script will go there too. @phdr should have
63824 * a leading colon.
63825 *
63826 - * Note that this macros defines __per_cpu_load as an absolute symbol.
63827 + * Note that this macros defines per_cpu_load as an absolute symbol.
63828 * If there is no need to put the percpu section at a predetermined
63829 * address, use PERCPU_SECTION.
63830 */
63831 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63832 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
63833 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63834 + per_cpu_load = .; \
63835 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63836 - LOAD_OFFSET) { \
63837 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63838 PERCPU_INPUT(cacheline) \
63839 } phdr \
63840 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63841 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63842
63843 /**
63844 * PERCPU_SECTION - define output section for percpu area, simple version
63845 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63846 index 418d270..bfd2794 100644
63847 --- a/include/crypto/algapi.h
63848 +++ b/include/crypto/algapi.h
63849 @@ -34,7 +34,7 @@ struct crypto_type {
63850 unsigned int maskclear;
63851 unsigned int maskset;
63852 unsigned int tfmsize;
63853 -};
63854 +} __do_const;
63855
63856 struct crypto_instance {
63857 struct crypto_alg alg;
63858 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63859 index fad21c9..3fff955 100644
63860 --- a/include/drm/drmP.h
63861 +++ b/include/drm/drmP.h
63862 @@ -72,6 +72,7 @@
63863 #include <linux/workqueue.h>
63864 #include <linux/poll.h>
63865 #include <asm/pgalloc.h>
63866 +#include <asm/local.h>
63867 #include <drm/drm.h>
63868 #include <drm/drm_sarea.h>
63869
63870 @@ -1068,7 +1069,7 @@ struct drm_device {
63871
63872 /** \name Usage Counters */
63873 /*@{ */
63874 - int open_count; /**< Outstanding files open */
63875 + local_t open_count; /**< Outstanding files open */
63876 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63877 atomic_t vma_count; /**< Outstanding vma areas open */
63878 int buf_use; /**< Buffers in use -- cannot alloc */
63879 @@ -1079,7 +1080,7 @@ struct drm_device {
63880 /*@{ */
63881 unsigned long counters;
63882 enum drm_stat_type types[15];
63883 - atomic_t counts[15];
63884 + atomic_unchecked_t counts[15];
63885 /*@} */
63886
63887 struct list_head filelist;
63888 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63889 index f43d556..94d9343 100644
63890 --- a/include/drm/drm_crtc_helper.h
63891 +++ b/include/drm/drm_crtc_helper.h
63892 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63893 struct drm_connector *connector);
63894 /* disable encoder when not in use - more explicit than dpms off */
63895 void (*disable)(struct drm_encoder *encoder);
63896 -};
63897 +} __no_const;
63898
63899 /**
63900 * drm_connector_helper_funcs - helper operations for connectors
63901 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63902 index 72dcbe8..8db58d7 100644
63903 --- a/include/drm/ttm/ttm_memory.h
63904 +++ b/include/drm/ttm/ttm_memory.h
63905 @@ -48,7 +48,7 @@
63906
63907 struct ttm_mem_shrink {
63908 int (*do_shrink) (struct ttm_mem_shrink *);
63909 -};
63910 +} __no_const;
63911
63912 /**
63913 * struct ttm_mem_global - Global memory accounting structure.
63914 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63915 index c1da539..4db35ec 100644
63916 --- a/include/linux/atmdev.h
63917 +++ b/include/linux/atmdev.h
63918 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63919 #endif
63920
63921 struct k_atm_aal_stats {
63922 -#define __HANDLE_ITEM(i) atomic_t i
63923 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63924 __AAL_STAT_ITEMS
63925 #undef __HANDLE_ITEM
63926 };
63927 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63928 index 0530b98..b127a9e 100644
63929 --- a/include/linux/binfmts.h
63930 +++ b/include/linux/binfmts.h
63931 @@ -73,6 +73,7 @@ struct linux_binfmt {
63932 int (*load_binary)(struct linux_binprm *);
63933 int (*load_shlib)(struct file *);
63934 int (*core_dump)(struct coredump_params *cprm);
63935 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63936 unsigned long min_coredump; /* minimal dump size */
63937 };
63938
63939 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63940 index f94bc83..62b9cfe 100644
63941 --- a/include/linux/blkdev.h
63942 +++ b/include/linux/blkdev.h
63943 @@ -1498,7 +1498,7 @@ struct block_device_operations {
63944 /* this callback is with swap_lock and sometimes page table lock held */
63945 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63946 struct module *owner;
63947 -};
63948 +} __do_const;
63949
63950 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63951 unsigned long);
63952 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63953 index 7c2e030..b72475d 100644
63954 --- a/include/linux/blktrace_api.h
63955 +++ b/include/linux/blktrace_api.h
63956 @@ -23,7 +23,7 @@ struct blk_trace {
63957 struct dentry *dir;
63958 struct dentry *dropped_file;
63959 struct dentry *msg_file;
63960 - atomic_t dropped;
63961 + atomic_unchecked_t dropped;
63962 };
63963
63964 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63965 diff --git a/include/linux/cache.h b/include/linux/cache.h
63966 index 4c57065..4307975 100644
63967 --- a/include/linux/cache.h
63968 +++ b/include/linux/cache.h
63969 @@ -16,6 +16,10 @@
63970 #define __read_mostly
63971 #endif
63972
63973 +#ifndef __read_only
63974 +#define __read_only __read_mostly
63975 +#endif
63976 +
63977 #ifndef ____cacheline_aligned
63978 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63979 #endif
63980 diff --git a/include/linux/capability.h b/include/linux/capability.h
63981 index 98503b7..cc36d18 100644
63982 --- a/include/linux/capability.h
63983 +++ b/include/linux/capability.h
63984 @@ -211,8 +211,13 @@ extern bool capable(int cap);
63985 extern bool ns_capable(struct user_namespace *ns, int cap);
63986 extern bool nsown_capable(int cap);
63987 extern bool inode_capable(const struct inode *inode, int cap);
63988 +extern bool capable_nolog(int cap);
63989 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63990 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
63991
63992 /* audit system wants to get cap info from files as well */
63993 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63994
63995 +extern int is_privileged_binary(const struct dentry *dentry);
63996 +
63997 #endif /* !_LINUX_CAPABILITY_H */
63998 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63999 index 8609d57..86e4d79 100644
64000 --- a/include/linux/cdrom.h
64001 +++ b/include/linux/cdrom.h
64002 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
64003
64004 /* driver specifications */
64005 const int capability; /* capability flags */
64006 - int n_minors; /* number of active minor devices */
64007 /* handle uniform packets for scsi type devices (scsi,atapi) */
64008 int (*generic_packet) (struct cdrom_device_info *,
64009 struct packet_command *);
64010 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
64011 index 42e55de..1cd0e66 100644
64012 --- a/include/linux/cleancache.h
64013 +++ b/include/linux/cleancache.h
64014 @@ -31,7 +31,7 @@ struct cleancache_ops {
64015 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
64016 void (*invalidate_inode)(int, struct cleancache_filekey);
64017 void (*invalidate_fs)(int);
64018 -};
64019 +} __no_const;
64020
64021 extern struct cleancache_ops
64022 cleancache_register_ops(struct cleancache_ops *ops);
64023 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
64024 index 662fd1b..e801992 100644
64025 --- a/include/linux/compiler-gcc4.h
64026 +++ b/include/linux/compiler-gcc4.h
64027 @@ -34,6 +34,21 @@
64028 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
64029
64030 #if __GNUC_MINOR__ >= 5
64031 +
64032 +#ifdef CONSTIFY_PLUGIN
64033 +#define __no_const __attribute__((no_const))
64034 +#define __do_const __attribute__((do_const))
64035 +#endif
64036 +
64037 +#ifdef SIZE_OVERFLOW_PLUGIN
64038 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
64039 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
64040 +#endif
64041 +
64042 +#ifdef LATENT_ENTROPY_PLUGIN
64043 +#define __latent_entropy __attribute__((latent_entropy))
64044 +#endif
64045 +
64046 /*
64047 * Mark a position in code as unreachable. This can be used to
64048 * suppress control flow warnings after asm blocks that transfer
64049 @@ -49,6 +64,11 @@
64050 #define __noclone __attribute__((__noclone__))
64051
64052 #endif
64053 +
64054 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
64055 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
64056 +#define __bos0(ptr) __bos((ptr), 0)
64057 +#define __bos1(ptr) __bos((ptr), 1)
64058 #endif
64059
64060 #if __GNUC_MINOR__ >= 6
64061 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
64062 index dd852b7..72924c0 100644
64063 --- a/include/linux/compiler.h
64064 +++ b/include/linux/compiler.h
64065 @@ -5,11 +5,14 @@
64066
64067 #ifdef __CHECKER__
64068 # define __user __attribute__((noderef, address_space(1)))
64069 +# define __force_user __force __user
64070 # define __kernel __attribute__((address_space(0)))
64071 +# define __force_kernel __force __kernel
64072 # define __safe __attribute__((safe))
64073 # define __force __attribute__((force))
64074 # define __nocast __attribute__((nocast))
64075 # define __iomem __attribute__((noderef, address_space(2)))
64076 +# define __force_iomem __force __iomem
64077 # define __must_hold(x) __attribute__((context(x,1,1)))
64078 # define __acquires(x) __attribute__((context(x,0,1)))
64079 # define __releases(x) __attribute__((context(x,1,0)))
64080 @@ -17,20 +20,48 @@
64081 # define __release(x) __context__(x,-1)
64082 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
64083 # define __percpu __attribute__((noderef, address_space(3)))
64084 +# define __force_percpu __force __percpu
64085 #ifdef CONFIG_SPARSE_RCU_POINTER
64086 # define __rcu __attribute__((noderef, address_space(4)))
64087 +# define __force_rcu __force __rcu
64088 #else
64089 # define __rcu
64090 +# define __force_rcu
64091 #endif
64092 extern void __chk_user_ptr(const volatile void __user *);
64093 extern void __chk_io_ptr(const volatile void __iomem *);
64094 +#elif defined(CHECKER_PLUGIN)
64095 +//# define __user
64096 +//# define __force_user
64097 +//# define __kernel
64098 +//# define __force_kernel
64099 +# define __safe
64100 +# define __force
64101 +# define __nocast
64102 +# define __iomem
64103 +# define __force_iomem
64104 +# define __chk_user_ptr(x) (void)0
64105 +# define __chk_io_ptr(x) (void)0
64106 +# define __builtin_warning(x, y...) (1)
64107 +# define __acquires(x)
64108 +# define __releases(x)
64109 +# define __acquire(x) (void)0
64110 +# define __release(x) (void)0
64111 +# define __cond_lock(x,c) (c)
64112 +# define __percpu
64113 +# define __force_percpu
64114 +# define __rcu
64115 +# define __force_rcu
64116 #else
64117 # define __user
64118 +# define __force_user
64119 # define __kernel
64120 +# define __force_kernel
64121 # define __safe
64122 # define __force
64123 # define __nocast
64124 # define __iomem
64125 +# define __force_iomem
64126 # define __chk_user_ptr(x) (void)0
64127 # define __chk_io_ptr(x) (void)0
64128 # define __builtin_warning(x, y...) (1)
64129 @@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
64130 # define __release(x) (void)0
64131 # define __cond_lock(x,c) (c)
64132 # define __percpu
64133 +# define __force_percpu
64134 # define __rcu
64135 +# define __force_rcu
64136 #endif
64137
64138 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
64139 @@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64140 # define __attribute_const__ /* unimplemented */
64141 #endif
64142
64143 +#ifndef __no_const
64144 +# define __no_const
64145 +#endif
64146 +
64147 +#ifndef __do_const
64148 +# define __do_const
64149 +#endif
64150 +
64151 +#ifndef __size_overflow
64152 +# define __size_overflow(...)
64153 +#endif
64154 +
64155 +#ifndef __intentional_overflow
64156 +# define __intentional_overflow(...)
64157 +#endif
64158 +
64159 +#ifndef __latent_entropy
64160 +# define __latent_entropy
64161 +#endif
64162 +
64163 /*
64164 * Tell gcc if a function is cold. The compiler will assume any path
64165 * directly leading to the call is unlikely.
64166 @@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64167 #define __cold
64168 #endif
64169
64170 +#ifndef __alloc_size
64171 +#define __alloc_size(...)
64172 +#endif
64173 +
64174 +#ifndef __bos
64175 +#define __bos(ptr, arg)
64176 +#endif
64177 +
64178 +#ifndef __bos0
64179 +#define __bos0(ptr)
64180 +#endif
64181 +
64182 +#ifndef __bos1
64183 +#define __bos1(ptr)
64184 +#endif
64185 +
64186 /* Simple shorthand for a section definition */
64187 #ifndef __section
64188 # define __section(S) __attribute__ ((__section__(#S)))
64189 @@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64190 * use is to mediate communication between process-level code and irq/NMI
64191 * handlers, all running on the same CPU.
64192 */
64193 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
64194 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
64195 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
64196
64197 #endif /* __LINUX_COMPILER_H */
64198 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
64199 index ce7a074..01ab8ac 100644
64200 --- a/include/linux/cpu.h
64201 +++ b/include/linux/cpu.h
64202 @@ -115,7 +115,7 @@ enum {
64203 /* Need to know about CPUs going up/down? */
64204 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
64205 #define cpu_notifier(fn, pri) { \
64206 - static struct notifier_block fn##_nb __cpuinitdata = \
64207 + static struct notifier_block fn##_nb = \
64208 { .notifier_call = fn, .priority = pri }; \
64209 register_cpu_notifier(&fn##_nb); \
64210 }
64211 diff --git a/include/linux/cred.h b/include/linux/cred.h
64212 index 04421e8..6bce4ef 100644
64213 --- a/include/linux/cred.h
64214 +++ b/include/linux/cred.h
64215 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
64216 static inline void validate_process_creds(void)
64217 {
64218 }
64219 +static inline void validate_task_creds(struct task_struct *task)
64220 +{
64221 +}
64222 #endif
64223
64224 /**
64225 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
64226 index b92eadf..b4ecdc1 100644
64227 --- a/include/linux/crypto.h
64228 +++ b/include/linux/crypto.h
64229 @@ -373,7 +373,7 @@ struct cipher_tfm {
64230 const u8 *key, unsigned int keylen);
64231 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64232 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64233 -};
64234 +} __no_const;
64235
64236 struct hash_tfm {
64237 int (*init)(struct hash_desc *desc);
64238 @@ -394,13 +394,13 @@ struct compress_tfm {
64239 int (*cot_decompress)(struct crypto_tfm *tfm,
64240 const u8 *src, unsigned int slen,
64241 u8 *dst, unsigned int *dlen);
64242 -};
64243 +} __no_const;
64244
64245 struct rng_tfm {
64246 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
64247 unsigned int dlen);
64248 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
64249 -};
64250 +} __no_const;
64251
64252 #define crt_ablkcipher crt_u.ablkcipher
64253 #define crt_aead crt_u.aead
64254 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
64255 index 7925bf0..d5143d2 100644
64256 --- a/include/linux/decompress/mm.h
64257 +++ b/include/linux/decompress/mm.h
64258 @@ -77,7 +77,7 @@ static void free(void *where)
64259 * warnings when not needed (indeed large_malloc / large_free are not
64260 * needed by inflate */
64261
64262 -#define malloc(a) kmalloc(a, GFP_KERNEL)
64263 +#define malloc(a) kmalloc((a), GFP_KERNEL)
64264 #define free(a) kfree(a)
64265
64266 #define large_malloc(a) vmalloc(a)
64267 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
64268 index 94af418..b1ca7a2 100644
64269 --- a/include/linux/dma-mapping.h
64270 +++ b/include/linux/dma-mapping.h
64271 @@ -54,7 +54,7 @@ struct dma_map_ops {
64272 u64 (*get_required_mask)(struct device *dev);
64273 #endif
64274 int is_phys;
64275 -};
64276 +} __do_const;
64277
64278 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
64279
64280 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
64281 index d3201e4..8281e63 100644
64282 --- a/include/linux/dmaengine.h
64283 +++ b/include/linux/dmaengine.h
64284 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
64285 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
64286 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
64287
64288 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64289 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64290 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
64291 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64292 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64293 struct dma_pinned_list *pinned_list, struct page *page,
64294 unsigned int offset, size_t len);
64295
64296 diff --git a/include/linux/efi.h b/include/linux/efi.h
64297 index 7a9498a..155713d 100644
64298 --- a/include/linux/efi.h
64299 +++ b/include/linux/efi.h
64300 @@ -733,6 +733,7 @@ struct efivar_operations {
64301 efi_set_variable_t *set_variable;
64302 efi_query_variable_info_t *query_variable_info;
64303 };
64304 +typedef struct efivar_operations __no_const efivar_operations_no_const;
64305
64306 struct efivars {
64307 /*
64308 diff --git a/include/linux/elf.h b/include/linux/elf.h
64309 index 8c9048e..16a4665 100644
64310 --- a/include/linux/elf.h
64311 +++ b/include/linux/elf.h
64312 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
64313 #define elf_note elf32_note
64314 #define elf_addr_t Elf32_Off
64315 #define Elf_Half Elf32_Half
64316 +#define elf_dyn Elf32_Dyn
64317
64318 #else
64319
64320 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
64321 #define elf_note elf64_note
64322 #define elf_addr_t Elf64_Off
64323 #define Elf_Half Elf64_Half
64324 +#define elf_dyn Elf64_Dyn
64325
64326 #endif
64327
64328 diff --git a/include/linux/filter.h b/include/linux/filter.h
64329 index c45eabc..baa0be5 100644
64330 --- a/include/linux/filter.h
64331 +++ b/include/linux/filter.h
64332 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
64333
64334 struct sk_buff;
64335 struct sock;
64336 +struct bpf_jit_work;
64337
64338 struct sk_filter
64339 {
64340 @@ -27,6 +28,9 @@ struct sk_filter
64341 unsigned int len; /* Number of filter blocks */
64342 unsigned int (*bpf_func)(const struct sk_buff *skb,
64343 const struct sock_filter *filter);
64344 +#ifdef CONFIG_BPF_JIT
64345 + struct bpf_jit_work *work;
64346 +#endif
64347 struct rcu_head rcu;
64348 struct sock_filter insns[0];
64349 };
64350 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
64351 index 3044254..9767f41 100644
64352 --- a/include/linux/frontswap.h
64353 +++ b/include/linux/frontswap.h
64354 @@ -11,7 +11,7 @@ struct frontswap_ops {
64355 int (*load)(unsigned, pgoff_t, struct page *);
64356 void (*invalidate_page)(unsigned, pgoff_t);
64357 void (*invalidate_area)(unsigned);
64358 -};
64359 +} __no_const;
64360
64361 extern bool frontswap_enabled;
64362 extern struct frontswap_ops
64363 diff --git a/include/linux/fs.h b/include/linux/fs.h
64364 index 7617ee0..b575199 100644
64365 --- a/include/linux/fs.h
64366 +++ b/include/linux/fs.h
64367 @@ -1541,7 +1541,8 @@ struct file_operations {
64368 long (*fallocate)(struct file *file, int mode, loff_t offset,
64369 loff_t len);
64370 int (*show_fdinfo)(struct seq_file *m, struct file *f);
64371 -};
64372 +} __do_const;
64373 +typedef struct file_operations __no_const file_operations_no_const;
64374
64375 struct inode_operations {
64376 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
64377 @@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
64378 inode->i_flags |= S_NOSEC;
64379 }
64380
64381 +static inline bool is_sidechannel_device(const struct inode *inode)
64382 +{
64383 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
64384 + umode_t mode = inode->i_mode;
64385 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
64386 +#else
64387 + return false;
64388 +#endif
64389 +}
64390 +
64391 #endif /* _LINUX_FS_H */
64392 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
64393 index d0ae3a8..0244b34 100644
64394 --- a/include/linux/fs_struct.h
64395 +++ b/include/linux/fs_struct.h
64396 @@ -6,7 +6,7 @@
64397 #include <linux/seqlock.h>
64398
64399 struct fs_struct {
64400 - int users;
64401 + atomic_t users;
64402 spinlock_t lock;
64403 seqcount_t seq;
64404 int umask;
64405 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
64406 index 5dfa0aa..6acf322 100644
64407 --- a/include/linux/fscache-cache.h
64408 +++ b/include/linux/fscache-cache.h
64409 @@ -112,7 +112,7 @@ struct fscache_operation {
64410 fscache_operation_release_t release;
64411 };
64412
64413 -extern atomic_t fscache_op_debug_id;
64414 +extern atomic_unchecked_t fscache_op_debug_id;
64415 extern void fscache_op_work_func(struct work_struct *work);
64416
64417 extern void fscache_enqueue_operation(struct fscache_operation *);
64418 @@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
64419 INIT_WORK(&op->work, fscache_op_work_func);
64420 atomic_set(&op->usage, 1);
64421 op->state = FSCACHE_OP_ST_INITIALISED;
64422 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
64423 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64424 op->processor = processor;
64425 op->release = release;
64426 INIT_LIST_HEAD(&op->pend_link);
64427 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
64428 index 0fbfb46..508eb0d 100644
64429 --- a/include/linux/fsnotify.h
64430 +++ b/include/linux/fsnotify.h
64431 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
64432 struct inode *inode = path->dentry->d_inode;
64433 __u32 mask = FS_ACCESS;
64434
64435 + if (is_sidechannel_device(inode))
64436 + return;
64437 +
64438 if (S_ISDIR(inode->i_mode))
64439 mask |= FS_ISDIR;
64440
64441 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
64442 struct inode *inode = path->dentry->d_inode;
64443 __u32 mask = FS_MODIFY;
64444
64445 + if (is_sidechannel_device(inode))
64446 + return;
64447 +
64448 if (S_ISDIR(inode->i_mode))
64449 mask |= FS_ISDIR;
64450
64451 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
64452 */
64453 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
64454 {
64455 - return kstrdup(name, GFP_KERNEL);
64456 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
64457 }
64458
64459 /*
64460 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
64461 index a3d4895..ddd2a50 100644
64462 --- a/include/linux/ftrace_event.h
64463 +++ b/include/linux/ftrace_event.h
64464 @@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
64465 extern int trace_add_event_call(struct ftrace_event_call *call);
64466 extern void trace_remove_event_call(struct ftrace_event_call *call);
64467
64468 -#define is_signed_type(type) (((type)(-1)) < 0)
64469 +#define is_signed_type(type) (((type)(-1)) < (type)1)
64470
64471 int trace_set_clr_event(const char *system, const char *event, int set);
64472
64473 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
64474 index 79b8bba..86b539e 100644
64475 --- a/include/linux/genhd.h
64476 +++ b/include/linux/genhd.h
64477 @@ -194,7 +194,7 @@ struct gendisk {
64478 struct kobject *slave_dir;
64479
64480 struct timer_rand_state *random;
64481 - atomic_t sync_io; /* RAID */
64482 + atomic_unchecked_t sync_io; /* RAID */
64483 struct disk_events *ev;
64484 #ifdef CONFIG_BLK_DEV_INTEGRITY
64485 struct blk_integrity *integrity;
64486 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
64487 index 0f615eb..5c3832f 100644
64488 --- a/include/linux/gfp.h
64489 +++ b/include/linux/gfp.h
64490 @@ -35,6 +35,13 @@ struct vm_area_struct;
64491 #define ___GFP_NO_KSWAPD 0x400000u
64492 #define ___GFP_OTHER_NODE 0x800000u
64493 #define ___GFP_WRITE 0x1000000u
64494 +
64495 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64496 +#define ___GFP_USERCOPY 0x2000000u
64497 +#else
64498 +#define ___GFP_USERCOPY 0
64499 +#endif
64500 +
64501 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
64502
64503 /*
64504 @@ -92,6 +99,7 @@ struct vm_area_struct;
64505 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
64506 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
64507 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
64508 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
64509
64510 /*
64511 * This may seem redundant, but it's a way of annotating false positives vs.
64512 @@ -99,7 +107,7 @@ struct vm_area_struct;
64513 */
64514 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
64515
64516 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
64517 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
64518 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
64519
64520 /* This equals 0, but use constants in case they ever change */
64521 @@ -153,6 +161,8 @@ struct vm_area_struct;
64522 /* 4GB DMA on some platforms */
64523 #define GFP_DMA32 __GFP_DMA32
64524
64525 +#define GFP_USERCOPY __GFP_USERCOPY
64526 +
64527 /* Convert GFP flags to their corresponding migrate type */
64528 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
64529 {
64530 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
64531 new file mode 100644
64532 index 0000000..ebe6d72
64533 --- /dev/null
64534 +++ b/include/linux/gracl.h
64535 @@ -0,0 +1,319 @@
64536 +#ifndef GR_ACL_H
64537 +#define GR_ACL_H
64538 +
64539 +#include <linux/grdefs.h>
64540 +#include <linux/resource.h>
64541 +#include <linux/capability.h>
64542 +#include <linux/dcache.h>
64543 +#include <asm/resource.h>
64544 +
64545 +/* Major status information */
64546 +
64547 +#define GR_VERSION "grsecurity 2.9.1"
64548 +#define GRSECURITY_VERSION 0x2901
64549 +
64550 +enum {
64551 + GR_SHUTDOWN = 0,
64552 + GR_ENABLE = 1,
64553 + GR_SPROLE = 2,
64554 + GR_RELOAD = 3,
64555 + GR_SEGVMOD = 4,
64556 + GR_STATUS = 5,
64557 + GR_UNSPROLE = 6,
64558 + GR_PASSSET = 7,
64559 + GR_SPROLEPAM = 8,
64560 +};
64561 +
64562 +/* Password setup definitions
64563 + * kernel/grhash.c */
64564 +enum {
64565 + GR_PW_LEN = 128,
64566 + GR_SALT_LEN = 16,
64567 + GR_SHA_LEN = 32,
64568 +};
64569 +
64570 +enum {
64571 + GR_SPROLE_LEN = 64,
64572 +};
64573 +
64574 +enum {
64575 + GR_NO_GLOB = 0,
64576 + GR_REG_GLOB,
64577 + GR_CREATE_GLOB
64578 +};
64579 +
64580 +#define GR_NLIMITS 32
64581 +
64582 +/* Begin Data Structures */
64583 +
64584 +struct sprole_pw {
64585 + unsigned char *rolename;
64586 + unsigned char salt[GR_SALT_LEN];
64587 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
64588 +};
64589 +
64590 +struct name_entry {
64591 + __u32 key;
64592 + ino_t inode;
64593 + dev_t device;
64594 + char *name;
64595 + __u16 len;
64596 + __u8 deleted;
64597 + struct name_entry *prev;
64598 + struct name_entry *next;
64599 +};
64600 +
64601 +struct inodev_entry {
64602 + struct name_entry *nentry;
64603 + struct inodev_entry *prev;
64604 + struct inodev_entry *next;
64605 +};
64606 +
64607 +struct acl_role_db {
64608 + struct acl_role_label **r_hash;
64609 + __u32 r_size;
64610 +};
64611 +
64612 +struct inodev_db {
64613 + struct inodev_entry **i_hash;
64614 + __u32 i_size;
64615 +};
64616 +
64617 +struct name_db {
64618 + struct name_entry **n_hash;
64619 + __u32 n_size;
64620 +};
64621 +
64622 +struct crash_uid {
64623 + uid_t uid;
64624 + unsigned long expires;
64625 +};
64626 +
64627 +struct gr_hash_struct {
64628 + void **table;
64629 + void **nametable;
64630 + void *first;
64631 + __u32 table_size;
64632 + __u32 used_size;
64633 + int type;
64634 +};
64635 +
64636 +/* Userspace Grsecurity ACL data structures */
64637 +
64638 +struct acl_subject_label {
64639 + char *filename;
64640 + ino_t inode;
64641 + dev_t device;
64642 + __u32 mode;
64643 + kernel_cap_t cap_mask;
64644 + kernel_cap_t cap_lower;
64645 + kernel_cap_t cap_invert_audit;
64646 +
64647 + struct rlimit res[GR_NLIMITS];
64648 + __u32 resmask;
64649 +
64650 + __u8 user_trans_type;
64651 + __u8 group_trans_type;
64652 + uid_t *user_transitions;
64653 + gid_t *group_transitions;
64654 + __u16 user_trans_num;
64655 + __u16 group_trans_num;
64656 +
64657 + __u32 sock_families[2];
64658 + __u32 ip_proto[8];
64659 + __u32 ip_type;
64660 + struct acl_ip_label **ips;
64661 + __u32 ip_num;
64662 + __u32 inaddr_any_override;
64663 +
64664 + __u32 crashes;
64665 + unsigned long expires;
64666 +
64667 + struct acl_subject_label *parent_subject;
64668 + struct gr_hash_struct *hash;
64669 + struct acl_subject_label *prev;
64670 + struct acl_subject_label *next;
64671 +
64672 + struct acl_object_label **obj_hash;
64673 + __u32 obj_hash_size;
64674 + __u16 pax_flags;
64675 +};
64676 +
64677 +struct role_allowed_ip {
64678 + __u32 addr;
64679 + __u32 netmask;
64680 +
64681 + struct role_allowed_ip *prev;
64682 + struct role_allowed_ip *next;
64683 +};
64684 +
64685 +struct role_transition {
64686 + char *rolename;
64687 +
64688 + struct role_transition *prev;
64689 + struct role_transition *next;
64690 +};
64691 +
64692 +struct acl_role_label {
64693 + char *rolename;
64694 + uid_t uidgid;
64695 + __u16 roletype;
64696 +
64697 + __u16 auth_attempts;
64698 + unsigned long expires;
64699 +
64700 + struct acl_subject_label *root_label;
64701 + struct gr_hash_struct *hash;
64702 +
64703 + struct acl_role_label *prev;
64704 + struct acl_role_label *next;
64705 +
64706 + struct role_transition *transitions;
64707 + struct role_allowed_ip *allowed_ips;
64708 + uid_t *domain_children;
64709 + __u16 domain_child_num;
64710 +
64711 + umode_t umask;
64712 +
64713 + struct acl_subject_label **subj_hash;
64714 + __u32 subj_hash_size;
64715 +};
64716 +
64717 +struct user_acl_role_db {
64718 + struct acl_role_label **r_table;
64719 + __u32 num_pointers; /* Number of allocations to track */
64720 + __u32 num_roles; /* Number of roles */
64721 + __u32 num_domain_children; /* Number of domain children */
64722 + __u32 num_subjects; /* Number of subjects */
64723 + __u32 num_objects; /* Number of objects */
64724 +};
64725 +
64726 +struct acl_object_label {
64727 + char *filename;
64728 + ino_t inode;
64729 + dev_t device;
64730 + __u32 mode;
64731 +
64732 + struct acl_subject_label *nested;
64733 + struct acl_object_label *globbed;
64734 +
64735 + /* next two structures not used */
64736 +
64737 + struct acl_object_label *prev;
64738 + struct acl_object_label *next;
64739 +};
64740 +
64741 +struct acl_ip_label {
64742 + char *iface;
64743 + __u32 addr;
64744 + __u32 netmask;
64745 + __u16 low, high;
64746 + __u8 mode;
64747 + __u32 type;
64748 + __u32 proto[8];
64749 +
64750 + /* next two structures not used */
64751 +
64752 + struct acl_ip_label *prev;
64753 + struct acl_ip_label *next;
64754 +};
64755 +
64756 +struct gr_arg {
64757 + struct user_acl_role_db role_db;
64758 + unsigned char pw[GR_PW_LEN];
64759 + unsigned char salt[GR_SALT_LEN];
64760 + unsigned char sum[GR_SHA_LEN];
64761 + unsigned char sp_role[GR_SPROLE_LEN];
64762 + struct sprole_pw *sprole_pws;
64763 + dev_t segv_device;
64764 + ino_t segv_inode;
64765 + uid_t segv_uid;
64766 + __u16 num_sprole_pws;
64767 + __u16 mode;
64768 +};
64769 +
64770 +struct gr_arg_wrapper {
64771 + struct gr_arg *arg;
64772 + __u32 version;
64773 + __u32 size;
64774 +};
64775 +
64776 +struct subject_map {
64777 + struct acl_subject_label *user;
64778 + struct acl_subject_label *kernel;
64779 + struct subject_map *prev;
64780 + struct subject_map *next;
64781 +};
64782 +
64783 +struct acl_subj_map_db {
64784 + struct subject_map **s_hash;
64785 + __u32 s_size;
64786 +};
64787 +
64788 +/* End Data Structures Section */
64789 +
64790 +/* Hash functions generated by empirical testing by Brad Spengler
64791 + Makes good use of the low bits of the inode. Generally 0-1 times
64792 + in loop for successful match. 0-3 for unsuccessful match.
64793 + Shift/add algorithm with modulus of table size and an XOR*/
64794 +
64795 +static __inline__ unsigned int
64796 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
64797 +{
64798 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
64799 +}
64800 +
64801 + static __inline__ unsigned int
64802 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64803 +{
64804 + return ((const unsigned long)userp % sz);
64805 +}
64806 +
64807 +static __inline__ unsigned int
64808 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64809 +{
64810 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64811 +}
64812 +
64813 +static __inline__ unsigned int
64814 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64815 +{
64816 + return full_name_hash((const unsigned char *)name, len) % sz;
64817 +}
64818 +
64819 +#define FOR_EACH_ROLE_START(role) \
64820 + role = role_list; \
64821 + while (role) {
64822 +
64823 +#define FOR_EACH_ROLE_END(role) \
64824 + role = role->prev; \
64825 + }
64826 +
64827 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64828 + subj = NULL; \
64829 + iter = 0; \
64830 + while (iter < role->subj_hash_size) { \
64831 + if (subj == NULL) \
64832 + subj = role->subj_hash[iter]; \
64833 + if (subj == NULL) { \
64834 + iter++; \
64835 + continue; \
64836 + }
64837 +
64838 +#define FOR_EACH_SUBJECT_END(subj,iter) \
64839 + subj = subj->next; \
64840 + if (subj == NULL) \
64841 + iter++; \
64842 + }
64843 +
64844 +
64845 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64846 + subj = role->hash->first; \
64847 + while (subj != NULL) {
64848 +
64849 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64850 + subj = subj->next; \
64851 + }
64852 +
64853 +#endif
64854 +
64855 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64856 new file mode 100644
64857 index 0000000..323ecf2
64858 --- /dev/null
64859 +++ b/include/linux/gralloc.h
64860 @@ -0,0 +1,9 @@
64861 +#ifndef __GRALLOC_H
64862 +#define __GRALLOC_H
64863 +
64864 +void acl_free_all(void);
64865 +int acl_alloc_stack_init(unsigned long size);
64866 +void *acl_alloc(unsigned long len);
64867 +void *acl_alloc_num(unsigned long num, unsigned long len);
64868 +
64869 +#endif
64870 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64871 new file mode 100644
64872 index 0000000..be66033
64873 --- /dev/null
64874 +++ b/include/linux/grdefs.h
64875 @@ -0,0 +1,140 @@
64876 +#ifndef GRDEFS_H
64877 +#define GRDEFS_H
64878 +
64879 +/* Begin grsecurity status declarations */
64880 +
64881 +enum {
64882 + GR_READY = 0x01,
64883 + GR_STATUS_INIT = 0x00 // disabled state
64884 +};
64885 +
64886 +/* Begin ACL declarations */
64887 +
64888 +/* Role flags */
64889 +
64890 +enum {
64891 + GR_ROLE_USER = 0x0001,
64892 + GR_ROLE_GROUP = 0x0002,
64893 + GR_ROLE_DEFAULT = 0x0004,
64894 + GR_ROLE_SPECIAL = 0x0008,
64895 + GR_ROLE_AUTH = 0x0010,
64896 + GR_ROLE_NOPW = 0x0020,
64897 + GR_ROLE_GOD = 0x0040,
64898 + GR_ROLE_LEARN = 0x0080,
64899 + GR_ROLE_TPE = 0x0100,
64900 + GR_ROLE_DOMAIN = 0x0200,
64901 + GR_ROLE_PAM = 0x0400,
64902 + GR_ROLE_PERSIST = 0x0800
64903 +};
64904 +
64905 +/* ACL Subject and Object mode flags */
64906 +enum {
64907 + GR_DELETED = 0x80000000
64908 +};
64909 +
64910 +/* ACL Object-only mode flags */
64911 +enum {
64912 + GR_READ = 0x00000001,
64913 + GR_APPEND = 0x00000002,
64914 + GR_WRITE = 0x00000004,
64915 + GR_EXEC = 0x00000008,
64916 + GR_FIND = 0x00000010,
64917 + GR_INHERIT = 0x00000020,
64918 + GR_SETID = 0x00000040,
64919 + GR_CREATE = 0x00000080,
64920 + GR_DELETE = 0x00000100,
64921 + GR_LINK = 0x00000200,
64922 + GR_AUDIT_READ = 0x00000400,
64923 + GR_AUDIT_APPEND = 0x00000800,
64924 + GR_AUDIT_WRITE = 0x00001000,
64925 + GR_AUDIT_EXEC = 0x00002000,
64926 + GR_AUDIT_FIND = 0x00004000,
64927 + GR_AUDIT_INHERIT= 0x00008000,
64928 + GR_AUDIT_SETID = 0x00010000,
64929 + GR_AUDIT_CREATE = 0x00020000,
64930 + GR_AUDIT_DELETE = 0x00040000,
64931 + GR_AUDIT_LINK = 0x00080000,
64932 + GR_PTRACERD = 0x00100000,
64933 + GR_NOPTRACE = 0x00200000,
64934 + GR_SUPPRESS = 0x00400000,
64935 + GR_NOLEARN = 0x00800000,
64936 + GR_INIT_TRANSFER= 0x01000000
64937 +};
64938 +
64939 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64940 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64941 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64942 +
64943 +/* ACL subject-only mode flags */
64944 +enum {
64945 + GR_KILL = 0x00000001,
64946 + GR_VIEW = 0x00000002,
64947 + GR_PROTECTED = 0x00000004,
64948 + GR_LEARN = 0x00000008,
64949 + GR_OVERRIDE = 0x00000010,
64950 + /* just a placeholder, this mode is only used in userspace */
64951 + GR_DUMMY = 0x00000020,
64952 + GR_PROTSHM = 0x00000040,
64953 + GR_KILLPROC = 0x00000080,
64954 + GR_KILLIPPROC = 0x00000100,
64955 + /* just a placeholder, this mode is only used in userspace */
64956 + GR_NOTROJAN = 0x00000200,
64957 + GR_PROTPROCFD = 0x00000400,
64958 + GR_PROCACCT = 0x00000800,
64959 + GR_RELAXPTRACE = 0x00001000,
64960 + //GR_NESTED = 0x00002000,
64961 + GR_INHERITLEARN = 0x00004000,
64962 + GR_PROCFIND = 0x00008000,
64963 + GR_POVERRIDE = 0x00010000,
64964 + GR_KERNELAUTH = 0x00020000,
64965 + GR_ATSECURE = 0x00040000,
64966 + GR_SHMEXEC = 0x00080000
64967 +};
64968 +
64969 +enum {
64970 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64971 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64972 + GR_PAX_ENABLE_MPROTECT = 0x0004,
64973 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
64974 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64975 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64976 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64977 + GR_PAX_DISABLE_MPROTECT = 0x0400,
64978 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
64979 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64980 +};
64981 +
64982 +enum {
64983 + GR_ID_USER = 0x01,
64984 + GR_ID_GROUP = 0x02,
64985 +};
64986 +
64987 +enum {
64988 + GR_ID_ALLOW = 0x01,
64989 + GR_ID_DENY = 0x02,
64990 +};
64991 +
64992 +#define GR_CRASH_RES 31
64993 +#define GR_UIDTABLE_MAX 500
64994 +
64995 +/* begin resource learning section */
64996 +enum {
64997 + GR_RLIM_CPU_BUMP = 60,
64998 + GR_RLIM_FSIZE_BUMP = 50000,
64999 + GR_RLIM_DATA_BUMP = 10000,
65000 + GR_RLIM_STACK_BUMP = 1000,
65001 + GR_RLIM_CORE_BUMP = 10000,
65002 + GR_RLIM_RSS_BUMP = 500000,
65003 + GR_RLIM_NPROC_BUMP = 1,
65004 + GR_RLIM_NOFILE_BUMP = 5,
65005 + GR_RLIM_MEMLOCK_BUMP = 50000,
65006 + GR_RLIM_AS_BUMP = 500000,
65007 + GR_RLIM_LOCKS_BUMP = 2,
65008 + GR_RLIM_SIGPENDING_BUMP = 5,
65009 + GR_RLIM_MSGQUEUE_BUMP = 10000,
65010 + GR_RLIM_NICE_BUMP = 1,
65011 + GR_RLIM_RTPRIO_BUMP = 1,
65012 + GR_RLIM_RTTIME_BUMP = 1000000
65013 +};
65014 +
65015 +#endif
65016 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
65017 new file mode 100644
65018 index 0000000..baa6e96
65019 --- /dev/null
65020 +++ b/include/linux/grinternal.h
65021 @@ -0,0 +1,215 @@
65022 +#ifndef __GRINTERNAL_H
65023 +#define __GRINTERNAL_H
65024 +
65025 +#ifdef CONFIG_GRKERNSEC
65026 +
65027 +#include <linux/fs.h>
65028 +#include <linux/mnt_namespace.h>
65029 +#include <linux/nsproxy.h>
65030 +#include <linux/gracl.h>
65031 +#include <linux/grdefs.h>
65032 +#include <linux/grmsg.h>
65033 +
65034 +void gr_add_learn_entry(const char *fmt, ...)
65035 + __attribute__ ((format (printf, 1, 2)));
65036 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
65037 + const struct vfsmount *mnt);
65038 +__u32 gr_check_create(const struct dentry *new_dentry,
65039 + const struct dentry *parent,
65040 + const struct vfsmount *mnt, const __u32 mode);
65041 +int gr_check_protected_task(const struct task_struct *task);
65042 +__u32 to_gr_audit(const __u32 reqmode);
65043 +int gr_set_acls(const int type);
65044 +int gr_apply_subject_to_task(struct task_struct *task);
65045 +int gr_acl_is_enabled(void);
65046 +char gr_roletype_to_char(void);
65047 +
65048 +void gr_handle_alertkill(struct task_struct *task);
65049 +char *gr_to_filename(const struct dentry *dentry,
65050 + const struct vfsmount *mnt);
65051 +char *gr_to_filename1(const struct dentry *dentry,
65052 + const struct vfsmount *mnt);
65053 +char *gr_to_filename2(const struct dentry *dentry,
65054 + const struct vfsmount *mnt);
65055 +char *gr_to_filename3(const struct dentry *dentry,
65056 + const struct vfsmount *mnt);
65057 +
65058 +extern int grsec_enable_ptrace_readexec;
65059 +extern int grsec_enable_harden_ptrace;
65060 +extern int grsec_enable_link;
65061 +extern int grsec_enable_fifo;
65062 +extern int grsec_enable_execve;
65063 +extern int grsec_enable_shm;
65064 +extern int grsec_enable_execlog;
65065 +extern int grsec_enable_signal;
65066 +extern int grsec_enable_audit_ptrace;
65067 +extern int grsec_enable_forkfail;
65068 +extern int grsec_enable_time;
65069 +extern int grsec_enable_rofs;
65070 +extern int grsec_enable_chroot_shmat;
65071 +extern int grsec_enable_chroot_mount;
65072 +extern int grsec_enable_chroot_double;
65073 +extern int grsec_enable_chroot_pivot;
65074 +extern int grsec_enable_chroot_chdir;
65075 +extern int grsec_enable_chroot_chmod;
65076 +extern int grsec_enable_chroot_mknod;
65077 +extern int grsec_enable_chroot_fchdir;
65078 +extern int grsec_enable_chroot_nice;
65079 +extern int grsec_enable_chroot_execlog;
65080 +extern int grsec_enable_chroot_caps;
65081 +extern int grsec_enable_chroot_sysctl;
65082 +extern int grsec_enable_chroot_unix;
65083 +extern int grsec_enable_symlinkown;
65084 +extern int grsec_symlinkown_gid;
65085 +extern int grsec_enable_tpe;
65086 +extern int grsec_tpe_gid;
65087 +extern int grsec_enable_tpe_all;
65088 +extern int grsec_enable_tpe_invert;
65089 +extern int grsec_enable_socket_all;
65090 +extern int grsec_socket_all_gid;
65091 +extern int grsec_enable_socket_client;
65092 +extern int grsec_socket_client_gid;
65093 +extern int grsec_enable_socket_server;
65094 +extern int grsec_socket_server_gid;
65095 +extern int grsec_audit_gid;
65096 +extern int grsec_enable_group;
65097 +extern int grsec_enable_audit_textrel;
65098 +extern int grsec_enable_log_rwxmaps;
65099 +extern int grsec_enable_mount;
65100 +extern int grsec_enable_chdir;
65101 +extern int grsec_resource_logging;
65102 +extern int grsec_enable_blackhole;
65103 +extern int grsec_lastack_retries;
65104 +extern int grsec_enable_brute;
65105 +extern int grsec_lock;
65106 +
65107 +extern spinlock_t grsec_alert_lock;
65108 +extern unsigned long grsec_alert_wtime;
65109 +extern unsigned long grsec_alert_fyet;
65110 +
65111 +extern spinlock_t grsec_audit_lock;
65112 +
65113 +extern rwlock_t grsec_exec_file_lock;
65114 +
65115 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
65116 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
65117 + (tsk)->exec_file->f_vfsmnt) : "/")
65118 +
65119 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
65120 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
65121 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65122 +
65123 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
65124 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
65125 + (tsk)->exec_file->f_vfsmnt) : "/")
65126 +
65127 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
65128 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
65129 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65130 +
65131 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
65132 +
65133 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
65134 +
65135 +#define GR_CHROOT_CAPS {{ \
65136 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
65137 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
65138 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
65139 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
65140 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
65141 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
65142 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
65143 +
65144 +#define security_learn(normal_msg,args...) \
65145 +({ \
65146 + read_lock(&grsec_exec_file_lock); \
65147 + gr_add_learn_entry(normal_msg "\n", ## args); \
65148 + read_unlock(&grsec_exec_file_lock); \
65149 +})
65150 +
65151 +enum {
65152 + GR_DO_AUDIT,
65153 + GR_DONT_AUDIT,
65154 + /* used for non-audit messages that we shouldn't kill the task on */
65155 + GR_DONT_AUDIT_GOOD
65156 +};
65157 +
65158 +enum {
65159 + GR_TTYSNIFF,
65160 + GR_RBAC,
65161 + GR_RBAC_STR,
65162 + GR_STR_RBAC,
65163 + GR_RBAC_MODE2,
65164 + GR_RBAC_MODE3,
65165 + GR_FILENAME,
65166 + GR_SYSCTL_HIDDEN,
65167 + GR_NOARGS,
65168 + GR_ONE_INT,
65169 + GR_ONE_INT_TWO_STR,
65170 + GR_ONE_STR,
65171 + GR_STR_INT,
65172 + GR_TWO_STR_INT,
65173 + GR_TWO_INT,
65174 + GR_TWO_U64,
65175 + GR_THREE_INT,
65176 + GR_FIVE_INT_TWO_STR,
65177 + GR_TWO_STR,
65178 + GR_THREE_STR,
65179 + GR_FOUR_STR,
65180 + GR_STR_FILENAME,
65181 + GR_FILENAME_STR,
65182 + GR_FILENAME_TWO_INT,
65183 + GR_FILENAME_TWO_INT_STR,
65184 + GR_TEXTREL,
65185 + GR_PTRACE,
65186 + GR_RESOURCE,
65187 + GR_CAP,
65188 + GR_SIG,
65189 + GR_SIG2,
65190 + GR_CRASH1,
65191 + GR_CRASH2,
65192 + GR_PSACCT,
65193 + GR_RWXMAP
65194 +};
65195 +
65196 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
65197 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
65198 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
65199 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
65200 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
65201 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
65202 +#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)
65203 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
65204 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
65205 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
65206 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
65207 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
65208 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
65209 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
65210 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
65211 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
65212 +#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)
65213 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
65214 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
65215 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
65216 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
65217 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
65218 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
65219 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
65220 +#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)
65221 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
65222 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
65223 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
65224 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
65225 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
65226 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
65227 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
65228 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
65229 +#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)
65230 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
65231 +
65232 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
65233 +
65234 +#endif
65235 +
65236 +#endif
65237 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
65238 new file mode 100644
65239 index 0000000..2bd4c8d
65240 --- /dev/null
65241 +++ b/include/linux/grmsg.h
65242 @@ -0,0 +1,111 @@
65243 +#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"
65244 +#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"
65245 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
65246 +#define GR_STOPMOD_MSG "denied modification of module state by "
65247 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
65248 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
65249 +#define GR_IOPERM_MSG "denied use of ioperm() by "
65250 +#define GR_IOPL_MSG "denied use of iopl() by "
65251 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
65252 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
65253 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
65254 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
65255 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
65256 +#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"
65257 +#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"
65258 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
65259 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
65260 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
65261 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
65262 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
65263 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
65264 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
65265 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
65266 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
65267 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
65268 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
65269 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
65270 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
65271 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
65272 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
65273 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
65274 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
65275 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
65276 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
65277 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
65278 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
65279 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
65280 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
65281 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
65282 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
65283 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
65284 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
65285 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
65286 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
65287 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
65288 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
65289 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
65290 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
65291 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
65292 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
65293 +#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"
65294 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
65295 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
65296 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
65297 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
65298 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
65299 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
65300 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
65301 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
65302 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
65303 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
65304 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
65305 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
65306 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
65307 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
65308 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
65309 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
65310 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
65311 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
65312 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
65313 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
65314 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
65315 +#define GR_NICE_CHROOT_MSG "denied priority change by "
65316 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
65317 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
65318 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
65319 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
65320 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
65321 +#define GR_TIME_MSG "time set by "
65322 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
65323 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
65324 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
65325 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
65326 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
65327 +#define GR_BIND_MSG "denied bind() by "
65328 +#define GR_CONNECT_MSG "denied connect() by "
65329 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
65330 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
65331 +#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"
65332 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
65333 +#define GR_CAP_ACL_MSG "use of %s denied for "
65334 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
65335 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
65336 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
65337 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
65338 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
65339 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
65340 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
65341 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
65342 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
65343 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
65344 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
65345 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
65346 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
65347 +#define GR_VM86_MSG "denied use of vm86 by "
65348 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
65349 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
65350 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
65351 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
65352 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
65353 +#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 "
65354 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
65355 new file mode 100644
65356 index 0000000..c5e5913
65357 --- /dev/null
65358 +++ b/include/linux/grsecurity.h
65359 @@ -0,0 +1,257 @@
65360 +#ifndef GR_SECURITY_H
65361 +#define GR_SECURITY_H
65362 +#include <linux/fs.h>
65363 +#include <linux/fs_struct.h>
65364 +#include <linux/binfmts.h>
65365 +#include <linux/gracl.h>
65366 +
65367 +/* notify of brain-dead configs */
65368 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65369 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
65370 +#endif
65371 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
65372 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
65373 +#endif
65374 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
65375 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
65376 +#endif
65377 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
65378 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
65379 +#endif
65380 +
65381 +#include <linux/compat.h>
65382 +
65383 +struct user_arg_ptr {
65384 +#ifdef CONFIG_COMPAT
65385 + bool is_compat;
65386 +#endif
65387 + union {
65388 + const char __user *const __user *native;
65389 +#ifdef CONFIG_COMPAT
65390 + const compat_uptr_t __user *compat;
65391 +#endif
65392 + } ptr;
65393 +};
65394 +
65395 +void gr_handle_brute_attach(unsigned long mm_flags);
65396 +void gr_handle_brute_check(void);
65397 +void gr_handle_kernel_exploit(void);
65398 +int gr_process_user_ban(void);
65399 +
65400 +char gr_roletype_to_char(void);
65401 +
65402 +int gr_acl_enable_at_secure(void);
65403 +
65404 +int gr_check_user_change(int real, int effective, int fs);
65405 +int gr_check_group_change(int real, int effective, int fs);
65406 +
65407 +void gr_del_task_from_ip_table(struct task_struct *p);
65408 +
65409 +int gr_pid_is_chrooted(struct task_struct *p);
65410 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
65411 +int gr_handle_chroot_nice(void);
65412 +int gr_handle_chroot_sysctl(const int op);
65413 +int gr_handle_chroot_setpriority(struct task_struct *p,
65414 + const int niceval);
65415 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
65416 +int gr_handle_chroot_chroot(const struct dentry *dentry,
65417 + const struct vfsmount *mnt);
65418 +void gr_handle_chroot_chdir(struct path *path);
65419 +int gr_handle_chroot_chmod(const struct dentry *dentry,
65420 + const struct vfsmount *mnt, const int mode);
65421 +int gr_handle_chroot_mknod(const struct dentry *dentry,
65422 + const struct vfsmount *mnt, const int mode);
65423 +int gr_handle_chroot_mount(const struct dentry *dentry,
65424 + const struct vfsmount *mnt,
65425 + const char *dev_name);
65426 +int gr_handle_chroot_pivot(void);
65427 +int gr_handle_chroot_unix(const pid_t pid);
65428 +
65429 +int gr_handle_rawio(const struct inode *inode);
65430 +
65431 +void gr_handle_ioperm(void);
65432 +void gr_handle_iopl(void);
65433 +
65434 +umode_t gr_acl_umask(void);
65435 +
65436 +int gr_tpe_allow(const struct file *file);
65437 +
65438 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
65439 +void gr_clear_chroot_entries(struct task_struct *task);
65440 +
65441 +void gr_log_forkfail(const int retval);
65442 +void gr_log_timechange(void);
65443 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
65444 +void gr_log_chdir(const struct dentry *dentry,
65445 + const struct vfsmount *mnt);
65446 +void gr_log_chroot_exec(const struct dentry *dentry,
65447 + const struct vfsmount *mnt);
65448 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
65449 +void gr_log_remount(const char *devname, const int retval);
65450 +void gr_log_unmount(const char *devname, const int retval);
65451 +void gr_log_mount(const char *from, const char *to, const int retval);
65452 +void gr_log_textrel(struct vm_area_struct *vma);
65453 +void gr_log_rwxmmap(struct file *file);
65454 +void gr_log_rwxmprotect(struct file *file);
65455 +
65456 +int gr_handle_follow_link(const struct inode *parent,
65457 + const struct inode *inode,
65458 + const struct dentry *dentry,
65459 + const struct vfsmount *mnt);
65460 +int gr_handle_fifo(const struct dentry *dentry,
65461 + const struct vfsmount *mnt,
65462 + const struct dentry *dir, const int flag,
65463 + const int acc_mode);
65464 +int gr_handle_hardlink(const struct dentry *dentry,
65465 + const struct vfsmount *mnt,
65466 + struct inode *inode,
65467 + const int mode, const struct filename *to);
65468 +
65469 +int gr_is_capable(const int cap);
65470 +int gr_is_capable_nolog(const int cap);
65471 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65472 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
65473 +
65474 +void gr_copy_label(struct task_struct *tsk);
65475 +void gr_handle_crash(struct task_struct *task, const int sig);
65476 +int gr_handle_signal(const struct task_struct *p, const int sig);
65477 +int gr_check_crash_uid(const uid_t uid);
65478 +int gr_check_protected_task(const struct task_struct *task);
65479 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
65480 +int gr_acl_handle_mmap(const struct file *file,
65481 + const unsigned long prot);
65482 +int gr_acl_handle_mprotect(const struct file *file,
65483 + const unsigned long prot);
65484 +int gr_check_hidden_task(const struct task_struct *tsk);
65485 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
65486 + const struct vfsmount *mnt);
65487 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
65488 + const struct vfsmount *mnt);
65489 +__u32 gr_acl_handle_access(const struct dentry *dentry,
65490 + const struct vfsmount *mnt, const int fmode);
65491 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
65492 + const struct vfsmount *mnt, umode_t *mode);
65493 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
65494 + const struct vfsmount *mnt);
65495 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
65496 + const struct vfsmount *mnt);
65497 +int gr_handle_ptrace(struct task_struct *task, const long request);
65498 +int gr_handle_proc_ptrace(struct task_struct *task);
65499 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
65500 + const struct vfsmount *mnt);
65501 +int gr_check_crash_exec(const struct file *filp);
65502 +int gr_acl_is_enabled(void);
65503 +void gr_set_kernel_label(struct task_struct *task);
65504 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
65505 + const gid_t gid);
65506 +int gr_set_proc_label(const struct dentry *dentry,
65507 + const struct vfsmount *mnt,
65508 + const int unsafe_flags);
65509 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
65510 + const struct vfsmount *mnt);
65511 +__u32 gr_acl_handle_open(const struct dentry *dentry,
65512 + const struct vfsmount *mnt, int acc_mode);
65513 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
65514 + const struct dentry *p_dentry,
65515 + const struct vfsmount *p_mnt,
65516 + int open_flags, int acc_mode, const int imode);
65517 +void gr_handle_create(const struct dentry *dentry,
65518 + const struct vfsmount *mnt);
65519 +void gr_handle_proc_create(const struct dentry *dentry,
65520 + const struct inode *inode);
65521 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
65522 + const struct dentry *parent_dentry,
65523 + const struct vfsmount *parent_mnt,
65524 + const int mode);
65525 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
65526 + const struct dentry *parent_dentry,
65527 + const struct vfsmount *parent_mnt);
65528 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
65529 + const struct vfsmount *mnt);
65530 +void gr_handle_delete(const ino_t ino, const dev_t dev);
65531 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
65532 + const struct vfsmount *mnt);
65533 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
65534 + const struct dentry *parent_dentry,
65535 + const struct vfsmount *parent_mnt,
65536 + const struct filename *from);
65537 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
65538 + const struct dentry *parent_dentry,
65539 + const struct vfsmount *parent_mnt,
65540 + const struct dentry *old_dentry,
65541 + const struct vfsmount *old_mnt, const struct filename *to);
65542 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
65543 +int gr_acl_handle_rename(struct dentry *new_dentry,
65544 + struct dentry *parent_dentry,
65545 + const struct vfsmount *parent_mnt,
65546 + struct dentry *old_dentry,
65547 + struct inode *old_parent_inode,
65548 + struct vfsmount *old_mnt, const struct filename *newname);
65549 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65550 + struct dentry *old_dentry,
65551 + struct dentry *new_dentry,
65552 + struct vfsmount *mnt, const __u8 replace);
65553 +__u32 gr_check_link(const struct dentry *new_dentry,
65554 + const struct dentry *parent_dentry,
65555 + const struct vfsmount *parent_mnt,
65556 + const struct dentry *old_dentry,
65557 + const struct vfsmount *old_mnt);
65558 +int gr_acl_handle_filldir(const struct file *file, const char *name,
65559 + const unsigned int namelen, const ino_t ino);
65560 +
65561 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
65562 + const struct vfsmount *mnt);
65563 +void gr_acl_handle_exit(void);
65564 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
65565 +int gr_acl_handle_procpidmem(const struct task_struct *task);
65566 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
65567 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
65568 +void gr_audit_ptrace(struct task_struct *task);
65569 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
65570 +void gr_put_exec_file(struct task_struct *task);
65571 +
65572 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
65573 +
65574 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
65575 +extern void gr_learn_resource(const struct task_struct *task, const int res,
65576 + const unsigned long wanted, const int gt);
65577 +#else
65578 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
65579 + const unsigned long wanted, const int gt)
65580 +{
65581 +}
65582 +#endif
65583 +
65584 +#ifdef CONFIG_GRKERNSEC_RESLOG
65585 +extern void gr_log_resource(const struct task_struct *task, const int res,
65586 + const unsigned long wanted, const int gt);
65587 +#else
65588 +static inline void gr_log_resource(const struct task_struct *task, const int res,
65589 + const unsigned long wanted, const int gt)
65590 +{
65591 +}
65592 +#endif
65593 +
65594 +#ifdef CONFIG_GRKERNSEC
65595 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
65596 +void gr_handle_vm86(void);
65597 +void gr_handle_mem_readwrite(u64 from, u64 to);
65598 +
65599 +void gr_log_badprocpid(const char *entry);
65600 +
65601 +extern int grsec_enable_dmesg;
65602 +extern int grsec_disable_privio;
65603 +
65604 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65605 +extern int grsec_proc_gid;
65606 +#endif
65607 +
65608 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65609 +extern int grsec_enable_chroot_findtask;
65610 +#endif
65611 +#ifdef CONFIG_GRKERNSEC_SETXID
65612 +extern int grsec_enable_setxid;
65613 +#endif
65614 +#endif
65615 +
65616 +#endif
65617 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
65618 new file mode 100644
65619 index 0000000..e7ffaaf
65620 --- /dev/null
65621 +++ b/include/linux/grsock.h
65622 @@ -0,0 +1,19 @@
65623 +#ifndef __GRSOCK_H
65624 +#define __GRSOCK_H
65625 +
65626 +extern void gr_attach_curr_ip(const struct sock *sk);
65627 +extern int gr_handle_sock_all(const int family, const int type,
65628 + const int protocol);
65629 +extern int gr_handle_sock_server(const struct sockaddr *sck);
65630 +extern int gr_handle_sock_server_other(const struct sock *sck);
65631 +extern int gr_handle_sock_client(const struct sockaddr *sck);
65632 +extern int gr_search_connect(struct socket * sock,
65633 + struct sockaddr_in * addr);
65634 +extern int gr_search_bind(struct socket * sock,
65635 + struct sockaddr_in * addr);
65636 +extern int gr_search_listen(struct socket * sock);
65637 +extern int gr_search_accept(struct socket * sock);
65638 +extern int gr_search_socket(const int domain, const int type,
65639 + const int protocol);
65640 +
65641 +#endif
65642 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
65643 index ef788b5..ac41b7b 100644
65644 --- a/include/linux/highmem.h
65645 +++ b/include/linux/highmem.h
65646 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
65647 kunmap_atomic(kaddr);
65648 }
65649
65650 +static inline void sanitize_highpage(struct page *page)
65651 +{
65652 + void *kaddr;
65653 + unsigned long flags;
65654 +
65655 + local_irq_save(flags);
65656 + kaddr = kmap_atomic(page);
65657 + clear_page(kaddr);
65658 + kunmap_atomic(kaddr);
65659 + local_irq_restore(flags);
65660 +}
65661 +
65662 static inline void zero_user_segments(struct page *page,
65663 unsigned start1, unsigned end1,
65664 unsigned start2, unsigned end2)
65665 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
65666 index d0c4db7..61b3577 100644
65667 --- a/include/linux/i2c.h
65668 +++ b/include/linux/i2c.h
65669 @@ -369,6 +369,7 @@ struct i2c_algorithm {
65670 /* To determine what the adapter supports */
65671 u32 (*functionality) (struct i2c_adapter *);
65672 };
65673 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
65674
65675 /*
65676 * i2c_adapter is the structure used to identify a physical i2c bus along
65677 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
65678 index d23c3c2..eb63c81 100644
65679 --- a/include/linux/i2o.h
65680 +++ b/include/linux/i2o.h
65681 @@ -565,7 +565,7 @@ struct i2o_controller {
65682 struct i2o_device *exec; /* Executive */
65683 #if BITS_PER_LONG == 64
65684 spinlock_t context_list_lock; /* lock for context_list */
65685 - atomic_t context_list_counter; /* needed for unique contexts */
65686 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
65687 struct list_head context_list; /* list of context id's
65688 and pointers */
65689 #endif
65690 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
65691 index aff7ad8..3942bbd 100644
65692 --- a/include/linux/if_pppox.h
65693 +++ b/include/linux/if_pppox.h
65694 @@ -76,7 +76,7 @@ struct pppox_proto {
65695 int (*ioctl)(struct socket *sock, unsigned int cmd,
65696 unsigned long arg);
65697 struct module *owner;
65698 -};
65699 +} __do_const;
65700
65701 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
65702 extern void unregister_pppox_proto(int proto_num);
65703 diff --git a/include/linux/init.h b/include/linux/init.h
65704 index 10ed4f4..8e8490d 100644
65705 --- a/include/linux/init.h
65706 +++ b/include/linux/init.h
65707 @@ -39,9 +39,36 @@
65708 * Also note, that this data cannot be "const".
65709 */
65710
65711 +#ifdef MODULE
65712 +#define add_init_latent_entropy
65713 +#define add_devinit_latent_entropy
65714 +#define add_cpuinit_latent_entropy
65715 +#define add_meminit_latent_entropy
65716 +#else
65717 +#define add_init_latent_entropy __latent_entropy
65718 +
65719 +#ifdef CONFIG_HOTPLUG
65720 +#define add_devinit_latent_entropy
65721 +#else
65722 +#define add_devinit_latent_entropy __latent_entropy
65723 +#endif
65724 +
65725 +#ifdef CONFIG_HOTPLUG_CPU
65726 +#define add_cpuinit_latent_entropy
65727 +#else
65728 +#define add_cpuinit_latent_entropy __latent_entropy
65729 +#endif
65730 +
65731 +#ifdef CONFIG_MEMORY_HOTPLUG
65732 +#define add_meminit_latent_entropy
65733 +#else
65734 +#define add_meminit_latent_entropy __latent_entropy
65735 +#endif
65736 +#endif
65737 +
65738 /* These are for everybody (although not all archs will actually
65739 discard it in modules) */
65740 -#define __init __section(.init.text) __cold notrace
65741 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
65742 #define __initdata __section(.init.data)
65743 #define __initconst __constsection(.init.rodata)
65744 #define __exitdata __section(.exit.data)
65745 @@ -94,7 +121,7 @@
65746 #define __exit __section(.exit.text) __exitused __cold notrace
65747
65748 /* Used for HOTPLUG_CPU */
65749 -#define __cpuinit __section(.cpuinit.text) __cold notrace
65750 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
65751 #define __cpuinitdata __section(.cpuinit.data)
65752 #define __cpuinitconst __constsection(.cpuinit.rodata)
65753 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
65754 @@ -102,7 +129,7 @@
65755 #define __cpuexitconst __constsection(.cpuexit.rodata)
65756
65757 /* Used for MEMORY_HOTPLUG */
65758 -#define __meminit __section(.meminit.text) __cold notrace
65759 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
65760 #define __meminitdata __section(.meminit.data)
65761 #define __meminitconst __constsection(.meminit.rodata)
65762 #define __memexit __section(.memexit.text) __exitused __cold notrace
65763 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
65764 index 6d087c5..401cab8 100644
65765 --- a/include/linux/init_task.h
65766 +++ b/include/linux/init_task.h
65767 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
65768
65769 #define INIT_TASK_COMM "swapper"
65770
65771 +#ifdef CONFIG_X86
65772 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
65773 +#else
65774 +#define INIT_TASK_THREAD_INFO
65775 +#endif
65776 +
65777 /*
65778 * INIT_TASK is used to set up the first task table, touch at
65779 * your own risk!. Base=0, limit=0x1fffff (=2MB)
65780 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
65781 RCU_POINTER_INITIALIZER(cred, &init_cred), \
65782 .comm = INIT_TASK_COMM, \
65783 .thread = INIT_THREAD, \
65784 + INIT_TASK_THREAD_INFO \
65785 .fs = &init_fs, \
65786 .files = &init_files, \
65787 .signal = &init_signals, \
65788 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
65789 index 5fa5afe..ac55b25 100644
65790 --- a/include/linux/interrupt.h
65791 +++ b/include/linux/interrupt.h
65792 @@ -430,7 +430,7 @@ enum
65793 /* map softirq index to softirq name. update 'softirq_to_name' in
65794 * kernel/softirq.c when adding a new softirq.
65795 */
65796 -extern char *softirq_to_name[NR_SOFTIRQS];
65797 +extern const char * const softirq_to_name[NR_SOFTIRQS];
65798
65799 /* softirq mask and active fields moved to irq_cpustat_t in
65800 * asm/hardirq.h to get better cache usage. KAO
65801 @@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65802
65803 struct softirq_action
65804 {
65805 - void (*action)(struct softirq_action *);
65806 -};
65807 + void (*action)(void);
65808 +} __no_const;
65809
65810 asmlinkage void do_softirq(void);
65811 asmlinkage void __do_softirq(void);
65812 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65813 +extern void open_softirq(int nr, void (*action)(void));
65814 extern void softirq_init(void);
65815 extern void __raise_softirq_irqoff(unsigned int nr);
65816
65817 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65818 index 6883e19..06992b1 100644
65819 --- a/include/linux/kallsyms.h
65820 +++ b/include/linux/kallsyms.h
65821 @@ -15,7 +15,8 @@
65822
65823 struct module;
65824
65825 -#ifdef CONFIG_KALLSYMS
65826 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65827 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65828 /* Lookup the address for a symbol. Returns 0 if not found. */
65829 unsigned long kallsyms_lookup_name(const char *name);
65830
65831 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65832 /* Stupid that this does nothing, but I didn't create this mess. */
65833 #define __print_symbol(fmt, addr)
65834 #endif /*CONFIG_KALLSYMS*/
65835 +#else /* when included by kallsyms.c, vsnprintf.c, or
65836 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65837 +extern void __print_symbol(const char *fmt, unsigned long address);
65838 +extern int sprint_backtrace(char *buffer, unsigned long address);
65839 +extern int sprint_symbol(char *buffer, unsigned long address);
65840 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65841 +const char *kallsyms_lookup(unsigned long addr,
65842 + unsigned long *symbolsize,
65843 + unsigned long *offset,
65844 + char **modname, char *namebuf);
65845 +#endif
65846
65847 /* This macro allows us to keep printk typechecking */
65848 static __printf(1, 2)
65849 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65850 index 4dff0c6..1ca9b72 100644
65851 --- a/include/linux/kgdb.h
65852 +++ b/include/linux/kgdb.h
65853 @@ -53,7 +53,7 @@ extern int kgdb_connected;
65854 extern int kgdb_io_module_registered;
65855
65856 extern atomic_t kgdb_setting_breakpoint;
65857 -extern atomic_t kgdb_cpu_doing_single_step;
65858 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65859
65860 extern struct task_struct *kgdb_usethread;
65861 extern struct task_struct *kgdb_contthread;
65862 @@ -255,7 +255,7 @@ struct kgdb_arch {
65863 void (*correct_hw_break)(void);
65864
65865 void (*enable_nmi)(bool on);
65866 -};
65867 +} __do_const;
65868
65869 /**
65870 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65871 @@ -280,7 +280,7 @@ struct kgdb_io {
65872 void (*pre_exception) (void);
65873 void (*post_exception) (void);
65874 int is_console;
65875 -};
65876 +} __do_const;
65877
65878 extern struct kgdb_arch arch_kgdb_ops;
65879
65880 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65881 index 5398d58..5883a34 100644
65882 --- a/include/linux/kmod.h
65883 +++ b/include/linux/kmod.h
65884 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65885 * usually useless though. */
65886 extern __printf(2, 3)
65887 int __request_module(bool wait, const char *name, ...);
65888 +extern __printf(3, 4)
65889 +int ___request_module(bool wait, char *param_name, const char *name, ...);
65890 #define request_module(mod...) __request_module(true, mod)
65891 #define request_module_nowait(mod...) __request_module(false, mod)
65892 #define try_then_request_module(x, mod...) \
65893 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65894 index 939b112..90b7f44 100644
65895 --- a/include/linux/kobject.h
65896 +++ b/include/linux/kobject.h
65897 @@ -111,7 +111,7 @@ struct kobj_type {
65898 struct attribute **default_attrs;
65899 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65900 const void *(*namespace)(struct kobject *kobj);
65901 -};
65902 +} __do_const;
65903
65904 struct kobj_uevent_env {
65905 char *envp[UEVENT_NUM_ENVP];
65906 diff --git a/include/linux/kref.h b/include/linux/kref.h
65907 index 4972e6e..de4d19b 100644
65908 --- a/include/linux/kref.h
65909 +++ b/include/linux/kref.h
65910 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65911 static inline int kref_sub(struct kref *kref, unsigned int count,
65912 void (*release)(struct kref *kref))
65913 {
65914 - WARN_ON(release == NULL);
65915 + BUG_ON(release == NULL);
65916
65917 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65918 release(kref);
65919 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65920 index 2c497ab..afe32f5 100644
65921 --- a/include/linux/kvm_host.h
65922 +++ b/include/linux/kvm_host.h
65923 @@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65924 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65925 void vcpu_put(struct kvm_vcpu *vcpu);
65926
65927 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65928 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65929 struct module *module);
65930 void kvm_exit(void);
65931
65932 @@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65933 struct kvm_guest_debug *dbg);
65934 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65935
65936 -int kvm_arch_init(void *opaque);
65937 +int kvm_arch_init(const void *opaque);
65938 void kvm_arch_exit(void);
65939
65940 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65941 diff --git a/include/linux/libata.h b/include/linux/libata.h
65942 index 649e5f8..ead5194 100644
65943 --- a/include/linux/libata.h
65944 +++ b/include/linux/libata.h
65945 @@ -915,7 +915,7 @@ struct ata_port_operations {
65946 * fields must be pointers.
65947 */
65948 const struct ata_port_operations *inherits;
65949 -};
65950 +} __do_const;
65951
65952 struct ata_port_info {
65953 unsigned long flags;
65954 diff --git a/include/linux/list.h b/include/linux/list.h
65955 index cc6d2aa..71febca 100644
65956 --- a/include/linux/list.h
65957 +++ b/include/linux/list.h
65958 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65959 extern void list_del(struct list_head *entry);
65960 #endif
65961
65962 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65963 +extern void pax_list_del(struct list_head *entry);
65964 +
65965 /**
65966 * list_replace - replace old entry by new one
65967 * @old : the element to be replaced
65968 diff --git a/include/linux/mm.h b/include/linux/mm.h
65969 index 66e2f7c..ea88001 100644
65970 --- a/include/linux/mm.h
65971 +++ b/include/linux/mm.h
65972 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65973 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65974 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65975 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65976 +
65977 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65978 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65979 +#endif
65980 +
65981 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65982
65983 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65984 @@ -231,6 +236,7 @@ struct vm_operations_struct {
65985 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
65986 unsigned long size, pgoff_t pgoff);
65987 };
65988 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
65989
65990 struct mmu_gather;
65991 struct inode;
65992 @@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
65993 int set_page_dirty_lock(struct page *page);
65994 int clear_page_dirty_for_io(struct page *page);
65995
65996 -/* Is the vma a continuation of the stack vma above it? */
65997 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65998 -{
65999 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
66000 -}
66001 -
66002 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
66003 - unsigned long addr)
66004 -{
66005 - return (vma->vm_flags & VM_GROWSDOWN) &&
66006 - (vma->vm_start == addr) &&
66007 - !vma_growsdown(vma->vm_prev, addr);
66008 -}
66009 -
66010 -/* Is the vma a continuation of the stack vma below it? */
66011 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
66012 -{
66013 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
66014 -}
66015 -
66016 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
66017 - unsigned long addr)
66018 -{
66019 - return (vma->vm_flags & VM_GROWSUP) &&
66020 - (vma->vm_end == addr) &&
66021 - !vma_growsup(vma->vm_next, addr);
66022 -}
66023 -
66024 extern pid_t
66025 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
66026
66027 @@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
66028 }
66029 #endif
66030
66031 +#ifdef CONFIG_MMU
66032 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
66033 +#else
66034 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
66035 +{
66036 + return __pgprot(0);
66037 +}
66038 +#endif
66039 +
66040 int vma_wants_writenotify(struct vm_area_struct *vma);
66041
66042 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
66043 @@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
66044 {
66045 return 0;
66046 }
66047 +
66048 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
66049 + unsigned long address)
66050 +{
66051 + return 0;
66052 +}
66053 #else
66054 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
66055 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
66056 #endif
66057
66058 #ifdef __PAGETABLE_PMD_FOLDED
66059 @@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
66060 {
66061 return 0;
66062 }
66063 +
66064 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
66065 + unsigned long address)
66066 +{
66067 + return 0;
66068 +}
66069 #else
66070 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
66071 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
66072 #endif
66073
66074 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
66075 @@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
66076 NULL: pud_offset(pgd, address);
66077 }
66078
66079 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
66080 +{
66081 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
66082 + NULL: pud_offset(pgd, address);
66083 +}
66084 +
66085 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
66086 {
66087 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
66088 NULL: pmd_offset(pud, address);
66089 }
66090 +
66091 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
66092 +{
66093 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
66094 + NULL: pmd_offset(pud, address);
66095 +}
66096 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
66097
66098 #if USE_SPLIT_PTLOCKS
66099 @@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
66100 unsigned long, unsigned long,
66101 unsigned long, unsigned long);
66102 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
66103 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
66104
66105 /* These take the mm semaphore themselves */
66106 extern unsigned long vm_brk(unsigned long, unsigned long);
66107 @@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
66108 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
66109 struct vm_area_struct **pprev);
66110
66111 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
66112 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
66113 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
66114 +
66115 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
66116 NULL if none. Assume start_addr < end_addr. */
66117 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
66118 @@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
66119 return vma;
66120 }
66121
66122 -#ifdef CONFIG_MMU
66123 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
66124 -#else
66125 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
66126 -{
66127 - return __pgprot(0);
66128 -}
66129 -#endif
66130 -
66131 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
66132 unsigned long change_prot_numa(struct vm_area_struct *vma,
66133 unsigned long start, unsigned long end);
66134 @@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
66135 extern int sysctl_memory_failure_early_kill;
66136 extern int sysctl_memory_failure_recovery;
66137 extern void shake_page(struct page *p, int access);
66138 -extern atomic_long_t mce_bad_pages;
66139 +extern atomic_long_unchecked_t mce_bad_pages;
66140 extern int soft_offline_page(struct page *page, int flags);
66141
66142 extern void dump_page(struct page *page);
66143 @@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
66144 static inline bool page_is_guard(struct page *page) { return false; }
66145 #endif /* CONFIG_DEBUG_PAGEALLOC */
66146
66147 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66148 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
66149 +#else
66150 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
66151 +#endif
66152 +
66153 #endif /* __KERNEL__ */
66154 #endif /* _LINUX_MM_H */
66155 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
66156 index f8f5162..6276a36 100644
66157 --- a/include/linux/mm_types.h
66158 +++ b/include/linux/mm_types.h
66159 @@ -288,6 +288,8 @@ struct vm_area_struct {
66160 #ifdef CONFIG_NUMA
66161 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
66162 #endif
66163 +
66164 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
66165 };
66166
66167 struct core_thread {
66168 @@ -362,7 +364,7 @@ struct mm_struct {
66169 unsigned long def_flags;
66170 unsigned long nr_ptes; /* Page table pages */
66171 unsigned long start_code, end_code, start_data, end_data;
66172 - unsigned long start_brk, brk, start_stack;
66173 + unsigned long brk_gap, start_brk, brk, start_stack;
66174 unsigned long arg_start, arg_end, env_start, env_end;
66175
66176 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
66177 @@ -436,6 +438,24 @@ struct mm_struct {
66178 int first_nid;
66179 #endif
66180 struct uprobes_state uprobes_state;
66181 +
66182 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66183 + unsigned long pax_flags;
66184 +#endif
66185 +
66186 +#ifdef CONFIG_PAX_DLRESOLVE
66187 + unsigned long call_dl_resolve;
66188 +#endif
66189 +
66190 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
66191 + unsigned long call_syscall;
66192 +#endif
66193 +
66194 +#ifdef CONFIG_PAX_ASLR
66195 + unsigned long delta_mmap; /* randomized offset */
66196 + unsigned long delta_stack; /* randomized offset */
66197 +#endif
66198 +
66199 };
66200
66201 /* first nid will either be a valid NID or one of these values */
66202 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
66203 index c5d5278..f0b68c8 100644
66204 --- a/include/linux/mmiotrace.h
66205 +++ b/include/linux/mmiotrace.h
66206 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
66207 /* Called from ioremap.c */
66208 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
66209 void __iomem *addr);
66210 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
66211 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
66212
66213 /* For anyone to insert markers. Remember trailing newline. */
66214 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
66215 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
66216 {
66217 }
66218
66219 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
66220 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
66221 {
66222 }
66223
66224 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
66225 index 73b64a3..6562925 100644
66226 --- a/include/linux/mmzone.h
66227 +++ b/include/linux/mmzone.h
66228 @@ -412,7 +412,7 @@ struct zone {
66229 unsigned long flags; /* zone flags, see below */
66230
66231 /* Zone statistics */
66232 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66233 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66234
66235 /*
66236 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
66237 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
66238 index fed3def..7cc3f93 100644
66239 --- a/include/linux/mod_devicetable.h
66240 +++ b/include/linux/mod_devicetable.h
66241 @@ -12,7 +12,7 @@
66242 typedef unsigned long kernel_ulong_t;
66243 #endif
66244
66245 -#define PCI_ANY_ID (~0)
66246 +#define PCI_ANY_ID ((__u16)~0)
66247
66248 struct pci_device_id {
66249 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
66250 @@ -139,7 +139,7 @@ struct usb_device_id {
66251 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
66252 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
66253
66254 -#define HID_ANY_ID (~0)
66255 +#define HID_ANY_ID (~0U)
66256 #define HID_BUS_ANY 0xffff
66257 #define HID_GROUP_ANY 0x0000
66258
66259 diff --git a/include/linux/module.h b/include/linux/module.h
66260 index 1375ee3..d631af0 100644
66261 --- a/include/linux/module.h
66262 +++ b/include/linux/module.h
66263 @@ -17,9 +17,11 @@
66264 #include <linux/moduleparam.h>
66265 #include <linux/tracepoint.h>
66266 #include <linux/export.h>
66267 +#include <linux/fs.h>
66268
66269 #include <linux/percpu.h>
66270 #include <asm/module.h>
66271 +#include <asm/pgtable.h>
66272
66273 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
66274 #define MODULE_SIG_STRING "~Module signature appended~\n"
66275 @@ -281,19 +283,16 @@ struct module
66276 int (*init)(void);
66277
66278 /* If this is non-NULL, vfree after init() returns */
66279 - void *module_init;
66280 + void *module_init_rx, *module_init_rw;
66281
66282 /* Here is the actual code + data, vfree'd on unload. */
66283 - void *module_core;
66284 + void *module_core_rx, *module_core_rw;
66285
66286 /* Here are the sizes of the init and core sections */
66287 - unsigned int init_size, core_size;
66288 + unsigned int init_size_rw, core_size_rw;
66289
66290 /* The size of the executable code in each section. */
66291 - unsigned int init_text_size, core_text_size;
66292 -
66293 - /* Size of RO sections of the module (text+rodata) */
66294 - unsigned int init_ro_size, core_ro_size;
66295 + unsigned int init_size_rx, core_size_rx;
66296
66297 /* Arch-specific module values */
66298 struct mod_arch_specific arch;
66299 @@ -349,6 +348,10 @@ struct module
66300 #ifdef CONFIG_EVENT_TRACING
66301 struct ftrace_event_call **trace_events;
66302 unsigned int num_trace_events;
66303 + struct file_operations trace_id;
66304 + struct file_operations trace_enable;
66305 + struct file_operations trace_format;
66306 + struct file_operations trace_filter;
66307 #endif
66308 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
66309 unsigned int num_ftrace_callsites;
66310 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
66311 bool is_module_percpu_address(unsigned long addr);
66312 bool is_module_text_address(unsigned long addr);
66313
66314 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
66315 +{
66316 +
66317 +#ifdef CONFIG_PAX_KERNEXEC
66318 + if (ktla_ktva(addr) >= (unsigned long)start &&
66319 + ktla_ktva(addr) < (unsigned long)start + size)
66320 + return 1;
66321 +#endif
66322 +
66323 + return ((void *)addr >= start && (void *)addr < start + size);
66324 +}
66325 +
66326 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
66327 +{
66328 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
66329 +}
66330 +
66331 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
66332 +{
66333 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
66334 +}
66335 +
66336 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
66337 +{
66338 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
66339 +}
66340 +
66341 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
66342 +{
66343 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
66344 +}
66345 +
66346 static inline int within_module_core(unsigned long addr, struct module *mod)
66347 {
66348 - return (unsigned long)mod->module_core <= addr &&
66349 - addr < (unsigned long)mod->module_core + mod->core_size;
66350 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
66351 }
66352
66353 static inline int within_module_init(unsigned long addr, struct module *mod)
66354 {
66355 - return (unsigned long)mod->module_init <= addr &&
66356 - addr < (unsigned long)mod->module_init + mod->init_size;
66357 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
66358 }
66359
66360 /* Search for module by name: must hold module_mutex. */
66361 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
66362 index 560ca53..5ee8d73 100644
66363 --- a/include/linux/moduleloader.h
66364 +++ b/include/linux/moduleloader.h
66365 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
66366
66367 /* Allocator used for allocating struct module, core sections and init
66368 sections. Returns NULL on failure. */
66369 -void *module_alloc(unsigned long size);
66370 +void *module_alloc(unsigned long size) __size_overflow(1);
66371 +
66372 +#ifdef CONFIG_PAX_KERNEXEC
66373 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
66374 +#else
66375 +#define module_alloc_exec(x) module_alloc(x)
66376 +#endif
66377
66378 /* Free memory returned from module_alloc. */
66379 void module_free(struct module *mod, void *module_region);
66380
66381 +#ifdef CONFIG_PAX_KERNEXEC
66382 +void module_free_exec(struct module *mod, void *module_region);
66383 +#else
66384 +#define module_free_exec(x, y) module_free((x), (y))
66385 +#endif
66386 +
66387 /*
66388 * Apply the given relocation to the (simplified) ELF. Return -error
66389 * or 0.
66390 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
66391 unsigned int relsec,
66392 struct module *me)
66393 {
66394 +#ifdef CONFIG_MODULES
66395 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66396 +#endif
66397 return -ENOEXEC;
66398 }
66399 #endif
66400 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
66401 unsigned int relsec,
66402 struct module *me)
66403 {
66404 +#ifdef CONFIG_MODULES
66405 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66406 +#endif
66407 return -ENOEXEC;
66408 }
66409 #endif
66410 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
66411 index 137b419..fe663ec 100644
66412 --- a/include/linux/moduleparam.h
66413 +++ b/include/linux/moduleparam.h
66414 @@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
66415 * @len is usually just sizeof(string).
66416 */
66417 #define module_param_string(name, string, len, perm) \
66418 - static const struct kparam_string __param_string_##name \
66419 + static const struct kparam_string __param_string_##name __used \
66420 = { len, string }; \
66421 __module_param_call(MODULE_PARAM_PREFIX, name, \
66422 &param_ops_string, \
66423 @@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
66424 */
66425 #define module_param_array_named(name, array, type, nump, perm) \
66426 param_check_##type(name, &(array)[0]); \
66427 - static const struct kparam_array __param_arr_##name \
66428 + static const struct kparam_array __param_arr_##name __used \
66429 = { .max = ARRAY_SIZE(array), .num = nump, \
66430 .ops = &param_ops_##type, \
66431 .elemsize = sizeof(array[0]), .elem = array }; \
66432 diff --git a/include/linux/namei.h b/include/linux/namei.h
66433 index 5a5ff57..5ae5070 100644
66434 --- a/include/linux/namei.h
66435 +++ b/include/linux/namei.h
66436 @@ -19,7 +19,7 @@ struct nameidata {
66437 unsigned seq;
66438 int last_type;
66439 unsigned depth;
66440 - char *saved_names[MAX_NESTED_LINKS + 1];
66441 + const char *saved_names[MAX_NESTED_LINKS + 1];
66442 };
66443
66444 /*
66445 @@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
66446
66447 extern void nd_jump_link(struct nameidata *nd, struct path *path);
66448
66449 -static inline void nd_set_link(struct nameidata *nd, char *path)
66450 +static inline void nd_set_link(struct nameidata *nd, const char *path)
66451 {
66452 nd->saved_names[nd->depth] = path;
66453 }
66454
66455 -static inline char *nd_get_link(struct nameidata *nd)
66456 +static inline const char *nd_get_link(const struct nameidata *nd)
66457 {
66458 return nd->saved_names[nd->depth];
66459 }
66460 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
66461 index 9ef07d0..130a5d9 100644
66462 --- a/include/linux/netdevice.h
66463 +++ b/include/linux/netdevice.h
66464 @@ -1012,6 +1012,7 @@ struct net_device_ops {
66465 u32 pid, u32 seq,
66466 struct net_device *dev);
66467 };
66468 +typedef struct net_device_ops __no_const net_device_ops_no_const;
66469
66470 /*
66471 * The DEVICE structure.
66472 @@ -1078,7 +1079,7 @@ struct net_device {
66473 int iflink;
66474
66475 struct net_device_stats stats;
66476 - atomic_long_t rx_dropped; /* dropped packets by core network
66477 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
66478 * Do not use this in drivers.
66479 */
66480
66481 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
66482 index 7958e84..ed74d7a 100644
66483 --- a/include/linux/netfilter/ipset/ip_set.h
66484 +++ b/include/linux/netfilter/ipset/ip_set.h
66485 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
66486 /* Return true if "b" set is the same as "a"
66487 * according to the create set parameters */
66488 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
66489 -};
66490 +} __do_const;
66491
66492 /* The core set type structure */
66493 struct ip_set_type {
66494 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
66495 index 4966dde..7d8ce06 100644
66496 --- a/include/linux/netfilter/nfnetlink.h
66497 +++ b/include/linux/netfilter/nfnetlink.h
66498 @@ -16,7 +16,7 @@ struct nfnl_callback {
66499 const struct nlattr * const cda[]);
66500 const struct nla_policy *policy; /* netlink attribute policy */
66501 const u_int16_t attr_count; /* number of nlattr's */
66502 -};
66503 +} __do_const;
66504
66505 struct nfnetlink_subsystem {
66506 const char *name;
66507 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
66508 new file mode 100644
66509 index 0000000..33f4af8
66510 --- /dev/null
66511 +++ b/include/linux/netfilter/xt_gradm.h
66512 @@ -0,0 +1,9 @@
66513 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
66514 +#define _LINUX_NETFILTER_XT_GRADM_H 1
66515 +
66516 +struct xt_gradm_mtinfo {
66517 + __u16 flags;
66518 + __u16 invflags;
66519 +};
66520 +
66521 +#endif
66522 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
66523 index d65746e..62e72c2 100644
66524 --- a/include/linux/notifier.h
66525 +++ b/include/linux/notifier.h
66526 @@ -51,7 +51,8 @@ struct notifier_block {
66527 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
66528 struct notifier_block __rcu *next;
66529 int priority;
66530 -};
66531 +} __do_const;
66532 +typedef struct notifier_block __no_const notifier_block_no_const;
66533
66534 struct atomic_notifier_head {
66535 spinlock_t lock;
66536 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
66537 index a4c5624..79d6d88 100644
66538 --- a/include/linux/oprofile.h
66539 +++ b/include/linux/oprofile.h
66540 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
66541 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
66542 char const * name, ulong * val);
66543
66544 -/** Create a file for read-only access to an atomic_t. */
66545 +/** Create a file for read-only access to an atomic_unchecked_t. */
66546 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
66547 - char const * name, atomic_t * val);
66548 + char const * name, atomic_unchecked_t * val);
66549
66550 /** create a directory */
66551 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
66552 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
66553 index 6bfb2faa..e5bc5e5 100644
66554 --- a/include/linux/perf_event.h
66555 +++ b/include/linux/perf_event.h
66556 @@ -328,8 +328,8 @@ struct perf_event {
66557
66558 enum perf_event_active_state state;
66559 unsigned int attach_state;
66560 - local64_t count;
66561 - atomic64_t child_count;
66562 + local64_t count; /* PaX: fix it one day */
66563 + atomic64_unchecked_t child_count;
66564
66565 /*
66566 * These are the total time in nanoseconds that the event
66567 @@ -380,8 +380,8 @@ struct perf_event {
66568 * These accumulate total time (in nanoseconds) that children
66569 * events have been enabled and running, respectively.
66570 */
66571 - atomic64_t child_total_time_enabled;
66572 - atomic64_t child_total_time_running;
66573 + atomic64_unchecked_t child_total_time_enabled;
66574 + atomic64_unchecked_t child_total_time_running;
66575
66576 /*
66577 * Protect attach/detach and child_list:
66578 @@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
66579 */
66580 #define perf_cpu_notifier(fn) \
66581 do { \
66582 - static struct notifier_block fn##_nb __cpuinitdata = \
66583 + static struct notifier_block fn##_nb = \
66584 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
66585 unsigned long cpu = smp_processor_id(); \
66586 unsigned long flags; \
66587 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
66588 index ad1a427..6419649 100644
66589 --- a/include/linux/pipe_fs_i.h
66590 +++ b/include/linux/pipe_fs_i.h
66591 @@ -45,9 +45,9 @@ struct pipe_buffer {
66592 struct pipe_inode_info {
66593 wait_queue_head_t wait;
66594 unsigned int nrbufs, curbuf, buffers;
66595 - unsigned int readers;
66596 - unsigned int writers;
66597 - unsigned int waiting_writers;
66598 + atomic_t readers;
66599 + atomic_t writers;
66600 + atomic_t waiting_writers;
66601 unsigned int r_counter;
66602 unsigned int w_counter;
66603 struct page *tmp_page;
66604 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
66605 index 5f28cae..3d23723 100644
66606 --- a/include/linux/platform_data/usb-ehci-s5p.h
66607 +++ b/include/linux/platform_data/usb-ehci-s5p.h
66608 @@ -14,7 +14,7 @@
66609 struct s5p_ehci_platdata {
66610 int (*phy_init)(struct platform_device *pdev, int type);
66611 int (*phy_exit)(struct platform_device *pdev, int type);
66612 -};
66613 +} __no_const;
66614
66615 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
66616
66617 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
66618 index f271860..6b3bec5 100644
66619 --- a/include/linux/pm_runtime.h
66620 +++ b/include/linux/pm_runtime.h
66621 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
66622
66623 static inline void pm_runtime_mark_last_busy(struct device *dev)
66624 {
66625 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
66626 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
66627 }
66628
66629 #else /* !CONFIG_PM_RUNTIME */
66630 diff --git a/include/linux/poison.h b/include/linux/poison.h
66631 index 2110a81..13a11bb 100644
66632 --- a/include/linux/poison.h
66633 +++ b/include/linux/poison.h
66634 @@ -19,8 +19,8 @@
66635 * under normal circumstances, used to verify that nobody uses
66636 * non-initialized list entries.
66637 */
66638 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
66639 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
66640 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
66641 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
66642
66643 /********** include/linux/timer.h **********/
66644 /*
66645 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
66646 index c0f44c2..1572583 100644
66647 --- a/include/linux/power/smartreflex.h
66648 +++ b/include/linux/power/smartreflex.h
66649 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
66650 int (*notify)(struct omap_sr *sr, u32 status);
66651 u8 notify_flags;
66652 u8 class_type;
66653 -};
66654 +} __do_const;
66655
66656 /**
66657 * struct omap_sr_nvalue_table - Smartreflex n-target value info
66658 diff --git a/include/linux/printk.h b/include/linux/printk.h
66659 index 9afc01e..92c32e8 100644
66660 --- a/include/linux/printk.h
66661 +++ b/include/linux/printk.h
66662 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
66663 extern int printk_needs_cpu(int cpu);
66664 extern void printk_tick(void);
66665
66666 +extern int kptr_restrict;
66667 +
66668 #ifdef CONFIG_PRINTK
66669 asmlinkage __printf(5, 0)
66670 int vprintk_emit(int facility, int level,
66671 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
66672
66673 extern int printk_delay_msec;
66674 extern int dmesg_restrict;
66675 -extern int kptr_restrict;
66676
66677 void log_buf_kexec_setup(void);
66678 void __init setup_log_buf(int early);
66679 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
66680 index 32676b3..8f7a182 100644
66681 --- a/include/linux/proc_fs.h
66682 +++ b/include/linux/proc_fs.h
66683 @@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
66684 return proc_create_data(name, mode, parent, proc_fops, NULL);
66685 }
66686
66687 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
66688 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
66689 +{
66690 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66691 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
66692 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66693 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
66694 +#else
66695 + return proc_create_data(name, mode, parent, proc_fops, NULL);
66696 +#endif
66697 +}
66698 +
66699 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
66700 umode_t mode, struct proc_dir_entry *base,
66701 read_proc_t *read_proc, void * data)
66702 diff --git a/include/linux/random.h b/include/linux/random.h
66703 index d984608..d6f0042 100644
66704 --- a/include/linux/random.h
66705 +++ b/include/linux/random.h
66706 @@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
66707 u32 prandom_u32_state(struct rnd_state *);
66708 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
66709
66710 +static inline unsigned long pax_get_random_long(void)
66711 +{
66712 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
66713 +}
66714 +
66715 /*
66716 * Handle minimum values for seeds
66717 */
66718 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
66719 index 23b3630..e1bc12b 100644
66720 --- a/include/linux/reboot.h
66721 +++ b/include/linux/reboot.h
66722 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
66723 * Architecture-specific implementations of sys_reboot commands.
66724 */
66725
66726 -extern void machine_restart(char *cmd);
66727 -extern void machine_halt(void);
66728 -extern void machine_power_off(void);
66729 +extern void machine_restart(char *cmd) __noreturn;
66730 +extern void machine_halt(void) __noreturn;
66731 +extern void machine_power_off(void) __noreturn;
66732
66733 extern void machine_shutdown(void);
66734 struct pt_regs;
66735 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
66736 */
66737
66738 extern void kernel_restart_prepare(char *cmd);
66739 -extern void kernel_restart(char *cmd);
66740 -extern void kernel_halt(void);
66741 -extern void kernel_power_off(void);
66742 +extern void kernel_restart(char *cmd) __noreturn;
66743 +extern void kernel_halt(void) __noreturn;
66744 +extern void kernel_power_off(void) __noreturn;
66745
66746 extern int C_A_D; /* for sysctl */
66747 void ctrl_alt_del(void);
66748 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
66749 * Emergency restart, callable from an interrupt handler.
66750 */
66751
66752 -extern void emergency_restart(void);
66753 +extern void emergency_restart(void) __noreturn;
66754 #include <asm/emergency-restart.h>
66755
66756 #endif /* _LINUX_REBOOT_H */
66757 diff --git a/include/linux/regset.h b/include/linux/regset.h
66758 index 8e0c9fe..ac4d221 100644
66759 --- a/include/linux/regset.h
66760 +++ b/include/linux/regset.h
66761 @@ -161,7 +161,8 @@ struct user_regset {
66762 unsigned int align;
66763 unsigned int bias;
66764 unsigned int core_note_type;
66765 -};
66766 +} __do_const;
66767 +typedef struct user_regset __no_const user_regset_no_const;
66768
66769 /**
66770 * struct user_regset_view - available regsets
66771 diff --git a/include/linux/relay.h b/include/linux/relay.h
66772 index 91cacc3..b55ff74 100644
66773 --- a/include/linux/relay.h
66774 +++ b/include/linux/relay.h
66775 @@ -160,7 +160,7 @@ struct rchan_callbacks
66776 * The callback should return 0 if successful, negative if not.
66777 */
66778 int (*remove_buf_file)(struct dentry *dentry);
66779 -};
66780 +} __no_const;
66781
66782 /*
66783 * CONFIG_RELAY kernel API, kernel/relay.c
66784 diff --git a/include/linux/rio.h b/include/linux/rio.h
66785 index a3e7842..d973ca6 100644
66786 --- a/include/linux/rio.h
66787 +++ b/include/linux/rio.h
66788 @@ -339,7 +339,7 @@ struct rio_ops {
66789 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
66790 u64 rstart, u32 size, u32 flags);
66791 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
66792 -};
66793 +} __no_const;
66794
66795 #define RIO_RESOURCE_MEM 0x00000100
66796 #define RIO_RESOURCE_DOORBELL 0x00000200
66797 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
66798 index c20635c..2f5def4 100644
66799 --- a/include/linux/rmap.h
66800 +++ b/include/linux/rmap.h
66801 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
66802 void anon_vma_init(void); /* create anon_vma_cachep */
66803 int anon_vma_prepare(struct vm_area_struct *);
66804 void unlink_anon_vmas(struct vm_area_struct *);
66805 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66806 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66807 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66808 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66809
66810 static inline void anon_vma_merge(struct vm_area_struct *vma,
66811 struct vm_area_struct *next)
66812 diff --git a/include/linux/sched.h b/include/linux/sched.h
66813 index d211247..d64a165 100644
66814 --- a/include/linux/sched.h
66815 +++ b/include/linux/sched.h
66816 @@ -61,6 +61,7 @@ struct bio_list;
66817 struct fs_struct;
66818 struct perf_event_context;
66819 struct blk_plug;
66820 +struct linux_binprm;
66821
66822 /*
66823 * List of flags we want to share for kernel threads,
66824 @@ -354,10 +355,23 @@ struct user_namespace;
66825 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66826
66827 extern int sysctl_max_map_count;
66828 +extern unsigned long sysctl_heap_stack_gap;
66829
66830 #include <linux/aio.h>
66831
66832 #ifdef CONFIG_MMU
66833 +
66834 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66835 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66836 +#else
66837 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66838 +{
66839 + return 0;
66840 +}
66841 +#endif
66842 +
66843 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66844 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66845 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66846 extern unsigned long
66847 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66848 @@ -639,6 +653,17 @@ struct signal_struct {
66849 #ifdef CONFIG_TASKSTATS
66850 struct taskstats *stats;
66851 #endif
66852 +
66853 +#ifdef CONFIG_GRKERNSEC
66854 + u32 curr_ip;
66855 + u32 saved_ip;
66856 + u32 gr_saddr;
66857 + u32 gr_daddr;
66858 + u16 gr_sport;
66859 + u16 gr_dport;
66860 + u8 used_accept:1;
66861 +#endif
66862 +
66863 #ifdef CONFIG_AUDIT
66864 unsigned audit_tty;
66865 struct tty_audit_buf *tty_audit_buf;
66866 @@ -717,6 +742,11 @@ struct user_struct {
66867 struct key *session_keyring; /* UID's default session keyring */
66868 #endif
66869
66870 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66871 + unsigned int banned;
66872 + unsigned long ban_expires;
66873 +#endif
66874 +
66875 /* Hash table maintenance information */
66876 struct hlist_node uidhash_node;
66877 kuid_t uid;
66878 @@ -1360,8 +1390,8 @@ struct task_struct {
66879 struct list_head thread_group;
66880
66881 struct completion *vfork_done; /* for vfork() */
66882 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66883 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66884 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66885 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66886
66887 cputime_t utime, stime, utimescaled, stimescaled;
66888 cputime_t gtime;
66889 @@ -1377,11 +1407,6 @@ struct task_struct {
66890 struct task_cputime cputime_expires;
66891 struct list_head cpu_timers[3];
66892
66893 -/* process credentials */
66894 - const struct cred __rcu *real_cred; /* objective and real subjective task
66895 - * credentials (COW) */
66896 - const struct cred __rcu *cred; /* effective (overridable) subjective task
66897 - * credentials (COW) */
66898 char comm[TASK_COMM_LEN]; /* executable name excluding path
66899 - access with [gs]et_task_comm (which lock
66900 it with task_lock())
66901 @@ -1398,6 +1423,10 @@ struct task_struct {
66902 #endif
66903 /* CPU-specific state of this task */
66904 struct thread_struct thread;
66905 +/* thread_info moved to task_struct */
66906 +#ifdef CONFIG_X86
66907 + struct thread_info tinfo;
66908 +#endif
66909 /* filesystem information */
66910 struct fs_struct *fs;
66911 /* open file information */
66912 @@ -1471,6 +1500,10 @@ struct task_struct {
66913 gfp_t lockdep_reclaim_gfp;
66914 #endif
66915
66916 +/* process credentials */
66917 + const struct cred __rcu *real_cred; /* objective and real subjective task
66918 + * credentials (COW) */
66919 +
66920 /* journalling filesystem info */
66921 void *journal_info;
66922
66923 @@ -1509,6 +1542,10 @@ struct task_struct {
66924 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66925 struct list_head cg_list;
66926 #endif
66927 +
66928 + const struct cred __rcu *cred; /* effective (overridable) subjective task
66929 + * credentials (COW) */
66930 +
66931 #ifdef CONFIG_FUTEX
66932 struct robust_list_head __user *robust_list;
66933 #ifdef CONFIG_COMPAT
66934 @@ -1605,8 +1642,74 @@ struct task_struct {
66935 #ifdef CONFIG_UPROBES
66936 struct uprobe_task *utask;
66937 #endif
66938 +
66939 +#ifdef CONFIG_GRKERNSEC
66940 + /* grsecurity */
66941 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66942 + u64 exec_id;
66943 +#endif
66944 +#ifdef CONFIG_GRKERNSEC_SETXID
66945 + const struct cred *delayed_cred;
66946 +#endif
66947 + struct dentry *gr_chroot_dentry;
66948 + struct acl_subject_label *acl;
66949 + struct acl_role_label *role;
66950 + struct file *exec_file;
66951 + unsigned long brute_expires;
66952 + u16 acl_role_id;
66953 + /* is this the task that authenticated to the special role */
66954 + u8 acl_sp_role;
66955 + u8 is_writable;
66956 + u8 brute;
66957 + u8 gr_is_chrooted;
66958 +#endif
66959 +
66960 };
66961
66962 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66963 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66964 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66965 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66966 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66967 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66968 +
66969 +#ifdef CONFIG_PAX_SOFTMODE
66970 +extern int pax_softmode;
66971 +#endif
66972 +
66973 +extern int pax_check_flags(unsigned long *);
66974 +
66975 +/* if tsk != current then task_lock must be held on it */
66976 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66977 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
66978 +{
66979 + if (likely(tsk->mm))
66980 + return tsk->mm->pax_flags;
66981 + else
66982 + return 0UL;
66983 +}
66984 +
66985 +/* if tsk != current then task_lock must be held on it */
66986 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66987 +{
66988 + if (likely(tsk->mm)) {
66989 + tsk->mm->pax_flags = flags;
66990 + return 0;
66991 + }
66992 + return -EINVAL;
66993 +}
66994 +#endif
66995 +
66996 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66997 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
66998 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66999 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
67000 +#endif
67001 +
67002 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
67003 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
67004 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
67005 +
67006 /* Future-safe accessor for struct task_struct's cpus_allowed. */
67007 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
67008
67009 @@ -2155,7 +2258,9 @@ void yield(void);
67010 extern struct exec_domain default_exec_domain;
67011
67012 union thread_union {
67013 +#ifndef CONFIG_X86
67014 struct thread_info thread_info;
67015 +#endif
67016 unsigned long stack[THREAD_SIZE/sizeof(long)];
67017 };
67018
67019 @@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
67020 */
67021
67022 extern struct task_struct *find_task_by_vpid(pid_t nr);
67023 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
67024 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
67025 struct pid_namespace *ns);
67026
67027 @@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
67028 extern void exit_itimers(struct signal_struct *);
67029 extern void flush_itimer_signals(void);
67030
67031 -extern void do_group_exit(int);
67032 +extern __noreturn void do_group_exit(int);
67033
67034 extern int allow_signal(int);
67035 extern int disallow_signal(int);
67036 @@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
67037
67038 #endif
67039
67040 -static inline int object_is_on_stack(void *obj)
67041 +static inline int object_starts_on_stack(void *obj)
67042 {
67043 - void *stack = task_stack_page(current);
67044 + const void *stack = task_stack_page(current);
67045
67046 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
67047 }
67048 diff --git a/include/linux/security.h b/include/linux/security.h
67049 index eee7478..290f7ba 100644
67050 --- a/include/linux/security.h
67051 +++ b/include/linux/security.h
67052 @@ -26,6 +26,7 @@
67053 #include <linux/capability.h>
67054 #include <linux/slab.h>
67055 #include <linux/err.h>
67056 +#include <linux/grsecurity.h>
67057
67058 struct linux_binprm;
67059 struct cred;
67060 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
67061 index 68a04a3..866e6a1 100644
67062 --- a/include/linux/seq_file.h
67063 +++ b/include/linux/seq_file.h
67064 @@ -26,6 +26,9 @@ struct seq_file {
67065 struct mutex lock;
67066 const struct seq_operations *op;
67067 int poll_event;
67068 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67069 + u64 exec_id;
67070 +#endif
67071 #ifdef CONFIG_USER_NS
67072 struct user_namespace *user_ns;
67073 #endif
67074 @@ -38,6 +41,7 @@ struct seq_operations {
67075 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
67076 int (*show) (struct seq_file *m, void *v);
67077 };
67078 +typedef struct seq_operations __no_const seq_operations_no_const;
67079
67080 #define SEQ_SKIP 1
67081
67082 diff --git a/include/linux/shm.h b/include/linux/shm.h
67083 index 429c199..4d42e38 100644
67084 --- a/include/linux/shm.h
67085 +++ b/include/linux/shm.h
67086 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
67087
67088 /* The task created the shm object. NULL if the task is dead. */
67089 struct task_struct *shm_creator;
67090 +#ifdef CONFIG_GRKERNSEC
67091 + time_t shm_createtime;
67092 + pid_t shm_lapid;
67093 +#endif
67094 };
67095
67096 /* shm_mode upper byte flags */
67097 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
67098 index 320e976..fd52553 100644
67099 --- a/include/linux/skbuff.h
67100 +++ b/include/linux/skbuff.h
67101 @@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
67102 extern struct sk_buff *__alloc_skb(unsigned int size,
67103 gfp_t priority, int flags, int node);
67104 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
67105 -static inline struct sk_buff *alloc_skb(unsigned int size,
67106 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
67107 gfp_t priority)
67108 {
67109 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
67110 @@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
67111 */
67112 static inline int skb_queue_empty(const struct sk_buff_head *list)
67113 {
67114 - return list->next == (struct sk_buff *)list;
67115 + return list->next == (const struct sk_buff *)list;
67116 }
67117
67118 /**
67119 @@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
67120 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67121 const struct sk_buff *skb)
67122 {
67123 - return skb->next == (struct sk_buff *)list;
67124 + return skb->next == (const struct sk_buff *)list;
67125 }
67126
67127 /**
67128 @@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67129 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
67130 const struct sk_buff *skb)
67131 {
67132 - return skb->prev == (struct sk_buff *)list;
67133 + return skb->prev == (const struct sk_buff *)list;
67134 }
67135
67136 /**
67137 @@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
67138 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
67139 */
67140 #ifndef NET_SKB_PAD
67141 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
67142 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
67143 #endif
67144
67145 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
67146 @@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
67147 int noblock, int *err);
67148 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
67149 struct poll_table_struct *wait);
67150 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
67151 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
67152 int offset, struct iovec *to,
67153 int size);
67154 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
67155 diff --git a/include/linux/slab.h b/include/linux/slab.h
67156 index 5d168d7..720bff3 100644
67157 --- a/include/linux/slab.h
67158 +++ b/include/linux/slab.h
67159 @@ -12,13 +12,20 @@
67160 #include <linux/gfp.h>
67161 #include <linux/types.h>
67162 #include <linux/workqueue.h>
67163 -
67164 +#include <linux/err.h>
67165
67166 /*
67167 * Flags to pass to kmem_cache_create().
67168 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
67169 */
67170 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
67171 +
67172 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67173 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
67174 +#else
67175 +#define SLAB_USERCOPY 0x00000000UL
67176 +#endif
67177 +
67178 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
67179 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
67180 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
67181 @@ -89,10 +96,13 @@
67182 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
67183 * Both make kfree a no-op.
67184 */
67185 -#define ZERO_SIZE_PTR ((void *)16)
67186 +#define ZERO_SIZE_PTR \
67187 +({ \
67188 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
67189 + (void *)(-MAX_ERRNO-1L); \
67190 +})
67191
67192 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
67193 - (unsigned long)ZERO_SIZE_PTR)
67194 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
67195
67196 /*
67197 * Common fields provided in kmem_cache by all slab allocators
67198 @@ -112,7 +122,7 @@ struct kmem_cache {
67199 unsigned int align; /* Alignment as calculated */
67200 unsigned long flags; /* Active flags on the slab */
67201 const char *name; /* Slab name for sysfs */
67202 - int refcount; /* Use counter */
67203 + atomic_t refcount; /* Use counter */
67204 void (*ctor)(void *); /* Called on object slot creation */
67205 struct list_head list; /* List of all slab caches on the system */
67206 };
67207 @@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
67208 void kfree(const void *);
67209 void kzfree(const void *);
67210 size_t ksize(const void *);
67211 +const char *check_heap_object(const void *ptr, unsigned long n);
67212 +bool is_usercopy_object(const void *ptr);
67213
67214 /*
67215 * Allocator specific definitions. These are mainly used to establish optimized
67216 @@ -311,6 +323,7 @@ size_t ksize(const void *);
67217 * for general use, and so are not documented here. For a full list of
67218 * potential flags, always refer to linux/gfp.h.
67219 */
67220 +
67221 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
67222 {
67223 if (size != 0 && n > SIZE_MAX / size)
67224 @@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
67225 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67226 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67227 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67228 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67229 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
67230 #define kmalloc_track_caller(size, flags) \
67231 __kmalloc_track_caller(size, flags, _RET_IP_)
67232 #else
67233 @@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67234 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67235 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67236 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67237 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
67238 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
67239 #define kmalloc_node_track_caller(size, flags, node) \
67240 __kmalloc_node_track_caller(size, flags, node, \
67241 _RET_IP_)
67242 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
67243 index 8bb6e0e..8eb0dbe 100644
67244 --- a/include/linux/slab_def.h
67245 +++ b/include/linux/slab_def.h
67246 @@ -52,7 +52,7 @@ struct kmem_cache {
67247 /* 4) cache creation/removal */
67248 const char *name;
67249 struct list_head list;
67250 - int refcount;
67251 + atomic_t refcount;
67252 int object_size;
67253 int align;
67254
67255 @@ -68,10 +68,10 @@ struct kmem_cache {
67256 unsigned long node_allocs;
67257 unsigned long node_frees;
67258 unsigned long node_overflow;
67259 - atomic_t allochit;
67260 - atomic_t allocmiss;
67261 - atomic_t freehit;
67262 - atomic_t freemiss;
67263 + atomic_unchecked_t allochit;
67264 + atomic_unchecked_t allocmiss;
67265 + atomic_unchecked_t freehit;
67266 + atomic_unchecked_t freemiss;
67267
67268 /*
67269 * If debugging is enabled, then the allocator can add additional
67270 @@ -111,11 +111,16 @@ struct cache_sizes {
67271 #ifdef CONFIG_ZONE_DMA
67272 struct kmem_cache *cs_dmacachep;
67273 #endif
67274 +
67275 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67276 + struct kmem_cache *cs_usercopycachep;
67277 +#endif
67278 +
67279 };
67280 extern struct cache_sizes malloc_sizes[];
67281
67282 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67283 -void *__kmalloc(size_t size, gfp_t flags);
67284 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
67285
67286 #ifdef CONFIG_TRACING
67287 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
67288 @@ -152,6 +157,13 @@ found:
67289 cachep = malloc_sizes[i].cs_dmacachep;
67290 else
67291 #endif
67292 +
67293 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67294 + if (flags & GFP_USERCOPY)
67295 + cachep = malloc_sizes[i].cs_usercopycachep;
67296 + else
67297 +#endif
67298 +
67299 cachep = malloc_sizes[i].cs_cachep;
67300
67301 ret = kmem_cache_alloc_trace(cachep, flags, size);
67302 @@ -162,7 +174,7 @@ found:
67303 }
67304
67305 #ifdef CONFIG_NUMA
67306 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
67307 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67308 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67309
67310 #ifdef CONFIG_TRACING
67311 @@ -205,6 +217,13 @@ found:
67312 cachep = malloc_sizes[i].cs_dmacachep;
67313 else
67314 #endif
67315 +
67316 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67317 + if (flags & GFP_USERCOPY)
67318 + cachep = malloc_sizes[i].cs_usercopycachep;
67319 + else
67320 +#endif
67321 +
67322 cachep = malloc_sizes[i].cs_cachep;
67323
67324 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
67325 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
67326 index f28e14a..7831211 100644
67327 --- a/include/linux/slob_def.h
67328 +++ b/include/linux/slob_def.h
67329 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
67330 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
67331 }
67332
67333 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
67334 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67335
67336 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
67337 {
67338 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67339 return __kmalloc_node(size, flags, NUMA_NO_NODE);
67340 }
67341
67342 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
67343 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
67344 {
67345 return kmalloc(size, flags);
67346 }
67347 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
67348 index 9db4825..ed42fb5 100644
67349 --- a/include/linux/slub_def.h
67350 +++ b/include/linux/slub_def.h
67351 @@ -91,7 +91,7 @@ struct kmem_cache {
67352 struct kmem_cache_order_objects max;
67353 struct kmem_cache_order_objects min;
67354 gfp_t allocflags; /* gfp flags to use on each alloc */
67355 - int refcount; /* Refcount for slab cache destroy */
67356 + atomic_t refcount; /* Refcount for slab cache destroy */
67357 void (*ctor)(void *);
67358 int inuse; /* Offset to metadata */
67359 int align; /* Alignment */
67360 @@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
67361 * Sorry that the following has to be that ugly but some versions of GCC
67362 * have trouble with constant propagation and loops.
67363 */
67364 -static __always_inline int kmalloc_index(size_t size)
67365 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
67366 {
67367 if (!size)
67368 return 0;
67369 @@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
67370 }
67371
67372 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67373 -void *__kmalloc(size_t size, gfp_t flags);
67374 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
67375
67376 static __always_inline void *
67377 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
67378 @@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
67379 }
67380 #endif
67381
67382 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
67383 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
67384 {
67385 unsigned int order = get_order(size);
67386 return kmalloc_order_trace(size, flags, order);
67387 @@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67388 }
67389
67390 #ifdef CONFIG_NUMA
67391 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
67392 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67393 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67394
67395 #ifdef CONFIG_TRACING
67396 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
67397 index 680f9a3..f13aeb0 100644
67398 --- a/include/linux/sonet.h
67399 +++ b/include/linux/sonet.h
67400 @@ -7,7 +7,7 @@
67401 #include <uapi/linux/sonet.h>
67402
67403 struct k_sonet_stats {
67404 -#define __HANDLE_ITEM(i) atomic_t i
67405 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
67406 __SONET_ITEMS
67407 #undef __HANDLE_ITEM
67408 };
67409 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
67410 index 34206b8..f019e06 100644
67411 --- a/include/linux/sunrpc/clnt.h
67412 +++ b/include/linux/sunrpc/clnt.h
67413 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
67414 {
67415 switch (sap->sa_family) {
67416 case AF_INET:
67417 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
67418 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
67419 case AF_INET6:
67420 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
67421 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
67422 }
67423 return 0;
67424 }
67425 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
67426 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
67427 const struct sockaddr *src)
67428 {
67429 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
67430 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
67431 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
67432
67433 dsin->sin_family = ssin->sin_family;
67434 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
67435 if (sa->sa_family != AF_INET6)
67436 return 0;
67437
67438 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
67439 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
67440 }
67441
67442 #endif /* __KERNEL__ */
67443 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
67444 index 0b8e3e6..33e0a01 100644
67445 --- a/include/linux/sunrpc/svc_rdma.h
67446 +++ b/include/linux/sunrpc/svc_rdma.h
67447 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
67448 extern unsigned int svcrdma_max_requests;
67449 extern unsigned int svcrdma_max_req_size;
67450
67451 -extern atomic_t rdma_stat_recv;
67452 -extern atomic_t rdma_stat_read;
67453 -extern atomic_t rdma_stat_write;
67454 -extern atomic_t rdma_stat_sq_starve;
67455 -extern atomic_t rdma_stat_rq_starve;
67456 -extern atomic_t rdma_stat_rq_poll;
67457 -extern atomic_t rdma_stat_rq_prod;
67458 -extern atomic_t rdma_stat_sq_poll;
67459 -extern atomic_t rdma_stat_sq_prod;
67460 +extern atomic_unchecked_t rdma_stat_recv;
67461 +extern atomic_unchecked_t rdma_stat_read;
67462 +extern atomic_unchecked_t rdma_stat_write;
67463 +extern atomic_unchecked_t rdma_stat_sq_starve;
67464 +extern atomic_unchecked_t rdma_stat_rq_starve;
67465 +extern atomic_unchecked_t rdma_stat_rq_poll;
67466 +extern atomic_unchecked_t rdma_stat_rq_prod;
67467 +extern atomic_unchecked_t rdma_stat_sq_poll;
67468 +extern atomic_unchecked_t rdma_stat_sq_prod;
67469
67470 #define RPCRDMA_VERSION 1
67471
67472 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
67473 index 14a8ff2..21fe4c7 100644
67474 --- a/include/linux/sysctl.h
67475 +++ b/include/linux/sysctl.h
67476 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
67477
67478 extern int proc_dostring(struct ctl_table *, int,
67479 void __user *, size_t *, loff_t *);
67480 +extern int proc_dostring_modpriv(struct ctl_table *, int,
67481 + void __user *, size_t *, loff_t *);
67482 extern int proc_dointvec(struct ctl_table *, int,
67483 void __user *, size_t *, loff_t *);
67484 extern int proc_dointvec_minmax(struct ctl_table *, int,
67485 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
67486 index 7faf933..eb6f5e3 100644
67487 --- a/include/linux/sysrq.h
67488 +++ b/include/linux/sysrq.h
67489 @@ -36,7 +36,7 @@ struct sysrq_key_op {
67490 char *help_msg;
67491 char *action_msg;
67492 int enable_mask;
67493 -};
67494 +} __do_const;
67495
67496 #ifdef CONFIG_MAGIC_SYSRQ
67497
67498 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
67499 index e7e0473..39b7b52 100644
67500 --- a/include/linux/thread_info.h
67501 +++ b/include/linux/thread_info.h
67502 @@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
67503 #error "no set_restore_sigmask() provided and default one won't work"
67504 #endif
67505
67506 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
67507 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
67508 +{
67509 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
67510 + if (!__builtin_constant_p(n))
67511 +#endif
67512 + __check_object_size(ptr, n, to);
67513 +}
67514 +
67515 #endif /* __KERNEL__ */
67516
67517 #endif /* _LINUX_THREAD_INFO_H */
67518 diff --git a/include/linux/tty.h b/include/linux/tty.h
67519 index 8db1b56..c16a040 100644
67520 --- a/include/linux/tty.h
67521 +++ b/include/linux/tty.h
67522 @@ -194,7 +194,7 @@ struct tty_port {
67523 const struct tty_port_operations *ops; /* Port operations */
67524 spinlock_t lock; /* Lock protecting tty field */
67525 int blocked_open; /* Waiting to open */
67526 - int count; /* Usage count */
67527 + atomic_t count; /* Usage count */
67528 wait_queue_head_t open_wait; /* Open waiters */
67529 wait_queue_head_t close_wait; /* Close waiters */
67530 wait_queue_head_t delta_msr_wait; /* Modem status change */
67531 @@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
67532 struct tty_struct *tty, struct file *filp);
67533 static inline int tty_port_users(struct tty_port *port)
67534 {
67535 - return port->count + port->blocked_open;
67536 + return atomic_read(&port->count) + port->blocked_open;
67537 }
67538
67539 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
67540 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
67541 index dd976cf..e272742 100644
67542 --- a/include/linux/tty_driver.h
67543 +++ b/include/linux/tty_driver.h
67544 @@ -284,7 +284,7 @@ struct tty_operations {
67545 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
67546 #endif
67547 const struct file_operations *proc_fops;
67548 -};
67549 +} __do_const;
67550
67551 struct tty_driver {
67552 int magic; /* magic number for this structure */
67553 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
67554 index fb79dd8d..07d4773 100644
67555 --- a/include/linux/tty_ldisc.h
67556 +++ b/include/linux/tty_ldisc.h
67557 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
67558
67559 struct module *owner;
67560
67561 - int refcount;
67562 + atomic_t refcount;
67563 };
67564
67565 struct tty_ldisc {
67566 diff --git a/include/linux/types.h b/include/linux/types.h
67567 index 4d118ba..c3ee9bf 100644
67568 --- a/include/linux/types.h
67569 +++ b/include/linux/types.h
67570 @@ -176,10 +176,26 @@ typedef struct {
67571 int counter;
67572 } atomic_t;
67573
67574 +#ifdef CONFIG_PAX_REFCOUNT
67575 +typedef struct {
67576 + int counter;
67577 +} atomic_unchecked_t;
67578 +#else
67579 +typedef atomic_t atomic_unchecked_t;
67580 +#endif
67581 +
67582 #ifdef CONFIG_64BIT
67583 typedef struct {
67584 long counter;
67585 } atomic64_t;
67586 +
67587 +#ifdef CONFIG_PAX_REFCOUNT
67588 +typedef struct {
67589 + long counter;
67590 +} atomic64_unchecked_t;
67591 +#else
67592 +typedef atomic64_t atomic64_unchecked_t;
67593 +#endif
67594 #endif
67595
67596 struct list_head {
67597 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
67598 index 5ca0951..ab496a5 100644
67599 --- a/include/linux/uaccess.h
67600 +++ b/include/linux/uaccess.h
67601 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
67602 long ret; \
67603 mm_segment_t old_fs = get_fs(); \
67604 \
67605 - set_fs(KERNEL_DS); \
67606 pagefault_disable(); \
67607 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
67608 - pagefault_enable(); \
67609 + set_fs(KERNEL_DS); \
67610 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
67611 set_fs(old_fs); \
67612 + pagefault_enable(); \
67613 ret; \
67614 })
67615
67616 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
67617 index 99c1b4d..bb94261 100644
67618 --- a/include/linux/unaligned/access_ok.h
67619 +++ b/include/linux/unaligned/access_ok.h
67620 @@ -6,32 +6,32 @@
67621
67622 static inline u16 get_unaligned_le16(const void *p)
67623 {
67624 - return le16_to_cpup((__le16 *)p);
67625 + return le16_to_cpup((const __le16 *)p);
67626 }
67627
67628 static inline u32 get_unaligned_le32(const void *p)
67629 {
67630 - return le32_to_cpup((__le32 *)p);
67631 + return le32_to_cpup((const __le32 *)p);
67632 }
67633
67634 static inline u64 get_unaligned_le64(const void *p)
67635 {
67636 - return le64_to_cpup((__le64 *)p);
67637 + return le64_to_cpup((const __le64 *)p);
67638 }
67639
67640 static inline u16 get_unaligned_be16(const void *p)
67641 {
67642 - return be16_to_cpup((__be16 *)p);
67643 + return be16_to_cpup((const __be16 *)p);
67644 }
67645
67646 static inline u32 get_unaligned_be32(const void *p)
67647 {
67648 - return be32_to_cpup((__be32 *)p);
67649 + return be32_to_cpup((const __be32 *)p);
67650 }
67651
67652 static inline u64 get_unaligned_be64(const void *p)
67653 {
67654 - return be64_to_cpup((__be64 *)p);
67655 + return be64_to_cpup((const __be64 *)p);
67656 }
67657
67658 static inline void put_unaligned_le16(u16 val, void *p)
67659 diff --git a/include/linux/usb.h b/include/linux/usb.h
67660 index 4d22d0f..ac43c2f 100644
67661 --- a/include/linux/usb.h
67662 +++ b/include/linux/usb.h
67663 @@ -554,7 +554,7 @@ struct usb_device {
67664 int maxchild;
67665
67666 u32 quirks;
67667 - atomic_t urbnum;
67668 + atomic_unchecked_t urbnum;
67669
67670 unsigned long active_duration;
67671
67672 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
67673 index c5d36c6..108f4f9 100644
67674 --- a/include/linux/usb/renesas_usbhs.h
67675 +++ b/include/linux/usb/renesas_usbhs.h
67676 @@ -39,7 +39,7 @@ enum {
67677 */
67678 struct renesas_usbhs_driver_callback {
67679 int (*notify_hotplug)(struct platform_device *pdev);
67680 -};
67681 +} __no_const;
67682
67683 /*
67684 * callback functions for platform
67685 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
67686 index 6f8fbcf..8259001 100644
67687 --- a/include/linux/vermagic.h
67688 +++ b/include/linux/vermagic.h
67689 @@ -25,9 +25,35 @@
67690 #define MODULE_ARCH_VERMAGIC ""
67691 #endif
67692
67693 +#ifdef CONFIG_PAX_REFCOUNT
67694 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
67695 +#else
67696 +#define MODULE_PAX_REFCOUNT ""
67697 +#endif
67698 +
67699 +#ifdef CONSTIFY_PLUGIN
67700 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
67701 +#else
67702 +#define MODULE_CONSTIFY_PLUGIN ""
67703 +#endif
67704 +
67705 +#ifdef STACKLEAK_PLUGIN
67706 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
67707 +#else
67708 +#define MODULE_STACKLEAK_PLUGIN ""
67709 +#endif
67710 +
67711 +#ifdef CONFIG_GRKERNSEC
67712 +#define MODULE_GRSEC "GRSEC "
67713 +#else
67714 +#define MODULE_GRSEC ""
67715 +#endif
67716 +
67717 #define VERMAGIC_STRING \
67718 UTS_RELEASE " " \
67719 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
67720 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
67721 - MODULE_ARCH_VERMAGIC
67722 + MODULE_ARCH_VERMAGIC \
67723 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
67724 + MODULE_GRSEC
67725
67726 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
67727 index 6071e91..ca6a489 100644
67728 --- a/include/linux/vmalloc.h
67729 +++ b/include/linux/vmalloc.h
67730 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
67731 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
67732 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
67733 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
67734 +
67735 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67736 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
67737 +#endif
67738 +
67739 /* bits [20..32] reserved for arch specific ioremap internals */
67740
67741 /*
67742 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
67743 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
67744 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
67745 unsigned long start, unsigned long end, gfp_t gfp_mask,
67746 - pgprot_t prot, int node, const void *caller);
67747 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
67748 extern void vfree(const void *addr);
67749
67750 extern void *vmap(struct page **pages, unsigned int count,
67751 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
67752 extern void free_vm_area(struct vm_struct *area);
67753
67754 /* for /dev/kmem */
67755 -extern long vread(char *buf, char *addr, unsigned long count);
67756 -extern long vwrite(char *buf, char *addr, unsigned long count);
67757 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
67758 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
67759
67760 /*
67761 * Internals. Dont't use..
67762 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
67763 index a13291f..af51fa3 100644
67764 --- a/include/linux/vmstat.h
67765 +++ b/include/linux/vmstat.h
67766 @@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
67767 /*
67768 * Zone based page accounting with per cpu differentials.
67769 */
67770 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67771 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67772
67773 static inline void zone_page_state_add(long x, struct zone *zone,
67774 enum zone_stat_item item)
67775 {
67776 - atomic_long_add(x, &zone->vm_stat[item]);
67777 - atomic_long_add(x, &vm_stat[item]);
67778 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67779 + atomic_long_add_unchecked(x, &vm_stat[item]);
67780 }
67781
67782 static inline unsigned long global_page_state(enum zone_stat_item item)
67783 {
67784 - long x = atomic_long_read(&vm_stat[item]);
67785 + long x = atomic_long_read_unchecked(&vm_stat[item]);
67786 #ifdef CONFIG_SMP
67787 if (x < 0)
67788 x = 0;
67789 @@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67790 static inline unsigned long zone_page_state(struct zone *zone,
67791 enum zone_stat_item item)
67792 {
67793 - long x = atomic_long_read(&zone->vm_stat[item]);
67794 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67795 #ifdef CONFIG_SMP
67796 if (x < 0)
67797 x = 0;
67798 @@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67799 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67800 enum zone_stat_item item)
67801 {
67802 - long x = atomic_long_read(&zone->vm_stat[item]);
67803 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67804
67805 #ifdef CONFIG_SMP
67806 int cpu;
67807 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67808
67809 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67810 {
67811 - atomic_long_inc(&zone->vm_stat[item]);
67812 - atomic_long_inc(&vm_stat[item]);
67813 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
67814 + atomic_long_inc_unchecked(&vm_stat[item]);
67815 }
67816
67817 static inline void __inc_zone_page_state(struct page *page,
67818 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
67819
67820 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67821 {
67822 - atomic_long_dec(&zone->vm_stat[item]);
67823 - atomic_long_dec(&vm_stat[item]);
67824 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
67825 + atomic_long_dec_unchecked(&vm_stat[item]);
67826 }
67827
67828 static inline void __dec_zone_page_state(struct page *page,
67829 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67830 index 95d1c91..6798cca 100644
67831 --- a/include/media/v4l2-dev.h
67832 +++ b/include/media/v4l2-dev.h
67833 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
67834 int (*mmap) (struct file *, struct vm_area_struct *);
67835 int (*open) (struct file *);
67836 int (*release) (struct file *);
67837 -};
67838 +} __do_const;
67839
67840 /*
67841 * Newer version of video_device, handled by videodev2.c
67842 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67843 index 4118ad1..cb7e25f 100644
67844 --- a/include/media/v4l2-ioctl.h
67845 +++ b/include/media/v4l2-ioctl.h
67846 @@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
67847 bool valid_prio, int cmd, void *arg);
67848 };
67849
67850 -
67851 /* v4l debugging and diagnostics */
67852
67853 /* Debug bitmask flags to be used on V4L2 */
67854 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67855 index 9e5425b..8136ffc 100644
67856 --- a/include/net/caif/cfctrl.h
67857 +++ b/include/net/caif/cfctrl.h
67858 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
67859 void (*radioset_rsp)(void);
67860 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67861 struct cflayer *client_layer);
67862 -};
67863 +} __no_const;
67864
67865 /* Link Setup Parameters for CAIF-Links. */
67866 struct cfctrl_link_param {
67867 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
67868 struct cfctrl {
67869 struct cfsrvl serv;
67870 struct cfctrl_rsp res;
67871 - atomic_t req_seq_no;
67872 - atomic_t rsp_seq_no;
67873 + atomic_unchecked_t req_seq_no;
67874 + atomic_unchecked_t rsp_seq_no;
67875 struct list_head list;
67876 /* Protects from simultaneous access to first_req list */
67877 spinlock_t info_list_lock;
67878 diff --git a/include/net/flow.h b/include/net/flow.h
67879 index 628e11b..4c475df 100644
67880 --- a/include/net/flow.h
67881 +++ b/include/net/flow.h
67882 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67883
67884 extern void flow_cache_flush(void);
67885 extern void flow_cache_flush_deferred(void);
67886 -extern atomic_t flow_cache_genid;
67887 +extern atomic_unchecked_t flow_cache_genid;
67888
67889 #endif
67890 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67891 index e5062c9..48a9a4b 100644
67892 --- a/include/net/gro_cells.h
67893 +++ b/include/net/gro_cells.h
67894 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67895 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67896
67897 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67898 - atomic_long_inc(&dev->rx_dropped);
67899 + atomic_long_inc_unchecked(&dev->rx_dropped);
67900 kfree_skb(skb);
67901 return;
67902 }
67903 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67904 int i;
67905
67906 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67907 - gcells->cells = kcalloc(sizeof(struct gro_cell),
67908 - gcells->gro_cells_mask + 1,
67909 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67910 + sizeof(struct gro_cell),
67911 GFP_KERNEL);
67912 if (!gcells->cells)
67913 return -ENOMEM;
67914 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67915 index 1832927..ce39aea 100644
67916 --- a/include/net/inet_connection_sock.h
67917 +++ b/include/net/inet_connection_sock.h
67918 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67919 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67920 int (*bind_conflict)(const struct sock *sk,
67921 const struct inet_bind_bucket *tb, bool relax);
67922 -};
67923 +} __do_const;
67924
67925 /** inet_connection_sock - INET connection oriented sock
67926 *
67927 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67928 index 53f464d..ba76aaa 100644
67929 --- a/include/net/inetpeer.h
67930 +++ b/include/net/inetpeer.h
67931 @@ -47,8 +47,8 @@ struct inet_peer {
67932 */
67933 union {
67934 struct {
67935 - atomic_t rid; /* Frag reception counter */
67936 - atomic_t ip_id_count; /* IP ID for the next packet */
67937 + atomic_unchecked_t rid; /* Frag reception counter */
67938 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67939 };
67940 struct rcu_head rcu;
67941 struct inet_peer *gc_next;
67942 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67943 more++;
67944 inet_peer_refcheck(p);
67945 do {
67946 - old = atomic_read(&p->ip_id_count);
67947 + old = atomic_read_unchecked(&p->ip_id_count);
67948 new = old + more;
67949 if (!new)
67950 new = 1;
67951 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67952 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67953 return new;
67954 }
67955
67956 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67957 index 9497be1..5a4fafe 100644
67958 --- a/include/net/ip_fib.h
67959 +++ b/include/net/ip_fib.h
67960 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67961
67962 #define FIB_RES_SADDR(net, res) \
67963 ((FIB_RES_NH(res).nh_saddr_genid == \
67964 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67965 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67966 FIB_RES_NH(res).nh_saddr : \
67967 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67968 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67969 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67970 index 68c69d5..2ee192b 100644
67971 --- a/include/net/ip_vs.h
67972 +++ b/include/net/ip_vs.h
67973 @@ -599,7 +599,7 @@ struct ip_vs_conn {
67974 struct ip_vs_conn *control; /* Master control connection */
67975 atomic_t n_control; /* Number of controlled ones */
67976 struct ip_vs_dest *dest; /* real server */
67977 - atomic_t in_pkts; /* incoming packet counter */
67978 + atomic_unchecked_t in_pkts; /* incoming packet counter */
67979
67980 /* packet transmitter for different forwarding methods. If it
67981 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67982 @@ -737,7 +737,7 @@ struct ip_vs_dest {
67983 __be16 port; /* port number of the server */
67984 union nf_inet_addr addr; /* IP address of the server */
67985 volatile unsigned int flags; /* dest status flags */
67986 - atomic_t conn_flags; /* flags to copy to conn */
67987 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
67988 atomic_t weight; /* server weight */
67989
67990 atomic_t refcnt; /* reference counter */
67991 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67992 index 80ffde3..968b0f4 100644
67993 --- a/include/net/irda/ircomm_tty.h
67994 +++ b/include/net/irda/ircomm_tty.h
67995 @@ -35,6 +35,7 @@
67996 #include <linux/termios.h>
67997 #include <linux/timer.h>
67998 #include <linux/tty.h> /* struct tty_struct */
67999 +#include <asm/local.h>
68000
68001 #include <net/irda/irias_object.h>
68002 #include <net/irda/ircomm_core.h>
68003 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
68004 index cc7c197..9f2da2a 100644
68005 --- a/include/net/iucv/af_iucv.h
68006 +++ b/include/net/iucv/af_iucv.h
68007 @@ -141,7 +141,7 @@ struct iucv_sock {
68008 struct iucv_sock_list {
68009 struct hlist_head head;
68010 rwlock_t lock;
68011 - atomic_t autobind_name;
68012 + atomic_unchecked_t autobind_name;
68013 };
68014
68015 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
68016 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
68017 index 0dab173..1b76af0 100644
68018 --- a/include/net/neighbour.h
68019 +++ b/include/net/neighbour.h
68020 @@ -123,7 +123,7 @@ struct neigh_ops {
68021 void (*error_report)(struct neighbour *, struct sk_buff *);
68022 int (*output)(struct neighbour *, struct sk_buff *);
68023 int (*connected_output)(struct neighbour *, struct sk_buff *);
68024 -};
68025 +} __do_const;
68026
68027 struct pneigh_entry {
68028 struct pneigh_entry *next;
68029 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
68030 index de644bc..666aed3 100644
68031 --- a/include/net/net_namespace.h
68032 +++ b/include/net/net_namespace.h
68033 @@ -115,7 +115,7 @@ struct net {
68034 #endif
68035 struct netns_ipvs *ipvs;
68036 struct sock *diag_nlsk;
68037 - atomic_t rt_genid;
68038 + atomic_unchecked_t rt_genid;
68039 };
68040
68041 /*
68042 @@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
68043
68044 static inline int rt_genid(struct net *net)
68045 {
68046 - return atomic_read(&net->rt_genid);
68047 + return atomic_read_unchecked(&net->rt_genid);
68048 }
68049
68050 static inline void rt_genid_bump(struct net *net)
68051 {
68052 - atomic_inc(&net->rt_genid);
68053 + atomic_inc_unchecked(&net->rt_genid);
68054 }
68055
68056 #endif /* __NET_NET_NAMESPACE_H */
68057 diff --git a/include/net/netdma.h b/include/net/netdma.h
68058 index 8ba8ce2..99b7fff 100644
68059 --- a/include/net/netdma.h
68060 +++ b/include/net/netdma.h
68061 @@ -24,7 +24,7 @@
68062 #include <linux/dmaengine.h>
68063 #include <linux/skbuff.h>
68064
68065 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68066 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68067 struct sk_buff *skb, int offset, struct iovec *to,
68068 size_t len, struct dma_pinned_list *pinned_list);
68069
68070 diff --git a/include/net/netlink.h b/include/net/netlink.h
68071 index 9690b0f..87aded7 100644
68072 --- a/include/net/netlink.h
68073 +++ b/include/net/netlink.h
68074 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
68075 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
68076 {
68077 if (mark)
68078 - skb_trim(skb, (unsigned char *) mark - skb->data);
68079 + skb_trim(skb, (const unsigned char *) mark - skb->data);
68080 }
68081
68082 /**
68083 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
68084 index 2ae2b83..dbdc85e 100644
68085 --- a/include/net/netns/ipv4.h
68086 +++ b/include/net/netns/ipv4.h
68087 @@ -64,7 +64,7 @@ struct netns_ipv4 {
68088 kgid_t sysctl_ping_group_range[2];
68089 long sysctl_tcp_mem[3];
68090
68091 - atomic_t dev_addr_genid;
68092 + atomic_unchecked_t dev_addr_genid;
68093
68094 #ifdef CONFIG_IP_MROUTE
68095 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
68096 diff --git a/include/net/protocol.h b/include/net/protocol.h
68097 index 047c047..b9dad15 100644
68098 --- a/include/net/protocol.h
68099 +++ b/include/net/protocol.h
68100 @@ -44,7 +44,7 @@ struct net_protocol {
68101 void (*err_handler)(struct sk_buff *skb, u32 info);
68102 unsigned int no_policy:1,
68103 netns_ok:1;
68104 -};
68105 +} __do_const;
68106
68107 #if IS_ENABLED(CONFIG_IPV6)
68108 struct inet6_protocol {
68109 @@ -57,7 +57,7 @@ struct inet6_protocol {
68110 u8 type, u8 code, int offset,
68111 __be32 info);
68112 unsigned int flags; /* INET6_PROTO_xxx */
68113 -};
68114 +} __do_const;
68115
68116 #define INET6_PROTO_NOPOLICY 0x1
68117 #define INET6_PROTO_FINAL 0x2
68118 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
68119 index 7fdf298..197e9f7 100644
68120 --- a/include/net/sctp/sctp.h
68121 +++ b/include/net/sctp/sctp.h
68122 @@ -330,9 +330,9 @@ do { \
68123
68124 #else /* SCTP_DEBUG */
68125
68126 -#define SCTP_DEBUG_PRINTK(whatever...)
68127 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
68128 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
68129 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
68130 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
68131 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
68132 #define SCTP_ENABLE_DEBUG
68133 #define SCTP_DISABLE_DEBUG
68134 #define SCTP_ASSERT(expr, str, func)
68135 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
68136 index fdeb85a..0c554d5 100644
68137 --- a/include/net/sctp/structs.h
68138 +++ b/include/net/sctp/structs.h
68139 @@ -497,7 +497,7 @@ struct sctp_af {
68140 int sockaddr_len;
68141 sa_family_t sa_family;
68142 struct list_head list;
68143 -};
68144 +} __do_const;
68145
68146 struct sctp_af *sctp_get_af_specific(sa_family_t);
68147 int sctp_register_af(struct sctp_af *);
68148 @@ -517,7 +517,7 @@ struct sctp_pf {
68149 struct sctp_association *asoc);
68150 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
68151 struct sctp_af *af;
68152 -};
68153 +} __do_const;
68154
68155
68156 /* Structure to track chunk fragments that have been acked, but peer
68157 diff --git a/include/net/sock.h b/include/net/sock.h
68158 index 182ca99..b7dc290 100644
68159 --- a/include/net/sock.h
68160 +++ b/include/net/sock.h
68161 @@ -322,7 +322,7 @@ struct sock {
68162 #ifdef CONFIG_RPS
68163 __u32 sk_rxhash;
68164 #endif
68165 - atomic_t sk_drops;
68166 + atomic_unchecked_t sk_drops;
68167 int sk_rcvbuf;
68168
68169 struct sk_filter __rcu *sk_filter;
68170 @@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
68171 }
68172
68173 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
68174 - char __user *from, char *to,
68175 + char __user *from, unsigned char *to,
68176 int copy, int offset)
68177 {
68178 if (skb->ip_summed == CHECKSUM_NONE) {
68179 @@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
68180 }
68181 }
68182
68183 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68184 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68185
68186 /**
68187 * sk_page_frag - return an appropriate page_frag
68188 diff --git a/include/net/tcp.h b/include/net/tcp.h
68189 index aed42c7..43890c6 100644
68190 --- a/include/net/tcp.h
68191 +++ b/include/net/tcp.h
68192 @@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
68193 extern void tcp_xmit_retransmit_queue(struct sock *);
68194 extern void tcp_simple_retransmit(struct sock *);
68195 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
68196 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68197 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68198
68199 extern void tcp_send_probe0(struct sock *);
68200 extern void tcp_send_partial(struct sock *);
68201 @@ -701,8 +701,8 @@ struct tcp_skb_cb {
68202 struct inet6_skb_parm h6;
68203 #endif
68204 } header; /* For incoming frames */
68205 - __u32 seq; /* Starting sequence number */
68206 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
68207 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
68208 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
68209 __u32 when; /* used to compute rtt's */
68210 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
68211
68212 @@ -716,7 +716,7 @@ struct tcp_skb_cb {
68213
68214 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
68215 /* 1 byte hole */
68216 - __u32 ack_seq; /* Sequence number ACK'd */
68217 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
68218 };
68219
68220 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
68221 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
68222 index 63445ed..74ef61d 100644
68223 --- a/include/net/xfrm.h
68224 +++ b/include/net/xfrm.h
68225 @@ -423,7 +423,7 @@ struct xfrm_mode {
68226 struct module *owner;
68227 unsigned int encap;
68228 int flags;
68229 -};
68230 +} __do_const;
68231
68232 /* Flags for xfrm_mode. */
68233 enum {
68234 @@ -514,7 +514,7 @@ struct xfrm_policy {
68235 struct timer_list timer;
68236
68237 struct flow_cache_object flo;
68238 - atomic_t genid;
68239 + atomic_unchecked_t genid;
68240 u32 priority;
68241 u32 index;
68242 struct xfrm_mark mark;
68243 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
68244 index 1a046b1..ee0bef0 100644
68245 --- a/include/rdma/iw_cm.h
68246 +++ b/include/rdma/iw_cm.h
68247 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
68248 int backlog);
68249
68250 int (*destroy_listen)(struct iw_cm_id *cm_id);
68251 -};
68252 +} __no_const;
68253
68254 /**
68255 * iw_create_cm_id - Create an IW CM identifier.
68256 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
68257 index 399162b..b337f1a 100644
68258 --- a/include/scsi/libfc.h
68259 +++ b/include/scsi/libfc.h
68260 @@ -762,6 +762,7 @@ struct libfc_function_template {
68261 */
68262 void (*disc_stop_final) (struct fc_lport *);
68263 };
68264 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
68265
68266 /**
68267 * struct fc_disc - Discovery context
68268 @@ -866,7 +867,7 @@ struct fc_lport {
68269 struct fc_vport *vport;
68270
68271 /* Operational Information */
68272 - struct libfc_function_template tt;
68273 + libfc_function_template_no_const tt;
68274 u8 link_up;
68275 u8 qfull;
68276 enum fc_lport_state state;
68277 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
68278 index e65c62e..aa2e5a2 100644
68279 --- a/include/scsi/scsi_device.h
68280 +++ b/include/scsi/scsi_device.h
68281 @@ -170,9 +170,9 @@ struct scsi_device {
68282 unsigned int max_device_blocked; /* what device_blocked counts down from */
68283 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
68284
68285 - atomic_t iorequest_cnt;
68286 - atomic_t iodone_cnt;
68287 - atomic_t ioerr_cnt;
68288 + atomic_unchecked_t iorequest_cnt;
68289 + atomic_unchecked_t iodone_cnt;
68290 + atomic_unchecked_t ioerr_cnt;
68291
68292 struct device sdev_gendev,
68293 sdev_dev;
68294 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
68295 index b797e8f..8e2c3aa 100644
68296 --- a/include/scsi/scsi_transport_fc.h
68297 +++ b/include/scsi/scsi_transport_fc.h
68298 @@ -751,7 +751,8 @@ struct fc_function_template {
68299 unsigned long show_host_system_hostname:1;
68300
68301 unsigned long disable_target_scan:1;
68302 -};
68303 +} __do_const;
68304 +typedef struct fc_function_template __no_const fc_function_template_no_const;
68305
68306
68307 /**
68308 diff --git a/include/sound/soc.h b/include/sound/soc.h
68309 index bc56738..a4be132 100644
68310 --- a/include/sound/soc.h
68311 +++ b/include/sound/soc.h
68312 @@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
68313 /* probe ordering - for components with runtime dependencies */
68314 int probe_order;
68315 int remove_order;
68316 -};
68317 +} __do_const;
68318
68319 /* SoC platform interface */
68320 struct snd_soc_platform_driver {
68321 @@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
68322 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
68323 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
68324 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
68325 -};
68326 +} __do_const;
68327
68328 struct snd_soc_platform {
68329 const char *name;
68330 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
68331 index 663e34a..91b306a 100644
68332 --- a/include/target/target_core_base.h
68333 +++ b/include/target/target_core_base.h
68334 @@ -654,7 +654,7 @@ struct se_device {
68335 spinlock_t stats_lock;
68336 /* Active commands on this virtual SE device */
68337 atomic_t simple_cmds;
68338 - atomic_t dev_ordered_id;
68339 + atomic_unchecked_t dev_ordered_id;
68340 atomic_t dev_ordered_sync;
68341 atomic_t dev_qf_count;
68342 int export_count;
68343 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
68344 new file mode 100644
68345 index 0000000..fb634b7
68346 --- /dev/null
68347 +++ b/include/trace/events/fs.h
68348 @@ -0,0 +1,53 @@
68349 +#undef TRACE_SYSTEM
68350 +#define TRACE_SYSTEM fs
68351 +
68352 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
68353 +#define _TRACE_FS_H
68354 +
68355 +#include <linux/fs.h>
68356 +#include <linux/tracepoint.h>
68357 +
68358 +TRACE_EVENT(do_sys_open,
68359 +
68360 + TP_PROTO(const char *filename, int flags, int mode),
68361 +
68362 + TP_ARGS(filename, flags, mode),
68363 +
68364 + TP_STRUCT__entry(
68365 + __string( filename, filename )
68366 + __field( int, flags )
68367 + __field( int, mode )
68368 + ),
68369 +
68370 + TP_fast_assign(
68371 + __assign_str(filename, filename);
68372 + __entry->flags = flags;
68373 + __entry->mode = mode;
68374 + ),
68375 +
68376 + TP_printk("\"%s\" %x %o",
68377 + __get_str(filename), __entry->flags, __entry->mode)
68378 +);
68379 +
68380 +TRACE_EVENT(open_exec,
68381 +
68382 + TP_PROTO(const char *filename),
68383 +
68384 + TP_ARGS(filename),
68385 +
68386 + TP_STRUCT__entry(
68387 + __string( filename, filename )
68388 + ),
68389 +
68390 + TP_fast_assign(
68391 + __assign_str(filename, filename);
68392 + ),
68393 +
68394 + TP_printk("\"%s\"",
68395 + __get_str(filename))
68396 +);
68397 +
68398 +#endif /* _TRACE_FS_H */
68399 +
68400 +/* This part must be outside protection */
68401 +#include <trace/define_trace.h>
68402 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
68403 index 1c09820..7f5ec79 100644
68404 --- a/include/trace/events/irq.h
68405 +++ b/include/trace/events/irq.h
68406 @@ -36,7 +36,7 @@ struct softirq_action;
68407 */
68408 TRACE_EVENT(irq_handler_entry,
68409
68410 - TP_PROTO(int irq, struct irqaction *action),
68411 + TP_PROTO(int irq, const struct irqaction *action),
68412
68413 TP_ARGS(irq, action),
68414
68415 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
68416 */
68417 TRACE_EVENT(irq_handler_exit,
68418
68419 - TP_PROTO(int irq, struct irqaction *action, int ret),
68420 + TP_PROTO(int irq, const struct irqaction *action, int ret),
68421
68422 TP_ARGS(irq, action, ret),
68423
68424 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
68425 index 7caf44c..23c6f27 100644
68426 --- a/include/uapi/linux/a.out.h
68427 +++ b/include/uapi/linux/a.out.h
68428 @@ -39,6 +39,14 @@ enum machine_type {
68429 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
68430 };
68431
68432 +/* Constants for the N_FLAGS field */
68433 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68434 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
68435 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
68436 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
68437 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68438 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68439 +
68440 #if !defined (N_MAGIC)
68441 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
68442 #endif
68443 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
68444 index d876736..b36014e 100644
68445 --- a/include/uapi/linux/byteorder/little_endian.h
68446 +++ b/include/uapi/linux/byteorder/little_endian.h
68447 @@ -42,51 +42,51 @@
68448
68449 static inline __le64 __cpu_to_le64p(const __u64 *p)
68450 {
68451 - return (__force __le64)*p;
68452 + return (__force const __le64)*p;
68453 }
68454 static inline __u64 __le64_to_cpup(const __le64 *p)
68455 {
68456 - return (__force __u64)*p;
68457 + return (__force const __u64)*p;
68458 }
68459 static inline __le32 __cpu_to_le32p(const __u32 *p)
68460 {
68461 - return (__force __le32)*p;
68462 + return (__force const __le32)*p;
68463 }
68464 static inline __u32 __le32_to_cpup(const __le32 *p)
68465 {
68466 - return (__force __u32)*p;
68467 + return (__force const __u32)*p;
68468 }
68469 static inline __le16 __cpu_to_le16p(const __u16 *p)
68470 {
68471 - return (__force __le16)*p;
68472 + return (__force const __le16)*p;
68473 }
68474 static inline __u16 __le16_to_cpup(const __le16 *p)
68475 {
68476 - return (__force __u16)*p;
68477 + return (__force const __u16)*p;
68478 }
68479 static inline __be64 __cpu_to_be64p(const __u64 *p)
68480 {
68481 - return (__force __be64)__swab64p(p);
68482 + return (__force const __be64)__swab64p(p);
68483 }
68484 static inline __u64 __be64_to_cpup(const __be64 *p)
68485 {
68486 - return __swab64p((__u64 *)p);
68487 + return __swab64p((const __u64 *)p);
68488 }
68489 static inline __be32 __cpu_to_be32p(const __u32 *p)
68490 {
68491 - return (__force __be32)__swab32p(p);
68492 + return (__force const __be32)__swab32p(p);
68493 }
68494 static inline __u32 __be32_to_cpup(const __be32 *p)
68495 {
68496 - return __swab32p((__u32 *)p);
68497 + return __swab32p((const __u32 *)p);
68498 }
68499 static inline __be16 __cpu_to_be16p(const __u16 *p)
68500 {
68501 - return (__force __be16)__swab16p(p);
68502 + return (__force const __be16)__swab16p(p);
68503 }
68504 static inline __u16 __be16_to_cpup(const __be16 *p)
68505 {
68506 - return __swab16p((__u16 *)p);
68507 + return __swab16p((const __u16 *)p);
68508 }
68509 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
68510 #define __le64_to_cpus(x) do { (void)(x); } while (0)
68511 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
68512 index 126a817..d522bd1 100644
68513 --- a/include/uapi/linux/elf.h
68514 +++ b/include/uapi/linux/elf.h
68515 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
68516 #define PT_GNU_EH_FRAME 0x6474e550
68517
68518 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
68519 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
68520 +
68521 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
68522 +
68523 +/* Constants for the e_flags field */
68524 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68525 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
68526 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
68527 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
68528 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68529 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68530
68531 /*
68532 * Extended Numbering
68533 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
68534 #define DT_DEBUG 21
68535 #define DT_TEXTREL 22
68536 #define DT_JMPREL 23
68537 +#define DT_FLAGS 30
68538 + #define DF_TEXTREL 0x00000004
68539 #define DT_ENCODING 32
68540 #define OLD_DT_LOOS 0x60000000
68541 #define DT_LOOS 0x6000000d
68542 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
68543 #define PF_W 0x2
68544 #define PF_X 0x1
68545
68546 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
68547 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
68548 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
68549 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
68550 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
68551 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
68552 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
68553 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
68554 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
68555 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
68556 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
68557 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
68558 +
68559 typedef struct elf32_phdr{
68560 Elf32_Word p_type;
68561 Elf32_Off p_offset;
68562 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
68563 #define EI_OSABI 7
68564 #define EI_PAD 8
68565
68566 +#define EI_PAX 14
68567 +
68568 #define ELFMAG0 0x7f /* EI_MAG */
68569 #define ELFMAG1 'E'
68570 #define ELFMAG2 'L'
68571 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
68572 index aa169c4..6a2771d 100644
68573 --- a/include/uapi/linux/personality.h
68574 +++ b/include/uapi/linux/personality.h
68575 @@ -30,6 +30,7 @@ enum {
68576 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
68577 ADDR_NO_RANDOMIZE | \
68578 ADDR_COMPAT_LAYOUT | \
68579 + ADDR_LIMIT_3GB | \
68580 MMAP_PAGE_ZERO)
68581
68582 /*
68583 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
68584 index 7530e74..e714828 100644
68585 --- a/include/uapi/linux/screen_info.h
68586 +++ b/include/uapi/linux/screen_info.h
68587 @@ -43,7 +43,8 @@ struct screen_info {
68588 __u16 pages; /* 0x32 */
68589 __u16 vesa_attributes; /* 0x34 */
68590 __u32 capabilities; /* 0x36 */
68591 - __u8 _reserved[6]; /* 0x3a */
68592 + __u16 vesapm_size; /* 0x3a */
68593 + __u8 _reserved[4]; /* 0x3c */
68594 } __attribute__((packed));
68595
68596 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68597 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
68598 index 6d67213..8dab561 100644
68599 --- a/include/uapi/linux/sysctl.h
68600 +++ b/include/uapi/linux/sysctl.h
68601 @@ -155,7 +155,11 @@ enum
68602 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68603 };
68604
68605 -
68606 +#ifdef CONFIG_PAX_SOFTMODE
68607 +enum {
68608 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68609 +};
68610 +#endif
68611
68612 /* CTL_VM names: */
68613 enum
68614 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
68615 index 26607bd..588b65f 100644
68616 --- a/include/uapi/linux/xattr.h
68617 +++ b/include/uapi/linux/xattr.h
68618 @@ -60,5 +60,9 @@
68619 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
68620 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
68621
68622 +/* User namespace */
68623 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
68624 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
68625 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
68626
68627 #endif /* _UAPI_LINUX_XATTR_H */
68628 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
68629 index f9466fa..f4e2b81 100644
68630 --- a/include/video/udlfb.h
68631 +++ b/include/video/udlfb.h
68632 @@ -53,10 +53,10 @@ struct dlfb_data {
68633 u32 pseudo_palette[256];
68634 int blank_mode; /*one of FB_BLANK_ */
68635 /* blit-only rendering path metrics, exposed through sysfs */
68636 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68637 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
68638 - atomic_t bytes_sent; /* to usb, after compression including overhead */
68639 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
68640 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68641 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
68642 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
68643 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
68644 };
68645
68646 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
68647 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
68648 index 0993a22..32ba2fe 100644
68649 --- a/include/video/uvesafb.h
68650 +++ b/include/video/uvesafb.h
68651 @@ -177,6 +177,7 @@ struct uvesafb_par {
68652 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
68653 u8 pmi_setpal; /* PMI for palette changes */
68654 u16 *pmi_base; /* protected mode interface location */
68655 + u8 *pmi_code; /* protected mode code location */
68656 void *pmi_start;
68657 void *pmi_pal;
68658 u8 *vbe_state_orig; /*
68659 diff --git a/init/Kconfig b/init/Kconfig
68660 index be8b7f5..b13cb62 100644
68661 --- a/init/Kconfig
68662 +++ b/init/Kconfig
68663 @@ -990,6 +990,7 @@ endif # CGROUPS
68664
68665 config CHECKPOINT_RESTORE
68666 bool "Checkpoint/restore support" if EXPERT
68667 + depends on !GRKERNSEC
68668 default n
68669 help
68670 Enables additional kernel features in a sake of checkpoint/restore.
68671 @@ -1079,6 +1080,8 @@ config UIDGID_CONVERTED
68672 depends on OCFS2_FS = n
68673 depends on XFS_FS = n
68674
68675 + depends on GRKERNSEC = n
68676 +
68677 config UIDGID_STRICT_TYPE_CHECKS
68678 bool "Require conversions between uid/gids and their internal representation"
68679 depends on UIDGID_CONVERTED
68680 @@ -1468,7 +1471,7 @@ config SLUB_DEBUG
68681
68682 config COMPAT_BRK
68683 bool "Disable heap randomization"
68684 - default y
68685 + default n
68686 help
68687 Randomizing heap placement makes heap exploits harder, but it
68688 also breaks ancient binaries (including anything libc5 based).
68689 @@ -1711,7 +1714,7 @@ config INIT_ALL_POSSIBLE
68690 config STOP_MACHINE
68691 bool
68692 default y
68693 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
68694 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
68695 help
68696 Need stop_machine() primitive.
68697
68698 diff --git a/init/Makefile b/init/Makefile
68699 index 7bc47ee..6da2dc7 100644
68700 --- a/init/Makefile
68701 +++ b/init/Makefile
68702 @@ -2,6 +2,9 @@
68703 # Makefile for the linux kernel.
68704 #
68705
68706 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
68707 +asflags-y := $(GCC_PLUGINS_AFLAGS)
68708 +
68709 obj-y := main.o version.o mounts.o
68710 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
68711 obj-y += noinitramfs.o
68712 diff --git a/init/do_mounts.c b/init/do_mounts.c
68713 index 1d1b634..a1c810f 100644
68714 --- a/init/do_mounts.c
68715 +++ b/init/do_mounts.c
68716 @@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
68717 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
68718 {
68719 struct super_block *s;
68720 - int err = sys_mount(name, "/root", fs, flags, data);
68721 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
68722 if (err)
68723 return err;
68724
68725 - sys_chdir("/root");
68726 + sys_chdir((const char __force_user *)"/root");
68727 s = current->fs->pwd.dentry->d_sb;
68728 ROOT_DEV = s->s_dev;
68729 printk(KERN_INFO
68730 @@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
68731 va_start(args, fmt);
68732 vsprintf(buf, fmt, args);
68733 va_end(args);
68734 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
68735 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
68736 if (fd >= 0) {
68737 sys_ioctl(fd, FDEJECT, 0);
68738 sys_close(fd);
68739 }
68740 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
68741 - fd = sys_open("/dev/console", O_RDWR, 0);
68742 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
68743 if (fd >= 0) {
68744 sys_ioctl(fd, TCGETS, (long)&termios);
68745 termios.c_lflag &= ~ICANON;
68746 sys_ioctl(fd, TCSETSF, (long)&termios);
68747 - sys_read(fd, &c, 1);
68748 + sys_read(fd, (char __user *)&c, 1);
68749 termios.c_lflag |= ICANON;
68750 sys_ioctl(fd, TCSETSF, (long)&termios);
68751 sys_close(fd);
68752 @@ -585,6 +585,6 @@ void __init prepare_namespace(void)
68753 mount_root();
68754 out:
68755 devtmpfs_mount("dev");
68756 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
68757 - sys_chroot(".");
68758 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68759 + sys_chroot((const char __force_user *)".");
68760 }
68761 diff --git a/init/do_mounts.h b/init/do_mounts.h
68762 index f5b978a..69dbfe8 100644
68763 --- a/init/do_mounts.h
68764 +++ b/init/do_mounts.h
68765 @@ -15,15 +15,15 @@ extern int root_mountflags;
68766
68767 static inline int create_dev(char *name, dev_t dev)
68768 {
68769 - sys_unlink(name);
68770 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68771 + sys_unlink((char __force_user *)name);
68772 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68773 }
68774
68775 #if BITS_PER_LONG == 32
68776 static inline u32 bstat(char *name)
68777 {
68778 struct stat64 stat;
68779 - if (sys_stat64(name, &stat) != 0)
68780 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68781 return 0;
68782 if (!S_ISBLK(stat.st_mode))
68783 return 0;
68784 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68785 static inline u32 bstat(char *name)
68786 {
68787 struct stat stat;
68788 - if (sys_newstat(name, &stat) != 0)
68789 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68790 return 0;
68791 if (!S_ISBLK(stat.st_mode))
68792 return 0;
68793 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68794 index f9acf71..1e19144 100644
68795 --- a/init/do_mounts_initrd.c
68796 +++ b/init/do_mounts_initrd.c
68797 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68798 create_dev("/dev/root.old", Root_RAM0);
68799 /* mount initrd on rootfs' /root */
68800 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68801 - sys_mkdir("/old", 0700);
68802 - sys_chdir("/old");
68803 + sys_mkdir((const char __force_user *)"/old", 0700);
68804 + sys_chdir((const char __force_user *)"/old");
68805
68806 /*
68807 * In case that a resume from disk is carried out by linuxrc or one of
68808 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68809 current->flags &= ~PF_FREEZER_SKIP;
68810
68811 /* move initrd to rootfs' /old */
68812 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
68813 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68814 /* switch root and cwd back to / of rootfs */
68815 - sys_chroot("..");
68816 + sys_chroot((const char __force_user *)"..");
68817
68818 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68819 - sys_chdir("/old");
68820 + sys_chdir((const char __force_user *)"/old");
68821 return;
68822 }
68823
68824 - sys_chdir("/");
68825 + sys_chdir((const char __force_user *)"/");
68826 ROOT_DEV = new_decode_dev(real_root_dev);
68827 mount_root();
68828
68829 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68830 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68831 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68832 if (!error)
68833 printk("okay\n");
68834 else {
68835 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
68836 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68837 if (error == -ENOENT)
68838 printk("/initrd does not exist. Ignored.\n");
68839 else
68840 printk("failed\n");
68841 printk(KERN_NOTICE "Unmounting old root\n");
68842 - sys_umount("/old", MNT_DETACH);
68843 + sys_umount((char __force_user *)"/old", MNT_DETACH);
68844 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68845 if (fd < 0) {
68846 error = fd;
68847 @@ -120,11 +120,11 @@ int __init initrd_load(void)
68848 * mounted in the normal path.
68849 */
68850 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68851 - sys_unlink("/initrd.image");
68852 + sys_unlink((const char __force_user *)"/initrd.image");
68853 handle_initrd();
68854 return 1;
68855 }
68856 }
68857 - sys_unlink("/initrd.image");
68858 + sys_unlink((const char __force_user *)"/initrd.image");
68859 return 0;
68860 }
68861 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68862 index 8cb6db5..d729f50 100644
68863 --- a/init/do_mounts_md.c
68864 +++ b/init/do_mounts_md.c
68865 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68866 partitioned ? "_d" : "", minor,
68867 md_setup_args[ent].device_names);
68868
68869 - fd = sys_open(name, 0, 0);
68870 + fd = sys_open((char __force_user *)name, 0, 0);
68871 if (fd < 0) {
68872 printk(KERN_ERR "md: open failed - cannot start "
68873 "array %s\n", name);
68874 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68875 * array without it
68876 */
68877 sys_close(fd);
68878 - fd = sys_open(name, 0, 0);
68879 + fd = sys_open((char __force_user *)name, 0, 0);
68880 sys_ioctl(fd, BLKRRPART, 0);
68881 }
68882 sys_close(fd);
68883 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68884
68885 wait_for_device_probe();
68886
68887 - fd = sys_open("/dev/md0", 0, 0);
68888 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68889 if (fd >= 0) {
68890 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68891 sys_close(fd);
68892 diff --git a/init/init_task.c b/init/init_task.c
68893 index 8b2f399..f0797c9 100644
68894 --- a/init/init_task.c
68895 +++ b/init/init_task.c
68896 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68897 * Initial thread structure. Alignment of this is handled by a special
68898 * linker map entry.
68899 */
68900 +#ifdef CONFIG_X86
68901 +union thread_union init_thread_union __init_task_data;
68902 +#else
68903 union thread_union init_thread_union __init_task_data =
68904 { INIT_THREAD_INFO(init_task) };
68905 +#endif
68906 diff --git a/init/initramfs.c b/init/initramfs.c
68907 index 84c6bf1..8899338 100644
68908 --- a/init/initramfs.c
68909 +++ b/init/initramfs.c
68910 @@ -84,7 +84,7 @@ static void __init free_hash(void)
68911 }
68912 }
68913
68914 -static long __init do_utime(char *filename, time_t mtime)
68915 +static long __init do_utime(char __force_user *filename, time_t mtime)
68916 {
68917 struct timespec t[2];
68918
68919 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
68920 struct dir_entry *de, *tmp;
68921 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68922 list_del(&de->list);
68923 - do_utime(de->name, de->mtime);
68924 + do_utime((char __force_user *)de->name, de->mtime);
68925 kfree(de->name);
68926 kfree(de);
68927 }
68928 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
68929 if (nlink >= 2) {
68930 char *old = find_link(major, minor, ino, mode, collected);
68931 if (old)
68932 - return (sys_link(old, collected) < 0) ? -1 : 1;
68933 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68934 }
68935 return 0;
68936 }
68937 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68938 {
68939 struct stat st;
68940
68941 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68942 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68943 if (S_ISDIR(st.st_mode))
68944 - sys_rmdir(path);
68945 + sys_rmdir((char __force_user *)path);
68946 else
68947 - sys_unlink(path);
68948 + sys_unlink((char __force_user *)path);
68949 }
68950 }
68951
68952 @@ -315,7 +315,7 @@ static int __init do_name(void)
68953 int openflags = O_WRONLY|O_CREAT;
68954 if (ml != 1)
68955 openflags |= O_TRUNC;
68956 - wfd = sys_open(collected, openflags, mode);
68957 + wfd = sys_open((char __force_user *)collected, openflags, mode);
68958
68959 if (wfd >= 0) {
68960 sys_fchown(wfd, uid, gid);
68961 @@ -327,17 +327,17 @@ static int __init do_name(void)
68962 }
68963 }
68964 } else if (S_ISDIR(mode)) {
68965 - sys_mkdir(collected, mode);
68966 - sys_chown(collected, uid, gid);
68967 - sys_chmod(collected, mode);
68968 + sys_mkdir((char __force_user *)collected, mode);
68969 + sys_chown((char __force_user *)collected, uid, gid);
68970 + sys_chmod((char __force_user *)collected, mode);
68971 dir_add(collected, mtime);
68972 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68973 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68974 if (maybe_link() == 0) {
68975 - sys_mknod(collected, mode, rdev);
68976 - sys_chown(collected, uid, gid);
68977 - sys_chmod(collected, mode);
68978 - do_utime(collected, mtime);
68979 + sys_mknod((char __force_user *)collected, mode, rdev);
68980 + sys_chown((char __force_user *)collected, uid, gid);
68981 + sys_chmod((char __force_user *)collected, mode);
68982 + do_utime((char __force_user *)collected, mtime);
68983 }
68984 }
68985 return 0;
68986 @@ -346,15 +346,15 @@ static int __init do_name(void)
68987 static int __init do_copy(void)
68988 {
68989 if (count >= body_len) {
68990 - sys_write(wfd, victim, body_len);
68991 + sys_write(wfd, (char __force_user *)victim, body_len);
68992 sys_close(wfd);
68993 - do_utime(vcollected, mtime);
68994 + do_utime((char __force_user *)vcollected, mtime);
68995 kfree(vcollected);
68996 eat(body_len);
68997 state = SkipIt;
68998 return 0;
68999 } else {
69000 - sys_write(wfd, victim, count);
69001 + sys_write(wfd, (char __force_user *)victim, count);
69002 body_len -= count;
69003 eat(count);
69004 return 1;
69005 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
69006 {
69007 collected[N_ALIGN(name_len) + body_len] = '\0';
69008 clean_path(collected, 0);
69009 - sys_symlink(collected + N_ALIGN(name_len), collected);
69010 - sys_lchown(collected, uid, gid);
69011 - do_utime(collected, mtime);
69012 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
69013 + sys_lchown((char __force_user *)collected, uid, gid);
69014 + do_utime((char __force_user *)collected, mtime);
69015 state = SkipIt;
69016 next_state = Reset;
69017 return 0;
69018 diff --git a/init/main.c b/init/main.c
69019 index cee4b5c..47f445e 100644
69020 --- a/init/main.c
69021 +++ b/init/main.c
69022 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
69023 extern void tc_init(void);
69024 #endif
69025
69026 +extern void grsecurity_init(void);
69027 +
69028 /*
69029 * Debug helper: via this flag we know that we are in 'early bootup code'
69030 * where only the boot processor is running with IRQ disabled. This means
69031 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
69032
69033 __setup("reset_devices", set_reset_devices);
69034
69035 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69036 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
69037 +static int __init setup_grsec_proc_gid(char *str)
69038 +{
69039 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
69040 + return 1;
69041 +}
69042 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
69043 +#endif
69044 +
69045 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
69046 +extern char pax_enter_kernel_user[];
69047 +extern char pax_exit_kernel_user[];
69048 +extern pgdval_t clone_pgd_mask;
69049 +#endif
69050 +
69051 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
69052 +static int __init setup_pax_nouderef(char *str)
69053 +{
69054 +#ifdef CONFIG_X86_32
69055 + unsigned int cpu;
69056 + struct desc_struct *gdt;
69057 +
69058 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
69059 + gdt = get_cpu_gdt_table(cpu);
69060 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
69061 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
69062 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
69063 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
69064 + }
69065 + loadsegment(ds, __KERNEL_DS);
69066 + loadsegment(es, __KERNEL_DS);
69067 + loadsegment(ss, __KERNEL_DS);
69068 +#else
69069 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
69070 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
69071 + clone_pgd_mask = ~(pgdval_t)0UL;
69072 +#endif
69073 +
69074 + return 0;
69075 +}
69076 +early_param("pax_nouderef", setup_pax_nouderef);
69077 +#endif
69078 +
69079 +#ifdef CONFIG_PAX_SOFTMODE
69080 +int pax_softmode;
69081 +
69082 +static int __init setup_pax_softmode(char *str)
69083 +{
69084 + get_option(&str, &pax_softmode);
69085 + return 1;
69086 +}
69087 +__setup("pax_softmode=", setup_pax_softmode);
69088 +#endif
69089 +
69090 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
69091 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
69092 static const char *panic_later, *panic_param;
69093 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
69094 {
69095 int count = preempt_count();
69096 int ret;
69097 + const char *msg1 = "", *msg2 = "";
69098
69099 if (initcall_debug)
69100 ret = do_one_initcall_debug(fn);
69101 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
69102 sprintf(msgbuf, "error code %d ", ret);
69103
69104 if (preempt_count() != count) {
69105 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
69106 + msg1 = " preemption imbalance";
69107 preempt_count() = count;
69108 }
69109 if (irqs_disabled()) {
69110 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
69111 + msg2 = " disabled interrupts";
69112 local_irq_enable();
69113 }
69114 - if (msgbuf[0]) {
69115 - printk("initcall %pF returned with %s\n", fn, msgbuf);
69116 + if (msgbuf[0] || *msg1 || *msg2) {
69117 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
69118 }
69119
69120 return ret;
69121 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
69122 "late",
69123 };
69124
69125 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69126 +u64 latent_entropy;
69127 +#endif
69128 +
69129 static void __init do_initcall_level(int level)
69130 {
69131 extern const struct kernel_param __start___param[], __stop___param[];
69132 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
69133 level, level,
69134 &repair_env_string);
69135
69136 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
69137 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
69138 do_one_initcall(*fn);
69139 +
69140 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69141 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69142 +#endif
69143 +
69144 + }
69145 }
69146
69147 static void __init do_initcalls(void)
69148 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
69149 {
69150 initcall_t *fn;
69151
69152 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
69153 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
69154 do_one_initcall(*fn);
69155 +
69156 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69157 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69158 +#endif
69159 +
69160 + }
69161 }
69162
69163 static int run_init_process(const char *init_filename)
69164 @@ -877,7 +951,7 @@ static noinline void __init kernel_init_freeable(void)
69165 do_basic_setup();
69166
69167 /* Open the /dev/console on the rootfs, this should never fail */
69168 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
69169 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
69170 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
69171
69172 (void) sys_dup(0);
69173 @@ -890,11 +964,13 @@ static noinline void __init kernel_init_freeable(void)
69174 if (!ramdisk_execute_command)
69175 ramdisk_execute_command = "/init";
69176
69177 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
69178 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
69179 ramdisk_execute_command = NULL;
69180 prepare_namespace();
69181 }
69182
69183 + grsecurity_init();
69184 +
69185 /*
69186 * Ok, we have completed the initial bootup, and
69187 * we're essentially up and running. Get rid of the
69188 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
69189 index 71a3ca1..cc330ee 100644
69190 --- a/ipc/mqueue.c
69191 +++ b/ipc/mqueue.c
69192 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
69193 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
69194 info->attr.mq_msgsize);
69195
69196 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
69197 spin_lock(&mq_lock);
69198 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
69199 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
69200 diff --git a/ipc/msg.c b/ipc/msg.c
69201 index 950572f..266c15f 100644
69202 --- a/ipc/msg.c
69203 +++ b/ipc/msg.c
69204 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
69205 return security_msg_queue_associate(msq, msgflg);
69206 }
69207
69208 +static struct ipc_ops msg_ops = {
69209 + .getnew = newque,
69210 + .associate = msg_security,
69211 + .more_checks = NULL
69212 +};
69213 +
69214 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
69215 {
69216 struct ipc_namespace *ns;
69217 - struct ipc_ops msg_ops;
69218 struct ipc_params msg_params;
69219
69220 ns = current->nsproxy->ipc_ns;
69221
69222 - msg_ops.getnew = newque;
69223 - msg_ops.associate = msg_security;
69224 - msg_ops.more_checks = NULL;
69225 -
69226 msg_params.key = key;
69227 msg_params.flg = msgflg;
69228
69229 diff --git a/ipc/sem.c b/ipc/sem.c
69230 index 58d31f1..cce7a55 100644
69231 --- a/ipc/sem.c
69232 +++ b/ipc/sem.c
69233 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
69234 return 0;
69235 }
69236
69237 +static struct ipc_ops sem_ops = {
69238 + .getnew = newary,
69239 + .associate = sem_security,
69240 + .more_checks = sem_more_checks
69241 +};
69242 +
69243 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69244 {
69245 struct ipc_namespace *ns;
69246 - struct ipc_ops sem_ops;
69247 struct ipc_params sem_params;
69248
69249 ns = current->nsproxy->ipc_ns;
69250 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69251 if (nsems < 0 || nsems > ns->sc_semmsl)
69252 return -EINVAL;
69253
69254 - sem_ops.getnew = newary;
69255 - sem_ops.associate = sem_security;
69256 - sem_ops.more_checks = sem_more_checks;
69257 -
69258 sem_params.key = key;
69259 sem_params.flg = semflg;
69260 sem_params.u.nsems = nsems;
69261 diff --git a/ipc/shm.c b/ipc/shm.c
69262 index 4fa6d8f..38dfd0c 100644
69263 --- a/ipc/shm.c
69264 +++ b/ipc/shm.c
69265 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
69266 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
69267 #endif
69268
69269 +#ifdef CONFIG_GRKERNSEC
69270 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69271 + const time_t shm_createtime, const uid_t cuid,
69272 + const int shmid);
69273 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69274 + const time_t shm_createtime);
69275 +#endif
69276 +
69277 void shm_init_ns(struct ipc_namespace *ns)
69278 {
69279 ns->shm_ctlmax = SHMMAX;
69280 @@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
69281 shp->shm_lprid = 0;
69282 shp->shm_atim = shp->shm_dtim = 0;
69283 shp->shm_ctim = get_seconds();
69284 +#ifdef CONFIG_GRKERNSEC
69285 + {
69286 + struct timespec timeval;
69287 + do_posix_clock_monotonic_gettime(&timeval);
69288 +
69289 + shp->shm_createtime = timeval.tv_sec;
69290 + }
69291 +#endif
69292 shp->shm_segsz = size;
69293 shp->shm_nattch = 0;
69294 shp->shm_file = file;
69295 @@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
69296 return 0;
69297 }
69298
69299 +static struct ipc_ops shm_ops = {
69300 + .getnew = newseg,
69301 + .associate = shm_security,
69302 + .more_checks = shm_more_checks
69303 +};
69304 +
69305 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
69306 {
69307 struct ipc_namespace *ns;
69308 - struct ipc_ops shm_ops;
69309 struct ipc_params shm_params;
69310
69311 ns = current->nsproxy->ipc_ns;
69312
69313 - shm_ops.getnew = newseg;
69314 - shm_ops.associate = shm_security;
69315 - shm_ops.more_checks = shm_more_checks;
69316 -
69317 shm_params.key = key;
69318 shm_params.flg = shmflg;
69319 shm_params.u.size = size;
69320 @@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69321 f_mode = FMODE_READ | FMODE_WRITE;
69322 }
69323 if (shmflg & SHM_EXEC) {
69324 +
69325 +#ifdef CONFIG_PAX_MPROTECT
69326 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
69327 + goto out;
69328 +#endif
69329 +
69330 prot |= PROT_EXEC;
69331 acc_mode |= S_IXUGO;
69332 }
69333 @@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69334 if (err)
69335 goto out_unlock;
69336
69337 +#ifdef CONFIG_GRKERNSEC
69338 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
69339 + shp->shm_perm.cuid, shmid) ||
69340 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
69341 + err = -EACCES;
69342 + goto out_unlock;
69343 + }
69344 +#endif
69345 +
69346 path = shp->shm_file->f_path;
69347 path_get(&path);
69348 shp->shm_nattch++;
69349 +#ifdef CONFIG_GRKERNSEC
69350 + shp->shm_lapid = current->pid;
69351 +#endif
69352 size = i_size_read(path.dentry->d_inode);
69353 shm_unlock(shp);
69354
69355 diff --git a/kernel/acct.c b/kernel/acct.c
69356 index 051e071..15e0920 100644
69357 --- a/kernel/acct.c
69358 +++ b/kernel/acct.c
69359 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
69360 */
69361 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
69362 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
69363 - file->f_op->write(file, (char *)&ac,
69364 + file->f_op->write(file, (char __force_user *)&ac,
69365 sizeof(acct_t), &file->f_pos);
69366 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
69367 set_fs(fs);
69368 diff --git a/kernel/audit.c b/kernel/audit.c
69369 index d596e53..dbef3c3 100644
69370 --- a/kernel/audit.c
69371 +++ b/kernel/audit.c
69372 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
69373 3) suppressed due to audit_rate_limit
69374 4) suppressed due to audit_backlog_limit
69375 */
69376 -static atomic_t audit_lost = ATOMIC_INIT(0);
69377 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
69378
69379 /* The netlink socket. */
69380 static struct sock *audit_sock;
69381 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
69382 unsigned long now;
69383 int print;
69384
69385 - atomic_inc(&audit_lost);
69386 + atomic_inc_unchecked(&audit_lost);
69387
69388 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
69389
69390 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
69391 printk(KERN_WARNING
69392 "audit: audit_lost=%d audit_rate_limit=%d "
69393 "audit_backlog_limit=%d\n",
69394 - atomic_read(&audit_lost),
69395 + atomic_read_unchecked(&audit_lost),
69396 audit_rate_limit,
69397 audit_backlog_limit);
69398 audit_panic(message);
69399 @@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
69400 status_set.pid = audit_pid;
69401 status_set.rate_limit = audit_rate_limit;
69402 status_set.backlog_limit = audit_backlog_limit;
69403 - status_set.lost = atomic_read(&audit_lost);
69404 + status_set.lost = atomic_read_unchecked(&audit_lost);
69405 status_set.backlog = skb_queue_len(&audit_skb_queue);
69406 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
69407 &status_set, sizeof(status_set));
69408 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
69409 index a371f85..da826c1 100644
69410 --- a/kernel/auditsc.c
69411 +++ b/kernel/auditsc.c
69412 @@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
69413 }
69414
69415 /* global counter which is incremented every time something logs in */
69416 -static atomic_t session_id = ATOMIC_INIT(0);
69417 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
69418
69419 /**
69420 * audit_set_loginuid - set current task's audit_context loginuid
69421 @@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
69422 return -EPERM;
69423 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
69424
69425 - sessionid = atomic_inc_return(&session_id);
69426 + sessionid = atomic_inc_return_unchecked(&session_id);
69427 if (context && context->in_syscall) {
69428 struct audit_buffer *ab;
69429
69430 diff --git a/kernel/capability.c b/kernel/capability.c
69431 index 493d972..f87dfbd 100644
69432 --- a/kernel/capability.c
69433 +++ b/kernel/capability.c
69434 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
69435 * before modification is attempted and the application
69436 * fails.
69437 */
69438 + if (tocopy > ARRAY_SIZE(kdata))
69439 + return -EFAULT;
69440 +
69441 if (copy_to_user(dataptr, kdata, tocopy
69442 * sizeof(struct __user_cap_data_struct))) {
69443 return -EFAULT;
69444 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
69445 int ret;
69446
69447 rcu_read_lock();
69448 - ret = security_capable(__task_cred(t), ns, cap);
69449 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
69450 + gr_task_is_capable(t, __task_cred(t), cap);
69451 rcu_read_unlock();
69452
69453 - return (ret == 0);
69454 + return ret;
69455 }
69456
69457 /**
69458 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
69459 int ret;
69460
69461 rcu_read_lock();
69462 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
69463 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
69464 rcu_read_unlock();
69465
69466 - return (ret == 0);
69467 + return ret;
69468 }
69469
69470 /**
69471 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
69472 BUG();
69473 }
69474
69475 - if (security_capable(current_cred(), ns, cap) == 0) {
69476 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
69477 current->flags |= PF_SUPERPRIV;
69478 return true;
69479 }
69480 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
69481 }
69482 EXPORT_SYMBOL(ns_capable);
69483
69484 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
69485 +{
69486 + if (unlikely(!cap_valid(cap))) {
69487 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
69488 + BUG();
69489 + }
69490 +
69491 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
69492 + current->flags |= PF_SUPERPRIV;
69493 + return true;
69494 + }
69495 + return false;
69496 +}
69497 +EXPORT_SYMBOL(ns_capable_nolog);
69498 +
69499 /**
69500 * capable - Determine if the current task has a superior capability in effect
69501 * @cap: The capability to be tested for
69502 @@ -408,6 +427,12 @@ bool capable(int cap)
69503 }
69504 EXPORT_SYMBOL(capable);
69505
69506 +bool capable_nolog(int cap)
69507 +{
69508 + return ns_capable_nolog(&init_user_ns, cap);
69509 +}
69510 +EXPORT_SYMBOL(capable_nolog);
69511 +
69512 /**
69513 * nsown_capable - Check superior capability to one's own user_ns
69514 * @cap: The capability in question
69515 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
69516
69517 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69518 }
69519 +
69520 +bool inode_capable_nolog(const struct inode *inode, int cap)
69521 +{
69522 + struct user_namespace *ns = current_user_ns();
69523 +
69524 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69525 +}
69526 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
69527 index 4855892..30d23b4 100644
69528 --- a/kernel/cgroup.c
69529 +++ b/kernel/cgroup.c
69530 @@ -5535,7 +5535,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
69531 struct css_set *cg = link->cg;
69532 struct task_struct *task;
69533 int count = 0;
69534 - seq_printf(seq, "css_set %p\n", cg);
69535 + seq_printf(seq, "css_set %pK\n", cg);
69536 list_for_each_entry(task, &cg->tasks, cg_list) {
69537 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
69538 seq_puts(seq, " ...\n");
69539 diff --git a/kernel/compat.c b/kernel/compat.c
69540 index 36700e9..73d770c 100644
69541 --- a/kernel/compat.c
69542 +++ b/kernel/compat.c
69543 @@ -13,6 +13,7 @@
69544
69545 #include <linux/linkage.h>
69546 #include <linux/compat.h>
69547 +#include <linux/module.h>
69548 #include <linux/errno.h>
69549 #include <linux/time.h>
69550 #include <linux/signal.h>
69551 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
69552 mm_segment_t oldfs;
69553 long ret;
69554
69555 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
69556 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
69557 oldfs = get_fs();
69558 set_fs(KERNEL_DS);
69559 ret = hrtimer_nanosleep_restart(restart);
69560 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
69561 oldfs = get_fs();
69562 set_fs(KERNEL_DS);
69563 ret = hrtimer_nanosleep(&tu,
69564 - rmtp ? (struct timespec __user *)&rmt : NULL,
69565 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
69566 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
69567 set_fs(oldfs);
69568
69569 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
69570 mm_segment_t old_fs = get_fs();
69571
69572 set_fs(KERNEL_DS);
69573 - ret = sys_sigpending((old_sigset_t __user *) &s);
69574 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
69575 set_fs(old_fs);
69576 if (ret == 0)
69577 ret = put_user(s, set);
69578 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
69579 mm_segment_t old_fs = get_fs();
69580
69581 set_fs(KERNEL_DS);
69582 - ret = sys_old_getrlimit(resource, &r);
69583 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
69584 set_fs(old_fs);
69585
69586 if (!ret) {
69587 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
69588 mm_segment_t old_fs = get_fs();
69589
69590 set_fs(KERNEL_DS);
69591 - ret = sys_getrusage(who, (struct rusage __user *) &r);
69592 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
69593 set_fs(old_fs);
69594
69595 if (ret)
69596 @@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
69597 set_fs (KERNEL_DS);
69598 ret = sys_wait4(pid,
69599 (stat_addr ?
69600 - (unsigned int __user *) &status : NULL),
69601 - options, (struct rusage __user *) &r);
69602 + (unsigned int __force_user *) &status : NULL),
69603 + options, (struct rusage __force_user *) &r);
69604 set_fs (old_fs);
69605
69606 if (ret > 0) {
69607 @@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
69608 memset(&info, 0, sizeof(info));
69609
69610 set_fs(KERNEL_DS);
69611 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
69612 - uru ? (struct rusage __user *)&ru : NULL);
69613 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
69614 + uru ? (struct rusage __force_user *)&ru : NULL);
69615 set_fs(old_fs);
69616
69617 if ((ret < 0) || (info.si_signo == 0))
69618 @@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
69619 oldfs = get_fs();
69620 set_fs(KERNEL_DS);
69621 err = sys_timer_settime(timer_id, flags,
69622 - (struct itimerspec __user *) &newts,
69623 - (struct itimerspec __user *) &oldts);
69624 + (struct itimerspec __force_user *) &newts,
69625 + (struct itimerspec __force_user *) &oldts);
69626 set_fs(oldfs);
69627 if (!err && old && put_compat_itimerspec(old, &oldts))
69628 return -EFAULT;
69629 @@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
69630 oldfs = get_fs();
69631 set_fs(KERNEL_DS);
69632 err = sys_timer_gettime(timer_id,
69633 - (struct itimerspec __user *) &ts);
69634 + (struct itimerspec __force_user *) &ts);
69635 set_fs(oldfs);
69636 if (!err && put_compat_itimerspec(setting, &ts))
69637 return -EFAULT;
69638 @@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
69639 oldfs = get_fs();
69640 set_fs(KERNEL_DS);
69641 err = sys_clock_settime(which_clock,
69642 - (struct timespec __user *) &ts);
69643 + (struct timespec __force_user *) &ts);
69644 set_fs(oldfs);
69645 return err;
69646 }
69647 @@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
69648 oldfs = get_fs();
69649 set_fs(KERNEL_DS);
69650 err = sys_clock_gettime(which_clock,
69651 - (struct timespec __user *) &ts);
69652 + (struct timespec __force_user *) &ts);
69653 set_fs(oldfs);
69654 if (!err && put_compat_timespec(&ts, tp))
69655 return -EFAULT;
69656 @@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
69657
69658 oldfs = get_fs();
69659 set_fs(KERNEL_DS);
69660 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
69661 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
69662 set_fs(oldfs);
69663
69664 err = compat_put_timex(utp, &txc);
69665 @@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
69666 oldfs = get_fs();
69667 set_fs(KERNEL_DS);
69668 err = sys_clock_getres(which_clock,
69669 - (struct timespec __user *) &ts);
69670 + (struct timespec __force_user *) &ts);
69671 set_fs(oldfs);
69672 if (!err && tp && put_compat_timespec(&ts, tp))
69673 return -EFAULT;
69674 @@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
69675 long err;
69676 mm_segment_t oldfs;
69677 struct timespec tu;
69678 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
69679 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
69680
69681 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
69682 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
69683 oldfs = get_fs();
69684 set_fs(KERNEL_DS);
69685 err = clock_nanosleep_restart(restart);
69686 @@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
69687 oldfs = get_fs();
69688 set_fs(KERNEL_DS);
69689 err = sys_clock_nanosleep(which_clock, flags,
69690 - (struct timespec __user *) &in,
69691 - (struct timespec __user *) &out);
69692 + (struct timespec __force_user *) &in,
69693 + (struct timespec __force_user *) &out);
69694 set_fs(oldfs);
69695
69696 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
69697 diff --git a/kernel/configs.c b/kernel/configs.c
69698 index 42e8fa0..9e7406b 100644
69699 --- a/kernel/configs.c
69700 +++ b/kernel/configs.c
69701 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
69702 struct proc_dir_entry *entry;
69703
69704 /* create the current config file */
69705 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
69706 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
69707 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
69708 + &ikconfig_file_ops);
69709 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69710 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
69711 + &ikconfig_file_ops);
69712 +#endif
69713 +#else
69714 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
69715 &ikconfig_file_ops);
69716 +#endif
69717 +
69718 if (!entry)
69719 return -ENOMEM;
69720
69721 diff --git a/kernel/cred.c b/kernel/cred.c
69722 index e0573a4..eefe488 100644
69723 --- a/kernel/cred.c
69724 +++ b/kernel/cred.c
69725 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
69726 validate_creds(cred);
69727 alter_cred_subscribers(cred, -1);
69728 put_cred(cred);
69729 +
69730 +#ifdef CONFIG_GRKERNSEC_SETXID
69731 + cred = (struct cred *) tsk->delayed_cred;
69732 + if (cred != NULL) {
69733 + tsk->delayed_cred = NULL;
69734 + validate_creds(cred);
69735 + alter_cred_subscribers(cred, -1);
69736 + put_cred(cred);
69737 + }
69738 +#endif
69739 }
69740
69741 /**
69742 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
69743 * Always returns 0 thus allowing this function to be tail-called at the end
69744 * of, say, sys_setgid().
69745 */
69746 -int commit_creds(struct cred *new)
69747 +static int __commit_creds(struct cred *new)
69748 {
69749 struct task_struct *task = current;
69750 const struct cred *old = task->real_cred;
69751 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
69752
69753 get_cred(new); /* we will require a ref for the subj creds too */
69754
69755 + gr_set_role_label(task, new->uid, new->gid);
69756 +
69757 /* dumpability changes */
69758 if (!uid_eq(old->euid, new->euid) ||
69759 !gid_eq(old->egid, new->egid) ||
69760 @@ -479,6 +491,101 @@ int commit_creds(struct cred *new)
69761 put_cred(old);
69762 return 0;
69763 }
69764 +#ifdef CONFIG_GRKERNSEC_SETXID
69765 +extern int set_user(struct cred *new);
69766 +
69767 +void gr_delayed_cred_worker(void)
69768 +{
69769 + const struct cred *new = current->delayed_cred;
69770 + struct cred *ncred;
69771 +
69772 + current->delayed_cred = NULL;
69773 +
69774 + if (current_uid() && new != NULL) {
69775 + // from doing get_cred on it when queueing this
69776 + put_cred(new);
69777 + return;
69778 + } else if (new == NULL)
69779 + return;
69780 +
69781 + ncred = prepare_creds();
69782 + if (!ncred)
69783 + goto die;
69784 + // uids
69785 + ncred->uid = new->uid;
69786 + ncred->euid = new->euid;
69787 + ncred->suid = new->suid;
69788 + ncred->fsuid = new->fsuid;
69789 + // gids
69790 + ncred->gid = new->gid;
69791 + ncred->egid = new->egid;
69792 + ncred->sgid = new->sgid;
69793 + ncred->fsgid = new->fsgid;
69794 + // groups
69795 + if (set_groups(ncred, new->group_info) < 0) {
69796 + abort_creds(ncred);
69797 + goto die;
69798 + }
69799 + // caps
69800 + ncred->securebits = new->securebits;
69801 + ncred->cap_inheritable = new->cap_inheritable;
69802 + ncred->cap_permitted = new->cap_permitted;
69803 + ncred->cap_effective = new->cap_effective;
69804 + ncred->cap_bset = new->cap_bset;
69805 +
69806 + if (set_user(ncred)) {
69807 + abort_creds(ncred);
69808 + goto die;
69809 + }
69810 +
69811 + // from doing get_cred on it when queueing this
69812 + put_cred(new);
69813 +
69814 + __commit_creds(ncred);
69815 + return;
69816 +die:
69817 + // from doing get_cred on it when queueing this
69818 + put_cred(new);
69819 + do_group_exit(SIGKILL);
69820 +}
69821 +#endif
69822 +
69823 +int commit_creds(struct cred *new)
69824 +{
69825 +#ifdef CONFIG_GRKERNSEC_SETXID
69826 + int ret;
69827 + int schedule_it = 0;
69828 + struct task_struct *t;
69829 +
69830 + /* we won't get called with tasklist_lock held for writing
69831 + and interrupts disabled as the cred struct in that case is
69832 + init_cred
69833 + */
69834 + if (grsec_enable_setxid && !current_is_single_threaded() &&
69835 + !current_uid() && new->uid) {
69836 + schedule_it = 1;
69837 + }
69838 + ret = __commit_creds(new);
69839 + if (schedule_it) {
69840 + rcu_read_lock();
69841 + read_lock(&tasklist_lock);
69842 + for (t = next_thread(current); t != current;
69843 + t = next_thread(t)) {
69844 + if (t->delayed_cred == NULL) {
69845 + t->delayed_cred = get_cred(new);
69846 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69847 + set_tsk_need_resched(t);
69848 + }
69849 + }
69850 + read_unlock(&tasklist_lock);
69851 + rcu_read_unlock();
69852 + }
69853 + return ret;
69854 +#else
69855 + return __commit_creds(new);
69856 +#endif
69857 +}
69858 +
69859 EXPORT_SYMBOL(commit_creds);
69860
69861 /**
69862 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69863 index 9a61738..c5c8f3a 100644
69864 --- a/kernel/debug/debug_core.c
69865 +++ b/kernel/debug/debug_core.c
69866 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69867 */
69868 static atomic_t masters_in_kgdb;
69869 static atomic_t slaves_in_kgdb;
69870 -static atomic_t kgdb_break_tasklet_var;
69871 +static atomic_unchecked_t kgdb_break_tasklet_var;
69872 atomic_t kgdb_setting_breakpoint;
69873
69874 struct task_struct *kgdb_usethread;
69875 @@ -132,7 +132,7 @@ int kgdb_single_step;
69876 static pid_t kgdb_sstep_pid;
69877
69878 /* to keep track of the CPU which is doing the single stepping*/
69879 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69880 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69881
69882 /*
69883 * If you are debugging a problem where roundup (the collection of
69884 @@ -540,7 +540,7 @@ return_normal:
69885 * kernel will only try for the value of sstep_tries before
69886 * giving up and continuing on.
69887 */
69888 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69889 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69890 (kgdb_info[cpu].task &&
69891 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69892 atomic_set(&kgdb_active, -1);
69893 @@ -634,8 +634,8 @@ cpu_master_loop:
69894 }
69895
69896 kgdb_restore:
69897 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69898 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69899 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69900 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69901 if (kgdb_info[sstep_cpu].task)
69902 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69903 else
69904 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69905 static void kgdb_tasklet_bpt(unsigned long ing)
69906 {
69907 kgdb_breakpoint();
69908 - atomic_set(&kgdb_break_tasklet_var, 0);
69909 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69910 }
69911
69912 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69913
69914 void kgdb_schedule_breakpoint(void)
69915 {
69916 - if (atomic_read(&kgdb_break_tasklet_var) ||
69917 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69918 atomic_read(&kgdb_active) != -1 ||
69919 atomic_read(&kgdb_setting_breakpoint))
69920 return;
69921 - atomic_inc(&kgdb_break_tasklet_var);
69922 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
69923 tasklet_schedule(&kgdb_tasklet_breakpoint);
69924 }
69925 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69926 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69927 index 8875254..7cf4928 100644
69928 --- a/kernel/debug/kdb/kdb_main.c
69929 +++ b/kernel/debug/kdb/kdb_main.c
69930 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69931 continue;
69932
69933 kdb_printf("%-20s%8u 0x%p ", mod->name,
69934 - mod->core_size, (void *)mod);
69935 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
69936 #ifdef CONFIG_MODULE_UNLOAD
69937 kdb_printf("%4ld ", module_refcount(mod));
69938 #endif
69939 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69940 kdb_printf(" (Loading)");
69941 else
69942 kdb_printf(" (Live)");
69943 - kdb_printf(" 0x%p", mod->module_core);
69944 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69945
69946 #ifdef CONFIG_MODULE_UNLOAD
69947 {
69948 diff --git a/kernel/events/core.c b/kernel/events/core.c
69949 index 7b6646a..3cb1135 100644
69950 --- a/kernel/events/core.c
69951 +++ b/kernel/events/core.c
69952 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69953 return 0;
69954 }
69955
69956 -static atomic64_t perf_event_id;
69957 +static atomic64_unchecked_t perf_event_id;
69958
69959 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69960 enum event_type_t event_type);
69961 @@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
69962
69963 static inline u64 perf_event_count(struct perf_event *event)
69964 {
69965 - return local64_read(&event->count) + atomic64_read(&event->child_count);
69966 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69967 }
69968
69969 static u64 perf_event_read(struct perf_event *event)
69970 @@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69971 mutex_lock(&event->child_mutex);
69972 total += perf_event_read(event);
69973 *enabled += event->total_time_enabled +
69974 - atomic64_read(&event->child_total_time_enabled);
69975 + atomic64_read_unchecked(&event->child_total_time_enabled);
69976 *running += event->total_time_running +
69977 - atomic64_read(&event->child_total_time_running);
69978 + atomic64_read_unchecked(&event->child_total_time_running);
69979
69980 list_for_each_entry(child, &event->child_list, child_list) {
69981 total += perf_event_read(child);
69982 @@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
69983 userpg->offset -= local64_read(&event->hw.prev_count);
69984
69985 userpg->time_enabled = enabled +
69986 - atomic64_read(&event->child_total_time_enabled);
69987 + atomic64_read_unchecked(&event->child_total_time_enabled);
69988
69989 userpg->time_running = running +
69990 - atomic64_read(&event->child_total_time_running);
69991 + atomic64_read_unchecked(&event->child_total_time_running);
69992
69993 arch_perf_update_userpage(userpg, now);
69994
69995 @@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69996 values[n++] = perf_event_count(event);
69997 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69998 values[n++] = enabled +
69999 - atomic64_read(&event->child_total_time_enabled);
70000 + atomic64_read_unchecked(&event->child_total_time_enabled);
70001 }
70002 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
70003 values[n++] = running +
70004 - atomic64_read(&event->child_total_time_running);
70005 + atomic64_read_unchecked(&event->child_total_time_running);
70006 }
70007 if (read_format & PERF_FORMAT_ID)
70008 values[n++] = primary_event_id(event);
70009 @@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
70010 * need to add enough zero bytes after the string to handle
70011 * the 64bit alignment we do later.
70012 */
70013 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
70014 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
70015 if (!buf) {
70016 name = strncpy(tmp, "//enomem", sizeof(tmp));
70017 goto got_name;
70018 }
70019 - name = d_path(&file->f_path, buf, PATH_MAX);
70020 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
70021 if (IS_ERR(name)) {
70022 name = strncpy(tmp, "//toolong", sizeof(tmp));
70023 goto got_name;
70024 @@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
70025 event->parent = parent_event;
70026
70027 event->ns = get_pid_ns(task_active_pid_ns(current));
70028 - event->id = atomic64_inc_return(&perf_event_id);
70029 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
70030
70031 event->state = PERF_EVENT_STATE_INACTIVE;
70032
70033 @@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
70034 /*
70035 * Add back the child's count to the parent's count:
70036 */
70037 - atomic64_add(child_val, &parent_event->child_count);
70038 - atomic64_add(child_event->total_time_enabled,
70039 + atomic64_add_unchecked(child_val, &parent_event->child_count);
70040 + atomic64_add_unchecked(child_event->total_time_enabled,
70041 &parent_event->child_total_time_enabled);
70042 - atomic64_add(child_event->total_time_running,
70043 + atomic64_add_unchecked(child_event->total_time_running,
70044 &parent_event->child_total_time_running);
70045
70046 /*
70047 diff --git a/kernel/exit.c b/kernel/exit.c
70048 index b4df219..f13c02d 100644
70049 --- a/kernel/exit.c
70050 +++ b/kernel/exit.c
70051 @@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
70052 struct task_struct *leader;
70053 int zap_leader;
70054 repeat:
70055 +#ifdef CONFIG_NET
70056 + gr_del_task_from_ip_table(p);
70057 +#endif
70058 +
70059 /* don't need to get the RCU readlock here - the process is dead and
70060 * can't be modifying its own credentials. But shut RCU-lockdep up */
70061 rcu_read_lock();
70062 @@ -338,7 +342,7 @@ int allow_signal(int sig)
70063 * know it'll be handled, so that they don't get converted to
70064 * SIGKILL or just silently dropped.
70065 */
70066 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
70067 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
70068 recalc_sigpending();
70069 spin_unlock_irq(&current->sighand->siglock);
70070 return 0;
70071 @@ -708,6 +712,8 @@ void do_exit(long code)
70072 struct task_struct *tsk = current;
70073 int group_dead;
70074
70075 + set_fs(USER_DS);
70076 +
70077 profile_task_exit(tsk);
70078
70079 WARN_ON(blk_needs_flush_plug(tsk));
70080 @@ -724,7 +730,6 @@ void do_exit(long code)
70081 * mm_release()->clear_child_tid() from writing to a user-controlled
70082 * kernel address.
70083 */
70084 - set_fs(USER_DS);
70085
70086 ptrace_event(PTRACE_EVENT_EXIT, code);
70087
70088 @@ -783,6 +788,9 @@ void do_exit(long code)
70089 tsk->exit_code = code;
70090 taskstats_exit(tsk, group_dead);
70091
70092 + gr_acl_handle_psacct(tsk, code);
70093 + gr_acl_handle_exit();
70094 +
70095 exit_mm(tsk);
70096
70097 if (group_dead)
70098 @@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
70099 * Take down every thread in the group. This is called by fatal signals
70100 * as well as by sys_exit_group (below).
70101 */
70102 -void
70103 +__noreturn void
70104 do_group_exit(int exit_code)
70105 {
70106 struct signal_struct *sig = current->signal;
70107 diff --git a/kernel/fork.c b/kernel/fork.c
70108 index c535f33..1d768f9 100644
70109 --- a/kernel/fork.c
70110 +++ b/kernel/fork.c
70111 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70112 *stackend = STACK_END_MAGIC; /* for overflow detection */
70113
70114 #ifdef CONFIG_CC_STACKPROTECTOR
70115 - tsk->stack_canary = get_random_int();
70116 + tsk->stack_canary = pax_get_random_long();
70117 #endif
70118
70119 /*
70120 @@ -344,13 +344,81 @@ free_tsk:
70121 }
70122
70123 #ifdef CONFIG_MMU
70124 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
70125 +{
70126 + struct vm_area_struct *tmp;
70127 + unsigned long charge;
70128 + struct mempolicy *pol;
70129 + struct file *file;
70130 +
70131 + charge = 0;
70132 + if (mpnt->vm_flags & VM_ACCOUNT) {
70133 + unsigned long len = vma_pages(mpnt);
70134 +
70135 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70136 + goto fail_nomem;
70137 + charge = len;
70138 + }
70139 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70140 + if (!tmp)
70141 + goto fail_nomem;
70142 + *tmp = *mpnt;
70143 + tmp->vm_mm = mm;
70144 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
70145 + pol = mpol_dup(vma_policy(mpnt));
70146 + if (IS_ERR(pol))
70147 + goto fail_nomem_policy;
70148 + vma_set_policy(tmp, pol);
70149 + if (anon_vma_fork(tmp, mpnt))
70150 + goto fail_nomem_anon_vma_fork;
70151 + tmp->vm_flags &= ~VM_LOCKED;
70152 + tmp->vm_next = tmp->vm_prev = NULL;
70153 + tmp->vm_mirror = NULL;
70154 + file = tmp->vm_file;
70155 + if (file) {
70156 + struct inode *inode = file->f_path.dentry->d_inode;
70157 + struct address_space *mapping = file->f_mapping;
70158 +
70159 + get_file(file);
70160 + if (tmp->vm_flags & VM_DENYWRITE)
70161 + atomic_dec(&inode->i_writecount);
70162 + mutex_lock(&mapping->i_mmap_mutex);
70163 + if (tmp->vm_flags & VM_SHARED)
70164 + mapping->i_mmap_writable++;
70165 + flush_dcache_mmap_lock(mapping);
70166 + /* insert tmp into the share list, just after mpnt */
70167 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70168 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
70169 + else
70170 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
70171 + flush_dcache_mmap_unlock(mapping);
70172 + mutex_unlock(&mapping->i_mmap_mutex);
70173 + }
70174 +
70175 + /*
70176 + * Clear hugetlb-related page reserves for children. This only
70177 + * affects MAP_PRIVATE mappings. Faults generated by the child
70178 + * are not guaranteed to succeed, even if read-only
70179 + */
70180 + if (is_vm_hugetlb_page(tmp))
70181 + reset_vma_resv_huge_pages(tmp);
70182 +
70183 + return tmp;
70184 +
70185 +fail_nomem_anon_vma_fork:
70186 + mpol_put(pol);
70187 +fail_nomem_policy:
70188 + kmem_cache_free(vm_area_cachep, tmp);
70189 +fail_nomem:
70190 + vm_unacct_memory(charge);
70191 + return NULL;
70192 +}
70193 +
70194 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70195 {
70196 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
70197 struct rb_node **rb_link, *rb_parent;
70198 int retval;
70199 - unsigned long charge;
70200 - struct mempolicy *pol;
70201
70202 uprobe_start_dup_mmap();
70203 down_write(&oldmm->mmap_sem);
70204 @@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70205 mm->locked_vm = 0;
70206 mm->mmap = NULL;
70207 mm->mmap_cache = NULL;
70208 - mm->free_area_cache = oldmm->mmap_base;
70209 - mm->cached_hole_size = ~0UL;
70210 + mm->free_area_cache = oldmm->free_area_cache;
70211 + mm->cached_hole_size = oldmm->cached_hole_size;
70212 mm->map_count = 0;
70213 cpumask_clear(mm_cpumask(mm));
70214 mm->mm_rb = RB_ROOT;
70215 @@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70216
70217 prev = NULL;
70218 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
70219 - struct file *file;
70220 -
70221 if (mpnt->vm_flags & VM_DONTCOPY) {
70222 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
70223 -vma_pages(mpnt));
70224 continue;
70225 }
70226 - charge = 0;
70227 - if (mpnt->vm_flags & VM_ACCOUNT) {
70228 - unsigned long len = vma_pages(mpnt);
70229 -
70230 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70231 - goto fail_nomem;
70232 - charge = len;
70233 - }
70234 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70235 - if (!tmp)
70236 - goto fail_nomem;
70237 - *tmp = *mpnt;
70238 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
70239 - pol = mpol_dup(vma_policy(mpnt));
70240 - retval = PTR_ERR(pol);
70241 - if (IS_ERR(pol))
70242 - goto fail_nomem_policy;
70243 - vma_set_policy(tmp, pol);
70244 - tmp->vm_mm = mm;
70245 - if (anon_vma_fork(tmp, mpnt))
70246 - goto fail_nomem_anon_vma_fork;
70247 - tmp->vm_flags &= ~VM_LOCKED;
70248 - tmp->vm_next = tmp->vm_prev = NULL;
70249 - file = tmp->vm_file;
70250 - if (file) {
70251 - struct inode *inode = file->f_path.dentry->d_inode;
70252 - struct address_space *mapping = file->f_mapping;
70253 -
70254 - get_file(file);
70255 - if (tmp->vm_flags & VM_DENYWRITE)
70256 - atomic_dec(&inode->i_writecount);
70257 - mutex_lock(&mapping->i_mmap_mutex);
70258 - if (tmp->vm_flags & VM_SHARED)
70259 - mapping->i_mmap_writable++;
70260 - flush_dcache_mmap_lock(mapping);
70261 - /* insert tmp into the share list, just after mpnt */
70262 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70263 - vma_nonlinear_insert(tmp,
70264 - &mapping->i_mmap_nonlinear);
70265 - else
70266 - vma_interval_tree_insert_after(tmp, mpnt,
70267 - &mapping->i_mmap);
70268 - flush_dcache_mmap_unlock(mapping);
70269 - mutex_unlock(&mapping->i_mmap_mutex);
70270 + tmp = dup_vma(mm, oldmm, mpnt);
70271 + if (!tmp) {
70272 + retval = -ENOMEM;
70273 + goto out;
70274 }
70275
70276 /*
70277 @@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70278 if (retval)
70279 goto out;
70280 }
70281 +
70282 +#ifdef CONFIG_PAX_SEGMEXEC
70283 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70284 + struct vm_area_struct *mpnt_m;
70285 +
70286 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70287 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70288 +
70289 + if (!mpnt->vm_mirror)
70290 + continue;
70291 +
70292 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70293 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70294 + mpnt->vm_mirror = mpnt_m;
70295 + } else {
70296 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70297 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70298 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70299 + mpnt->vm_mirror->vm_mirror = mpnt;
70300 + }
70301 + }
70302 + BUG_ON(mpnt_m);
70303 + }
70304 +#endif
70305 +
70306 /* a new mm has just been created */
70307 arch_dup_mmap(oldmm, mm);
70308 retval = 0;
70309 @@ -472,14 +523,6 @@ out:
70310 up_write(&oldmm->mmap_sem);
70311 uprobe_end_dup_mmap();
70312 return retval;
70313 -fail_nomem_anon_vma_fork:
70314 - mpol_put(pol);
70315 -fail_nomem_policy:
70316 - kmem_cache_free(vm_area_cachep, tmp);
70317 -fail_nomem:
70318 - retval = -ENOMEM;
70319 - vm_unacct_memory(charge);
70320 - goto out;
70321 }
70322
70323 static inline int mm_alloc_pgd(struct mm_struct *mm)
70324 @@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
70325 return ERR_PTR(err);
70326
70327 mm = get_task_mm(task);
70328 - if (mm && mm != current->mm &&
70329 - !ptrace_may_access(task, mode)) {
70330 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
70331 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
70332 mmput(mm);
70333 mm = ERR_PTR(-EACCES);
70334 }
70335 @@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70336 spin_unlock(&fs->lock);
70337 return -EAGAIN;
70338 }
70339 - fs->users++;
70340 + atomic_inc(&fs->users);
70341 spin_unlock(&fs->lock);
70342 return 0;
70343 }
70344 tsk->fs = copy_fs_struct(fs);
70345 if (!tsk->fs)
70346 return -ENOMEM;
70347 + /* Carry through gr_chroot_dentry and is_chrooted instead
70348 + of recomputing it here. Already copied when the task struct
70349 + is duplicated. This allows pivot_root to not be treated as
70350 + a chroot
70351 + */
70352 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
70353 +
70354 return 0;
70355 }
70356
70357 @@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70358 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70359 #endif
70360 retval = -EAGAIN;
70361 +
70362 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70363 +
70364 if (atomic_read(&p->real_cred->user->processes) >=
70365 task_rlimit(p, RLIMIT_NPROC)) {
70366 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70367 @@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70368 goto bad_fork_free_pid;
70369 }
70370
70371 + /* synchronizes with gr_set_acls()
70372 + we need to call this past the point of no return for fork()
70373 + */
70374 + gr_copy_label(p);
70375 +
70376 if (clone_flags & CLONE_THREAD) {
70377 current->signal->nr_threads++;
70378 atomic_inc(&current->signal->live);
70379 @@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
70380 bad_fork_free:
70381 free_task(p);
70382 fork_out:
70383 + gr_log_forkfail(retval);
70384 +
70385 return ERR_PTR(retval);
70386 }
70387
70388 @@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
70389 return -EINVAL;
70390 }
70391
70392 +#ifdef CONFIG_GRKERNSEC
70393 + if (clone_flags & CLONE_NEWUSER) {
70394 + /*
70395 + * This doesn't really inspire confidence:
70396 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
70397 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
70398 + * Increases kernel attack surface in areas developers
70399 + * previously cared little about ("low importance due
70400 + * to requiring "root" capability")
70401 + * To be removed when this code receives *proper* review
70402 + */
70403 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
70404 + !capable(CAP_SETGID))
70405 + return -EPERM;
70406 + }
70407 +#endif
70408 +
70409 /*
70410 * Determine whether and which event to report to ptracer. When
70411 * called from kernel_thread or CLONE_UNTRACED is explicitly
70412 @@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
70413 if (clone_flags & CLONE_PARENT_SETTID)
70414 put_user(nr, parent_tidptr);
70415
70416 + gr_handle_brute_check();
70417 +
70418 if (clone_flags & CLONE_VFORK) {
70419 p->vfork_done = &vfork;
70420 init_completion(&vfork);
70421 @@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
70422 return 0;
70423
70424 /* don't need lock here; in the worst case we'll do useless copy */
70425 - if (fs->users == 1)
70426 + if (atomic_read(&fs->users) == 1)
70427 return 0;
70428
70429 *new_fsp = copy_fs_struct(fs);
70430 @@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
70431 fs = current->fs;
70432 spin_lock(&fs->lock);
70433 current->fs = new_fs;
70434 - if (--fs->users)
70435 + gr_set_chroot_entries(current, &current->fs->root);
70436 + if (atomic_dec_return(&fs->users))
70437 new_fs = NULL;
70438 else
70439 new_fs = fs;
70440 diff --git a/kernel/futex.c b/kernel/futex.c
70441 index 19eb089..b8c65ea 100644
70442 --- a/kernel/futex.c
70443 +++ b/kernel/futex.c
70444 @@ -54,6 +54,7 @@
70445 #include <linux/mount.h>
70446 #include <linux/pagemap.h>
70447 #include <linux/syscalls.h>
70448 +#include <linux/ptrace.h>
70449 #include <linux/signal.h>
70450 #include <linux/export.h>
70451 #include <linux/magic.h>
70452 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
70453 struct page *page, *page_head;
70454 int err, ro = 0;
70455
70456 +#ifdef CONFIG_PAX_SEGMEXEC
70457 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
70458 + return -EFAULT;
70459 +#endif
70460 +
70461 /*
70462 * The futex address must be "naturally" aligned.
70463 */
70464 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
70465 {
70466 u32 curval;
70467 int i;
70468 + mm_segment_t oldfs;
70469
70470 /*
70471 * This will fail and we want it. Some arch implementations do
70472 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
70473 * implementation, the non-functional ones will return
70474 * -ENOSYS.
70475 */
70476 + oldfs = get_fs();
70477 + set_fs(USER_DS);
70478 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
70479 futex_cmpxchg_enabled = 1;
70480 + set_fs(oldfs);
70481
70482 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
70483 plist_head_init(&futex_queues[i].chain);
70484 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
70485 index 9b22d03..6295b62 100644
70486 --- a/kernel/gcov/base.c
70487 +++ b/kernel/gcov/base.c
70488 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
70489 }
70490
70491 #ifdef CONFIG_MODULES
70492 -static inline int within(void *addr, void *start, unsigned long size)
70493 -{
70494 - return ((addr >= start) && (addr < start + size));
70495 -}
70496 -
70497 /* Update list and generate events when modules are unloaded. */
70498 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70499 void *data)
70500 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70501 prev = NULL;
70502 /* Remove entries located in module from linked list. */
70503 for (info = gcov_info_head; info; info = info->next) {
70504 - if (within(info, mod->module_core, mod->core_size)) {
70505 + if (within_module_core_rw((unsigned long)info, mod)) {
70506 if (prev)
70507 prev->next = info->next;
70508 else
70509 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
70510 index 6db7a5e..0d600bd 100644
70511 --- a/kernel/hrtimer.c
70512 +++ b/kernel/hrtimer.c
70513 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
70514 local_irq_restore(flags);
70515 }
70516
70517 -static void run_hrtimer_softirq(struct softirq_action *h)
70518 +static void run_hrtimer_softirq(void)
70519 {
70520 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
70521
70522 @@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
70523 return NOTIFY_OK;
70524 }
70525
70526 -static struct notifier_block __cpuinitdata hrtimers_nb = {
70527 +static struct notifier_block hrtimers_nb = {
70528 .notifier_call = hrtimer_cpu_notify,
70529 };
70530
70531 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
70532 index 60f48fa..7f3a770 100644
70533 --- a/kernel/jump_label.c
70534 +++ b/kernel/jump_label.c
70535 @@ -13,6 +13,7 @@
70536 #include <linux/sort.h>
70537 #include <linux/err.h>
70538 #include <linux/static_key.h>
70539 +#include <linux/mm.h>
70540
70541 #ifdef HAVE_JUMP_LABEL
70542
70543 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
70544
70545 size = (((unsigned long)stop - (unsigned long)start)
70546 / sizeof(struct jump_entry));
70547 + pax_open_kernel();
70548 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
70549 + pax_close_kernel();
70550 }
70551
70552 static void jump_label_update(struct static_key *key, int enable);
70553 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
70554 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
70555 struct jump_entry *iter;
70556
70557 + pax_open_kernel();
70558 for (iter = iter_start; iter < iter_stop; iter++) {
70559 if (within_module_init(iter->code, mod))
70560 iter->code = 0;
70561 }
70562 + pax_close_kernel();
70563 }
70564
70565 static int
70566 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
70567 index 2169fee..45c017a 100644
70568 --- a/kernel/kallsyms.c
70569 +++ b/kernel/kallsyms.c
70570 @@ -11,6 +11,9 @@
70571 * Changed the compression method from stem compression to "table lookup"
70572 * compression (see scripts/kallsyms.c for a more complete description)
70573 */
70574 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70575 +#define __INCLUDED_BY_HIDESYM 1
70576 +#endif
70577 #include <linux/kallsyms.h>
70578 #include <linux/module.h>
70579 #include <linux/init.h>
70580 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
70581
70582 static inline int is_kernel_inittext(unsigned long addr)
70583 {
70584 + if (system_state != SYSTEM_BOOTING)
70585 + return 0;
70586 +
70587 if (addr >= (unsigned long)_sinittext
70588 && addr <= (unsigned long)_einittext)
70589 return 1;
70590 return 0;
70591 }
70592
70593 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70594 +#ifdef CONFIG_MODULES
70595 +static inline int is_module_text(unsigned long addr)
70596 +{
70597 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
70598 + return 1;
70599 +
70600 + addr = ktla_ktva(addr);
70601 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
70602 +}
70603 +#else
70604 +static inline int is_module_text(unsigned long addr)
70605 +{
70606 + return 0;
70607 +}
70608 +#endif
70609 +#endif
70610 +
70611 static inline int is_kernel_text(unsigned long addr)
70612 {
70613 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
70614 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
70615
70616 static inline int is_kernel(unsigned long addr)
70617 {
70618 +
70619 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70620 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
70621 + return 1;
70622 +
70623 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
70624 +#else
70625 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
70626 +#endif
70627 +
70628 return 1;
70629 return in_gate_area_no_mm(addr);
70630 }
70631
70632 static int is_ksym_addr(unsigned long addr)
70633 {
70634 +
70635 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70636 + if (is_module_text(addr))
70637 + return 0;
70638 +#endif
70639 +
70640 if (all_var)
70641 return is_kernel(addr);
70642
70643 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
70644
70645 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
70646 {
70647 - iter->name[0] = '\0';
70648 iter->nameoff = get_symbol_offset(new_pos);
70649 iter->pos = new_pos;
70650 }
70651 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
70652 {
70653 struct kallsym_iter *iter = m->private;
70654
70655 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70656 + if (current_uid())
70657 + return 0;
70658 +#endif
70659 +
70660 /* Some debugging symbols have no name. Ignore them. */
70661 if (!iter->name[0])
70662 return 0;
70663 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
70664 */
70665 type = iter->exported ? toupper(iter->type) :
70666 tolower(iter->type);
70667 +
70668 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
70669 type, iter->name, iter->module_name);
70670 } else
70671 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
70672 struct kallsym_iter *iter;
70673 int ret;
70674
70675 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
70676 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
70677 if (!iter)
70678 return -ENOMEM;
70679 reset_iter(iter, 0);
70680 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
70681 index e30ac0f..3528cac 100644
70682 --- a/kernel/kcmp.c
70683 +++ b/kernel/kcmp.c
70684 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
70685 struct task_struct *task1, *task2;
70686 int ret;
70687
70688 +#ifdef CONFIG_GRKERNSEC
70689 + return -ENOSYS;
70690 +#endif
70691 +
70692 rcu_read_lock();
70693
70694 /*
70695 diff --git a/kernel/kexec.c b/kernel/kexec.c
70696 index 5e4bd78..00c5b91 100644
70697 --- a/kernel/kexec.c
70698 +++ b/kernel/kexec.c
70699 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
70700 unsigned long flags)
70701 {
70702 struct compat_kexec_segment in;
70703 - struct kexec_segment out, __user *ksegments;
70704 + struct kexec_segment out;
70705 + struct kexec_segment __user *ksegments;
70706 unsigned long i, result;
70707
70708 /* Don't allow clients that don't understand the native
70709 diff --git a/kernel/kmod.c b/kernel/kmod.c
70710 index 0023a87..3fe3781 100644
70711 --- a/kernel/kmod.c
70712 +++ b/kernel/kmod.c
70713 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
70714 kfree(info->argv);
70715 }
70716
70717 -static int call_modprobe(char *module_name, int wait)
70718 +static int call_modprobe(char *module_name, char *module_param, int wait)
70719 {
70720 static char *envp[] = {
70721 "HOME=/",
70722 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
70723 NULL
70724 };
70725
70726 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
70727 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
70728 if (!argv)
70729 goto out;
70730
70731 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
70732 argv[1] = "-q";
70733 argv[2] = "--";
70734 argv[3] = module_name; /* check free_modprobe_argv() */
70735 - argv[4] = NULL;
70736 + argv[4] = module_param;
70737 + argv[5] = NULL;
70738
70739 return call_usermodehelper_fns(modprobe_path, argv, envp,
70740 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
70741 @@ -120,9 +121,8 @@ out:
70742 * If module auto-loading support is disabled then this function
70743 * becomes a no-operation.
70744 */
70745 -int __request_module(bool wait, const char *fmt, ...)
70746 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
70747 {
70748 - va_list args;
70749 char module_name[MODULE_NAME_LEN];
70750 unsigned int max_modprobes;
70751 int ret;
70752 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
70753 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
70754 static int kmod_loop_msg;
70755
70756 - va_start(args, fmt);
70757 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
70758 - va_end(args);
70759 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
70760 if (ret >= MODULE_NAME_LEN)
70761 return -ENAMETOOLONG;
70762
70763 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
70764 if (ret)
70765 return ret;
70766
70767 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70768 + if (!current_uid()) {
70769 + /* hack to workaround consolekit/udisks stupidity */
70770 + read_lock(&tasklist_lock);
70771 + if (!strcmp(current->comm, "mount") &&
70772 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
70773 + read_unlock(&tasklist_lock);
70774 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
70775 + return -EPERM;
70776 + }
70777 + read_unlock(&tasklist_lock);
70778 + }
70779 +#endif
70780 +
70781 /* If modprobe needs a service that is in a module, we get a recursive
70782 * loop. Limit the number of running kmod threads to max_threads/2 or
70783 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70784 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70785
70786 trace_module_request(module_name, wait, _RET_IP_);
70787
70788 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70789 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70790
70791 atomic_dec(&kmod_concurrent);
70792 return ret;
70793 }
70794 +
70795 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70796 +{
70797 + va_list args;
70798 + int ret;
70799 +
70800 + va_start(args, fmt);
70801 + ret = ____request_module(wait, module_param, fmt, args);
70802 + va_end(args);
70803 +
70804 + return ret;
70805 +}
70806 +
70807 +int __request_module(bool wait, const char *fmt, ...)
70808 +{
70809 + va_list args;
70810 + int ret;
70811 +
70812 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70813 + if (current_uid()) {
70814 + char module_param[MODULE_NAME_LEN];
70815 +
70816 + memset(module_param, 0, sizeof(module_param));
70817 +
70818 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70819 +
70820 + va_start(args, fmt);
70821 + ret = ____request_module(wait, module_param, fmt, args);
70822 + va_end(args);
70823 +
70824 + return ret;
70825 + }
70826 +#endif
70827 +
70828 + va_start(args, fmt);
70829 + ret = ____request_module(wait, NULL, fmt, args);
70830 + va_end(args);
70831 +
70832 + return ret;
70833 +}
70834 +
70835 EXPORT_SYMBOL(__request_module);
70836 #endif /* CONFIG_MODULES */
70837
70838 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70839 *
70840 * Thus the __user pointer cast is valid here.
70841 */
70842 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
70843 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70844
70845 /*
70846 * If ret is 0, either ____call_usermodehelper failed and the
70847 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70848 index 098f396..fe85ff1 100644
70849 --- a/kernel/kprobes.c
70850 +++ b/kernel/kprobes.c
70851 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70852 * kernel image and loaded module images reside. This is required
70853 * so x86_64 can correctly handle the %rip-relative fixups.
70854 */
70855 - kip->insns = module_alloc(PAGE_SIZE);
70856 + kip->insns = module_alloc_exec(PAGE_SIZE);
70857 if (!kip->insns) {
70858 kfree(kip);
70859 return NULL;
70860 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70861 */
70862 if (!list_is_singular(&kip->list)) {
70863 list_del(&kip->list);
70864 - module_free(NULL, kip->insns);
70865 + module_free_exec(NULL, kip->insns);
70866 kfree(kip);
70867 }
70868 return 1;
70869 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70870 {
70871 int i, err = 0;
70872 unsigned long offset = 0, size = 0;
70873 - char *modname, namebuf[128];
70874 + char *modname, namebuf[KSYM_NAME_LEN];
70875 const char *symbol_name;
70876 void *addr;
70877 struct kprobe_blackpoint *kb;
70878 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70879 kprobe_type = "k";
70880
70881 if (sym)
70882 - seq_printf(pi, "%p %s %s+0x%x %s ",
70883 + seq_printf(pi, "%pK %s %s+0x%x %s ",
70884 p->addr, kprobe_type, sym, offset,
70885 (modname ? modname : " "));
70886 else
70887 - seq_printf(pi, "%p %s %p ",
70888 + seq_printf(pi, "%pK %s %pK ",
70889 p->addr, kprobe_type, p->addr);
70890
70891 if (!pp)
70892 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70893 const char *sym = NULL;
70894 unsigned int i = *(loff_t *) v;
70895 unsigned long offset = 0;
70896 - char *modname, namebuf[128];
70897 + char *modname, namebuf[KSYM_NAME_LEN];
70898
70899 head = &kprobe_table[i];
70900 preempt_disable();
70901 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70902 index 6ada93c..55baf4d 100644
70903 --- a/kernel/ksysfs.c
70904 +++ b/kernel/ksysfs.c
70905 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70906 {
70907 if (count+1 > UEVENT_HELPER_PATH_LEN)
70908 return -ENOENT;
70909 + if (!capable(CAP_SYS_ADMIN))
70910 + return -EPERM;
70911 memcpy(uevent_helper, buf, count);
70912 uevent_helper[count] = '\0';
70913 if (count && uevent_helper[count-1] == '\n')
70914 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70915 index 7981e5b..7f2105c 100644
70916 --- a/kernel/lockdep.c
70917 +++ b/kernel/lockdep.c
70918 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
70919 end = (unsigned long) &_end,
70920 addr = (unsigned long) obj;
70921
70922 +#ifdef CONFIG_PAX_KERNEXEC
70923 + start = ktla_ktva(start);
70924 +#endif
70925 +
70926 /*
70927 * static variable?
70928 */
70929 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70930 if (!static_obj(lock->key)) {
70931 debug_locks_off();
70932 printk("INFO: trying to register non-static key.\n");
70933 + printk("lock:%pS key:%pS.\n", lock, lock->key);
70934 printk("the code is fine but needs lockdep annotation.\n");
70935 printk("turning off the locking correctness validator.\n");
70936 dump_stack();
70937 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70938 if (!class)
70939 return 0;
70940 }
70941 - atomic_inc((atomic_t *)&class->ops);
70942 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70943 if (very_verbose(class)) {
70944 printk("\nacquire class [%p] %s", class->key, class->name);
70945 if (class->name_version > 1)
70946 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70947 index b2c71c5..7b88d63 100644
70948 --- a/kernel/lockdep_proc.c
70949 +++ b/kernel/lockdep_proc.c
70950 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70951 return 0;
70952 }
70953
70954 - seq_printf(m, "%p", class->key);
70955 + seq_printf(m, "%pK", class->key);
70956 #ifdef CONFIG_DEBUG_LOCKDEP
70957 seq_printf(m, " OPS:%8ld", class->ops);
70958 #endif
70959 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70960
70961 list_for_each_entry(entry, &class->locks_after, entry) {
70962 if (entry->distance == 1) {
70963 - seq_printf(m, " -> [%p] ", entry->class->key);
70964 + seq_printf(m, " -> [%pK] ", entry->class->key);
70965 print_name(m, entry->class);
70966 seq_puts(m, "\n");
70967 }
70968 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70969 if (!class->key)
70970 continue;
70971
70972 - seq_printf(m, "[%p] ", class->key);
70973 + seq_printf(m, "[%pK] ", class->key);
70974 print_name(m, class);
70975 seq_puts(m, "\n");
70976 }
70977 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70978 if (!i)
70979 seq_line(m, '-', 40-namelen, namelen);
70980
70981 - snprintf(ip, sizeof(ip), "[<%p>]",
70982 + snprintf(ip, sizeof(ip), "[<%pK>]",
70983 (void *)class->contention_point[i]);
70984 seq_printf(m, "%40s %14lu %29s %pS\n",
70985 name, stats->contention_point[i],
70986 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70987 if (!i)
70988 seq_line(m, '-', 40-namelen, namelen);
70989
70990 - snprintf(ip, sizeof(ip), "[<%p>]",
70991 + snprintf(ip, sizeof(ip), "[<%pK>]",
70992 (void *)class->contending_point[i]);
70993 seq_printf(m, "%40s %14lu %29s %pS\n",
70994 name, stats->contending_point[i],
70995 diff --git a/kernel/module.c b/kernel/module.c
70996 index eab0827..75ede66 100644
70997 --- a/kernel/module.c
70998 +++ b/kernel/module.c
70999 @@ -61,6 +61,7 @@
71000 #include <linux/pfn.h>
71001 #include <linux/bsearch.h>
71002 #include <linux/fips.h>
71003 +#include <linux/grsecurity.h>
71004 #include <uapi/linux/module.h>
71005 #include "module-internal.h"
71006
71007 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
71008
71009 /* Bounds of module allocation, for speeding __module_address.
71010 * Protected by module_mutex. */
71011 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
71012 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
71013 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
71014
71015 int register_module_notifier(struct notifier_block * nb)
71016 {
71017 @@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
71018 return true;
71019
71020 list_for_each_entry_rcu(mod, &modules, list) {
71021 - struct symsearch arr[] = {
71022 + struct symsearch modarr[] = {
71023 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
71024 NOT_GPL_ONLY, false },
71025 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
71026 @@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
71027 if (mod->state == MODULE_STATE_UNFORMED)
71028 continue;
71029
71030 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
71031 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
71032 return true;
71033 }
71034 return false;
71035 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
71036 static int percpu_modalloc(struct module *mod,
71037 unsigned long size, unsigned long align)
71038 {
71039 - if (align > PAGE_SIZE) {
71040 + if (align-1 >= PAGE_SIZE) {
71041 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
71042 mod->name, align, PAGE_SIZE);
71043 align = PAGE_SIZE;
71044 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
71045 static ssize_t show_coresize(struct module_attribute *mattr,
71046 struct module_kobject *mk, char *buffer)
71047 {
71048 - return sprintf(buffer, "%u\n", mk->mod->core_size);
71049 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
71050 }
71051
71052 static struct module_attribute modinfo_coresize =
71053 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
71054 static ssize_t show_initsize(struct module_attribute *mattr,
71055 struct module_kobject *mk, char *buffer)
71056 {
71057 - return sprintf(buffer, "%u\n", mk->mod->init_size);
71058 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
71059 }
71060
71061 static struct module_attribute modinfo_initsize =
71062 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
71063 */
71064 #ifdef CONFIG_SYSFS
71065
71066 -#ifdef CONFIG_KALLSYMS
71067 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
71068 static inline bool sect_empty(const Elf_Shdr *sect)
71069 {
71070 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
71071 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
71072
71073 static void unset_module_core_ro_nx(struct module *mod)
71074 {
71075 - set_page_attributes(mod->module_core + mod->core_text_size,
71076 - mod->module_core + mod->core_size,
71077 + set_page_attributes(mod->module_core_rw,
71078 + mod->module_core_rw + mod->core_size_rw,
71079 set_memory_x);
71080 - set_page_attributes(mod->module_core,
71081 - mod->module_core + mod->core_ro_size,
71082 + set_page_attributes(mod->module_core_rx,
71083 + mod->module_core_rx + mod->core_size_rx,
71084 set_memory_rw);
71085 }
71086
71087 static void unset_module_init_ro_nx(struct module *mod)
71088 {
71089 - set_page_attributes(mod->module_init + mod->init_text_size,
71090 - mod->module_init + mod->init_size,
71091 + set_page_attributes(mod->module_init_rw,
71092 + mod->module_init_rw + mod->init_size_rw,
71093 set_memory_x);
71094 - set_page_attributes(mod->module_init,
71095 - mod->module_init + mod->init_ro_size,
71096 + set_page_attributes(mod->module_init_rx,
71097 + mod->module_init_rx + mod->init_size_rx,
71098 set_memory_rw);
71099 }
71100
71101 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
71102 list_for_each_entry_rcu(mod, &modules, list) {
71103 if (mod->state == MODULE_STATE_UNFORMED)
71104 continue;
71105 - if ((mod->module_core) && (mod->core_text_size)) {
71106 - set_page_attributes(mod->module_core,
71107 - mod->module_core + mod->core_text_size,
71108 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
71109 + set_page_attributes(mod->module_core_rx,
71110 + mod->module_core_rx + mod->core_size_rx,
71111 set_memory_rw);
71112 }
71113 - if ((mod->module_init) && (mod->init_text_size)) {
71114 - set_page_attributes(mod->module_init,
71115 - mod->module_init + mod->init_text_size,
71116 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
71117 + set_page_attributes(mod->module_init_rx,
71118 + mod->module_init_rx + mod->init_size_rx,
71119 set_memory_rw);
71120 }
71121 }
71122 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
71123 list_for_each_entry_rcu(mod, &modules, list) {
71124 if (mod->state == MODULE_STATE_UNFORMED)
71125 continue;
71126 - if ((mod->module_core) && (mod->core_text_size)) {
71127 - set_page_attributes(mod->module_core,
71128 - mod->module_core + mod->core_text_size,
71129 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
71130 + set_page_attributes(mod->module_core_rx,
71131 + mod->module_core_rx + mod->core_size_rx,
71132 set_memory_ro);
71133 }
71134 - if ((mod->module_init) && (mod->init_text_size)) {
71135 - set_page_attributes(mod->module_init,
71136 - mod->module_init + mod->init_text_size,
71137 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
71138 + set_page_attributes(mod->module_init_rx,
71139 + mod->module_init_rx + mod->init_size_rx,
71140 set_memory_ro);
71141 }
71142 }
71143 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
71144
71145 /* This may be NULL, but that's OK */
71146 unset_module_init_ro_nx(mod);
71147 - module_free(mod, mod->module_init);
71148 + module_free(mod, mod->module_init_rw);
71149 + module_free_exec(mod, mod->module_init_rx);
71150 kfree(mod->args);
71151 percpu_modfree(mod);
71152
71153 /* Free lock-classes: */
71154 - lockdep_free_key_range(mod->module_core, mod->core_size);
71155 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71156 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71157
71158 /* Finally, free the core (containing the module structure) */
71159 unset_module_core_ro_nx(mod);
71160 - module_free(mod, mod->module_core);
71161 + module_free_exec(mod, mod->module_core_rx);
71162 + module_free(mod, mod->module_core_rw);
71163
71164 #ifdef CONFIG_MPU
71165 update_protections(current->mm);
71166 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71167 int ret = 0;
71168 const struct kernel_symbol *ksym;
71169
71170 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71171 + int is_fs_load = 0;
71172 + int register_filesystem_found = 0;
71173 + char *p;
71174 +
71175 + p = strstr(mod->args, "grsec_modharden_fs");
71176 + if (p) {
71177 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
71178 + /* copy \0 as well */
71179 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71180 + is_fs_load = 1;
71181 + }
71182 +#endif
71183 +
71184 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
71185 const char *name = info->strtab + sym[i].st_name;
71186
71187 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71188 + /* it's a real shame this will never get ripped and copied
71189 + upstream! ;(
71190 + */
71191 + if (is_fs_load && !strcmp(name, "register_filesystem"))
71192 + register_filesystem_found = 1;
71193 +#endif
71194 +
71195 switch (sym[i].st_shndx) {
71196 case SHN_COMMON:
71197 /* We compiled with -fno-common. These are not
71198 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71199 ksym = resolve_symbol_wait(mod, info, name);
71200 /* Ok if resolved. */
71201 if (ksym && !IS_ERR(ksym)) {
71202 + pax_open_kernel();
71203 sym[i].st_value = ksym->value;
71204 + pax_close_kernel();
71205 break;
71206 }
71207
71208 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71209 secbase = (unsigned long)mod_percpu(mod);
71210 else
71211 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
71212 + pax_open_kernel();
71213 sym[i].st_value += secbase;
71214 + pax_close_kernel();
71215 break;
71216 }
71217 }
71218
71219 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71220 + if (is_fs_load && !register_filesystem_found) {
71221 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71222 + ret = -EPERM;
71223 + }
71224 +#endif
71225 +
71226 return ret;
71227 }
71228
71229 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
71230 || s->sh_entsize != ~0UL
71231 || strstarts(sname, ".init"))
71232 continue;
71233 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71234 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71235 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71236 + else
71237 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71238 pr_debug("\t%s\n", sname);
71239 }
71240 - switch (m) {
71241 - case 0: /* executable */
71242 - mod->core_size = debug_align(mod->core_size);
71243 - mod->core_text_size = mod->core_size;
71244 - break;
71245 - case 1: /* RO: text and ro-data */
71246 - mod->core_size = debug_align(mod->core_size);
71247 - mod->core_ro_size = mod->core_size;
71248 - break;
71249 - case 3: /* whole core */
71250 - mod->core_size = debug_align(mod->core_size);
71251 - break;
71252 - }
71253 }
71254
71255 pr_debug("Init section allocation order:\n");
71256 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
71257 || s->sh_entsize != ~0UL
71258 || !strstarts(sname, ".init"))
71259 continue;
71260 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71261 - | INIT_OFFSET_MASK);
71262 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71263 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71264 + else
71265 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71266 + s->sh_entsize |= INIT_OFFSET_MASK;
71267 pr_debug("\t%s\n", sname);
71268 }
71269 - switch (m) {
71270 - case 0: /* executable */
71271 - mod->init_size = debug_align(mod->init_size);
71272 - mod->init_text_size = mod->init_size;
71273 - break;
71274 - case 1: /* RO: text and ro-data */
71275 - mod->init_size = debug_align(mod->init_size);
71276 - mod->init_ro_size = mod->init_size;
71277 - break;
71278 - case 3: /* whole init */
71279 - mod->init_size = debug_align(mod->init_size);
71280 - break;
71281 - }
71282 }
71283 }
71284
71285 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71286
71287 /* Put symbol section at end of init part of module. */
71288 symsect->sh_flags |= SHF_ALLOC;
71289 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71290 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71291 info->index.sym) | INIT_OFFSET_MASK;
71292 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
71293
71294 @@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71295 }
71296
71297 /* Append room for core symbols at end of core part. */
71298 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71299 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
71300 - mod->core_size += strtab_size;
71301 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71302 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
71303 + mod->core_size_rx += strtab_size;
71304
71305 /* Put string table section at end of init part of module. */
71306 strsect->sh_flags |= SHF_ALLOC;
71307 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71308 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71309 info->index.str) | INIT_OFFSET_MASK;
71310 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
71311 }
71312 @@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71313 /* Make sure we get permanent strtab: don't use info->strtab. */
71314 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
71315
71316 + pax_open_kernel();
71317 +
71318 /* Set types up while we still have access to sections. */
71319 for (i = 0; i < mod->num_symtab; i++)
71320 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
71321
71322 - mod->core_symtab = dst = mod->module_core + info->symoffs;
71323 - mod->core_strtab = s = mod->module_core + info->stroffs;
71324 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
71325 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
71326 src = mod->symtab;
71327 for (ndst = i = 0; i < mod->num_symtab; i++) {
71328 if (i == 0 ||
71329 @@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71330 }
71331 }
71332 mod->core_num_syms = ndst;
71333 +
71334 + pax_close_kernel();
71335 }
71336 #else
71337 static inline void layout_symtab(struct module *mod, struct load_info *info)
71338 @@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
71339 return vmalloc_exec(size);
71340 }
71341
71342 -static void *module_alloc_update_bounds(unsigned long size)
71343 +static void *module_alloc_update_bounds_rw(unsigned long size)
71344 {
71345 void *ret = module_alloc(size);
71346
71347 if (ret) {
71348 mutex_lock(&module_mutex);
71349 /* Update module bounds. */
71350 - if ((unsigned long)ret < module_addr_min)
71351 - module_addr_min = (unsigned long)ret;
71352 - if ((unsigned long)ret + size > module_addr_max)
71353 - module_addr_max = (unsigned long)ret + size;
71354 + if ((unsigned long)ret < module_addr_min_rw)
71355 + module_addr_min_rw = (unsigned long)ret;
71356 + if ((unsigned long)ret + size > module_addr_max_rw)
71357 + module_addr_max_rw = (unsigned long)ret + size;
71358 + mutex_unlock(&module_mutex);
71359 + }
71360 + return ret;
71361 +}
71362 +
71363 +static void *module_alloc_update_bounds_rx(unsigned long size)
71364 +{
71365 + void *ret = module_alloc_exec(size);
71366 +
71367 + if (ret) {
71368 + mutex_lock(&module_mutex);
71369 + /* Update module bounds. */
71370 + if ((unsigned long)ret < module_addr_min_rx)
71371 + module_addr_min_rx = (unsigned long)ret;
71372 + if ((unsigned long)ret + size > module_addr_max_rx)
71373 + module_addr_max_rx = (unsigned long)ret + size;
71374 mutex_unlock(&module_mutex);
71375 }
71376 return ret;
71377 @@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
71378 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71379 {
71380 const char *modmagic = get_modinfo(info, "vermagic");
71381 + const char *license = get_modinfo(info, "license");
71382 int err;
71383
71384 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
71385 + if (!license || !license_is_gpl_compatible(license))
71386 + return -ENOEXEC;
71387 +#endif
71388 +
71389 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
71390 modmagic = NULL;
71391
71392 @@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71393 }
71394
71395 /* Set up license info based on the info section */
71396 - set_license(mod, get_modinfo(info, "license"));
71397 + set_license(mod, license);
71398
71399 return 0;
71400 }
71401 @@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
71402 void *ptr;
71403
71404 /* Do the allocs. */
71405 - ptr = module_alloc_update_bounds(mod->core_size);
71406 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
71407 /*
71408 * The pointer to this block is stored in the module structure
71409 * which is inside the block. Just mark it as not being a
71410 @@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
71411 if (!ptr)
71412 return -ENOMEM;
71413
71414 - memset(ptr, 0, mod->core_size);
71415 - mod->module_core = ptr;
71416 + memset(ptr, 0, mod->core_size_rw);
71417 + mod->module_core_rw = ptr;
71418
71419 - if (mod->init_size) {
71420 - ptr = module_alloc_update_bounds(mod->init_size);
71421 + if (mod->init_size_rw) {
71422 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
71423 /*
71424 * The pointer to this block is stored in the module structure
71425 * which is inside the block. This block doesn't need to be
71426 @@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
71427 */
71428 kmemleak_ignore(ptr);
71429 if (!ptr) {
71430 - module_free(mod, mod->module_core);
71431 + module_free(mod, mod->module_core_rw);
71432 return -ENOMEM;
71433 }
71434 - memset(ptr, 0, mod->init_size);
71435 - mod->module_init = ptr;
71436 + memset(ptr, 0, mod->init_size_rw);
71437 + mod->module_init_rw = ptr;
71438 } else
71439 - mod->module_init = NULL;
71440 + mod->module_init_rw = NULL;
71441 +
71442 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
71443 + kmemleak_not_leak(ptr);
71444 + if (!ptr) {
71445 + if (mod->module_init_rw)
71446 + module_free(mod, mod->module_init_rw);
71447 + module_free(mod, mod->module_core_rw);
71448 + return -ENOMEM;
71449 + }
71450 +
71451 + pax_open_kernel();
71452 + memset(ptr, 0, mod->core_size_rx);
71453 + pax_close_kernel();
71454 + mod->module_core_rx = ptr;
71455 +
71456 + if (mod->init_size_rx) {
71457 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
71458 + kmemleak_ignore(ptr);
71459 + if (!ptr && mod->init_size_rx) {
71460 + module_free_exec(mod, mod->module_core_rx);
71461 + if (mod->module_init_rw)
71462 + module_free(mod, mod->module_init_rw);
71463 + module_free(mod, mod->module_core_rw);
71464 + return -ENOMEM;
71465 + }
71466 +
71467 + pax_open_kernel();
71468 + memset(ptr, 0, mod->init_size_rx);
71469 + pax_close_kernel();
71470 + mod->module_init_rx = ptr;
71471 + } else
71472 + mod->module_init_rx = NULL;
71473
71474 /* Transfer each section which specifies SHF_ALLOC */
71475 pr_debug("final section addresses:\n");
71476 @@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
71477 if (!(shdr->sh_flags & SHF_ALLOC))
71478 continue;
71479
71480 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
71481 - dest = mod->module_init
71482 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71483 - else
71484 - dest = mod->module_core + shdr->sh_entsize;
71485 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
71486 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71487 + dest = mod->module_init_rw
71488 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71489 + else
71490 + dest = mod->module_init_rx
71491 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71492 + } else {
71493 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71494 + dest = mod->module_core_rw + shdr->sh_entsize;
71495 + else
71496 + dest = mod->module_core_rx + shdr->sh_entsize;
71497 + }
71498 +
71499 + if (shdr->sh_type != SHT_NOBITS) {
71500 +
71501 +#ifdef CONFIG_PAX_KERNEXEC
71502 +#ifdef CONFIG_X86_64
71503 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
71504 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
71505 +#endif
71506 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
71507 + pax_open_kernel();
71508 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71509 + pax_close_kernel();
71510 + } else
71511 +#endif
71512
71513 - if (shdr->sh_type != SHT_NOBITS)
71514 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71515 + }
71516 /* Update sh_addr to point to copy in image. */
71517 - shdr->sh_addr = (unsigned long)dest;
71518 +
71519 +#ifdef CONFIG_PAX_KERNEXEC
71520 + if (shdr->sh_flags & SHF_EXECINSTR)
71521 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
71522 + else
71523 +#endif
71524 +
71525 + shdr->sh_addr = (unsigned long)dest;
71526 pr_debug("\t0x%lx %s\n",
71527 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
71528 }
71529 @@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
71530 * Do it before processing of module parameters, so the module
71531 * can provide parameter accessor functions of its own.
71532 */
71533 - if (mod->module_init)
71534 - flush_icache_range((unsigned long)mod->module_init,
71535 - (unsigned long)mod->module_init
71536 - + mod->init_size);
71537 - flush_icache_range((unsigned long)mod->module_core,
71538 - (unsigned long)mod->module_core + mod->core_size);
71539 + if (mod->module_init_rx)
71540 + flush_icache_range((unsigned long)mod->module_init_rx,
71541 + (unsigned long)mod->module_init_rx
71542 + + mod->init_size_rx);
71543 + flush_icache_range((unsigned long)mod->module_core_rx,
71544 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
71545
71546 set_fs(old_fs);
71547 }
71548 @@ -2983,8 +3088,10 @@ out:
71549 static void module_deallocate(struct module *mod, struct load_info *info)
71550 {
71551 percpu_modfree(mod);
71552 - module_free(mod, mod->module_init);
71553 - module_free(mod, mod->module_core);
71554 + module_free_exec(mod, mod->module_init_rx);
71555 + module_free_exec(mod, mod->module_core_rx);
71556 + module_free(mod, mod->module_init_rw);
71557 + module_free(mod, mod->module_core_rw);
71558 }
71559
71560 int __weak module_finalize(const Elf_Ehdr *hdr,
71561 @@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
71562 static int post_relocation(struct module *mod, const struct load_info *info)
71563 {
71564 /* Sort exception table now relocations are done. */
71565 + pax_open_kernel();
71566 sort_extable(mod->extable, mod->extable + mod->num_exentries);
71567 + pax_close_kernel();
71568
71569 /* Copy relocated percpu area over. */
71570 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
71571 @@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
71572 MODULE_STATE_COMING, mod);
71573
71574 /* Set RO and NX regions for core */
71575 - set_section_ro_nx(mod->module_core,
71576 - mod->core_text_size,
71577 - mod->core_ro_size,
71578 - mod->core_size);
71579 + set_section_ro_nx(mod->module_core_rx,
71580 + mod->core_size_rx,
71581 + mod->core_size_rx,
71582 + mod->core_size_rx);
71583
71584 /* Set RO and NX regions for init */
71585 - set_section_ro_nx(mod->module_init,
71586 - mod->init_text_size,
71587 - mod->init_ro_size,
71588 - mod->init_size);
71589 + set_section_ro_nx(mod->module_init_rx,
71590 + mod->init_size_rx,
71591 + mod->init_size_rx,
71592 + mod->init_size_rx);
71593
71594 do_mod_ctors(mod);
71595 /* Start the module */
71596 @@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
71597 mod->strtab = mod->core_strtab;
71598 #endif
71599 unset_module_init_ro_nx(mod);
71600 - module_free(mod, mod->module_init);
71601 - mod->module_init = NULL;
71602 - mod->init_size = 0;
71603 - mod->init_ro_size = 0;
71604 - mod->init_text_size = 0;
71605 + module_free(mod, mod->module_init_rw);
71606 + module_free_exec(mod, mod->module_init_rx);
71607 + mod->module_init_rw = NULL;
71608 + mod->module_init_rx = NULL;
71609 + mod->init_size_rw = 0;
71610 + mod->init_size_rx = 0;
71611 mutex_unlock(&module_mutex);
71612 wake_up_all(&module_wq);
71613
71614 @@ -3209,9 +3319,38 @@ again:
71615 if (err)
71616 goto free_unload;
71617
71618 + /* Now copy in args */
71619 + mod->args = strndup_user(uargs, ~0UL >> 1);
71620 + if (IS_ERR(mod->args)) {
71621 + err = PTR_ERR(mod->args);
71622 + goto free_unload;
71623 + }
71624 +
71625 /* Set up MODINFO_ATTR fields */
71626 setup_modinfo(mod, info);
71627
71628 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71629 + {
71630 + char *p, *p2;
71631 +
71632 + if (strstr(mod->args, "grsec_modharden_netdev")) {
71633 + 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);
71634 + err = -EPERM;
71635 + goto free_modinfo;
71636 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
71637 + p += sizeof("grsec_modharden_normal") - 1;
71638 + p2 = strstr(p, "_");
71639 + if (p2) {
71640 + *p2 = '\0';
71641 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
71642 + *p2 = '_';
71643 + }
71644 + err = -EPERM;
71645 + goto free_modinfo;
71646 + }
71647 + }
71648 +#endif
71649 +
71650 /* Fix up syms, so that st_value is a pointer to location. */
71651 err = simplify_symbols(mod, info);
71652 if (err < 0)
71653 @@ -3227,13 +3366,6 @@ again:
71654
71655 flush_module_icache(mod);
71656
71657 - /* Now copy in args */
71658 - mod->args = strndup_user(uargs, ~0UL >> 1);
71659 - if (IS_ERR(mod->args)) {
71660 - err = PTR_ERR(mod->args);
71661 - goto free_arch_cleanup;
71662 - }
71663 -
71664 dynamic_debug_setup(info->debug, info->num_debug);
71665
71666 mutex_lock(&module_mutex);
71667 @@ -3278,11 +3410,10 @@ again:
71668 mutex_unlock(&module_mutex);
71669 dynamic_debug_remove(info->debug);
71670 synchronize_sched();
71671 - kfree(mod->args);
71672 - free_arch_cleanup:
71673 module_arch_cleanup(mod);
71674 free_modinfo:
71675 free_modinfo(mod);
71676 + kfree(mod->args);
71677 free_unload:
71678 module_unload_free(mod);
71679 unlink_mod:
71680 @@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
71681 unsigned long nextval;
71682
71683 /* At worse, next value is at end of module */
71684 - if (within_module_init(addr, mod))
71685 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
71686 + if (within_module_init_rx(addr, mod))
71687 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
71688 + else if (within_module_init_rw(addr, mod))
71689 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
71690 + else if (within_module_core_rx(addr, mod))
71691 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
71692 + else if (within_module_core_rw(addr, mod))
71693 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
71694 else
71695 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
71696 + return NULL;
71697
71698 /* Scan for closest preceding symbol, and next symbol. (ELF
71699 starts real symbols at 1). */
71700 @@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
71701 return 0;
71702
71703 seq_printf(m, "%s %u",
71704 - mod->name, mod->init_size + mod->core_size);
71705 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
71706 print_unload_info(m, mod);
71707
71708 /* Informative for users. */
71709 @@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
71710 mod->state == MODULE_STATE_COMING ? "Loading":
71711 "Live");
71712 /* Used by oprofile and other similar tools. */
71713 - seq_printf(m, " 0x%pK", mod->module_core);
71714 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
71715
71716 /* Taints info */
71717 if (mod->taints)
71718 @@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
71719
71720 static int __init proc_modules_init(void)
71721 {
71722 +#ifndef CONFIG_GRKERNSEC_HIDESYM
71723 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71724 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71725 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71726 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
71727 +#else
71728 proc_create("modules", 0, NULL, &proc_modules_operations);
71729 +#endif
71730 +#else
71731 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71732 +#endif
71733 return 0;
71734 }
71735 module_init(proc_modules_init);
71736 @@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
71737 {
71738 struct module *mod;
71739
71740 - if (addr < module_addr_min || addr > module_addr_max)
71741 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
71742 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
71743 return NULL;
71744
71745 list_for_each_entry_rcu(mod, &modules, list) {
71746 if (mod->state == MODULE_STATE_UNFORMED)
71747 continue;
71748 - if (within_module_core(addr, mod)
71749 - || within_module_init(addr, mod))
71750 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
71751 return mod;
71752 }
71753 return NULL;
71754 @@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
71755 */
71756 struct module *__module_text_address(unsigned long addr)
71757 {
71758 - struct module *mod = __module_address(addr);
71759 + struct module *mod;
71760 +
71761 +#ifdef CONFIG_X86_32
71762 + addr = ktla_ktva(addr);
71763 +#endif
71764 +
71765 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
71766 + return NULL;
71767 +
71768 + mod = __module_address(addr);
71769 +
71770 if (mod) {
71771 /* Make sure it's within the text section. */
71772 - if (!within(addr, mod->module_init, mod->init_text_size)
71773 - && !within(addr, mod->module_core, mod->core_text_size))
71774 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
71775 mod = NULL;
71776 }
71777 return mod;
71778 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
71779 index 7e3443f..b2a1e6b 100644
71780 --- a/kernel/mutex-debug.c
71781 +++ b/kernel/mutex-debug.c
71782 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
71783 }
71784
71785 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71786 - struct thread_info *ti)
71787 + struct task_struct *task)
71788 {
71789 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
71790
71791 /* Mark the current thread as blocked on the lock: */
71792 - ti->task->blocked_on = waiter;
71793 + task->blocked_on = waiter;
71794 }
71795
71796 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71797 - struct thread_info *ti)
71798 + struct task_struct *task)
71799 {
71800 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71801 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71802 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71803 - ti->task->blocked_on = NULL;
71804 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
71805 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71806 + task->blocked_on = NULL;
71807
71808 list_del_init(&waiter->list);
71809 waiter->task = NULL;
71810 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71811 index 0799fd3..d06ae3b 100644
71812 --- a/kernel/mutex-debug.h
71813 +++ b/kernel/mutex-debug.h
71814 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71815 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71816 extern void debug_mutex_add_waiter(struct mutex *lock,
71817 struct mutex_waiter *waiter,
71818 - struct thread_info *ti);
71819 + struct task_struct *task);
71820 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71821 - struct thread_info *ti);
71822 + struct task_struct *task);
71823 extern void debug_mutex_unlock(struct mutex *lock);
71824 extern void debug_mutex_init(struct mutex *lock, const char *name,
71825 struct lock_class_key *key);
71826 diff --git a/kernel/mutex.c b/kernel/mutex.c
71827 index a307cc9..27fd2e9 100644
71828 --- a/kernel/mutex.c
71829 +++ b/kernel/mutex.c
71830 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71831 spin_lock_mutex(&lock->wait_lock, flags);
71832
71833 debug_mutex_lock_common(lock, &waiter);
71834 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71835 + debug_mutex_add_waiter(lock, &waiter, task);
71836
71837 /* add waiting tasks to the end of the waitqueue (FIFO): */
71838 list_add_tail(&waiter.list, &lock->wait_list);
71839 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71840 * TASK_UNINTERRUPTIBLE case.)
71841 */
71842 if (unlikely(signal_pending_state(state, task))) {
71843 - mutex_remove_waiter(lock, &waiter,
71844 - task_thread_info(task));
71845 + mutex_remove_waiter(lock, &waiter, task);
71846 mutex_release(&lock->dep_map, 1, ip);
71847 spin_unlock_mutex(&lock->wait_lock, flags);
71848
71849 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71850 done:
71851 lock_acquired(&lock->dep_map, ip);
71852 /* got the lock - rejoice! */
71853 - mutex_remove_waiter(lock, &waiter, current_thread_info());
71854 + mutex_remove_waiter(lock, &waiter, task);
71855 mutex_set_owner(lock);
71856
71857 /* set it to 0 if there are no waiters left: */
71858 diff --git a/kernel/notifier.c b/kernel/notifier.c
71859 index 2d5cc4c..d9ea600 100644
71860 --- a/kernel/notifier.c
71861 +++ b/kernel/notifier.c
71862 @@ -5,6 +5,7 @@
71863 #include <linux/rcupdate.h>
71864 #include <linux/vmalloc.h>
71865 #include <linux/reboot.h>
71866 +#include <linux/mm.h>
71867
71868 /*
71869 * Notifier list for kernel code which wants to be called
71870 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71871 while ((*nl) != NULL) {
71872 if (n->priority > (*nl)->priority)
71873 break;
71874 - nl = &((*nl)->next);
71875 + nl = (struct notifier_block **)&((*nl)->next);
71876 }
71877 - n->next = *nl;
71878 + pax_open_kernel();
71879 + *(const void **)&n->next = *nl;
71880 rcu_assign_pointer(*nl, n);
71881 + pax_close_kernel();
71882 return 0;
71883 }
71884
71885 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71886 return 0;
71887 if (n->priority > (*nl)->priority)
71888 break;
71889 - nl = &((*nl)->next);
71890 + nl = (struct notifier_block **)&((*nl)->next);
71891 }
71892 - n->next = *nl;
71893 + pax_open_kernel();
71894 + *(const void **)&n->next = *nl;
71895 rcu_assign_pointer(*nl, n);
71896 + pax_close_kernel();
71897 return 0;
71898 }
71899
71900 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71901 {
71902 while ((*nl) != NULL) {
71903 if ((*nl) == n) {
71904 + pax_open_kernel();
71905 rcu_assign_pointer(*nl, n->next);
71906 + pax_close_kernel();
71907 return 0;
71908 }
71909 - nl = &((*nl)->next);
71910 + nl = (struct notifier_block **)&((*nl)->next);
71911 }
71912 return -ENOENT;
71913 }
71914 diff --git a/kernel/panic.c b/kernel/panic.c
71915 index e1b2822..5edc1d9 100644
71916 --- a/kernel/panic.c
71917 +++ b/kernel/panic.c
71918 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71919 const char *board;
71920
71921 printk(KERN_WARNING "------------[ cut here ]------------\n");
71922 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71923 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71924 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71925 if (board)
71926 printk(KERN_WARNING "Hardware name: %s\n", board);
71927 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71928 */
71929 void __stack_chk_fail(void)
71930 {
71931 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
71932 + dump_stack();
71933 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71934 __builtin_return_address(0));
71935 }
71936 EXPORT_SYMBOL(__stack_chk_fail);
71937 diff --git a/kernel/pid.c b/kernel/pid.c
71938 index f2c6a68..4922d97 100644
71939 --- a/kernel/pid.c
71940 +++ b/kernel/pid.c
71941 @@ -33,6 +33,7 @@
71942 #include <linux/rculist.h>
71943 #include <linux/bootmem.h>
71944 #include <linux/hash.h>
71945 +#include <linux/security.h>
71946 #include <linux/pid_namespace.h>
71947 #include <linux/init_task.h>
71948 #include <linux/syscalls.h>
71949 @@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71950
71951 int pid_max = PID_MAX_DEFAULT;
71952
71953 -#define RESERVED_PIDS 300
71954 +#define RESERVED_PIDS 500
71955
71956 int pid_max_min = RESERVED_PIDS + 1;
71957 int pid_max_max = PID_MAX_LIMIT;
71958 @@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
71959 */
71960 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71961 {
71962 + struct task_struct *task;
71963 +
71964 rcu_lockdep_assert(rcu_read_lock_held(),
71965 "find_task_by_pid_ns() needs rcu_read_lock()"
71966 " protection");
71967 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71968 +
71969 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71970 +
71971 + if (gr_pid_is_chrooted(task))
71972 + return NULL;
71973 +
71974 + return task;
71975 }
71976
71977 struct task_struct *find_task_by_vpid(pid_t vnr)
71978 @@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71979 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
71980 }
71981
71982 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71983 +{
71984 + rcu_lockdep_assert(rcu_read_lock_held(),
71985 + "find_task_by_pid_ns() needs rcu_read_lock()"
71986 + " protection");
71987 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
71988 +}
71989 +
71990 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71991 {
71992 struct pid *pid;
71993 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71994 index a278cad..bff5bd3 100644
71995 --- a/kernel/posix-cpu-timers.c
71996 +++ b/kernel/posix-cpu-timers.c
71997 @@ -1557,14 +1557,14 @@ struct k_clock clock_posix_cpu = {
71998
71999 static __init int init_posix_cpu_timers(void)
72000 {
72001 - struct k_clock process = {
72002 + static struct k_clock process = {
72003 .clock_getres = process_cpu_clock_getres,
72004 .clock_get = process_cpu_clock_get,
72005 .timer_create = process_cpu_timer_create,
72006 .nsleep = process_cpu_nsleep,
72007 .nsleep_restart = process_cpu_nsleep_restart,
72008 };
72009 - struct k_clock thread = {
72010 + static struct k_clock thread = {
72011 .clock_getres = thread_cpu_clock_getres,
72012 .clock_get = thread_cpu_clock_get,
72013 .timer_create = thread_cpu_timer_create,
72014 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
72015 index 69185ae..cc2847a 100644
72016 --- a/kernel/posix-timers.c
72017 +++ b/kernel/posix-timers.c
72018 @@ -43,6 +43,7 @@
72019 #include <linux/idr.h>
72020 #include <linux/posix-clock.h>
72021 #include <linux/posix-timers.h>
72022 +#include <linux/grsecurity.h>
72023 #include <linux/syscalls.h>
72024 #include <linux/wait.h>
72025 #include <linux/workqueue.h>
72026 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
72027 * which we beg off on and pass to do_sys_settimeofday().
72028 */
72029
72030 -static struct k_clock posix_clocks[MAX_CLOCKS];
72031 +static struct k_clock *posix_clocks[MAX_CLOCKS];
72032
72033 /*
72034 * These ones are defined below.
72035 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
72036 */
72037 static __init int init_posix_timers(void)
72038 {
72039 - struct k_clock clock_realtime = {
72040 + static struct k_clock clock_realtime = {
72041 .clock_getres = hrtimer_get_res,
72042 .clock_get = posix_clock_realtime_get,
72043 .clock_set = posix_clock_realtime_set,
72044 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
72045 .timer_get = common_timer_get,
72046 .timer_del = common_timer_del,
72047 };
72048 - struct k_clock clock_monotonic = {
72049 + static struct k_clock clock_monotonic = {
72050 .clock_getres = hrtimer_get_res,
72051 .clock_get = posix_ktime_get_ts,
72052 .nsleep = common_nsleep,
72053 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
72054 .timer_get = common_timer_get,
72055 .timer_del = common_timer_del,
72056 };
72057 - struct k_clock clock_monotonic_raw = {
72058 + static struct k_clock clock_monotonic_raw = {
72059 .clock_getres = hrtimer_get_res,
72060 .clock_get = posix_get_monotonic_raw,
72061 };
72062 - struct k_clock clock_realtime_coarse = {
72063 + static struct k_clock clock_realtime_coarse = {
72064 .clock_getres = posix_get_coarse_res,
72065 .clock_get = posix_get_realtime_coarse,
72066 };
72067 - struct k_clock clock_monotonic_coarse = {
72068 + static struct k_clock clock_monotonic_coarse = {
72069 .clock_getres = posix_get_coarse_res,
72070 .clock_get = posix_get_monotonic_coarse,
72071 };
72072 - struct k_clock clock_boottime = {
72073 + static struct k_clock clock_boottime = {
72074 .clock_getres = hrtimer_get_res,
72075 .clock_get = posix_get_boottime,
72076 .nsleep = common_nsleep,
72077 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
72078 return;
72079 }
72080
72081 - posix_clocks[clock_id] = *new_clock;
72082 + posix_clocks[clock_id] = new_clock;
72083 }
72084 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
72085
72086 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
72087 return (id & CLOCKFD_MASK) == CLOCKFD ?
72088 &clock_posix_dynamic : &clock_posix_cpu;
72089
72090 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
72091 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
72092 return NULL;
72093 - return &posix_clocks[id];
72094 + return posix_clocks[id];
72095 }
72096
72097 static int common_timer_create(struct k_itimer *new_timer)
72098 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72099 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72100 return -EFAULT;
72101
72102 + /* only the CLOCK_REALTIME clock can be set, all other clocks
72103 + have their clock_set fptr set to a nosettime dummy function
72104 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72105 + call common_clock_set, which calls do_sys_settimeofday, which
72106 + we hook
72107 + */
72108 +
72109 return kc->clock_set(which_clock, &new_tp);
72110 }
72111
72112 diff --git a/kernel/power/process.c b/kernel/power/process.c
72113 index d5a258b..4271191 100644
72114 --- a/kernel/power/process.c
72115 +++ b/kernel/power/process.c
72116 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
72117 u64 elapsed_csecs64;
72118 unsigned int elapsed_csecs;
72119 bool wakeup = false;
72120 + bool timedout = false;
72121
72122 do_gettimeofday(&start);
72123
72124 @@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
72125
72126 while (true) {
72127 todo = 0;
72128 + if (time_after(jiffies, end_time))
72129 + timedout = true;
72130 read_lock(&tasklist_lock);
72131 do_each_thread(g, p) {
72132 if (p == current || !freeze_task(p))
72133 continue;
72134
72135 - if (!freezer_should_skip(p))
72136 + if (!freezer_should_skip(p)) {
72137 todo++;
72138 + if (timedout) {
72139 + printk(KERN_ERR "Task refusing to freeze:\n");
72140 + sched_show_task(p);
72141 + }
72142 + }
72143 } while_each_thread(g, p);
72144 read_unlock(&tasklist_lock);
72145
72146 @@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
72147 todo += wq_busy;
72148 }
72149
72150 - if (!todo || time_after(jiffies, end_time))
72151 + if (!todo || timedout)
72152 break;
72153
72154 if (pm_wakeup_pending()) {
72155 diff --git a/kernel/printk.c b/kernel/printk.c
72156 index 267ce78..952f8a8 100644
72157 --- a/kernel/printk.c
72158 +++ b/kernel/printk.c
72159 @@ -834,6 +834,11 @@ static int check_syslog_permissions(int type, bool from_file)
72160 if (from_file && type != SYSLOG_ACTION_OPEN)
72161 return 0;
72162
72163 +#ifdef CONFIG_GRKERNSEC_DMESG
72164 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
72165 + return -EPERM;
72166 +#endif
72167 +
72168 if (syslog_action_restricted(type)) {
72169 if (capable(CAP_SYSLOG))
72170 return 0;
72171 diff --git a/kernel/profile.c b/kernel/profile.c
72172 index 1f39181..86093471 100644
72173 --- a/kernel/profile.c
72174 +++ b/kernel/profile.c
72175 @@ -40,7 +40,7 @@ struct profile_hit {
72176 /* Oprofile timer tick hook */
72177 static int (*timer_hook)(struct pt_regs *) __read_mostly;
72178
72179 -static atomic_t *prof_buffer;
72180 +static atomic_unchecked_t *prof_buffer;
72181 static unsigned long prof_len, prof_shift;
72182
72183 int prof_on __read_mostly;
72184 @@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
72185 hits[i].pc = 0;
72186 continue;
72187 }
72188 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72189 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72190 hits[i].hits = hits[i].pc = 0;
72191 }
72192 }
72193 @@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72194 * Add the current hit(s) and flush the write-queue out
72195 * to the global buffer:
72196 */
72197 - atomic_add(nr_hits, &prof_buffer[pc]);
72198 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
72199 for (i = 0; i < NR_PROFILE_HIT; ++i) {
72200 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72201 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72202 hits[i].pc = hits[i].hits = 0;
72203 }
72204 out:
72205 @@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72206 {
72207 unsigned long pc;
72208 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
72209 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72210 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72211 }
72212 #endif /* !CONFIG_SMP */
72213
72214 @@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
72215 return -EFAULT;
72216 buf++; p++; count--; read++;
72217 }
72218 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
72219 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
72220 if (copy_to_user(buf, (void *)pnt, count))
72221 return -EFAULT;
72222 read += count;
72223 @@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
72224 }
72225 #endif
72226 profile_discard_flip_buffers();
72227 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
72228 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
72229 return count;
72230 }
72231
72232 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
72233 index 6cbeaae..363c48a 100644
72234 --- a/kernel/ptrace.c
72235 +++ b/kernel/ptrace.c
72236 @@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
72237 if (seize)
72238 flags |= PT_SEIZED;
72239 rcu_read_lock();
72240 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72241 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72242 flags |= PT_PTRACE_CAP;
72243 rcu_read_unlock();
72244 task->ptrace = flags;
72245 @@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
72246 break;
72247 return -EIO;
72248 }
72249 - if (copy_to_user(dst, buf, retval))
72250 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
72251 return -EFAULT;
72252 copied += retval;
72253 src += retval;
72254 @@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
72255 bool seized = child->ptrace & PT_SEIZED;
72256 int ret = -EIO;
72257 siginfo_t siginfo, *si;
72258 - void __user *datavp = (void __user *) data;
72259 + void __user *datavp = (__force void __user *) data;
72260 unsigned long __user *datalp = datavp;
72261 unsigned long flags;
72262
72263 @@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
72264 goto out;
72265 }
72266
72267 + if (gr_handle_ptrace(child, request)) {
72268 + ret = -EPERM;
72269 + goto out_put_task_struct;
72270 + }
72271 +
72272 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72273 ret = ptrace_attach(child, request, addr, data);
72274 /*
72275 * Some architectures need to do book-keeping after
72276 * a ptrace attach.
72277 */
72278 - if (!ret)
72279 + if (!ret) {
72280 arch_ptrace_attach(child);
72281 + gr_audit_ptrace(child);
72282 + }
72283 goto out_put_task_struct;
72284 }
72285
72286 @@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
72287 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
72288 if (copied != sizeof(tmp))
72289 return -EIO;
72290 - return put_user(tmp, (unsigned long __user *)data);
72291 + return put_user(tmp, (__force unsigned long __user *)data);
72292 }
72293
72294 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
72295 @@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72296 goto out;
72297 }
72298
72299 + if (gr_handle_ptrace(child, request)) {
72300 + ret = -EPERM;
72301 + goto out_put_task_struct;
72302 + }
72303 +
72304 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72305 ret = ptrace_attach(child, request, addr, data);
72306 /*
72307 * Some architectures need to do book-keeping after
72308 * a ptrace attach.
72309 */
72310 - if (!ret)
72311 + if (!ret) {
72312 arch_ptrace_attach(child);
72313 + gr_audit_ptrace(child);
72314 + }
72315 goto out_put_task_struct;
72316 }
72317
72318 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
72319 index e7dce58..ad0d7b7 100644
72320 --- a/kernel/rcutiny.c
72321 +++ b/kernel/rcutiny.c
72322 @@ -46,7 +46,7 @@
72323 struct rcu_ctrlblk;
72324 static void invoke_rcu_callbacks(void);
72325 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
72326 -static void rcu_process_callbacks(struct softirq_action *unused);
72327 +static void rcu_process_callbacks(void);
72328 static void __call_rcu(struct rcu_head *head,
72329 void (*func)(struct rcu_head *rcu),
72330 struct rcu_ctrlblk *rcp);
72331 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
72332 rcu_is_callbacks_kthread()));
72333 }
72334
72335 -static void rcu_process_callbacks(struct softirq_action *unused)
72336 +static void rcu_process_callbacks(void)
72337 {
72338 __rcu_process_callbacks(&rcu_sched_ctrlblk);
72339 __rcu_process_callbacks(&rcu_bh_ctrlblk);
72340 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
72341 index f85016a..91cb03b 100644
72342 --- a/kernel/rcutiny_plugin.h
72343 +++ b/kernel/rcutiny_plugin.h
72344 @@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
72345 have_rcu_kthread_work = morework;
72346 local_irq_restore(flags);
72347 if (work)
72348 - rcu_process_callbacks(NULL);
72349 + rcu_process_callbacks();
72350 schedule_timeout_interruptible(1); /* Leave CPU for others. */
72351 }
72352
72353 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
72354 index 31dea01..ad91ffb 100644
72355 --- a/kernel/rcutorture.c
72356 +++ b/kernel/rcutorture.c
72357 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
72358 { 0 };
72359 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
72360 { 0 };
72361 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72362 -static atomic_t n_rcu_torture_alloc;
72363 -static atomic_t n_rcu_torture_alloc_fail;
72364 -static atomic_t n_rcu_torture_free;
72365 -static atomic_t n_rcu_torture_mberror;
72366 -static atomic_t n_rcu_torture_error;
72367 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72368 +static atomic_unchecked_t n_rcu_torture_alloc;
72369 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
72370 +static atomic_unchecked_t n_rcu_torture_free;
72371 +static atomic_unchecked_t n_rcu_torture_mberror;
72372 +static atomic_unchecked_t n_rcu_torture_error;
72373 static long n_rcu_torture_barrier_error;
72374 static long n_rcu_torture_boost_ktrerror;
72375 static long n_rcu_torture_boost_rterror;
72376 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
72377
72378 spin_lock_bh(&rcu_torture_lock);
72379 if (list_empty(&rcu_torture_freelist)) {
72380 - atomic_inc(&n_rcu_torture_alloc_fail);
72381 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
72382 spin_unlock_bh(&rcu_torture_lock);
72383 return NULL;
72384 }
72385 - atomic_inc(&n_rcu_torture_alloc);
72386 + atomic_inc_unchecked(&n_rcu_torture_alloc);
72387 p = rcu_torture_freelist.next;
72388 list_del_init(p);
72389 spin_unlock_bh(&rcu_torture_lock);
72390 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
72391 static void
72392 rcu_torture_free(struct rcu_torture *p)
72393 {
72394 - atomic_inc(&n_rcu_torture_free);
72395 + atomic_inc_unchecked(&n_rcu_torture_free);
72396 spin_lock_bh(&rcu_torture_lock);
72397 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
72398 spin_unlock_bh(&rcu_torture_lock);
72399 @@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
72400 i = rp->rtort_pipe_count;
72401 if (i > RCU_TORTURE_PIPE_LEN)
72402 i = RCU_TORTURE_PIPE_LEN;
72403 - atomic_inc(&rcu_torture_wcount[i]);
72404 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72405 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72406 rp->rtort_mbtest = 0;
72407 rcu_torture_free(rp);
72408 @@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
72409 i = rp->rtort_pipe_count;
72410 if (i > RCU_TORTURE_PIPE_LEN)
72411 i = RCU_TORTURE_PIPE_LEN;
72412 - atomic_inc(&rcu_torture_wcount[i]);
72413 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72414 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72415 rp->rtort_mbtest = 0;
72416 list_del(&rp->rtort_free);
72417 @@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
72418 i = old_rp->rtort_pipe_count;
72419 if (i > RCU_TORTURE_PIPE_LEN)
72420 i = RCU_TORTURE_PIPE_LEN;
72421 - atomic_inc(&rcu_torture_wcount[i]);
72422 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72423 old_rp->rtort_pipe_count++;
72424 cur_ops->deferred_free(old_rp);
72425 }
72426 @@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
72427 }
72428 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72429 if (p->rtort_mbtest == 0)
72430 - atomic_inc(&n_rcu_torture_mberror);
72431 + atomic_inc_unchecked(&n_rcu_torture_mberror);
72432 spin_lock(&rand_lock);
72433 cur_ops->read_delay(&rand);
72434 n_rcu_torture_timers++;
72435 @@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
72436 }
72437 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72438 if (p->rtort_mbtest == 0)
72439 - atomic_inc(&n_rcu_torture_mberror);
72440 + atomic_inc_unchecked(&n_rcu_torture_mberror);
72441 cur_ops->read_delay(&rand);
72442 preempt_disable();
72443 pipe_count = p->rtort_pipe_count;
72444 @@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
72445 rcu_torture_current,
72446 rcu_torture_current_version,
72447 list_empty(&rcu_torture_freelist),
72448 - atomic_read(&n_rcu_torture_alloc),
72449 - atomic_read(&n_rcu_torture_alloc_fail),
72450 - atomic_read(&n_rcu_torture_free));
72451 + atomic_read_unchecked(&n_rcu_torture_alloc),
72452 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
72453 + atomic_read_unchecked(&n_rcu_torture_free));
72454 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
72455 - atomic_read(&n_rcu_torture_mberror),
72456 + atomic_read_unchecked(&n_rcu_torture_mberror),
72457 n_rcu_torture_boost_ktrerror,
72458 n_rcu_torture_boost_rterror);
72459 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
72460 @@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
72461 n_barrier_attempts,
72462 n_rcu_torture_barrier_error);
72463 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
72464 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
72465 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
72466 n_rcu_torture_barrier_error != 0 ||
72467 n_rcu_torture_boost_ktrerror != 0 ||
72468 n_rcu_torture_boost_rterror != 0 ||
72469 n_rcu_torture_boost_failure != 0 ||
72470 i > 1) {
72471 cnt += sprintf(&page[cnt], "!!! ");
72472 - atomic_inc(&n_rcu_torture_error);
72473 + atomic_inc_unchecked(&n_rcu_torture_error);
72474 WARN_ON_ONCE(1);
72475 }
72476 cnt += sprintf(&page[cnt], "Reader Pipe: ");
72477 @@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
72478 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
72479 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72480 cnt += sprintf(&page[cnt], " %d",
72481 - atomic_read(&rcu_torture_wcount[i]));
72482 + atomic_read_unchecked(&rcu_torture_wcount[i]));
72483 }
72484 cnt += sprintf(&page[cnt], "\n");
72485 if (cur_ops->stats)
72486 @@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
72487
72488 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72489
72490 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72491 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72492 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
72493 else if (n_online_successes != n_online_attempts ||
72494 n_offline_successes != n_offline_attempts)
72495 @@ -1989,18 +1989,18 @@ rcu_torture_init(void)
72496
72497 rcu_torture_current = NULL;
72498 rcu_torture_current_version = 0;
72499 - atomic_set(&n_rcu_torture_alloc, 0);
72500 - atomic_set(&n_rcu_torture_alloc_fail, 0);
72501 - atomic_set(&n_rcu_torture_free, 0);
72502 - atomic_set(&n_rcu_torture_mberror, 0);
72503 - atomic_set(&n_rcu_torture_error, 0);
72504 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
72505 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
72506 + atomic_set_unchecked(&n_rcu_torture_free, 0);
72507 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
72508 + atomic_set_unchecked(&n_rcu_torture_error, 0);
72509 n_rcu_torture_barrier_error = 0;
72510 n_rcu_torture_boost_ktrerror = 0;
72511 n_rcu_torture_boost_rterror = 0;
72512 n_rcu_torture_boost_failure = 0;
72513 n_rcu_torture_boosts = 0;
72514 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
72515 - atomic_set(&rcu_torture_wcount[i], 0);
72516 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
72517 for_each_possible_cpu(cpu) {
72518 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72519 per_cpu(rcu_torture_count, cpu)[i] = 0;
72520 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
72521 index e441b77..dd54f17 100644
72522 --- a/kernel/rcutree.c
72523 +++ b/kernel/rcutree.c
72524 @@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
72525 rcu_prepare_for_idle(smp_processor_id());
72526 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72527 smp_mb__before_atomic_inc(); /* See above. */
72528 - atomic_inc(&rdtp->dynticks);
72529 + atomic_inc_unchecked(&rdtp->dynticks);
72530 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
72531 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72532 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72533
72534 /*
72535 * It is illegal to enter an extended quiescent state while
72536 @@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
72537 int user)
72538 {
72539 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
72540 - atomic_inc(&rdtp->dynticks);
72541 + atomic_inc_unchecked(&rdtp->dynticks);
72542 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72543 smp_mb__after_atomic_inc(); /* See above. */
72544 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72545 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72546 rcu_cleanup_after_idle(smp_processor_id());
72547 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
72548 if (!user && !is_idle_task(current)) {
72549 @@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
72550 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
72551
72552 if (rdtp->dynticks_nmi_nesting == 0 &&
72553 - (atomic_read(&rdtp->dynticks) & 0x1))
72554 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
72555 return;
72556 rdtp->dynticks_nmi_nesting++;
72557 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
72558 - atomic_inc(&rdtp->dynticks);
72559 + atomic_inc_unchecked(&rdtp->dynticks);
72560 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72561 smp_mb__after_atomic_inc(); /* See above. */
72562 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72563 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72564 }
72565
72566 /**
72567 @@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
72568 return;
72569 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72570 smp_mb__before_atomic_inc(); /* See above. */
72571 - atomic_inc(&rdtp->dynticks);
72572 + atomic_inc_unchecked(&rdtp->dynticks);
72573 smp_mb__after_atomic_inc(); /* Force delay to next write. */
72574 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72575 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72576 }
72577
72578 /**
72579 @@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
72580 int ret;
72581
72582 preempt_disable();
72583 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72584 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72585 preempt_enable();
72586 return ret;
72587 }
72588 @@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
72589 */
72590 static int dyntick_save_progress_counter(struct rcu_data *rdp)
72591 {
72592 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
72593 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72594 return (rdp->dynticks_snap & 0x1) == 0;
72595 }
72596
72597 @@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
72598 unsigned int curr;
72599 unsigned int snap;
72600
72601 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
72602 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72603 snap = (unsigned int)rdp->dynticks_snap;
72604
72605 /*
72606 @@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
72607 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
72608 */
72609 if (till_stall_check < 3) {
72610 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
72611 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
72612 till_stall_check = 3;
72613 } else if (till_stall_check > 300) {
72614 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
72615 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
72616 till_stall_check = 300;
72617 }
72618 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
72619 @@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
72620 rsp->qlen += rdp->qlen;
72621 rdp->n_cbs_orphaned += rdp->qlen;
72622 rdp->qlen_lazy = 0;
72623 - ACCESS_ONCE(rdp->qlen) = 0;
72624 + ACCESS_ONCE_RW(rdp->qlen) = 0;
72625 }
72626
72627 /*
72628 @@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
72629 }
72630 smp_mb(); /* List handling before counting for rcu_barrier(). */
72631 rdp->qlen_lazy -= count_lazy;
72632 - ACCESS_ONCE(rdp->qlen) -= count;
72633 + ACCESS_ONCE_RW(rdp->qlen) -= count;
72634 rdp->n_cbs_invoked += count;
72635
72636 /* Reinstate batch limit if we have worked down the excess. */
72637 @@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
72638 /*
72639 * Do RCU core processing for the current CPU.
72640 */
72641 -static void rcu_process_callbacks(struct softirq_action *unused)
72642 +static void rcu_process_callbacks(void)
72643 {
72644 struct rcu_state *rsp;
72645
72646 @@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
72647 local_irq_restore(flags);
72648 return;
72649 }
72650 - ACCESS_ONCE(rdp->qlen)++;
72651 + ACCESS_ONCE_RW(rdp->qlen)++;
72652 if (lazy)
72653 rdp->qlen_lazy++;
72654 else
72655 @@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
72656 * counter wrap on a 32-bit system. Quite a few more CPUs would of
72657 * course be required on a 64-bit system.
72658 */
72659 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
72660 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
72661 (ulong)atomic_long_read(&rsp->expedited_done) +
72662 ULONG_MAX / 8)) {
72663 synchronize_sched();
72664 - atomic_long_inc(&rsp->expedited_wrap);
72665 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
72666 return;
72667 }
72668
72669 @@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
72670 * Take a ticket. Note that atomic_inc_return() implies a
72671 * full memory barrier.
72672 */
72673 - snap = atomic_long_inc_return(&rsp->expedited_start);
72674 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
72675 firstsnap = snap;
72676 get_online_cpus();
72677 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
72678 @@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
72679 synchronize_sched_expedited_cpu_stop,
72680 NULL) == -EAGAIN) {
72681 put_online_cpus();
72682 - atomic_long_inc(&rsp->expedited_tryfail);
72683 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
72684
72685 /* Check to see if someone else did our work for us. */
72686 s = atomic_long_read(&rsp->expedited_done);
72687 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72688 /* ensure test happens before caller kfree */
72689 smp_mb__before_atomic_inc(); /* ^^^ */
72690 - atomic_long_inc(&rsp->expedited_workdone1);
72691 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
72692 return;
72693 }
72694
72695 @@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
72696 udelay(trycount * num_online_cpus());
72697 } else {
72698 wait_rcu_gp(call_rcu_sched);
72699 - atomic_long_inc(&rsp->expedited_normal);
72700 + atomic_long_inc_unchecked(&rsp->expedited_normal);
72701 return;
72702 }
72703
72704 @@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
72705 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72706 /* ensure test happens before caller kfree */
72707 smp_mb__before_atomic_inc(); /* ^^^ */
72708 - atomic_long_inc(&rsp->expedited_workdone2);
72709 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
72710 return;
72711 }
72712
72713 @@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
72714 * period works for us.
72715 */
72716 get_online_cpus();
72717 - snap = atomic_long_read(&rsp->expedited_start);
72718 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
72719 smp_mb(); /* ensure read is before try_stop_cpus(). */
72720 }
72721 - atomic_long_inc(&rsp->expedited_stoppedcpus);
72722 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
72723
72724 /*
72725 * Everyone up to our most recent fetch is covered by our grace
72726 @@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
72727 * than we did already did their update.
72728 */
72729 do {
72730 - atomic_long_inc(&rsp->expedited_done_tries);
72731 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
72732 s = atomic_long_read(&rsp->expedited_done);
72733 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
72734 /* ensure test happens before caller kfree */
72735 smp_mb__before_atomic_inc(); /* ^^^ */
72736 - atomic_long_inc(&rsp->expedited_done_lost);
72737 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
72738 break;
72739 }
72740 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
72741 - atomic_long_inc(&rsp->expedited_done_exit);
72742 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
72743
72744 put_online_cpus();
72745 }
72746 @@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72747 * ACCESS_ONCE() to prevent the compiler from speculating
72748 * the increment to precede the early-exit check.
72749 */
72750 - ACCESS_ONCE(rsp->n_barrier_done)++;
72751 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72752 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
72753 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
72754 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
72755 @@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72756
72757 /* Increment ->n_barrier_done to prevent duplicate work. */
72758 smp_mb(); /* Keep increment after above mechanism. */
72759 - ACCESS_ONCE(rsp->n_barrier_done)++;
72760 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72761 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
72762 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
72763 smp_mb(); /* Keep increment before caller's subsequent code. */
72764 @@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
72765 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
72766 init_callback_list(rdp);
72767 rdp->qlen_lazy = 0;
72768 - ACCESS_ONCE(rdp->qlen) = 0;
72769 + ACCESS_ONCE_RW(rdp->qlen) = 0;
72770 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
72771 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
72772 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
72773 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
72774 #ifdef CONFIG_RCU_USER_QS
72775 WARN_ON_ONCE(rdp->dynticks->in_user);
72776 #endif
72777 @@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
72778 rdp->blimit = blimit;
72779 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
72780 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
72781 - atomic_set(&rdp->dynticks->dynticks,
72782 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
72783 + atomic_set_unchecked(&rdp->dynticks->dynticks,
72784 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
72785 rcu_prepare_for_idle_init(cpu);
72786 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
72787
72788 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
72789 index 4b69291..704c92e 100644
72790 --- a/kernel/rcutree.h
72791 +++ b/kernel/rcutree.h
72792 @@ -86,7 +86,7 @@ struct rcu_dynticks {
72793 long long dynticks_nesting; /* Track irq/process nesting level. */
72794 /* Process level is worth LLONG_MAX/2. */
72795 int dynticks_nmi_nesting; /* Track NMI nesting level. */
72796 - atomic_t dynticks; /* Even value for idle, else odd. */
72797 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
72798 #ifdef CONFIG_RCU_FAST_NO_HZ
72799 int dyntick_drain; /* Prepare-for-idle state variable. */
72800 unsigned long dyntick_holdoff;
72801 @@ -423,17 +423,17 @@ struct rcu_state {
72802 /* _rcu_barrier(). */
72803 /* End of fields guarded by barrier_mutex. */
72804
72805 - atomic_long_t expedited_start; /* Starting ticket. */
72806 - atomic_long_t expedited_done; /* Done ticket. */
72807 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
72808 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
72809 - atomic_long_t expedited_workdone1; /* # done by others #1. */
72810 - atomic_long_t expedited_workdone2; /* # done by others #2. */
72811 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
72812 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
72813 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
72814 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
72815 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
72816 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
72817 + atomic_long_t expedited_done; /* Done ticket. */
72818 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
72819 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
72820 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
72821 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
72822 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
72823 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
72824 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
72825 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
72826 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
72827
72828 unsigned long jiffies_force_qs; /* Time at which to invoke */
72829 /* force_quiescent_state(). */
72830 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
72831 index c1cc7e1..5043e0e 100644
72832 --- a/kernel/rcutree_plugin.h
72833 +++ b/kernel/rcutree_plugin.h
72834 @@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
72835
72836 /* Clean up and exit. */
72837 smp_mb(); /* ensure expedited GP seen before counter increment. */
72838 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72839 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72840 unlock_mb_ret:
72841 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72842 mb_ret:
72843 @@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72844 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72845 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72846 cpu, ticks_value, ticks_title,
72847 - atomic_read(&rdtp->dynticks) & 0xfff,
72848 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72849 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72850 fast_no_hz);
72851 }
72852 @@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
72853
72854 /* Enqueue the callback on the nocb list and update counts. */
72855 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
72856 - ACCESS_ONCE(*old_rhpp) = rhp;
72857 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
72858 atomic_long_add(rhcount, &rdp->nocb_q_count);
72859 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
72860
72861 @@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
72862 * Extract queued callbacks, update counts, and wait
72863 * for a grace period to elapse.
72864 */
72865 - ACCESS_ONCE(rdp->nocb_head) = NULL;
72866 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
72867 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
72868 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
72869 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
72870 - ACCESS_ONCE(rdp->nocb_p_count) += c;
72871 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
72872 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
72873 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
72874 wait_rcu_gp(rdp->rsp->call_remote);
72875
72876 /* Each pass through the following loop invokes a callback. */
72877 @@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
72878 list = next;
72879 }
72880 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
72881 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
72882 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
72883 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
72884 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
72885 rdp->n_nocbs_invoked += c;
72886 }
72887 return 0;
72888 @@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
72889 rdp = per_cpu_ptr(rsp->rda, cpu);
72890 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
72891 BUG_ON(IS_ERR(t));
72892 - ACCESS_ONCE(rdp->nocb_kthread) = t;
72893 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
72894 }
72895 }
72896
72897 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72898 index 0d095dc..1985b19 100644
72899 --- a/kernel/rcutree_trace.c
72900 +++ b/kernel/rcutree_trace.c
72901 @@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72902 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
72903 rdp->passed_quiesce, rdp->qs_pending);
72904 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72905 - atomic_read(&rdp->dynticks->dynticks),
72906 + atomic_read_unchecked(&rdp->dynticks->dynticks),
72907 rdp->dynticks->dynticks_nesting,
72908 rdp->dynticks->dynticks_nmi_nesting,
72909 rdp->dynticks_fqs);
72910 @@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
72911 struct rcu_state *rsp = (struct rcu_state *)m->private;
72912
72913 seq_printf(m, "s=%lu d=%lu w=%lu tf=%lu wd1=%lu wd2=%lu n=%lu sc=%lu dt=%lu dl=%lu dx=%lu\n",
72914 - atomic_long_read(&rsp->expedited_start),
72915 + atomic_long_read_unchecked(&rsp->expedited_start),
72916 atomic_long_read(&rsp->expedited_done),
72917 - atomic_long_read(&rsp->expedited_wrap),
72918 - atomic_long_read(&rsp->expedited_tryfail),
72919 - atomic_long_read(&rsp->expedited_workdone1),
72920 - atomic_long_read(&rsp->expedited_workdone2),
72921 - atomic_long_read(&rsp->expedited_normal),
72922 - atomic_long_read(&rsp->expedited_stoppedcpus),
72923 - atomic_long_read(&rsp->expedited_done_tries),
72924 - atomic_long_read(&rsp->expedited_done_lost),
72925 - atomic_long_read(&rsp->expedited_done_exit));
72926 + atomic_long_read_unchecked(&rsp->expedited_wrap),
72927 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
72928 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
72929 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
72930 + atomic_long_read_unchecked(&rsp->expedited_normal),
72931 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
72932 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
72933 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
72934 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
72935 return 0;
72936 }
72937
72938 diff --git a/kernel/resource.c b/kernel/resource.c
72939 index 73f35d4..4684fc4 100644
72940 --- a/kernel/resource.c
72941 +++ b/kernel/resource.c
72942 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
72943
72944 static int __init ioresources_init(void)
72945 {
72946 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72947 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72948 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
72949 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
72950 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72951 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
72952 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
72953 +#endif
72954 +#else
72955 proc_create("ioports", 0, NULL, &proc_ioports_operations);
72956 proc_create("iomem", 0, NULL, &proc_iomem_operations);
72957 +#endif
72958 return 0;
72959 }
72960 __initcall(ioresources_init);
72961 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
72962 index 98ec494..4241d6d 100644
72963 --- a/kernel/rtmutex-tester.c
72964 +++ b/kernel/rtmutex-tester.c
72965 @@ -20,7 +20,7 @@
72966 #define MAX_RT_TEST_MUTEXES 8
72967
72968 static spinlock_t rttest_lock;
72969 -static atomic_t rttest_event;
72970 +static atomic_unchecked_t rttest_event;
72971
72972 struct test_thread_data {
72973 int opcode;
72974 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72975
72976 case RTTEST_LOCKCONT:
72977 td->mutexes[td->opdata] = 1;
72978 - td->event = atomic_add_return(1, &rttest_event);
72979 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72980 return 0;
72981
72982 case RTTEST_RESET:
72983 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72984 return 0;
72985
72986 case RTTEST_RESETEVENT:
72987 - atomic_set(&rttest_event, 0);
72988 + atomic_set_unchecked(&rttest_event, 0);
72989 return 0;
72990
72991 default:
72992 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72993 return ret;
72994
72995 td->mutexes[id] = 1;
72996 - td->event = atomic_add_return(1, &rttest_event);
72997 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72998 rt_mutex_lock(&mutexes[id]);
72999 - td->event = atomic_add_return(1, &rttest_event);
73000 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73001 td->mutexes[id] = 4;
73002 return 0;
73003
73004 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73005 return ret;
73006
73007 td->mutexes[id] = 1;
73008 - td->event = atomic_add_return(1, &rttest_event);
73009 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73010 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
73011 - td->event = atomic_add_return(1, &rttest_event);
73012 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73013 td->mutexes[id] = ret ? 0 : 4;
73014 return ret ? -EINTR : 0;
73015
73016 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73017 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
73018 return ret;
73019
73020 - td->event = atomic_add_return(1, &rttest_event);
73021 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73022 rt_mutex_unlock(&mutexes[id]);
73023 - td->event = atomic_add_return(1, &rttest_event);
73024 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73025 td->mutexes[id] = 0;
73026 return 0;
73027
73028 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73029 break;
73030
73031 td->mutexes[dat] = 2;
73032 - td->event = atomic_add_return(1, &rttest_event);
73033 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73034 break;
73035
73036 default:
73037 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73038 return;
73039
73040 td->mutexes[dat] = 3;
73041 - td->event = atomic_add_return(1, &rttest_event);
73042 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73043 break;
73044
73045 case RTTEST_LOCKNOWAIT:
73046 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73047 return;
73048
73049 td->mutexes[dat] = 1;
73050 - td->event = atomic_add_return(1, &rttest_event);
73051 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73052 return;
73053
73054 default:
73055 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
73056 index 0984a21..939f183 100644
73057 --- a/kernel/sched/auto_group.c
73058 +++ b/kernel/sched/auto_group.c
73059 @@ -11,7 +11,7 @@
73060
73061 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
73062 static struct autogroup autogroup_default;
73063 -static atomic_t autogroup_seq_nr;
73064 +static atomic_unchecked_t autogroup_seq_nr;
73065
73066 void __init autogroup_init(struct task_struct *init_task)
73067 {
73068 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
73069
73070 kref_init(&ag->kref);
73071 init_rwsem(&ag->lock);
73072 - ag->id = atomic_inc_return(&autogroup_seq_nr);
73073 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
73074 ag->tg = tg;
73075 #ifdef CONFIG_RT_GROUP_SCHED
73076 /*
73077 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
73078 index 26058d0..06f15dd 100644
73079 --- a/kernel/sched/core.c
73080 +++ b/kernel/sched/core.c
73081 @@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
73082 /* convert nice value [19,-20] to rlimit style value [1,40] */
73083 int nice_rlim = 20 - nice;
73084
73085 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
73086 +
73087 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
73088 capable(CAP_SYS_NICE));
73089 }
73090 @@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73091 if (nice > 19)
73092 nice = 19;
73093
73094 - if (increment < 0 && !can_nice(current, nice))
73095 + if (increment < 0 && (!can_nice(current, nice) ||
73096 + gr_handle_chroot_nice()))
73097 return -EPERM;
73098
73099 retval = security_task_setnice(current, nice);
73100 @@ -3818,6 +3821,7 @@ recheck:
73101 unsigned long rlim_rtprio =
73102 task_rlimit(p, RLIMIT_RTPRIO);
73103
73104 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
73105 /* can't set/change the rt policy */
73106 if (policy != p->policy && !rlim_rtprio)
73107 return -EPERM;
73108 @@ -5162,7 +5166,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
73109 * happens before everything else. This has to be lower priority than
73110 * the notifier in the perf_event subsystem, though.
73111 */
73112 -static struct notifier_block __cpuinitdata migration_notifier = {
73113 +static struct notifier_block migration_notifier = {
73114 .notifier_call = migration_call,
73115 .priority = CPU_PRI_MIGRATION,
73116 };
73117 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
73118 index 81fa536..80fa821 100644
73119 --- a/kernel/sched/fair.c
73120 +++ b/kernel/sched/fair.c
73121 @@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
73122
73123 static void reset_ptenuma_scan(struct task_struct *p)
73124 {
73125 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
73126 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
73127 p->mm->numa_scan_offset = 0;
73128 }
73129
73130 @@ -5663,7 +5663,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
73131 * run_rebalance_domains is triggered when needed from the scheduler tick.
73132 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
73133 */
73134 -static void run_rebalance_domains(struct softirq_action *h)
73135 +static void run_rebalance_domains(void)
73136 {
73137 int this_cpu = smp_processor_id();
73138 struct rq *this_rq = cpu_rq(this_cpu);
73139 diff --git a/kernel/signal.c b/kernel/signal.c
73140 index 3d09cf6..a67d2c6 100644
73141 --- a/kernel/signal.c
73142 +++ b/kernel/signal.c
73143 @@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
73144
73145 int print_fatal_signals __read_mostly;
73146
73147 -static void __user *sig_handler(struct task_struct *t, int sig)
73148 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
73149 {
73150 return t->sighand->action[sig - 1].sa.sa_handler;
73151 }
73152
73153 -static int sig_handler_ignored(void __user *handler, int sig)
73154 +static int sig_handler_ignored(__sighandler_t handler, int sig)
73155 {
73156 /* Is it explicitly or implicitly ignored? */
73157 return handler == SIG_IGN ||
73158 @@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73159
73160 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
73161 {
73162 - void __user *handler;
73163 + __sighandler_t handler;
73164
73165 handler = sig_handler(t, sig);
73166
73167 @@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
73168 atomic_inc(&user->sigpending);
73169 rcu_read_unlock();
73170
73171 + if (!override_rlimit)
73172 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73173 +
73174 if (override_rlimit ||
73175 atomic_read(&user->sigpending) <=
73176 task_rlimit(t, RLIMIT_SIGPENDING)) {
73177 @@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73178
73179 int unhandled_signal(struct task_struct *tsk, int sig)
73180 {
73181 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73182 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73183 if (is_global_init(tsk))
73184 return 1;
73185 if (handler != SIG_IGN && handler != SIG_DFL)
73186 @@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73187 }
73188 }
73189
73190 + /* allow glibc communication via tgkill to other threads in our
73191 + thread group */
73192 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73193 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73194 + && gr_handle_signal(t, sig))
73195 + return -EPERM;
73196 +
73197 return security_task_kill(t, info, sig, 0);
73198 }
73199
73200 @@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73201 return send_signal(sig, info, p, 1);
73202 }
73203
73204 -static int
73205 +int
73206 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73207 {
73208 return send_signal(sig, info, t, 0);
73209 @@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73210 unsigned long int flags;
73211 int ret, blocked, ignored;
73212 struct k_sigaction *action;
73213 + int is_unhandled = 0;
73214
73215 spin_lock_irqsave(&t->sighand->siglock, flags);
73216 action = &t->sighand->action[sig-1];
73217 @@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73218 }
73219 if (action->sa.sa_handler == SIG_DFL)
73220 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73221 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73222 + is_unhandled = 1;
73223 ret = specific_send_sig_info(sig, info, t);
73224 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73225
73226 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
73227 + normal operation */
73228 + if (is_unhandled) {
73229 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73230 + gr_handle_crash(t, sig);
73231 + }
73232 +
73233 return ret;
73234 }
73235
73236 @@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73237 ret = check_kill_permission(sig, info, p);
73238 rcu_read_unlock();
73239
73240 - if (!ret && sig)
73241 + if (!ret && sig) {
73242 ret = do_send_sig_info(sig, info, p, true);
73243 + if (!ret)
73244 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73245 + }
73246
73247 return ret;
73248 }
73249 @@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73250 int error = -ESRCH;
73251
73252 rcu_read_lock();
73253 - p = find_task_by_vpid(pid);
73254 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73255 + /* allow glibc communication via tgkill to other threads in our
73256 + thread group */
73257 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73258 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
73259 + p = find_task_by_vpid_unrestricted(pid);
73260 + else
73261 +#endif
73262 + p = find_task_by_vpid(pid);
73263 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73264 error = check_kill_permission(sig, info, p);
73265 /*
73266 @@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
73267 }
73268 seg = get_fs();
73269 set_fs(KERNEL_DS);
73270 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
73271 - (stack_t __force __user *) &uoss,
73272 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
73273 + (stack_t __force_user *) &uoss,
73274 compat_user_stack_pointer());
73275 set_fs(seg);
73276 if (ret >= 0 && uoss_ptr) {
73277 diff --git a/kernel/smp.c b/kernel/smp.c
73278 index 69f38bd..77bbf12 100644
73279 --- a/kernel/smp.c
73280 +++ b/kernel/smp.c
73281 @@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
73282 return NOTIFY_OK;
73283 }
73284
73285 -static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
73286 +static struct notifier_block hotplug_cfd_notifier = {
73287 .notifier_call = hotplug_cfd,
73288 };
73289
73290 diff --git a/kernel/softirq.c b/kernel/softirq.c
73291 index ed567ba..dc61b61 100644
73292 --- a/kernel/softirq.c
73293 +++ b/kernel/softirq.c
73294 @@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
73295 EXPORT_SYMBOL(irq_stat);
73296 #endif
73297
73298 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
73299 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
73300
73301 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73302
73303 -char *softirq_to_name[NR_SOFTIRQS] = {
73304 +const char * const softirq_to_name[NR_SOFTIRQS] = {
73305 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73306 "TASKLET", "SCHED", "HRTIMER", "RCU"
73307 };
73308 @@ -244,7 +244,7 @@ restart:
73309 kstat_incr_softirqs_this_cpu(vec_nr);
73310
73311 trace_softirq_entry(vec_nr);
73312 - h->action(h);
73313 + h->action();
73314 trace_softirq_exit(vec_nr);
73315 if (unlikely(prev_count != preempt_count())) {
73316 printk(KERN_ERR "huh, entered softirq %u %s %p"
73317 @@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
73318 or_softirq_pending(1UL << nr);
73319 }
73320
73321 -void open_softirq(int nr, void (*action)(struct softirq_action *))
73322 +void __init open_softirq(int nr, void (*action)(void))
73323 {
73324 softirq_vec[nr].action = action;
73325 }
73326 @@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73327
73328 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73329
73330 -static void tasklet_action(struct softirq_action *a)
73331 +static void tasklet_action(void)
73332 {
73333 struct tasklet_struct *list;
73334
73335 @@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
73336 }
73337 }
73338
73339 -static void tasklet_hi_action(struct softirq_action *a)
73340 +static void tasklet_hi_action(void)
73341 {
73342 struct tasklet_struct *list;
73343
73344 @@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
73345 return NOTIFY_OK;
73346 }
73347
73348 -static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
73349 +static struct notifier_block remote_softirq_cpu_notifier = {
73350 .notifier_call = remote_softirq_cpu_notify,
73351 };
73352
73353 @@ -835,7 +835,7 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
73354 return NOTIFY_OK;
73355 }
73356
73357 -static struct notifier_block __cpuinitdata cpu_nfb = {
73358 +static struct notifier_block cpu_nfb = {
73359 .notifier_call = cpu_callback
73360 };
73361
73362 diff --git a/kernel/srcu.c b/kernel/srcu.c
73363 index 2b85982..d52ab26 100644
73364 --- a/kernel/srcu.c
73365 +++ b/kernel/srcu.c
73366 @@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
73367 preempt_disable();
73368 idx = rcu_dereference_index_check(sp->completed,
73369 rcu_read_lock_sched_held()) & 0x1;
73370 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73371 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73372 smp_mb(); /* B */ /* Avoid leaking the critical section. */
73373 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73374 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73375 preempt_enable();
73376 return idx;
73377 }
73378 @@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
73379 {
73380 preempt_disable();
73381 smp_mb(); /* C */ /* Avoid leaking the critical section. */
73382 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73383 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73384 preempt_enable();
73385 }
73386 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
73387 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
73388 index 2f194e9..2c05ea9 100644
73389 --- a/kernel/stop_machine.c
73390 +++ b/kernel/stop_machine.c
73391 @@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
73392 * cpu notifiers. It currently shares the same priority as sched
73393 * migration_notifier.
73394 */
73395 -static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
73396 +static struct notifier_block cpu_stop_cpu_notifier = {
73397 .notifier_call = cpu_stop_cpu_callback,
73398 .priority = 10,
73399 };
73400 diff --git a/kernel/sys.c b/kernel/sys.c
73401 index 265b376..b0cd50d 100644
73402 --- a/kernel/sys.c
73403 +++ b/kernel/sys.c
73404 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
73405 error = -EACCES;
73406 goto out;
73407 }
73408 +
73409 + if (gr_handle_chroot_setpriority(p, niceval)) {
73410 + error = -EACCES;
73411 + goto out;
73412 + }
73413 +
73414 no_nice = security_task_setnice(p, niceval);
73415 if (no_nice) {
73416 error = no_nice;
73417 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
73418 goto error;
73419 }
73420
73421 + if (gr_check_group_change(new->gid, new->egid, -1))
73422 + goto error;
73423 +
73424 if (rgid != (gid_t) -1 ||
73425 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
73426 new->sgid = new->egid;
73427 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
73428 old = current_cred();
73429
73430 retval = -EPERM;
73431 +
73432 + if (gr_check_group_change(kgid, kgid, kgid))
73433 + goto error;
73434 +
73435 if (nsown_capable(CAP_SETGID))
73436 new->gid = new->egid = new->sgid = new->fsgid = kgid;
73437 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
73438 @@ -647,7 +660,7 @@ error:
73439 /*
73440 * change the user struct in a credentials set to match the new UID
73441 */
73442 -static int set_user(struct cred *new)
73443 +int set_user(struct cred *new)
73444 {
73445 struct user_struct *new_user;
73446
73447 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
73448 goto error;
73449 }
73450
73451 + if (gr_check_user_change(new->uid, new->euid, -1))
73452 + goto error;
73453 +
73454 if (!uid_eq(new->uid, old->uid)) {
73455 retval = set_user(new);
73456 if (retval < 0)
73457 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
73458 old = current_cred();
73459
73460 retval = -EPERM;
73461 +
73462 + if (gr_check_crash_uid(kuid))
73463 + goto error;
73464 + if (gr_check_user_change(kuid, kuid, kuid))
73465 + goto error;
73466 +
73467 if (nsown_capable(CAP_SETUID)) {
73468 new->suid = new->uid = kuid;
73469 if (!uid_eq(kuid, old->uid)) {
73470 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
73471 goto error;
73472 }
73473
73474 + if (gr_check_user_change(kruid, keuid, -1))
73475 + goto error;
73476 +
73477 if (ruid != (uid_t) -1) {
73478 new->uid = kruid;
73479 if (!uid_eq(kruid, old->uid)) {
73480 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
73481 goto error;
73482 }
73483
73484 + if (gr_check_group_change(krgid, kegid, -1))
73485 + goto error;
73486 +
73487 if (rgid != (gid_t) -1)
73488 new->gid = krgid;
73489 if (egid != (gid_t) -1)
73490 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73491 if (!uid_valid(kuid))
73492 return old_fsuid;
73493
73494 + if (gr_check_user_change(-1, -1, kuid))
73495 + goto error;
73496 +
73497 new = prepare_creds();
73498 if (!new)
73499 return old_fsuid;
73500 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73501 }
73502 }
73503
73504 +error:
73505 abort_creds(new);
73506 return old_fsuid;
73507
73508 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
73509 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
73510 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
73511 nsown_capable(CAP_SETGID)) {
73512 + if (gr_check_group_change(-1, -1, kgid))
73513 + goto error;
73514 +
73515 if (!gid_eq(kgid, old->fsgid)) {
73516 new->fsgid = kgid;
73517 goto change_okay;
73518 }
73519 }
73520
73521 +error:
73522 abort_creds(new);
73523 return old_fsgid;
73524
73525 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
73526 return -EFAULT;
73527
73528 down_read(&uts_sem);
73529 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
73530 + error = __copy_to_user(name->sysname, &utsname()->sysname,
73531 __OLD_UTS_LEN);
73532 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
73533 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
73534 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
73535 __OLD_UTS_LEN);
73536 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
73537 - error |= __copy_to_user(&name->release, &utsname()->release,
73538 + error |= __copy_to_user(name->release, &utsname()->release,
73539 __OLD_UTS_LEN);
73540 error |= __put_user(0, name->release + __OLD_UTS_LEN);
73541 - error |= __copy_to_user(&name->version, &utsname()->version,
73542 + error |= __copy_to_user(name->version, &utsname()->version,
73543 __OLD_UTS_LEN);
73544 error |= __put_user(0, name->version + __OLD_UTS_LEN);
73545 - error |= __copy_to_user(&name->machine, &utsname()->machine,
73546 + error |= __copy_to_user(name->machine, &utsname()->machine,
73547 __OLD_UTS_LEN);
73548 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
73549 up_read(&uts_sem);
73550 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
73551 error = get_dumpable(me->mm);
73552 break;
73553 case PR_SET_DUMPABLE:
73554 - if (arg2 < 0 || arg2 > 1) {
73555 + if (arg2 > 1) {
73556 error = -EINVAL;
73557 break;
73558 }
73559 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
73560 index c88878d..99d321b 100644
73561 --- a/kernel/sysctl.c
73562 +++ b/kernel/sysctl.c
73563 @@ -92,7 +92,6 @@
73564
73565
73566 #if defined(CONFIG_SYSCTL)
73567 -
73568 /* External variables not in a header file. */
73569 extern int sysctl_overcommit_memory;
73570 extern int sysctl_overcommit_ratio;
73571 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
73572 void __user *buffer, size_t *lenp, loff_t *ppos);
73573 #endif
73574
73575 -#ifdef CONFIG_PRINTK
73576 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73577 void __user *buffer, size_t *lenp, loff_t *ppos);
73578 -#endif
73579
73580 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
73581 void __user *buffer, size_t *lenp, loff_t *ppos);
73582 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
73583
73584 #endif
73585
73586 +extern struct ctl_table grsecurity_table[];
73587 +
73588 static struct ctl_table kern_table[];
73589 static struct ctl_table vm_table[];
73590 static struct ctl_table fs_table[];
73591 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
73592 int sysctl_legacy_va_layout;
73593 #endif
73594
73595 +#ifdef CONFIG_PAX_SOFTMODE
73596 +static ctl_table pax_table[] = {
73597 + {
73598 + .procname = "softmode",
73599 + .data = &pax_softmode,
73600 + .maxlen = sizeof(unsigned int),
73601 + .mode = 0600,
73602 + .proc_handler = &proc_dointvec,
73603 + },
73604 +
73605 + { }
73606 +};
73607 +#endif
73608 +
73609 /* The default sysctl tables: */
73610
73611 static struct ctl_table sysctl_base_table[] = {
73612 @@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
73613 #endif
73614
73615 static struct ctl_table kern_table[] = {
73616 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
73617 + {
73618 + .procname = "grsecurity",
73619 + .mode = 0500,
73620 + .child = grsecurity_table,
73621 + },
73622 +#endif
73623 +
73624 +#ifdef CONFIG_PAX_SOFTMODE
73625 + {
73626 + .procname = "pax",
73627 + .mode = 0500,
73628 + .child = pax_table,
73629 + },
73630 +#endif
73631 +
73632 {
73633 .procname = "sched_child_runs_first",
73634 .data = &sysctl_sched_child_runs_first,
73635 @@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
73636 .data = &modprobe_path,
73637 .maxlen = KMOD_PATH_LEN,
73638 .mode = 0644,
73639 - .proc_handler = proc_dostring,
73640 + .proc_handler = proc_dostring_modpriv,
73641 },
73642 {
73643 .procname = "modules_disabled",
73644 @@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
73645 .extra1 = &zero,
73646 .extra2 = &one,
73647 },
73648 +#endif
73649 {
73650 .procname = "kptr_restrict",
73651 .data = &kptr_restrict,
73652 .maxlen = sizeof(int),
73653 .mode = 0644,
73654 .proc_handler = proc_dointvec_minmax_sysadmin,
73655 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73656 + .extra1 = &two,
73657 +#else
73658 .extra1 = &zero,
73659 +#endif
73660 .extra2 = &two,
73661 },
73662 -#endif
73663 {
73664 .procname = "ngroups_max",
73665 .data = &ngroups_max,
73666 @@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
73667 .proc_handler = proc_dointvec_minmax,
73668 .extra1 = &zero,
73669 },
73670 + {
73671 + .procname = "heap_stack_gap",
73672 + .data = &sysctl_heap_stack_gap,
73673 + .maxlen = sizeof(sysctl_heap_stack_gap),
73674 + .mode = 0644,
73675 + .proc_handler = proc_doulongvec_minmax,
73676 + },
73677 #else
73678 {
73679 .procname = "nr_trim_pages",
73680 @@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
73681 buffer, lenp, ppos);
73682 }
73683
73684 +int proc_dostring_modpriv(struct ctl_table *table, int write,
73685 + void __user *buffer, size_t *lenp, loff_t *ppos)
73686 +{
73687 + if (write && !capable(CAP_SYS_MODULE))
73688 + return -EPERM;
73689 +
73690 + return _proc_do_string(table->data, table->maxlen, write,
73691 + buffer, lenp, ppos);
73692 +}
73693 +
73694 static size_t proc_skip_spaces(char **buf)
73695 {
73696 size_t ret;
73697 @@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
73698 len = strlen(tmp);
73699 if (len > *size)
73700 len = *size;
73701 + if (len > sizeof(tmp))
73702 + len = sizeof(tmp);
73703 if (copy_to_user(*buf, tmp, len))
73704 return -EFAULT;
73705 *size -= len;
73706 @@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
73707 return err;
73708 }
73709
73710 -#ifdef CONFIG_PRINTK
73711 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73712 void __user *buffer, size_t *lenp, loff_t *ppos)
73713 {
73714 @@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73715
73716 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
73717 }
73718 -#endif
73719
73720 struct do_proc_dointvec_minmax_conv_param {
73721 int *min;
73722 @@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
73723 *i = val;
73724 } else {
73725 val = convdiv * (*i) / convmul;
73726 - if (!first)
73727 + if (!first) {
73728 err = proc_put_char(&buffer, &left, '\t');
73729 + if (err)
73730 + break;
73731 + }
73732 err = proc_put_long(&buffer, &left, val, false);
73733 if (err)
73734 break;
73735 @@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
73736 return -ENOSYS;
73737 }
73738
73739 +int proc_dostring_modpriv(struct ctl_table *table, int write,
73740 + void __user *buffer, size_t *lenp, loff_t *ppos)
73741 +{
73742 + return -ENOSYS;
73743 +}
73744 +
73745 int proc_dointvec(struct ctl_table *table, int write,
73746 void __user *buffer, size_t *lenp, loff_t *ppos)
73747 {
73748 @@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
73749 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
73750 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
73751 EXPORT_SYMBOL(proc_dostring);
73752 +EXPORT_SYMBOL(proc_dostring_modpriv);
73753 EXPORT_SYMBOL(proc_doulongvec_minmax);
73754 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
73755 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
73756 index 5a63844..25dfc5c 100644
73757 --- a/kernel/sysctl_binary.c
73758 +++ b/kernel/sysctl_binary.c
73759 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
73760 int i;
73761
73762 set_fs(KERNEL_DS);
73763 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73764 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73765 set_fs(old_fs);
73766 if (result < 0)
73767 goto out_kfree;
73768 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
73769 }
73770
73771 set_fs(KERNEL_DS);
73772 - result = vfs_write(file, buffer, str - buffer, &pos);
73773 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73774 set_fs(old_fs);
73775 if (result < 0)
73776 goto out_kfree;
73777 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
73778 int i;
73779
73780 set_fs(KERNEL_DS);
73781 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73782 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73783 set_fs(old_fs);
73784 if (result < 0)
73785 goto out_kfree;
73786 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
73787 }
73788
73789 set_fs(KERNEL_DS);
73790 - result = vfs_write(file, buffer, str - buffer, &pos);
73791 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73792 set_fs(old_fs);
73793 if (result < 0)
73794 goto out_kfree;
73795 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
73796 int i;
73797
73798 set_fs(KERNEL_DS);
73799 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73800 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73801 set_fs(old_fs);
73802 if (result < 0)
73803 goto out;
73804 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73805 __le16 dnaddr;
73806
73807 set_fs(KERNEL_DS);
73808 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73809 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73810 set_fs(old_fs);
73811 if (result < 0)
73812 goto out;
73813 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73814 le16_to_cpu(dnaddr) & 0x3ff);
73815
73816 set_fs(KERNEL_DS);
73817 - result = vfs_write(file, buf, len, &pos);
73818 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
73819 set_fs(old_fs);
73820 if (result < 0)
73821 goto out;
73822 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
73823 index 145bb4d..b2aa969 100644
73824 --- a/kernel/taskstats.c
73825 +++ b/kernel/taskstats.c
73826 @@ -28,9 +28,12 @@
73827 #include <linux/fs.h>
73828 #include <linux/file.h>
73829 #include <linux/pid_namespace.h>
73830 +#include <linux/grsecurity.h>
73831 #include <net/genetlink.h>
73832 #include <linux/atomic.h>
73833
73834 +extern int gr_is_taskstats_denied(int pid);
73835 +
73836 /*
73837 * Maximum length of a cpumask that can be specified in
73838 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
73839 @@ -570,6 +573,9 @@ err:
73840
73841 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
73842 {
73843 + if (gr_is_taskstats_denied(current->pid))
73844 + return -EACCES;
73845 +
73846 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
73847 return cmd_attr_register_cpumask(info);
73848 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
73849 diff --git a/kernel/time.c b/kernel/time.c
73850 index d226c6a..c7c0960 100644
73851 --- a/kernel/time.c
73852 +++ b/kernel/time.c
73853 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
73854 return error;
73855
73856 if (tz) {
73857 + /* we log in do_settimeofday called below, so don't log twice
73858 + */
73859 + if (!tv)
73860 + gr_log_timechange();
73861 +
73862 sys_tz = *tz;
73863 update_vsyscall_tz();
73864 if (firsttime) {
73865 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
73866 index f11d83b..d016d91 100644
73867 --- a/kernel/time/alarmtimer.c
73868 +++ b/kernel/time/alarmtimer.c
73869 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
73870 struct platform_device *pdev;
73871 int error = 0;
73872 int i;
73873 - struct k_clock alarm_clock = {
73874 + static struct k_clock alarm_clock = {
73875 .clock_getres = alarm_clock_getres,
73876 .clock_get = alarm_clock_get,
73877 .timer_create = alarm_timer_create,
73878 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
73879 index f113755..ec24223 100644
73880 --- a/kernel/time/tick-broadcast.c
73881 +++ b/kernel/time/tick-broadcast.c
73882 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
73883 * then clear the broadcast bit.
73884 */
73885 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
73886 - int cpu = smp_processor_id();
73887 + cpu = smp_processor_id();
73888
73889 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
73890 tick_broadcast_clear_oneshot(cpu);
73891 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
73892 index cbc6acb..3a77191 100644
73893 --- a/kernel/time/timekeeping.c
73894 +++ b/kernel/time/timekeeping.c
73895 @@ -15,6 +15,7 @@
73896 #include <linux/init.h>
73897 #include <linux/mm.h>
73898 #include <linux/sched.h>
73899 +#include <linux/grsecurity.h>
73900 #include <linux/syscore_ops.h>
73901 #include <linux/clocksource.h>
73902 #include <linux/jiffies.h>
73903 @@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
73904 if (!timespec_valid_strict(tv))
73905 return -EINVAL;
73906
73907 + gr_log_timechange();
73908 +
73909 write_seqlock_irqsave(&tk->lock, flags);
73910
73911 timekeeping_forward_now(tk);
73912 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
73913 index af5a7e9..715611a 100644
73914 --- a/kernel/time/timer_list.c
73915 +++ b/kernel/time/timer_list.c
73916 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
73917
73918 static void print_name_offset(struct seq_file *m, void *sym)
73919 {
73920 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73921 + SEQ_printf(m, "<%p>", NULL);
73922 +#else
73923 char symname[KSYM_NAME_LEN];
73924
73925 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
73926 SEQ_printf(m, "<%pK>", sym);
73927 else
73928 SEQ_printf(m, "%s", symname);
73929 +#endif
73930 }
73931
73932 static void
73933 @@ -112,7 +116,11 @@ next_one:
73934 static void
73935 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
73936 {
73937 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73938 + SEQ_printf(m, " .base: %p\n", NULL);
73939 +#else
73940 SEQ_printf(m, " .base: %pK\n", base);
73941 +#endif
73942 SEQ_printf(m, " .index: %d\n",
73943 base->index);
73944 SEQ_printf(m, " .resolution: %Lu nsecs\n",
73945 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
73946 {
73947 struct proc_dir_entry *pe;
73948
73949 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73950 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
73951 +#else
73952 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
73953 +#endif
73954 if (!pe)
73955 return -ENOMEM;
73956 return 0;
73957 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
73958 index 0b537f2..40d6c20 100644
73959 --- a/kernel/time/timer_stats.c
73960 +++ b/kernel/time/timer_stats.c
73961 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
73962 static unsigned long nr_entries;
73963 static struct entry entries[MAX_ENTRIES];
73964
73965 -static atomic_t overflow_count;
73966 +static atomic_unchecked_t overflow_count;
73967
73968 /*
73969 * The entries are in a hash-table, for fast lookup:
73970 @@ -140,7 +140,7 @@ static void reset_entries(void)
73971 nr_entries = 0;
73972 memset(entries, 0, sizeof(entries));
73973 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
73974 - atomic_set(&overflow_count, 0);
73975 + atomic_set_unchecked(&overflow_count, 0);
73976 }
73977
73978 static struct entry *alloc_entry(void)
73979 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73980 if (likely(entry))
73981 entry->count++;
73982 else
73983 - atomic_inc(&overflow_count);
73984 + atomic_inc_unchecked(&overflow_count);
73985
73986 out_unlock:
73987 raw_spin_unlock_irqrestore(lock, flags);
73988 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73989
73990 static void print_name_offset(struct seq_file *m, unsigned long addr)
73991 {
73992 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73993 + seq_printf(m, "<%p>", NULL);
73994 +#else
73995 char symname[KSYM_NAME_LEN];
73996
73997 if (lookup_symbol_name(addr, symname) < 0)
73998 - seq_printf(m, "<%p>", (void *)addr);
73999 + seq_printf(m, "<%pK>", (void *)addr);
74000 else
74001 seq_printf(m, "%s", symname);
74002 +#endif
74003 }
74004
74005 static int tstats_show(struct seq_file *m, void *v)
74006 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
74007
74008 seq_puts(m, "Timer Stats Version: v0.2\n");
74009 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
74010 - if (atomic_read(&overflow_count))
74011 + if (atomic_read_unchecked(&overflow_count))
74012 seq_printf(m, "Overflow: %d entries\n",
74013 - atomic_read(&overflow_count));
74014 + atomic_read_unchecked(&overflow_count));
74015
74016 for (i = 0; i < nr_entries; i++) {
74017 entry = entries + i;
74018 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
74019 {
74020 struct proc_dir_entry *pe;
74021
74022 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74023 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
74024 +#else
74025 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
74026 +#endif
74027 if (!pe)
74028 return -ENOMEM;
74029 return 0;
74030 diff --git a/kernel/timer.c b/kernel/timer.c
74031 index 367d008..1ee9ed9 100644
74032 --- a/kernel/timer.c
74033 +++ b/kernel/timer.c
74034 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
74035 /*
74036 * This function runs timers and the timer-tq in bottom half context.
74037 */
74038 -static void run_timer_softirq(struct softirq_action *h)
74039 +static void run_timer_softirq(void)
74040 {
74041 struct tvec_base *base = __this_cpu_read(tvec_bases);
74042
74043 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
74044 return NOTIFY_OK;
74045 }
74046
74047 -static struct notifier_block __cpuinitdata timers_nb = {
74048 +static struct notifier_block timers_nb = {
74049 .notifier_call = timer_cpu_notify,
74050 };
74051
74052 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
74053 index c0bd030..62a1927 100644
74054 --- a/kernel/trace/blktrace.c
74055 +++ b/kernel/trace/blktrace.c
74056 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
74057 struct blk_trace *bt = filp->private_data;
74058 char buf[16];
74059
74060 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
74061 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
74062
74063 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
74064 }
74065 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
74066 return 1;
74067
74068 bt = buf->chan->private_data;
74069 - atomic_inc(&bt->dropped);
74070 + atomic_inc_unchecked(&bt->dropped);
74071 return 0;
74072 }
74073
74074 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
74075
74076 bt->dir = dir;
74077 bt->dev = dev;
74078 - atomic_set(&bt->dropped, 0);
74079 + atomic_set_unchecked(&bt->dropped, 0);
74080
74081 ret = -EIO;
74082 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
74083 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
74084 index 41473b4..325fcfc 100644
74085 --- a/kernel/trace/ftrace.c
74086 +++ b/kernel/trace/ftrace.c
74087 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74088 if (unlikely(ftrace_disabled))
74089 return 0;
74090
74091 + ret = ftrace_arch_code_modify_prepare();
74092 + FTRACE_WARN_ON(ret);
74093 + if (ret)
74094 + return 0;
74095 +
74096 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74097 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74098 if (ret) {
74099 ftrace_bug(ret, ip);
74100 - return 0;
74101 }
74102 - return 1;
74103 + return ret ? 0 : 1;
74104 }
74105
74106 /*
74107 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
74108
74109 int
74110 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
74111 - void *data)
74112 + void *data)
74113 {
74114 struct ftrace_func_probe *entry;
74115 struct ftrace_page *pg;
74116 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
74117 if (!count)
74118 return 0;
74119
74120 + pax_open_kernel();
74121 sort(start, count, sizeof(*start),
74122 ftrace_cmp_ips, ftrace_swap_ips);
74123 + pax_close_kernel();
74124
74125 start_pg = ftrace_allocate_pages(count);
74126 if (!start_pg)
74127 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
74128 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
74129
74130 static int ftrace_graph_active;
74131 -static struct notifier_block ftrace_suspend_notifier;
74132 -
74133 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
74134 {
74135 return 0;
74136 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
74137 return NOTIFY_DONE;
74138 }
74139
74140 +static struct notifier_block ftrace_suspend_notifier = {
74141 + .notifier_call = ftrace_suspend_notifier_call
74142 +};
74143 +
74144 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74145 trace_func_graph_ent_t entryfunc)
74146 {
74147 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74148 goto out;
74149 }
74150
74151 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
74152 register_pm_notifier(&ftrace_suspend_notifier);
74153
74154 ftrace_graph_active++;
74155 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74156 index ce8514f..8233573 100644
74157 --- a/kernel/trace/ring_buffer.c
74158 +++ b/kernel/trace/ring_buffer.c
74159 @@ -346,9 +346,9 @@ struct buffer_data_page {
74160 */
74161 struct buffer_page {
74162 struct list_head list; /* list of buffer pages */
74163 - local_t write; /* index for next write */
74164 + local_unchecked_t write; /* index for next write */
74165 unsigned read; /* index for next read */
74166 - local_t entries; /* entries on this page */
74167 + local_unchecked_t entries; /* entries on this page */
74168 unsigned long real_end; /* real end of data */
74169 struct buffer_data_page *page; /* Actual data page */
74170 };
74171 @@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
74172 unsigned long last_overrun;
74173 local_t entries_bytes;
74174 local_t entries;
74175 - local_t overrun;
74176 - local_t commit_overrun;
74177 + local_unchecked_t overrun;
74178 + local_unchecked_t commit_overrun;
74179 local_t dropped_events;
74180 local_t committing;
74181 local_t commits;
74182 @@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74183 *
74184 * We add a counter to the write field to denote this.
74185 */
74186 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
74187 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
74188 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
74189 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
74190
74191 /*
74192 * Just make sure we have seen our old_write and synchronize
74193 @@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74194 * cmpxchg to only update if an interrupt did not already
74195 * do it for us. If the cmpxchg fails, we don't care.
74196 */
74197 - (void)local_cmpxchg(&next_page->write, old_write, val);
74198 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
74199 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
74200 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
74201
74202 /*
74203 * No need to worry about races with clearing out the commit.
74204 @@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
74205
74206 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
74207 {
74208 - return local_read(&bpage->entries) & RB_WRITE_MASK;
74209 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
74210 }
74211
74212 static inline unsigned long rb_page_write(struct buffer_page *bpage)
74213 {
74214 - return local_read(&bpage->write) & RB_WRITE_MASK;
74215 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
74216 }
74217
74218 static int
74219 @@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
74220 * bytes consumed in ring buffer from here.
74221 * Increment overrun to account for the lost events.
74222 */
74223 - local_add(page_entries, &cpu_buffer->overrun);
74224 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
74225 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74226 }
74227
74228 @@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74229 * it is our responsibility to update
74230 * the counters.
74231 */
74232 - local_add(entries, &cpu_buffer->overrun);
74233 + local_add_unchecked(entries, &cpu_buffer->overrun);
74234 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74235
74236 /*
74237 @@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74238 if (tail == BUF_PAGE_SIZE)
74239 tail_page->real_end = 0;
74240
74241 - local_sub(length, &tail_page->write);
74242 + local_sub_unchecked(length, &tail_page->write);
74243 return;
74244 }
74245
74246 @@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74247 rb_event_set_padding(event);
74248
74249 /* Set the write back to the previous setting */
74250 - local_sub(length, &tail_page->write);
74251 + local_sub_unchecked(length, &tail_page->write);
74252 return;
74253 }
74254
74255 @@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74256
74257 /* Set write to end of buffer */
74258 length = (tail + length) - BUF_PAGE_SIZE;
74259 - local_sub(length, &tail_page->write);
74260 + local_sub_unchecked(length, &tail_page->write);
74261 }
74262
74263 /*
74264 @@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74265 * about it.
74266 */
74267 if (unlikely(next_page == commit_page)) {
74268 - local_inc(&cpu_buffer->commit_overrun);
74269 + local_inc_unchecked(&cpu_buffer->commit_overrun);
74270 goto out_reset;
74271 }
74272
74273 @@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74274 cpu_buffer->tail_page) &&
74275 (cpu_buffer->commit_page ==
74276 cpu_buffer->reader_page))) {
74277 - local_inc(&cpu_buffer->commit_overrun);
74278 + local_inc_unchecked(&cpu_buffer->commit_overrun);
74279 goto out_reset;
74280 }
74281 }
74282 @@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74283 length += RB_LEN_TIME_EXTEND;
74284
74285 tail_page = cpu_buffer->tail_page;
74286 - write = local_add_return(length, &tail_page->write);
74287 + write = local_add_return_unchecked(length, &tail_page->write);
74288
74289 /* set write to only the index of the write */
74290 write &= RB_WRITE_MASK;
74291 @@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74292 kmemcheck_annotate_bitfield(event, bitfield);
74293 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
74294
74295 - local_inc(&tail_page->entries);
74296 + local_inc_unchecked(&tail_page->entries);
74297
74298 /*
74299 * If this is the first commit on the page, then update
74300 @@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74301
74302 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
74303 unsigned long write_mask =
74304 - local_read(&bpage->write) & ~RB_WRITE_MASK;
74305 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
74306 unsigned long event_length = rb_event_length(event);
74307 /*
74308 * This is on the tail page. It is possible that
74309 @@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74310 */
74311 old_index += write_mask;
74312 new_index += write_mask;
74313 - index = local_cmpxchg(&bpage->write, old_index, new_index);
74314 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
74315 if (index == old_index) {
74316 /* update counters */
74317 local_sub(event_length, &cpu_buffer->entries_bytes);
74318 @@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74319
74320 /* Do the likely case first */
74321 if (likely(bpage->page == (void *)addr)) {
74322 - local_dec(&bpage->entries);
74323 + local_dec_unchecked(&bpage->entries);
74324 return;
74325 }
74326
74327 @@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74328 start = bpage;
74329 do {
74330 if (bpage->page == (void *)addr) {
74331 - local_dec(&bpage->entries);
74332 + local_dec_unchecked(&bpage->entries);
74333 return;
74334 }
74335 rb_inc_page(cpu_buffer, &bpage);
74336 @@ -2926,7 +2926,7 @@ static inline unsigned long
74337 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
74338 {
74339 return local_read(&cpu_buffer->entries) -
74340 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
74341 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
74342 }
74343
74344 /**
74345 @@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
74346 return 0;
74347
74348 cpu_buffer = buffer->buffers[cpu];
74349 - ret = local_read(&cpu_buffer->overrun);
74350 + ret = local_read_unchecked(&cpu_buffer->overrun);
74351
74352 return ret;
74353 }
74354 @@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
74355 return 0;
74356
74357 cpu_buffer = buffer->buffers[cpu];
74358 - ret = local_read(&cpu_buffer->commit_overrun);
74359 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
74360
74361 return ret;
74362 }
74363 @@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
74364 /* if you care about this being correct, lock the buffer */
74365 for_each_buffer_cpu(buffer, cpu) {
74366 cpu_buffer = buffer->buffers[cpu];
74367 - overruns += local_read(&cpu_buffer->overrun);
74368 + overruns += local_read_unchecked(&cpu_buffer->overrun);
74369 }
74370
74371 return overruns;
74372 @@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74373 /*
74374 * Reset the reader page to size zero.
74375 */
74376 - local_set(&cpu_buffer->reader_page->write, 0);
74377 - local_set(&cpu_buffer->reader_page->entries, 0);
74378 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74379 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74380 local_set(&cpu_buffer->reader_page->page->commit, 0);
74381 cpu_buffer->reader_page->real_end = 0;
74382
74383 @@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74384 * want to compare with the last_overrun.
74385 */
74386 smp_mb();
74387 - overwrite = local_read(&(cpu_buffer->overrun));
74388 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
74389
74390 /*
74391 * Here's the tricky part.
74392 @@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74393
74394 cpu_buffer->head_page
74395 = list_entry(cpu_buffer->pages, struct buffer_page, list);
74396 - local_set(&cpu_buffer->head_page->write, 0);
74397 - local_set(&cpu_buffer->head_page->entries, 0);
74398 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
74399 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
74400 local_set(&cpu_buffer->head_page->page->commit, 0);
74401
74402 cpu_buffer->head_page->read = 0;
74403 @@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74404
74405 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
74406 INIT_LIST_HEAD(&cpu_buffer->new_pages);
74407 - local_set(&cpu_buffer->reader_page->write, 0);
74408 - local_set(&cpu_buffer->reader_page->entries, 0);
74409 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74410 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74411 local_set(&cpu_buffer->reader_page->page->commit, 0);
74412 cpu_buffer->reader_page->read = 0;
74413
74414 local_set(&cpu_buffer->entries_bytes, 0);
74415 - local_set(&cpu_buffer->overrun, 0);
74416 - local_set(&cpu_buffer->commit_overrun, 0);
74417 + local_set_unchecked(&cpu_buffer->overrun, 0);
74418 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
74419 local_set(&cpu_buffer->dropped_events, 0);
74420 local_set(&cpu_buffer->entries, 0);
74421 local_set(&cpu_buffer->committing, 0);
74422 @@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
74423 rb_init_page(bpage);
74424 bpage = reader->page;
74425 reader->page = *data_page;
74426 - local_set(&reader->write, 0);
74427 - local_set(&reader->entries, 0);
74428 + local_set_unchecked(&reader->write, 0);
74429 + local_set_unchecked(&reader->entries, 0);
74430 reader->read = 0;
74431 *data_page = bpage;
74432
74433 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74434 index 3c13e46..883d039 100644
74435 --- a/kernel/trace/trace.c
74436 +++ b/kernel/trace/trace.c
74437 @@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74438 };
74439 #endif
74440
74441 -static struct dentry *d_tracer;
74442 -
74443 struct dentry *tracing_init_dentry(void)
74444 {
74445 + static struct dentry *d_tracer;
74446 static int once;
74447
74448 if (d_tracer)
74449 @@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
74450 return d_tracer;
74451 }
74452
74453 -static struct dentry *d_percpu;
74454 -
74455 struct dentry *tracing_dentry_percpu(void)
74456 {
74457 + static struct dentry *d_percpu;
74458 static int once;
74459 struct dentry *d_tracer;
74460
74461 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74462 index 880073d..42db7c3 100644
74463 --- a/kernel/trace/trace_events.c
74464 +++ b/kernel/trace/trace_events.c
74465 @@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
74466 struct ftrace_module_file_ops {
74467 struct list_head list;
74468 struct module *mod;
74469 - struct file_operations id;
74470 - struct file_operations enable;
74471 - struct file_operations format;
74472 - struct file_operations filter;
74473 };
74474
74475 static struct ftrace_module_file_ops *
74476 @@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
74477
74478 file_ops->mod = mod;
74479
74480 - file_ops->id = ftrace_event_id_fops;
74481 - file_ops->id.owner = mod;
74482 -
74483 - file_ops->enable = ftrace_enable_fops;
74484 - file_ops->enable.owner = mod;
74485 -
74486 - file_ops->filter = ftrace_event_filter_fops;
74487 - file_ops->filter.owner = mod;
74488 -
74489 - file_ops->format = ftrace_event_format_fops;
74490 - file_ops->format.owner = mod;
74491 + pax_open_kernel();
74492 + mod->trace_id.owner = mod;
74493 + mod->trace_enable.owner = mod;
74494 + mod->trace_filter.owner = mod;
74495 + mod->trace_format.owner = mod;
74496 + pax_close_kernel();
74497
74498 list_add(&file_ops->list, &ftrace_module_file_list);
74499
74500 @@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
74501
74502 for_each_event(call, start, end) {
74503 __trace_add_event_call(*call, mod,
74504 - &file_ops->id, &file_ops->enable,
74505 - &file_ops->filter, &file_ops->format);
74506 + &mod->trace_id, &mod->trace_enable,
74507 + &mod->trace_filter, &mod->trace_format);
74508 }
74509 }
74510
74511 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74512 index fd3c8aa..5f324a6 100644
74513 --- a/kernel/trace/trace_mmiotrace.c
74514 +++ b/kernel/trace/trace_mmiotrace.c
74515 @@ -24,7 +24,7 @@ struct header_iter {
74516 static struct trace_array *mmio_trace_array;
74517 static bool overrun_detected;
74518 static unsigned long prev_overruns;
74519 -static atomic_t dropped_count;
74520 +static atomic_unchecked_t dropped_count;
74521
74522 static void mmio_reset_data(struct trace_array *tr)
74523 {
74524 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
74525
74526 static unsigned long count_overruns(struct trace_iterator *iter)
74527 {
74528 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
74529 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74530 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74531
74532 if (over > prev_overruns)
74533 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74534 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74535 sizeof(*entry), 0, pc);
74536 if (!event) {
74537 - atomic_inc(&dropped_count);
74538 + atomic_inc_unchecked(&dropped_count);
74539 return;
74540 }
74541 entry = ring_buffer_event_data(event);
74542 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74543 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74544 sizeof(*entry), 0, pc);
74545 if (!event) {
74546 - atomic_inc(&dropped_count);
74547 + atomic_inc_unchecked(&dropped_count);
74548 return;
74549 }
74550 entry = ring_buffer_event_data(event);
74551 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74552 index 194d796..76edb8f 100644
74553 --- a/kernel/trace/trace_output.c
74554 +++ b/kernel/trace/trace_output.c
74555 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
74556
74557 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74558 if (!IS_ERR(p)) {
74559 - p = mangle_path(s->buffer + s->len, p, "\n");
74560 + p = mangle_path(s->buffer + s->len, p, "\n\\");
74561 if (p) {
74562 s->len = p - s->buffer;
74563 return 1;
74564 @@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
74565 goto out;
74566 }
74567
74568 + pax_open_kernel();
74569 if (event->funcs->trace == NULL)
74570 - event->funcs->trace = trace_nop_print;
74571 + *(void **)&event->funcs->trace = trace_nop_print;
74572 if (event->funcs->raw == NULL)
74573 - event->funcs->raw = trace_nop_print;
74574 + *(void **)&event->funcs->raw = trace_nop_print;
74575 if (event->funcs->hex == NULL)
74576 - event->funcs->hex = trace_nop_print;
74577 + *(void **)&event->funcs->hex = trace_nop_print;
74578 if (event->funcs->binary == NULL)
74579 - event->funcs->binary = trace_nop_print;
74580 + *(void **)&event->funcs->binary = trace_nop_print;
74581 + pax_close_kernel();
74582
74583 key = event->type & (EVENT_HASHSIZE - 1);
74584
74585 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74586 index 42ca822..cdcacc6 100644
74587 --- a/kernel/trace/trace_stack.c
74588 +++ b/kernel/trace/trace_stack.c
74589 @@ -52,7 +52,7 @@ static inline void check_stack(void)
74590 return;
74591
74592 /* we do not handle interrupt stacks yet */
74593 - if (!object_is_on_stack(&this_size))
74594 + if (!object_starts_on_stack(&this_size))
74595 return;
74596
74597 local_irq_save(flags);
74598 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74599 index 67604e5..3ebb003 100644
74600 --- a/lib/Kconfig.debug
74601 +++ b/lib/Kconfig.debug
74602 @@ -1278,6 +1278,7 @@ config LATENCYTOP
74603 depends on DEBUG_KERNEL
74604 depends on STACKTRACE_SUPPORT
74605 depends on PROC_FS
74606 + depends on !GRKERNSEC_HIDESYM
74607 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
74608 select KALLSYMS
74609 select KALLSYMS_ALL
74610 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
74611
74612 config PROVIDE_OHCI1394_DMA_INIT
74613 bool "Remote debugging over FireWire early on boot"
74614 - depends on PCI && X86
74615 + depends on PCI && X86 && !GRKERNSEC
74616 help
74617 If you want to debug problems which hang or crash the kernel early
74618 on boot and the crashing machine has a FireWire port, you can use
74619 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
74620
74621 config FIREWIRE_OHCI_REMOTE_DMA
74622 bool "Remote debugging over FireWire with firewire-ohci"
74623 - depends on FIREWIRE_OHCI
74624 + depends on FIREWIRE_OHCI && !GRKERNSEC
74625 help
74626 This option lets you use the FireWire bus for remote debugging
74627 with help of the firewire-ohci driver. It enables unfiltered
74628 diff --git a/lib/Makefile b/lib/Makefile
74629 index 02ed6c0..bd243da 100644
74630 --- a/lib/Makefile
74631 +++ b/lib/Makefile
74632 @@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
74633
74634 obj-$(CONFIG_BTREE) += btree.o
74635 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
74636 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
74637 +obj-y += list_debug.o
74638 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
74639
74640 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
74641 diff --git a/lib/bitmap.c b/lib/bitmap.c
74642 index 06f7e4f..f3cf2b0 100644
74643 --- a/lib/bitmap.c
74644 +++ b/lib/bitmap.c
74645 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74646 {
74647 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74648 u32 chunk;
74649 - const char __user __force *ubuf = (const char __user __force *)buf;
74650 + const char __user *ubuf = (const char __force_user *)buf;
74651
74652 bitmap_zero(maskp, nmaskbits);
74653
74654 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
74655 {
74656 if (!access_ok(VERIFY_READ, ubuf, ulen))
74657 return -EFAULT;
74658 - return __bitmap_parse((const char __force *)ubuf,
74659 + return __bitmap_parse((const char __force_kernel *)ubuf,
74660 ulen, 1, maskp, nmaskbits);
74661
74662 }
74663 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
74664 {
74665 unsigned a, b;
74666 int c, old_c, totaldigits;
74667 - const char __user __force *ubuf = (const char __user __force *)buf;
74668 + const char __user *ubuf = (const char __force_user *)buf;
74669 int exp_digit, in_range;
74670
74671 totaldigits = c = 0;
74672 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
74673 {
74674 if (!access_ok(VERIFY_READ, ubuf, ulen))
74675 return -EFAULT;
74676 - return __bitmap_parselist((const char __force *)ubuf,
74677 + return __bitmap_parselist((const char __force_kernel *)ubuf,
74678 ulen, 1, maskp, nmaskbits);
74679 }
74680 EXPORT_SYMBOL(bitmap_parselist_user);
74681 diff --git a/lib/bug.c b/lib/bug.c
74682 index d0cdf14..4d07bd2 100644
74683 --- a/lib/bug.c
74684 +++ b/lib/bug.c
74685 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74686 return BUG_TRAP_TYPE_NONE;
74687
74688 bug = find_bug(bugaddr);
74689 + if (!bug)
74690 + return BUG_TRAP_TYPE_NONE;
74691
74692 file = NULL;
74693 line = 0;
74694 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74695 index d11808c..dc2d6f8 100644
74696 --- a/lib/debugobjects.c
74697 +++ b/lib/debugobjects.c
74698 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74699 if (limit > 4)
74700 return;
74701
74702 - is_on_stack = object_is_on_stack(addr);
74703 + is_on_stack = object_starts_on_stack(addr);
74704 if (is_on_stack == onstack)
74705 return;
74706
74707 diff --git a/lib/devres.c b/lib/devres.c
74708 index 80b9c76..9e32279 100644
74709 --- a/lib/devres.c
74710 +++ b/lib/devres.c
74711 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
74712 void devm_iounmap(struct device *dev, void __iomem *addr)
74713 {
74714 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74715 - (void *)addr));
74716 + (void __force *)addr));
74717 iounmap(addr);
74718 }
74719 EXPORT_SYMBOL(devm_iounmap);
74720 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
74721 {
74722 ioport_unmap(addr);
74723 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
74724 - devm_ioport_map_match, (void *)addr));
74725 + devm_ioport_map_match, (void __force *)addr));
74726 }
74727 EXPORT_SYMBOL(devm_ioport_unmap);
74728
74729 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
74730 index 5e396ac..58d5de1 100644
74731 --- a/lib/dma-debug.c
74732 +++ b/lib/dma-debug.c
74733 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
74734
74735 void dma_debug_add_bus(struct bus_type *bus)
74736 {
74737 - struct notifier_block *nb;
74738 + notifier_block_no_const *nb;
74739
74740 if (global_disable)
74741 return;
74742 @@ -942,7 +942,7 @@ out:
74743
74744 static void check_for_stack(struct device *dev, void *addr)
74745 {
74746 - if (object_is_on_stack(addr))
74747 + if (object_starts_on_stack(addr))
74748 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
74749 "stack [addr=%p]\n", addr);
74750 }
74751 diff --git a/lib/inflate.c b/lib/inflate.c
74752 index 013a761..c28f3fc 100644
74753 --- a/lib/inflate.c
74754 +++ b/lib/inflate.c
74755 @@ -269,7 +269,7 @@ static void free(void *where)
74756 malloc_ptr = free_mem_ptr;
74757 }
74758 #else
74759 -#define malloc(a) kmalloc(a, GFP_KERNEL)
74760 +#define malloc(a) kmalloc((a), GFP_KERNEL)
74761 #define free(a) kfree(a)
74762 #endif
74763
74764 diff --git a/lib/ioremap.c b/lib/ioremap.c
74765 index 0c9216c..863bd89 100644
74766 --- a/lib/ioremap.c
74767 +++ b/lib/ioremap.c
74768 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
74769 unsigned long next;
74770
74771 phys_addr -= addr;
74772 - pmd = pmd_alloc(&init_mm, pud, addr);
74773 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74774 if (!pmd)
74775 return -ENOMEM;
74776 do {
74777 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
74778 unsigned long next;
74779
74780 phys_addr -= addr;
74781 - pud = pud_alloc(&init_mm, pgd, addr);
74782 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
74783 if (!pud)
74784 return -ENOMEM;
74785 do {
74786 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
74787 index bd2bea9..6b3c95e 100644
74788 --- a/lib/is_single_threaded.c
74789 +++ b/lib/is_single_threaded.c
74790 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
74791 struct task_struct *p, *t;
74792 bool ret;
74793
74794 + if (!mm)
74795 + return true;
74796 +
74797 if (atomic_read(&task->signal->live) != 1)
74798 return false;
74799
74800 diff --git a/lib/list_debug.c b/lib/list_debug.c
74801 index c24c2f7..3fc5da0 100644
74802 --- a/lib/list_debug.c
74803 +++ b/lib/list_debug.c
74804 @@ -11,7 +11,9 @@
74805 #include <linux/bug.h>
74806 #include <linux/kernel.h>
74807 #include <linux/rculist.h>
74808 +#include <linux/mm.h>
74809
74810 +#ifdef CONFIG_DEBUG_LIST
74811 /*
74812 * Insert a new entry between two known consecutive entries.
74813 *
74814 @@ -19,21 +21,32 @@
74815 * the prev/next entries already!
74816 */
74817
74818 -void __list_add(struct list_head *new,
74819 - struct list_head *prev,
74820 - struct list_head *next)
74821 +static bool __list_add_debug(struct list_head *new,
74822 + struct list_head *prev,
74823 + struct list_head *next)
74824 {
74825 - WARN(next->prev != prev,
74826 + if (WARN(next->prev != prev,
74827 "list_add corruption. next->prev should be "
74828 "prev (%p), but was %p. (next=%p).\n",
74829 - prev, next->prev, next);
74830 - WARN(prev->next != next,
74831 + prev, next->prev, next) ||
74832 + WARN(prev->next != next,
74833 "list_add corruption. prev->next should be "
74834 "next (%p), but was %p. (prev=%p).\n",
74835 - next, prev->next, prev);
74836 - WARN(new == prev || new == next,
74837 + next, prev->next, prev) ||
74838 + WARN(new == prev || new == next,
74839 "list_add double add: new=%p, prev=%p, next=%p.\n",
74840 - new, prev, next);
74841 + new, prev, next))
74842 + return false;
74843 + return true;
74844 +}
74845 +
74846 +void __list_add(struct list_head *new,
74847 + struct list_head *prev,
74848 + struct list_head *next)
74849 +{
74850 + if (!__list_add_debug(new, prev, next))
74851 + return;
74852 +
74853 next->prev = new;
74854 new->next = next;
74855 new->prev = prev;
74856 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
74857 }
74858 EXPORT_SYMBOL(__list_add);
74859
74860 -void __list_del_entry(struct list_head *entry)
74861 +static bool __list_del_entry_debug(struct list_head *entry)
74862 {
74863 struct list_head *prev, *next;
74864
74865 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
74866 WARN(next->prev != entry,
74867 "list_del corruption. next->prev should be %p, "
74868 "but was %p\n", entry, next->prev))
74869 + return false;
74870 + return true;
74871 +}
74872 +
74873 +void __list_del_entry(struct list_head *entry)
74874 +{
74875 + if (!__list_del_entry_debug(entry))
74876 return;
74877
74878 - __list_del(prev, next);
74879 + __list_del(entry->prev, entry->next);
74880 }
74881 EXPORT_SYMBOL(__list_del_entry);
74882
74883 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
74884 void __list_add_rcu(struct list_head *new,
74885 struct list_head *prev, struct list_head *next)
74886 {
74887 - WARN(next->prev != prev,
74888 + if (WARN(next->prev != prev,
74889 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
74890 - prev, next->prev, next);
74891 - WARN(prev->next != next,
74892 + prev, next->prev, next) ||
74893 + WARN(prev->next != next,
74894 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
74895 - next, prev->next, prev);
74896 + next, prev->next, prev))
74897 + return;
74898 +
74899 new->next = next;
74900 new->prev = prev;
74901 rcu_assign_pointer(list_next_rcu(prev), new);
74902 next->prev = new;
74903 }
74904 EXPORT_SYMBOL(__list_add_rcu);
74905 +#endif
74906 +
74907 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
74908 +{
74909 + struct list_head *prev, *next;
74910 +
74911 + prev = head->prev;
74912 + next = head;
74913 +
74914 +#ifdef CONFIG_DEBUG_LIST
74915 + if (!__list_add_debug(new, prev, next))
74916 + return;
74917 +#endif
74918 +
74919 + pax_open_kernel();
74920 + next->prev = new;
74921 + new->next = next;
74922 + new->prev = prev;
74923 + prev->next = new;
74924 + pax_close_kernel();
74925 +}
74926 +EXPORT_SYMBOL(pax_list_add_tail);
74927 +
74928 +void pax_list_del(struct list_head *entry)
74929 +{
74930 +#ifdef CONFIG_DEBUG_LIST
74931 + if (!__list_del_entry_debug(entry))
74932 + return;
74933 +#endif
74934 +
74935 + pax_open_kernel();
74936 + __list_del(entry->prev, entry->next);
74937 + entry->next = LIST_POISON1;
74938 + entry->prev = LIST_POISON2;
74939 + pax_close_kernel();
74940 +}
74941 +EXPORT_SYMBOL(pax_list_del);
74942 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
74943 index e796429..6e38f9f 100644
74944 --- a/lib/radix-tree.c
74945 +++ b/lib/radix-tree.c
74946 @@ -92,7 +92,7 @@ struct radix_tree_preload {
74947 int nr;
74948 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
74949 };
74950 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
74951 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
74952
74953 static inline void *ptr_to_indirect(void *ptr)
74954 {
74955 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
74956 index bb2b201..46abaf9 100644
74957 --- a/lib/strncpy_from_user.c
74958 +++ b/lib/strncpy_from_user.c
74959 @@ -21,7 +21,7 @@
74960 */
74961 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
74962 {
74963 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74964 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74965 long res = 0;
74966
74967 /*
74968 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
74969 index a28df52..3d55877 100644
74970 --- a/lib/strnlen_user.c
74971 +++ b/lib/strnlen_user.c
74972 @@ -26,7 +26,7 @@
74973 */
74974 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
74975 {
74976 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74977 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74978 long align, res = 0;
74979 unsigned long c;
74980
74981 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
74982 index fab33a9..3b5fe68 100644
74983 --- a/lib/vsprintf.c
74984 +++ b/lib/vsprintf.c
74985 @@ -16,6 +16,9 @@
74986 * - scnprintf and vscnprintf
74987 */
74988
74989 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74990 +#define __INCLUDED_BY_HIDESYM 1
74991 +#endif
74992 #include <stdarg.h>
74993 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
74994 #include <linux/types.h>
74995 @@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
74996 char sym[KSYM_SYMBOL_LEN];
74997 if (ext == 'B')
74998 sprint_backtrace(sym, value);
74999 - else if (ext != 'f' && ext != 's')
75000 + else if (ext != 'f' && ext != 's' && ext != 'a')
75001 sprint_symbol(sym, value);
75002 else
75003 sprint_symbol_no_offset(sym, value);
75004 @@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
75005 return number(buf, end, *(const netdev_features_t *)addr, spec);
75006 }
75007
75008 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75009 +int kptr_restrict __read_mostly = 2;
75010 +#else
75011 int kptr_restrict __read_mostly;
75012 +#endif
75013
75014 /*
75015 * Show a '%p' thing. A kernel extension is that the '%p' is followed
75016 @@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
75017 * - 'S' For symbolic direct pointers with offset
75018 * - 's' For symbolic direct pointers without offset
75019 * - 'B' For backtraced symbolic direct pointers with offset
75020 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75021 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75022 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
75023 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
75024 * - 'M' For a 6-byte MAC address, it prints the address in the
75025 @@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75026
75027 if (!ptr && *fmt != 'K') {
75028 /*
75029 - * Print (null) with the same width as a pointer so it makes
75030 + * Print (nil) with the same width as a pointer so it makes
75031 * tabular output look nice.
75032 */
75033 if (spec.field_width == -1)
75034 spec.field_width = default_width;
75035 - return string(buf, end, "(null)", spec);
75036 + return string(buf, end, "(nil)", spec);
75037 }
75038
75039 switch (*fmt) {
75040 @@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75041 /* Fallthrough */
75042 case 'S':
75043 case 's':
75044 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75045 + break;
75046 +#else
75047 + return symbol_string(buf, end, ptr, spec, *fmt);
75048 +#endif
75049 + case 'A':
75050 + case 'a':
75051 case 'B':
75052 return symbol_string(buf, end, ptr, spec, *fmt);
75053 case 'R':
75054 @@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75055 va_end(va);
75056 return buf;
75057 }
75058 + case 'P':
75059 + break;
75060 case 'K':
75061 /*
75062 * %pK cannot be used in IRQ context because its test
75063 @@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75064 }
75065 break;
75066 }
75067 +
75068 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75069 + /* 'P' = approved pointers to copy to userland,
75070 + as in the /proc/kallsyms case, as we make it display nothing
75071 + for non-root users, and the real contents for root users
75072 + Also ignore 'K' pointers, since we force their NULLing for non-root users
75073 + above
75074 + */
75075 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
75076 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
75077 + dump_stack();
75078 + ptr = NULL;
75079 + }
75080 +#endif
75081 +
75082 spec.flags |= SMALL;
75083 if (spec.field_width == -1) {
75084 spec.field_width = default_width;
75085 @@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75086 typeof(type) value; \
75087 if (sizeof(type) == 8) { \
75088 args = PTR_ALIGN(args, sizeof(u32)); \
75089 - *(u32 *)&value = *(u32 *)args; \
75090 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75091 + *(u32 *)&value = *(const u32 *)args; \
75092 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75093 } else { \
75094 args = PTR_ALIGN(args, sizeof(type)); \
75095 - value = *(typeof(type) *)args; \
75096 + value = *(const typeof(type) *)args; \
75097 } \
75098 args += sizeof(type); \
75099 value; \
75100 @@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75101 case FORMAT_TYPE_STR: {
75102 const char *str_arg = args;
75103 args += strlen(str_arg) + 1;
75104 - str = string(str, end, (char *)str_arg, spec);
75105 + str = string(str, end, str_arg, spec);
75106 break;
75107 }
75108
75109 diff --git a/localversion-grsec b/localversion-grsec
75110 new file mode 100644
75111 index 0000000..7cd6065
75112 --- /dev/null
75113 +++ b/localversion-grsec
75114 @@ -0,0 +1 @@
75115 +-grsec
75116 diff --git a/mm/Kconfig b/mm/Kconfig
75117 index 278e3ab..87c384d 100644
75118 --- a/mm/Kconfig
75119 +++ b/mm/Kconfig
75120 @@ -286,10 +286,10 @@ config KSM
75121 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
75122
75123 config DEFAULT_MMAP_MIN_ADDR
75124 - int "Low address space to protect from user allocation"
75125 + int "Low address space to protect from user allocation"
75126 depends on MMU
75127 - default 4096
75128 - help
75129 + default 65536
75130 + help
75131 This is the portion of low virtual memory which should be protected
75132 from userspace allocation. Keeping a user from writing to low pages
75133 can help reduce the impact of kernel NULL pointer bugs.
75134 @@ -320,7 +320,7 @@ config MEMORY_FAILURE
75135
75136 config HWPOISON_INJECT
75137 tristate "HWPoison pages injector"
75138 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
75139 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
75140 select PROC_PAGE_MONITOR
75141
75142 config NOMMU_INITIAL_TRIM_EXCESS
75143 diff --git a/mm/filemap.c b/mm/filemap.c
75144 index 83efee7..3f99381 100644
75145 --- a/mm/filemap.c
75146 +++ b/mm/filemap.c
75147 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75148 struct address_space *mapping = file->f_mapping;
75149
75150 if (!mapping->a_ops->readpage)
75151 - return -ENOEXEC;
75152 + return -ENODEV;
75153 file_accessed(file);
75154 vma->vm_ops = &generic_file_vm_ops;
75155 return 0;
75156 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75157 *pos = i_size_read(inode);
75158
75159 if (limit != RLIM_INFINITY) {
75160 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75161 if (*pos >= limit) {
75162 send_sig(SIGXFSZ, current, 0);
75163 return -EFBIG;
75164 diff --git a/mm/fremap.c b/mm/fremap.c
75165 index a0aaf0e..20325c3 100644
75166 --- a/mm/fremap.c
75167 +++ b/mm/fremap.c
75168 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75169 retry:
75170 vma = find_vma(mm, start);
75171
75172 +#ifdef CONFIG_PAX_SEGMEXEC
75173 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75174 + goto out;
75175 +#endif
75176 +
75177 /*
75178 * Make sure the vma is shared, that it supports prefaulting,
75179 * and that the remapped range is valid and fully within
75180 diff --git a/mm/highmem.c b/mm/highmem.c
75181 index b32b70c..e512eb0 100644
75182 --- a/mm/highmem.c
75183 +++ b/mm/highmem.c
75184 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
75185 * So no dangers, even with speculative execution.
75186 */
75187 page = pte_page(pkmap_page_table[i]);
75188 + pax_open_kernel();
75189 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
75190 -
75191 + pax_close_kernel();
75192 set_page_address(page, NULL);
75193 need_flush = 1;
75194 }
75195 @@ -198,9 +199,11 @@ start:
75196 }
75197 }
75198 vaddr = PKMAP_ADDR(last_pkmap_nr);
75199 +
75200 + pax_open_kernel();
75201 set_pte_at(&init_mm, vaddr,
75202 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75203 -
75204 + pax_close_kernel();
75205 pkmap_count[last_pkmap_nr] = 1;
75206 set_page_address(page, (void *)vaddr);
75207
75208 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75209 index 546db81..01d5c53 100644
75210 --- a/mm/hugetlb.c
75211 +++ b/mm/hugetlb.c
75212 @@ -2511,6 +2511,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75213 return 1;
75214 }
75215
75216 +#ifdef CONFIG_PAX_SEGMEXEC
75217 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75218 +{
75219 + struct mm_struct *mm = vma->vm_mm;
75220 + struct vm_area_struct *vma_m;
75221 + unsigned long address_m;
75222 + pte_t *ptep_m;
75223 +
75224 + vma_m = pax_find_mirror_vma(vma);
75225 + if (!vma_m)
75226 + return;
75227 +
75228 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75229 + address_m = address + SEGMEXEC_TASK_SIZE;
75230 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75231 + get_page(page_m);
75232 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
75233 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75234 +}
75235 +#endif
75236 +
75237 /*
75238 * Hugetlb_cow() should be called with page lock of the original hugepage held.
75239 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
75240 @@ -2629,6 +2650,11 @@ retry_avoidcopy:
75241 make_huge_pte(vma, new_page, 1));
75242 page_remove_rmap(old_page);
75243 hugepage_add_new_anon_rmap(new_page, vma, address);
75244 +
75245 +#ifdef CONFIG_PAX_SEGMEXEC
75246 + pax_mirror_huge_pte(vma, address, new_page);
75247 +#endif
75248 +
75249 /* Make the old page be freed below */
75250 new_page = old_page;
75251 }
75252 @@ -2788,6 +2814,10 @@ retry:
75253 && (vma->vm_flags & VM_SHARED)));
75254 set_huge_pte_at(mm, address, ptep, new_pte);
75255
75256 +#ifdef CONFIG_PAX_SEGMEXEC
75257 + pax_mirror_huge_pte(vma, address, page);
75258 +#endif
75259 +
75260 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75261 /* Optimization, do the COW without a second fault */
75262 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75263 @@ -2817,6 +2847,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75264 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75265 struct hstate *h = hstate_vma(vma);
75266
75267 +#ifdef CONFIG_PAX_SEGMEXEC
75268 + struct vm_area_struct *vma_m;
75269 +#endif
75270 +
75271 address &= huge_page_mask(h);
75272
75273 ptep = huge_pte_offset(mm, address);
75274 @@ -2830,6 +2864,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75275 VM_FAULT_SET_HINDEX(hstate_index(h));
75276 }
75277
75278 +#ifdef CONFIG_PAX_SEGMEXEC
75279 + vma_m = pax_find_mirror_vma(vma);
75280 + if (vma_m) {
75281 + unsigned long address_m;
75282 +
75283 + if (vma->vm_start > vma_m->vm_start) {
75284 + address_m = address;
75285 + address -= SEGMEXEC_TASK_SIZE;
75286 + vma = vma_m;
75287 + h = hstate_vma(vma);
75288 + } else
75289 + address_m = address + SEGMEXEC_TASK_SIZE;
75290 +
75291 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75292 + return VM_FAULT_OOM;
75293 + address_m &= HPAGE_MASK;
75294 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75295 + }
75296 +#endif
75297 +
75298 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75299 if (!ptep)
75300 return VM_FAULT_OOM;
75301 diff --git a/mm/internal.h b/mm/internal.h
75302 index 9ba2110..eaf0674 100644
75303 --- a/mm/internal.h
75304 +++ b/mm/internal.h
75305 @@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
75306 * in mm/page_alloc.c
75307 */
75308 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75309 +extern void free_compound_page(struct page *page);
75310 extern void prep_compound_page(struct page *page, unsigned long order);
75311 #ifdef CONFIG_MEMORY_FAILURE
75312 extern bool is_free_buddy_page(struct page *page);
75313 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75314 index 752a705..6c3102e 100644
75315 --- a/mm/kmemleak.c
75316 +++ b/mm/kmemleak.c
75317 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
75318
75319 for (i = 0; i < object->trace_len; i++) {
75320 void *ptr = (void *)object->trace[i];
75321 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75322 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
75323 }
75324 }
75325
75326 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
75327 return -ENOMEM;
75328 }
75329
75330 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
75331 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
75332 &kmemleak_fops);
75333 if (!dentry)
75334 pr_warning("Failed to create the debugfs kmemleak file\n");
75335 diff --git a/mm/maccess.c b/mm/maccess.c
75336 index d53adf9..03a24bf 100644
75337 --- a/mm/maccess.c
75338 +++ b/mm/maccess.c
75339 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
75340 set_fs(KERNEL_DS);
75341 pagefault_disable();
75342 ret = __copy_from_user_inatomic(dst,
75343 - (__force const void __user *)src, size);
75344 + (const void __force_user *)src, size);
75345 pagefault_enable();
75346 set_fs(old_fs);
75347
75348 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
75349
75350 set_fs(KERNEL_DS);
75351 pagefault_disable();
75352 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75353 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75354 pagefault_enable();
75355 set_fs(old_fs);
75356
75357 diff --git a/mm/madvise.c b/mm/madvise.c
75358 index 03dfa5c..b032917 100644
75359 --- a/mm/madvise.c
75360 +++ b/mm/madvise.c
75361 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75362 pgoff_t pgoff;
75363 unsigned long new_flags = vma->vm_flags;
75364
75365 +#ifdef CONFIG_PAX_SEGMEXEC
75366 + struct vm_area_struct *vma_m;
75367 +#endif
75368 +
75369 switch (behavior) {
75370 case MADV_NORMAL:
75371 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75372 @@ -123,6 +127,13 @@ success:
75373 /*
75374 * vm_flags is protected by the mmap_sem held in write mode.
75375 */
75376 +
75377 +#ifdef CONFIG_PAX_SEGMEXEC
75378 + vma_m = pax_find_mirror_vma(vma);
75379 + if (vma_m)
75380 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75381 +#endif
75382 +
75383 vma->vm_flags = new_flags;
75384
75385 out:
75386 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75387 struct vm_area_struct ** prev,
75388 unsigned long start, unsigned long end)
75389 {
75390 +
75391 +#ifdef CONFIG_PAX_SEGMEXEC
75392 + struct vm_area_struct *vma_m;
75393 +#endif
75394 +
75395 *prev = vma;
75396 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75397 return -EINVAL;
75398 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75399 zap_page_range(vma, start, end - start, &details);
75400 } else
75401 zap_page_range(vma, start, end - start, NULL);
75402 +
75403 +#ifdef CONFIG_PAX_SEGMEXEC
75404 + vma_m = pax_find_mirror_vma(vma);
75405 + if (vma_m) {
75406 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75407 + struct zap_details details = {
75408 + .nonlinear_vma = vma_m,
75409 + .last_index = ULONG_MAX,
75410 + };
75411 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75412 + } else
75413 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75414 + }
75415 +#endif
75416 +
75417 return 0;
75418 }
75419
75420 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75421 if (end < start)
75422 goto out;
75423
75424 +#ifdef CONFIG_PAX_SEGMEXEC
75425 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75426 + if (end > SEGMEXEC_TASK_SIZE)
75427 + goto out;
75428 + } else
75429 +#endif
75430 +
75431 + if (end > TASK_SIZE)
75432 + goto out;
75433 +
75434 error = 0;
75435 if (end == start)
75436 goto out;
75437 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75438 index c6e4dd3..fdb2ca6 100644
75439 --- a/mm/memory-failure.c
75440 +++ b/mm/memory-failure.c
75441 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75442
75443 int sysctl_memory_failure_recovery __read_mostly = 1;
75444
75445 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75446 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75447
75448 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
75449
75450 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
75451 pfn, t->comm, t->pid);
75452 si.si_signo = SIGBUS;
75453 si.si_errno = 0;
75454 - si.si_addr = (void *)addr;
75455 + si.si_addr = (void __user *)addr;
75456 #ifdef __ARCH_SI_TRAPNO
75457 si.si_trapno = trapno;
75458 #endif
75459 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75460 }
75461
75462 nr_pages = 1 << compound_trans_order(hpage);
75463 - atomic_long_add(nr_pages, &mce_bad_pages);
75464 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
75465
75466 /*
75467 * We need/can do nothing about count=0 pages.
75468 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75469 if (!PageHWPoison(hpage)
75470 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
75471 || (p != hpage && TestSetPageHWPoison(hpage))) {
75472 - atomic_long_sub(nr_pages, &mce_bad_pages);
75473 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75474 return 0;
75475 }
75476 set_page_hwpoison_huge_page(hpage);
75477 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75478 }
75479 if (hwpoison_filter(p)) {
75480 if (TestClearPageHWPoison(p))
75481 - atomic_long_sub(nr_pages, &mce_bad_pages);
75482 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75483 unlock_page(hpage);
75484 put_page(hpage);
75485 return 0;
75486 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
75487 return 0;
75488 }
75489 if (TestClearPageHWPoison(p))
75490 - atomic_long_sub(nr_pages, &mce_bad_pages);
75491 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75492 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
75493 return 0;
75494 }
75495 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
75496 */
75497 if (TestClearPageHWPoison(page)) {
75498 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
75499 - atomic_long_sub(nr_pages, &mce_bad_pages);
75500 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75501 freeit = 1;
75502 if (PageHuge(page))
75503 clear_page_hwpoison_huge_page(page);
75504 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
75505 }
75506 done:
75507 if (!PageHWPoison(hpage))
75508 - atomic_long_add(1 << compound_trans_order(hpage),
75509 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
75510 &mce_bad_pages);
75511 set_page_hwpoison_huge_page(hpage);
75512 dequeue_hwpoisoned_huge_page(hpage);
75513 @@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
75514 return ret;
75515
75516 done:
75517 - atomic_long_add(1, &mce_bad_pages);
75518 + atomic_long_add_unchecked(1, &mce_bad_pages);
75519 SetPageHWPoison(page);
75520 /* keep elevated page count for bad page */
75521 return ret;
75522 diff --git a/mm/memory.c b/mm/memory.c
75523 index bb1369f..efb96b5 100644
75524 --- a/mm/memory.c
75525 +++ b/mm/memory.c
75526 @@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75527 free_pte_range(tlb, pmd, addr);
75528 } while (pmd++, addr = next, addr != end);
75529
75530 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75531 start &= PUD_MASK;
75532 if (start < floor)
75533 return;
75534 @@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75535 pmd = pmd_offset(pud, start);
75536 pud_clear(pud);
75537 pmd_free_tlb(tlb, pmd, start);
75538 +#endif
75539 +
75540 }
75541
75542 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75543 @@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75544 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
75545 } while (pud++, addr = next, addr != end);
75546
75547 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75548 start &= PGDIR_MASK;
75549 if (start < floor)
75550 return;
75551 @@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75552 pud = pud_offset(pgd, start);
75553 pgd_clear(pgd);
75554 pud_free_tlb(tlb, pud, start);
75555 +#endif
75556 +
75557 }
75558
75559 /*
75560 @@ -1618,12 +1624,6 @@ no_page_table:
75561 return page;
75562 }
75563
75564 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
75565 -{
75566 - return stack_guard_page_start(vma, addr) ||
75567 - stack_guard_page_end(vma, addr+PAGE_SIZE);
75568 -}
75569 -
75570 /**
75571 * __get_user_pages() - pin user pages in memory
75572 * @tsk: task_struct of target task
75573 @@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75574
75575 i = 0;
75576
75577 - do {
75578 + while (nr_pages) {
75579 struct vm_area_struct *vma;
75580
75581 - vma = find_extend_vma(mm, start);
75582 + vma = find_vma(mm, start);
75583 if (!vma && in_gate_area(mm, start)) {
75584 unsigned long pg = start & PAGE_MASK;
75585 pgd_t *pgd;
75586 @@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75587 goto next_page;
75588 }
75589
75590 - if (!vma ||
75591 + if (!vma || start < vma->vm_start ||
75592 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75593 !(vm_flags & vma->vm_flags))
75594 return i ? : -EFAULT;
75595 @@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75596 int ret;
75597 unsigned int fault_flags = 0;
75598
75599 - /* For mlock, just skip the stack guard page. */
75600 - if (foll_flags & FOLL_MLOCK) {
75601 - if (stack_guard_page(vma, start))
75602 - goto next_page;
75603 - }
75604 if (foll_flags & FOLL_WRITE)
75605 fault_flags |= FAULT_FLAG_WRITE;
75606 if (nonblocking)
75607 @@ -1865,7 +1860,7 @@ next_page:
75608 start += PAGE_SIZE;
75609 nr_pages--;
75610 } while (nr_pages && start < vma->vm_end);
75611 - } while (nr_pages);
75612 + }
75613 return i;
75614 }
75615 EXPORT_SYMBOL(__get_user_pages);
75616 @@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75617 page_add_file_rmap(page);
75618 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75619
75620 +#ifdef CONFIG_PAX_SEGMEXEC
75621 + pax_mirror_file_pte(vma, addr, page, ptl);
75622 +#endif
75623 +
75624 retval = 0;
75625 pte_unmap_unlock(pte, ptl);
75626 return retval;
75627 @@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75628 if (!page_count(page))
75629 return -EINVAL;
75630 if (!(vma->vm_flags & VM_MIXEDMAP)) {
75631 +
75632 +#ifdef CONFIG_PAX_SEGMEXEC
75633 + struct vm_area_struct *vma_m;
75634 +#endif
75635 +
75636 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
75637 BUG_ON(vma->vm_flags & VM_PFNMAP);
75638 vma->vm_flags |= VM_MIXEDMAP;
75639 +
75640 +#ifdef CONFIG_PAX_SEGMEXEC
75641 + vma_m = pax_find_mirror_vma(vma);
75642 + if (vma_m)
75643 + vma_m->vm_flags |= VM_MIXEDMAP;
75644 +#endif
75645 +
75646 }
75647 return insert_page(vma, addr, page, vma->vm_page_prot);
75648 }
75649 @@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75650 unsigned long pfn)
75651 {
75652 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75653 + BUG_ON(vma->vm_mirror);
75654
75655 if (addr < vma->vm_start || addr >= vma->vm_end)
75656 return -EFAULT;
75657 @@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
75658
75659 BUG_ON(pud_huge(*pud));
75660
75661 - pmd = pmd_alloc(mm, pud, addr);
75662 + pmd = (mm == &init_mm) ?
75663 + pmd_alloc_kernel(mm, pud, addr) :
75664 + pmd_alloc(mm, pud, addr);
75665 if (!pmd)
75666 return -ENOMEM;
75667 do {
75668 @@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
75669 unsigned long next;
75670 int err;
75671
75672 - pud = pud_alloc(mm, pgd, addr);
75673 + pud = (mm == &init_mm) ?
75674 + pud_alloc_kernel(mm, pgd, addr) :
75675 + pud_alloc(mm, pgd, addr);
75676 if (!pud)
75677 return -ENOMEM;
75678 do {
75679 @@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75680 copy_user_highpage(dst, src, va, vma);
75681 }
75682
75683 +#ifdef CONFIG_PAX_SEGMEXEC
75684 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75685 +{
75686 + struct mm_struct *mm = vma->vm_mm;
75687 + spinlock_t *ptl;
75688 + pte_t *pte, entry;
75689 +
75690 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75691 + entry = *pte;
75692 + if (!pte_present(entry)) {
75693 + if (!pte_none(entry)) {
75694 + BUG_ON(pte_file(entry));
75695 + free_swap_and_cache(pte_to_swp_entry(entry));
75696 + pte_clear_not_present_full(mm, address, pte, 0);
75697 + }
75698 + } else {
75699 + struct page *page;
75700 +
75701 + flush_cache_page(vma, address, pte_pfn(entry));
75702 + entry = ptep_clear_flush(vma, address, pte);
75703 + BUG_ON(pte_dirty(entry));
75704 + page = vm_normal_page(vma, address, entry);
75705 + if (page) {
75706 + update_hiwater_rss(mm);
75707 + if (PageAnon(page))
75708 + dec_mm_counter_fast(mm, MM_ANONPAGES);
75709 + else
75710 + dec_mm_counter_fast(mm, MM_FILEPAGES);
75711 + page_remove_rmap(page);
75712 + page_cache_release(page);
75713 + }
75714 + }
75715 + pte_unmap_unlock(pte, ptl);
75716 +}
75717 +
75718 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
75719 + *
75720 + * the ptl of the lower mapped page is held on entry and is not released on exit
75721 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75722 + */
75723 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75724 +{
75725 + struct mm_struct *mm = vma->vm_mm;
75726 + unsigned long address_m;
75727 + spinlock_t *ptl_m;
75728 + struct vm_area_struct *vma_m;
75729 + pmd_t *pmd_m;
75730 + pte_t *pte_m, entry_m;
75731 +
75732 + BUG_ON(!page_m || !PageAnon(page_m));
75733 +
75734 + vma_m = pax_find_mirror_vma(vma);
75735 + if (!vma_m)
75736 + return;
75737 +
75738 + BUG_ON(!PageLocked(page_m));
75739 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75740 + address_m = address + SEGMEXEC_TASK_SIZE;
75741 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75742 + pte_m = pte_offset_map(pmd_m, address_m);
75743 + ptl_m = pte_lockptr(mm, pmd_m);
75744 + if (ptl != ptl_m) {
75745 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75746 + if (!pte_none(*pte_m))
75747 + goto out;
75748 + }
75749 +
75750 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75751 + page_cache_get(page_m);
75752 + page_add_anon_rmap(page_m, vma_m, address_m);
75753 + inc_mm_counter_fast(mm, MM_ANONPAGES);
75754 + set_pte_at(mm, address_m, pte_m, entry_m);
75755 + update_mmu_cache(vma_m, address_m, entry_m);
75756 +out:
75757 + if (ptl != ptl_m)
75758 + spin_unlock(ptl_m);
75759 + pte_unmap(pte_m);
75760 + unlock_page(page_m);
75761 +}
75762 +
75763 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75764 +{
75765 + struct mm_struct *mm = vma->vm_mm;
75766 + unsigned long address_m;
75767 + spinlock_t *ptl_m;
75768 + struct vm_area_struct *vma_m;
75769 + pmd_t *pmd_m;
75770 + pte_t *pte_m, entry_m;
75771 +
75772 + BUG_ON(!page_m || PageAnon(page_m));
75773 +
75774 + vma_m = pax_find_mirror_vma(vma);
75775 + if (!vma_m)
75776 + return;
75777 +
75778 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75779 + address_m = address + SEGMEXEC_TASK_SIZE;
75780 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75781 + pte_m = pte_offset_map(pmd_m, address_m);
75782 + ptl_m = pte_lockptr(mm, pmd_m);
75783 + if (ptl != ptl_m) {
75784 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75785 + if (!pte_none(*pte_m))
75786 + goto out;
75787 + }
75788 +
75789 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75790 + page_cache_get(page_m);
75791 + page_add_file_rmap(page_m);
75792 + inc_mm_counter_fast(mm, MM_FILEPAGES);
75793 + set_pte_at(mm, address_m, pte_m, entry_m);
75794 + update_mmu_cache(vma_m, address_m, entry_m);
75795 +out:
75796 + if (ptl != ptl_m)
75797 + spin_unlock(ptl_m);
75798 + pte_unmap(pte_m);
75799 +}
75800 +
75801 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
75802 +{
75803 + struct mm_struct *mm = vma->vm_mm;
75804 + unsigned long address_m;
75805 + spinlock_t *ptl_m;
75806 + struct vm_area_struct *vma_m;
75807 + pmd_t *pmd_m;
75808 + pte_t *pte_m, entry_m;
75809 +
75810 + vma_m = pax_find_mirror_vma(vma);
75811 + if (!vma_m)
75812 + return;
75813 +
75814 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75815 + address_m = address + SEGMEXEC_TASK_SIZE;
75816 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75817 + pte_m = pte_offset_map(pmd_m, address_m);
75818 + ptl_m = pte_lockptr(mm, pmd_m);
75819 + if (ptl != ptl_m) {
75820 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75821 + if (!pte_none(*pte_m))
75822 + goto out;
75823 + }
75824 +
75825 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
75826 + set_pte_at(mm, address_m, pte_m, entry_m);
75827 +out:
75828 + if (ptl != ptl_m)
75829 + spin_unlock(ptl_m);
75830 + pte_unmap(pte_m);
75831 +}
75832 +
75833 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
75834 +{
75835 + struct page *page_m;
75836 + pte_t entry;
75837 +
75838 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
75839 + goto out;
75840 +
75841 + entry = *pte;
75842 + page_m = vm_normal_page(vma, address, entry);
75843 + if (!page_m)
75844 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
75845 + else if (PageAnon(page_m)) {
75846 + if (pax_find_mirror_vma(vma)) {
75847 + pte_unmap_unlock(pte, ptl);
75848 + lock_page(page_m);
75849 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
75850 + if (pte_same(entry, *pte))
75851 + pax_mirror_anon_pte(vma, address, page_m, ptl);
75852 + else
75853 + unlock_page(page_m);
75854 + }
75855 + } else
75856 + pax_mirror_file_pte(vma, address, page_m, ptl);
75857 +
75858 +out:
75859 + pte_unmap_unlock(pte, ptl);
75860 +}
75861 +#endif
75862 +
75863 /*
75864 * This routine handles present pages, when users try to write
75865 * to a shared page. It is done by copying the page to a new address
75866 @@ -2725,6 +2921,12 @@ gotten:
75867 */
75868 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75869 if (likely(pte_same(*page_table, orig_pte))) {
75870 +
75871 +#ifdef CONFIG_PAX_SEGMEXEC
75872 + if (pax_find_mirror_vma(vma))
75873 + BUG_ON(!trylock_page(new_page));
75874 +#endif
75875 +
75876 if (old_page) {
75877 if (!PageAnon(old_page)) {
75878 dec_mm_counter_fast(mm, MM_FILEPAGES);
75879 @@ -2776,6 +2978,10 @@ gotten:
75880 page_remove_rmap(old_page);
75881 }
75882
75883 +#ifdef CONFIG_PAX_SEGMEXEC
75884 + pax_mirror_anon_pte(vma, address, new_page, ptl);
75885 +#endif
75886 +
75887 /* Free the old page.. */
75888 new_page = old_page;
75889 ret |= VM_FAULT_WRITE;
75890 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75891 swap_free(entry);
75892 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
75893 try_to_free_swap(page);
75894 +
75895 +#ifdef CONFIG_PAX_SEGMEXEC
75896 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
75897 +#endif
75898 +
75899 unlock_page(page);
75900 if (swapcache) {
75901 /*
75902 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75903
75904 /* No need to invalidate - it was non-present before */
75905 update_mmu_cache(vma, address, page_table);
75906 +
75907 +#ifdef CONFIG_PAX_SEGMEXEC
75908 + pax_mirror_anon_pte(vma, address, page, ptl);
75909 +#endif
75910 +
75911 unlock:
75912 pte_unmap_unlock(page_table, ptl);
75913 out:
75914 @@ -3093,40 +3309,6 @@ out_release:
75915 }
75916
75917 /*
75918 - * This is like a special single-page "expand_{down|up}wards()",
75919 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
75920 - * doesn't hit another vma.
75921 - */
75922 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
75923 -{
75924 - address &= PAGE_MASK;
75925 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
75926 - struct vm_area_struct *prev = vma->vm_prev;
75927 -
75928 - /*
75929 - * Is there a mapping abutting this one below?
75930 - *
75931 - * That's only ok if it's the same stack mapping
75932 - * that has gotten split..
75933 - */
75934 - if (prev && prev->vm_end == address)
75935 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
75936 -
75937 - expand_downwards(vma, address - PAGE_SIZE);
75938 - }
75939 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
75940 - struct vm_area_struct *next = vma->vm_next;
75941 -
75942 - /* As VM_GROWSDOWN but s/below/above/ */
75943 - if (next && next->vm_start == address + PAGE_SIZE)
75944 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
75945 -
75946 - expand_upwards(vma, address + PAGE_SIZE);
75947 - }
75948 - return 0;
75949 -}
75950 -
75951 -/*
75952 * We enter with non-exclusive mmap_sem (to exclude vma changes,
75953 * but allow concurrent faults), and pte mapped but not yet locked.
75954 * We return with mmap_sem still held, but pte unmapped and unlocked.
75955 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75956 unsigned long address, pte_t *page_table, pmd_t *pmd,
75957 unsigned int flags)
75958 {
75959 - struct page *page;
75960 + struct page *page = NULL;
75961 spinlock_t *ptl;
75962 pte_t entry;
75963
75964 - pte_unmap(page_table);
75965 -
75966 - /* Check if we need to add a guard page to the stack */
75967 - if (check_stack_guard_page(vma, address) < 0)
75968 - return VM_FAULT_SIGBUS;
75969 -
75970 - /* Use the zero-page for reads */
75971 if (!(flags & FAULT_FLAG_WRITE)) {
75972 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
75973 vma->vm_page_prot));
75974 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75975 + ptl = pte_lockptr(mm, pmd);
75976 + spin_lock(ptl);
75977 if (!pte_none(*page_table))
75978 goto unlock;
75979 goto setpte;
75980 }
75981
75982 /* Allocate our own private page. */
75983 + pte_unmap(page_table);
75984 +
75985 if (unlikely(anon_vma_prepare(vma)))
75986 goto oom;
75987 page = alloc_zeroed_user_highpage_movable(vma, address);
75988 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75989 if (!pte_none(*page_table))
75990 goto release;
75991
75992 +#ifdef CONFIG_PAX_SEGMEXEC
75993 + if (pax_find_mirror_vma(vma))
75994 + BUG_ON(!trylock_page(page));
75995 +#endif
75996 +
75997 inc_mm_counter_fast(mm, MM_ANONPAGES);
75998 page_add_new_anon_rmap(page, vma, address);
75999 setpte:
76000 @@ -3181,6 +3364,12 @@ setpte:
76001
76002 /* No need to invalidate - it was non-present before */
76003 update_mmu_cache(vma, address, page_table);
76004 +
76005 +#ifdef CONFIG_PAX_SEGMEXEC
76006 + if (page)
76007 + pax_mirror_anon_pte(vma, address, page, ptl);
76008 +#endif
76009 +
76010 unlock:
76011 pte_unmap_unlock(page_table, ptl);
76012 return 0;
76013 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76014 */
76015 /* Only go through if we didn't race with anybody else... */
76016 if (likely(pte_same(*page_table, orig_pte))) {
76017 +
76018 +#ifdef CONFIG_PAX_SEGMEXEC
76019 + if (anon && pax_find_mirror_vma(vma))
76020 + BUG_ON(!trylock_page(page));
76021 +#endif
76022 +
76023 flush_icache_page(vma, page);
76024 entry = mk_pte(page, vma->vm_page_prot);
76025 if (flags & FAULT_FLAG_WRITE)
76026 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76027
76028 /* no need to invalidate: a not-present page won't be cached */
76029 update_mmu_cache(vma, address, page_table);
76030 +
76031 +#ifdef CONFIG_PAX_SEGMEXEC
76032 + if (anon)
76033 + pax_mirror_anon_pte(vma, address, page, ptl);
76034 + else
76035 + pax_mirror_file_pte(vma, address, page, ptl);
76036 +#endif
76037 +
76038 } else {
76039 if (cow_page)
76040 mem_cgroup_uncharge_page(cow_page);
76041 @@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
76042 if (flags & FAULT_FLAG_WRITE)
76043 flush_tlb_fix_spurious_fault(vma, address);
76044 }
76045 +
76046 +#ifdef CONFIG_PAX_SEGMEXEC
76047 + pax_mirror_pte(vma, address, pte, pmd, ptl);
76048 + return 0;
76049 +#endif
76050 +
76051 unlock:
76052 pte_unmap_unlock(pte, ptl);
76053 return 0;
76054 @@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76055 pmd_t *pmd;
76056 pte_t *pte;
76057
76058 +#ifdef CONFIG_PAX_SEGMEXEC
76059 + struct vm_area_struct *vma_m;
76060 +#endif
76061 +
76062 __set_current_state(TASK_RUNNING);
76063
76064 count_vm_event(PGFAULT);
76065 @@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76066 if (unlikely(is_vm_hugetlb_page(vma)))
76067 return hugetlb_fault(mm, vma, address, flags);
76068
76069 +#ifdef CONFIG_PAX_SEGMEXEC
76070 + vma_m = pax_find_mirror_vma(vma);
76071 + if (vma_m) {
76072 + unsigned long address_m;
76073 + pgd_t *pgd_m;
76074 + pud_t *pud_m;
76075 + pmd_t *pmd_m;
76076 +
76077 + if (vma->vm_start > vma_m->vm_start) {
76078 + address_m = address;
76079 + address -= SEGMEXEC_TASK_SIZE;
76080 + vma = vma_m;
76081 + } else
76082 + address_m = address + SEGMEXEC_TASK_SIZE;
76083 +
76084 + pgd_m = pgd_offset(mm, address_m);
76085 + pud_m = pud_alloc(mm, pgd_m, address_m);
76086 + if (!pud_m)
76087 + return VM_FAULT_OOM;
76088 + pmd_m = pmd_alloc(mm, pud_m, address_m);
76089 + if (!pmd_m)
76090 + return VM_FAULT_OOM;
76091 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
76092 + return VM_FAULT_OOM;
76093 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76094 + }
76095 +#endif
76096 +
76097 retry:
76098 pgd = pgd_offset(mm, address);
76099 pud = pud_alloc(mm, pgd, address);
76100 @@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76101 spin_unlock(&mm->page_table_lock);
76102 return 0;
76103 }
76104 +
76105 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76106 +{
76107 + pud_t *new = pud_alloc_one(mm, address);
76108 + if (!new)
76109 + return -ENOMEM;
76110 +
76111 + smp_wmb(); /* See comment in __pte_alloc */
76112 +
76113 + spin_lock(&mm->page_table_lock);
76114 + if (pgd_present(*pgd)) /* Another has populated it */
76115 + pud_free(mm, new);
76116 + else
76117 + pgd_populate_kernel(mm, pgd, new);
76118 + spin_unlock(&mm->page_table_lock);
76119 + return 0;
76120 +}
76121 #endif /* __PAGETABLE_PUD_FOLDED */
76122
76123 #ifndef __PAGETABLE_PMD_FOLDED
76124 @@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76125 spin_unlock(&mm->page_table_lock);
76126 return 0;
76127 }
76128 +
76129 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76130 +{
76131 + pmd_t *new = pmd_alloc_one(mm, address);
76132 + if (!new)
76133 + return -ENOMEM;
76134 +
76135 + smp_wmb(); /* See comment in __pte_alloc */
76136 +
76137 + spin_lock(&mm->page_table_lock);
76138 +#ifndef __ARCH_HAS_4LEVEL_HACK
76139 + if (pud_present(*pud)) /* Another has populated it */
76140 + pmd_free(mm, new);
76141 + else
76142 + pud_populate_kernel(mm, pud, new);
76143 +#else
76144 + if (pgd_present(*pud)) /* Another has populated it */
76145 + pmd_free(mm, new);
76146 + else
76147 + pgd_populate_kernel(mm, pud, new);
76148 +#endif /* __ARCH_HAS_4LEVEL_HACK */
76149 + spin_unlock(&mm->page_table_lock);
76150 + return 0;
76151 +}
76152 #endif /* __PAGETABLE_PMD_FOLDED */
76153
76154 int make_pages_present(unsigned long addr, unsigned long end)
76155 @@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
76156 gate_vma.vm_start = FIXADDR_USER_START;
76157 gate_vma.vm_end = FIXADDR_USER_END;
76158 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76159 - gate_vma.vm_page_prot = __P101;
76160 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76161
76162 return 0;
76163 }
76164 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76165 index e2df1c1..1e31d57 100644
76166 --- a/mm/mempolicy.c
76167 +++ b/mm/mempolicy.c
76168 @@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76169 unsigned long vmstart;
76170 unsigned long vmend;
76171
76172 +#ifdef CONFIG_PAX_SEGMEXEC
76173 + struct vm_area_struct *vma_m;
76174 +#endif
76175 +
76176 vma = find_vma(mm, start);
76177 if (!vma || vma->vm_start > start)
76178 return -EFAULT;
76179 @@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76180 if (err)
76181 goto out;
76182 }
76183 +
76184 err = vma_replace_policy(vma, new_pol);
76185 if (err)
76186 goto out;
76187 +
76188 +#ifdef CONFIG_PAX_SEGMEXEC
76189 + vma_m = pax_find_mirror_vma(vma);
76190 + if (vma_m) {
76191 + err = vma_replace_policy(vma_m, new_pol);
76192 + if (err)
76193 + goto out;
76194 + }
76195 +#endif
76196 +
76197 }
76198
76199 out:
76200 @@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76201
76202 if (end < start)
76203 return -EINVAL;
76204 +
76205 +#ifdef CONFIG_PAX_SEGMEXEC
76206 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76207 + if (end > SEGMEXEC_TASK_SIZE)
76208 + return -EINVAL;
76209 + } else
76210 +#endif
76211 +
76212 + if (end > TASK_SIZE)
76213 + return -EINVAL;
76214 +
76215 if (end == start)
76216 return 0;
76217
76218 @@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76219 */
76220 tcred = __task_cred(task);
76221 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76222 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76223 - !capable(CAP_SYS_NICE)) {
76224 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76225 rcu_read_unlock();
76226 err = -EPERM;
76227 goto out_put;
76228 @@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76229 goto out;
76230 }
76231
76232 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76233 + if (mm != current->mm &&
76234 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76235 + mmput(mm);
76236 + err = -EPERM;
76237 + goto out;
76238 + }
76239 +#endif
76240 +
76241 err = do_migrate_pages(mm, old, new,
76242 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
76243
76244 diff --git a/mm/migrate.c b/mm/migrate.c
76245 index 2fd8b4a..d70358f 100644
76246 --- a/mm/migrate.c
76247 +++ b/mm/migrate.c
76248 @@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76249 */
76250 tcred = __task_cred(task);
76251 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76252 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76253 - !capable(CAP_SYS_NICE)) {
76254 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76255 rcu_read_unlock();
76256 err = -EPERM;
76257 goto out;
76258 diff --git a/mm/mlock.c b/mm/mlock.c
76259 index c9bd528..da8d069 100644
76260 --- a/mm/mlock.c
76261 +++ b/mm/mlock.c
76262 @@ -13,6 +13,7 @@
76263 #include <linux/pagemap.h>
76264 #include <linux/mempolicy.h>
76265 #include <linux/syscalls.h>
76266 +#include <linux/security.h>
76267 #include <linux/sched.h>
76268 #include <linux/export.h>
76269 #include <linux/rmap.h>
76270 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76271 {
76272 unsigned long nstart, end, tmp;
76273 struct vm_area_struct * vma, * prev;
76274 - int error;
76275 + int error = 0;
76276
76277 VM_BUG_ON(start & ~PAGE_MASK);
76278 VM_BUG_ON(len != PAGE_ALIGN(len));
76279 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76280 return -EINVAL;
76281 if (end == start)
76282 return 0;
76283 + if (end > TASK_SIZE)
76284 + return -EINVAL;
76285 +
76286 vma = find_vma(current->mm, start);
76287 if (!vma || vma->vm_start > start)
76288 return -ENOMEM;
76289 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76290 for (nstart = start ; ; ) {
76291 vm_flags_t newflags;
76292
76293 +#ifdef CONFIG_PAX_SEGMEXEC
76294 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76295 + break;
76296 +#endif
76297 +
76298 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76299
76300 newflags = vma->vm_flags | VM_LOCKED;
76301 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76302 lock_limit >>= PAGE_SHIFT;
76303
76304 /* check against resource limits */
76305 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76306 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76307 error = do_mlock(start, len, 1);
76308 up_write(&current->mm->mmap_sem);
76309 @@ -528,6 +538,12 @@ static int do_mlockall(int flags)
76310 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76311 vm_flags_t newflags;
76312
76313 +#ifdef CONFIG_PAX_SEGMEXEC
76314 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76315 + break;
76316 +#endif
76317 +
76318 + BUG_ON(vma->vm_end > TASK_SIZE);
76319 newflags = vma->vm_flags | VM_LOCKED;
76320 if (!(flags & MCL_CURRENT))
76321 newflags &= ~VM_LOCKED;
76322 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76323 lock_limit >>= PAGE_SHIFT;
76324
76325 ret = -ENOMEM;
76326 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76327 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76328 capable(CAP_IPC_LOCK))
76329 ret = do_mlockall(flags);
76330 diff --git a/mm/mmap.c b/mm/mmap.c
76331 index d1e4124..32a6988 100644
76332 --- a/mm/mmap.c
76333 +++ b/mm/mmap.c
76334 @@ -32,6 +32,7 @@
76335 #include <linux/khugepaged.h>
76336 #include <linux/uprobes.h>
76337 #include <linux/rbtree_augmented.h>
76338 +#include <linux/random.h>
76339
76340 #include <asm/uaccess.h>
76341 #include <asm/cacheflush.h>
76342 @@ -48,6 +49,16 @@
76343 #define arch_rebalance_pgtables(addr, len) (addr)
76344 #endif
76345
76346 +static inline void verify_mm_writelocked(struct mm_struct *mm)
76347 +{
76348 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76349 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76350 + up_read(&mm->mmap_sem);
76351 + BUG();
76352 + }
76353 +#endif
76354 +}
76355 +
76356 static void unmap_region(struct mm_struct *mm,
76357 struct vm_area_struct *vma, struct vm_area_struct *prev,
76358 unsigned long start, unsigned long end);
76359 @@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
76360 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76361 *
76362 */
76363 -pgprot_t protection_map[16] = {
76364 +pgprot_t protection_map[16] __read_only = {
76365 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76366 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76367 };
76368
76369 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
76370 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76371 {
76372 - return __pgprot(pgprot_val(protection_map[vm_flags &
76373 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76374 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76375 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76376 +
76377 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76378 + if (!(__supported_pte_mask & _PAGE_NX) &&
76379 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76380 + (vm_flags & (VM_READ | VM_WRITE)))
76381 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76382 +#endif
76383 +
76384 + return prot;
76385 }
76386 EXPORT_SYMBOL(vm_get_page_prot);
76387
76388 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
76389 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
76390 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76391 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76392 /*
76393 * Make sure vm_committed_as in one cacheline and not cacheline shared with
76394 * other variables. It can be updated by several CPUs frequently.
76395 @@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76396 struct vm_area_struct *next = vma->vm_next;
76397
76398 might_sleep();
76399 + BUG_ON(vma->vm_mirror);
76400 if (vma->vm_ops && vma->vm_ops->close)
76401 vma->vm_ops->close(vma);
76402 if (vma->vm_file)
76403 @@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76404 * not page aligned -Ram Gupta
76405 */
76406 rlim = rlimit(RLIMIT_DATA);
76407 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76408 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76409 (mm->end_data - mm->start_data) > rlim)
76410 goto out;
76411 @@ -888,6 +911,12 @@ static int
76412 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76413 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76414 {
76415 +
76416 +#ifdef CONFIG_PAX_SEGMEXEC
76417 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76418 + return 0;
76419 +#endif
76420 +
76421 if (is_mergeable_vma(vma, file, vm_flags) &&
76422 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76423 if (vma->vm_pgoff == vm_pgoff)
76424 @@ -907,6 +936,12 @@ static int
76425 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76426 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76427 {
76428 +
76429 +#ifdef CONFIG_PAX_SEGMEXEC
76430 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76431 + return 0;
76432 +#endif
76433 +
76434 if (is_mergeable_vma(vma, file, vm_flags) &&
76435 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76436 pgoff_t vm_pglen;
76437 @@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76438 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76439 struct vm_area_struct *prev, unsigned long addr,
76440 unsigned long end, unsigned long vm_flags,
76441 - struct anon_vma *anon_vma, struct file *file,
76442 + struct anon_vma *anon_vma, struct file *file,
76443 pgoff_t pgoff, struct mempolicy *policy)
76444 {
76445 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76446 struct vm_area_struct *area, *next;
76447 int err;
76448
76449 +#ifdef CONFIG_PAX_SEGMEXEC
76450 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76451 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76452 +
76453 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76454 +#endif
76455 +
76456 /*
76457 * We later require that vma->vm_flags == vm_flags,
76458 * so this tests vma->vm_flags & VM_SPECIAL, too.
76459 @@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76460 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76461 next = next->vm_next;
76462
76463 +#ifdef CONFIG_PAX_SEGMEXEC
76464 + if (prev)
76465 + prev_m = pax_find_mirror_vma(prev);
76466 + if (area)
76467 + area_m = pax_find_mirror_vma(area);
76468 + if (next)
76469 + next_m = pax_find_mirror_vma(next);
76470 +#endif
76471 +
76472 /*
76473 * Can it merge with the predecessor?
76474 */
76475 @@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76476 /* cases 1, 6 */
76477 err = vma_adjust(prev, prev->vm_start,
76478 next->vm_end, prev->vm_pgoff, NULL);
76479 - } else /* cases 2, 5, 7 */
76480 +
76481 +#ifdef CONFIG_PAX_SEGMEXEC
76482 + if (!err && prev_m)
76483 + err = vma_adjust(prev_m, prev_m->vm_start,
76484 + next_m->vm_end, prev_m->vm_pgoff, NULL);
76485 +#endif
76486 +
76487 + } else { /* cases 2, 5, 7 */
76488 err = vma_adjust(prev, prev->vm_start,
76489 end, prev->vm_pgoff, NULL);
76490 +
76491 +#ifdef CONFIG_PAX_SEGMEXEC
76492 + if (!err && prev_m)
76493 + err = vma_adjust(prev_m, prev_m->vm_start,
76494 + end_m, prev_m->vm_pgoff, NULL);
76495 +#endif
76496 +
76497 + }
76498 if (err)
76499 return NULL;
76500 khugepaged_enter_vma_merge(prev);
76501 @@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76502 mpol_equal(policy, vma_policy(next)) &&
76503 can_vma_merge_before(next, vm_flags,
76504 anon_vma, file, pgoff+pglen)) {
76505 - if (prev && addr < prev->vm_end) /* case 4 */
76506 + if (prev && addr < prev->vm_end) { /* case 4 */
76507 err = vma_adjust(prev, prev->vm_start,
76508 addr, prev->vm_pgoff, NULL);
76509 - else /* cases 3, 8 */
76510 +
76511 +#ifdef CONFIG_PAX_SEGMEXEC
76512 + if (!err && prev_m)
76513 + err = vma_adjust(prev_m, prev_m->vm_start,
76514 + addr_m, prev_m->vm_pgoff, NULL);
76515 +#endif
76516 +
76517 + } else { /* cases 3, 8 */
76518 err = vma_adjust(area, addr, next->vm_end,
76519 next->vm_pgoff - pglen, NULL);
76520 +
76521 +#ifdef CONFIG_PAX_SEGMEXEC
76522 + if (!err && area_m)
76523 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
76524 + next_m->vm_pgoff - pglen, NULL);
76525 +#endif
76526 +
76527 + }
76528 if (err)
76529 return NULL;
76530 khugepaged_enter_vma_merge(area);
76531 @@ -1120,16 +1201,13 @@ none:
76532 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76533 struct file *file, long pages)
76534 {
76535 - const unsigned long stack_flags
76536 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76537 -
76538 mm->total_vm += pages;
76539
76540 if (file) {
76541 mm->shared_vm += pages;
76542 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76543 mm->exec_vm += pages;
76544 - } else if (flags & stack_flags)
76545 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76546 mm->stack_vm += pages;
76547 }
76548 #endif /* CONFIG_PROC_FS */
76549 @@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76550 * (the exception is when the underlying filesystem is noexec
76551 * mounted, in which case we dont add PROT_EXEC.)
76552 */
76553 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76554 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76555 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76556 prot |= PROT_EXEC;
76557
76558 @@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76559 /* Obtain the address to map to. we verify (or select) it and ensure
76560 * that it represents a valid section of the address space.
76561 */
76562 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
76563 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76564 if (addr & ~PAGE_MASK)
76565 return addr;
76566
76567 @@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76568 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76569 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76570
76571 +#ifdef CONFIG_PAX_MPROTECT
76572 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76573 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76574 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76575 + gr_log_rwxmmap(file);
76576 +
76577 +#ifdef CONFIG_PAX_EMUPLT
76578 + vm_flags &= ~VM_EXEC;
76579 +#else
76580 + return -EPERM;
76581 +#endif
76582 +
76583 + }
76584 +
76585 + if (!(vm_flags & VM_EXEC))
76586 + vm_flags &= ~VM_MAYEXEC;
76587 +#else
76588 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76589 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76590 +#endif
76591 + else
76592 + vm_flags &= ~VM_MAYWRITE;
76593 + }
76594 +#endif
76595 +
76596 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76597 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76598 + vm_flags &= ~VM_PAGEEXEC;
76599 +#endif
76600 +
76601 if (flags & MAP_LOCKED)
76602 if (!can_do_mlock())
76603 return -EPERM;
76604 @@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76605 locked += mm->locked_vm;
76606 lock_limit = rlimit(RLIMIT_MEMLOCK);
76607 lock_limit >>= PAGE_SHIFT;
76608 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76609 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76610 return -EAGAIN;
76611 }
76612 @@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76613 }
76614 }
76615
76616 + if (!gr_acl_handle_mmap(file, prot))
76617 + return -EACCES;
76618 +
76619 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76620 }
76621
76622 @@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
76623 vm_flags_t vm_flags = vma->vm_flags;
76624
76625 /* If it was private or non-writable, the write bit is already clear */
76626 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76627 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76628 return 0;
76629
76630 /* The backer wishes to know when pages are first written to? */
76631 @@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76632 unsigned long charged = 0;
76633 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76634
76635 +#ifdef CONFIG_PAX_SEGMEXEC
76636 + struct vm_area_struct *vma_m = NULL;
76637 +#endif
76638 +
76639 + /*
76640 + * mm->mmap_sem is required to protect against another thread
76641 + * changing the mappings in case we sleep.
76642 + */
76643 + verify_mm_writelocked(mm);
76644 +
76645 /* Clear old maps */
76646 error = -ENOMEM;
76647 -munmap_back:
76648 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76649 if (do_munmap(mm, addr, len))
76650 return -ENOMEM;
76651 - goto munmap_back;
76652 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76653 }
76654
76655 /* Check against address space limit. */
76656 @@ -1460,6 +1581,16 @@ munmap_back:
76657 goto unacct_error;
76658 }
76659
76660 +#ifdef CONFIG_PAX_SEGMEXEC
76661 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76662 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76663 + if (!vma_m) {
76664 + error = -ENOMEM;
76665 + goto free_vma;
76666 + }
76667 + }
76668 +#endif
76669 +
76670 vma->vm_mm = mm;
76671 vma->vm_start = addr;
76672 vma->vm_end = addr + len;
76673 @@ -1484,6 +1615,13 @@ munmap_back:
76674 if (error)
76675 goto unmap_and_free_vma;
76676
76677 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76678 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76679 + vma->vm_flags |= VM_PAGEEXEC;
76680 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76681 + }
76682 +#endif
76683 +
76684 /* Can addr have changed??
76685 *
76686 * Answer: Yes, several device drivers can do it in their
76687 @@ -1522,6 +1660,11 @@ munmap_back:
76688 vma_link(mm, vma, prev, rb_link, rb_parent);
76689 file = vma->vm_file;
76690
76691 +#ifdef CONFIG_PAX_SEGMEXEC
76692 + if (vma_m)
76693 + BUG_ON(pax_mirror_vma(vma_m, vma));
76694 +#endif
76695 +
76696 /* Once vma denies write, undo our temporary denial count */
76697 if (correct_wcount)
76698 atomic_inc(&inode->i_writecount);
76699 @@ -1529,6 +1672,7 @@ out:
76700 perf_event_mmap(vma);
76701
76702 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76703 + track_exec_limit(mm, addr, addr + len, vm_flags);
76704 if (vm_flags & VM_LOCKED) {
76705 if (!mlock_vma_pages_range(vma, addr, addr + len))
76706 mm->locked_vm += (len >> PAGE_SHIFT);
76707 @@ -1550,6 +1694,12 @@ unmap_and_free_vma:
76708 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76709 charged = 0;
76710 free_vma:
76711 +
76712 +#ifdef CONFIG_PAX_SEGMEXEC
76713 + if (vma_m)
76714 + kmem_cache_free(vm_area_cachep, vma_m);
76715 +#endif
76716 +
76717 kmem_cache_free(vm_area_cachep, vma);
76718 unacct_error:
76719 if (charged)
76720 @@ -1557,6 +1707,62 @@ unacct_error:
76721 return error;
76722 }
76723
76724 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76725 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76726 +{
76727 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
76728 + return (random32() & 0xFF) << PAGE_SHIFT;
76729 +
76730 + return 0;
76731 +}
76732 +#endif
76733 +
76734 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
76735 +{
76736 + if (!vma) {
76737 +#ifdef CONFIG_STACK_GROWSUP
76738 + if (addr > sysctl_heap_stack_gap)
76739 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76740 + else
76741 + vma = find_vma(current->mm, 0);
76742 + if (vma && (vma->vm_flags & VM_GROWSUP))
76743 + return false;
76744 +#endif
76745 + return true;
76746 + }
76747 +
76748 + if (addr + len > vma->vm_start)
76749 + return false;
76750 +
76751 + if (vma->vm_flags & VM_GROWSDOWN)
76752 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76753 +#ifdef CONFIG_STACK_GROWSUP
76754 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76755 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76756 +#endif
76757 + else if (offset)
76758 + return offset <= vma->vm_start - addr - len;
76759 +
76760 + return true;
76761 +}
76762 +
76763 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
76764 +{
76765 + if (vma->vm_start < len)
76766 + return -ENOMEM;
76767 +
76768 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
76769 + if (offset <= vma->vm_start - len)
76770 + return vma->vm_start - len - offset;
76771 + else
76772 + return -ENOMEM;
76773 + }
76774 +
76775 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
76776 + return vma->vm_start - len - sysctl_heap_stack_gap;
76777 + return -ENOMEM;
76778 +}
76779 +
76780 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
76781 {
76782 /*
76783 @@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76784 struct mm_struct *mm = current->mm;
76785 struct vm_area_struct *vma;
76786 struct vm_unmapped_area_info info;
76787 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76788
76789 if (len > TASK_SIZE)
76790 return -ENOMEM;
76791 @@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76792 if (flags & MAP_FIXED)
76793 return addr;
76794
76795 +#ifdef CONFIG_PAX_RANDMMAP
76796 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76797 +#endif
76798 +
76799 if (addr) {
76800 addr = PAGE_ALIGN(addr);
76801 vma = find_vma(mm, addr);
76802 - if (TASK_SIZE - len >= addr &&
76803 - (!vma || addr + len <= vma->vm_start))
76804 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76805 return addr;
76806 }
76807
76808 info.flags = 0;
76809 info.length = len;
76810 info.low_limit = TASK_UNMAPPED_BASE;
76811 +
76812 +#ifdef CONFIG_PAX_RANDMMAP
76813 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76814 + info.low_limit += mm->delta_mmap;
76815 +#endif
76816 +
76817 info.high_limit = TASK_SIZE;
76818 info.align_mask = 0;
76819 return vm_unmapped_area(&info);
76820 @@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76821
76822 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
76823 {
76824 +
76825 +#ifdef CONFIG_PAX_SEGMEXEC
76826 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76827 + return;
76828 +#endif
76829 +
76830 /*
76831 * Is this a new hole at the lowest possible address?
76832 */
76833 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
76834 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
76835 mm->free_area_cache = addr;
76836 }
76837
76838 @@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76839 struct mm_struct *mm = current->mm;
76840 unsigned long addr = addr0;
76841 struct vm_unmapped_area_info info;
76842 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76843
76844 /* requested length too big for entire address space */
76845 if (len > TASK_SIZE)
76846 @@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76847 if (flags & MAP_FIXED)
76848 return addr;
76849
76850 +#ifdef CONFIG_PAX_RANDMMAP
76851 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76852 +#endif
76853 +
76854 /* requesting a specific address */
76855 if (addr) {
76856 addr = PAGE_ALIGN(addr);
76857 vma = find_vma(mm, addr);
76858 - if (TASK_SIZE - len >= addr &&
76859 - (!vma || addr + len <= vma->vm_start))
76860 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76861 return addr;
76862 }
76863
76864 @@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76865 VM_BUG_ON(addr != -ENOMEM);
76866 info.flags = 0;
76867 info.low_limit = TASK_UNMAPPED_BASE;
76868 +
76869 +#ifdef CONFIG_PAX_RANDMMAP
76870 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76871 + info.low_limit += mm->delta_mmap;
76872 +#endif
76873 +
76874 info.high_limit = TASK_SIZE;
76875 addr = vm_unmapped_area(&info);
76876 }
76877 @@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76878
76879 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76880 {
76881 +
76882 +#ifdef CONFIG_PAX_SEGMEXEC
76883 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76884 + return;
76885 +#endif
76886 +
76887 /*
76888 * Is this a new hole at the highest possible address?
76889 */
76890 @@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76891 mm->free_area_cache = addr;
76892
76893 /* dont allow allocations above current base */
76894 - if (mm->free_area_cache > mm->mmap_base)
76895 + if (mm->free_area_cache > mm->mmap_base) {
76896 mm->free_area_cache = mm->mmap_base;
76897 + mm->cached_hole_size = ~0UL;
76898 + }
76899 }
76900
76901 unsigned long
76902 @@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
76903 return vma;
76904 }
76905
76906 +#ifdef CONFIG_PAX_SEGMEXEC
76907 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
76908 +{
76909 + struct vm_area_struct *vma_m;
76910 +
76911 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
76912 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
76913 + BUG_ON(vma->vm_mirror);
76914 + return NULL;
76915 + }
76916 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
76917 + vma_m = vma->vm_mirror;
76918 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
76919 + BUG_ON(vma->vm_file != vma_m->vm_file);
76920 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
76921 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
76922 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
76923 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
76924 + return vma_m;
76925 +}
76926 +#endif
76927 +
76928 /*
76929 * Verify that the stack growth is acceptable and
76930 * update accounting. This is shared with both the
76931 @@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76932 return -ENOMEM;
76933
76934 /* Stack limit test */
76935 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
76936 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
76937 return -ENOMEM;
76938
76939 @@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76940 locked = mm->locked_vm + grow;
76941 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
76942 limit >>= PAGE_SHIFT;
76943 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76944 if (locked > limit && !capable(CAP_IPC_LOCK))
76945 return -ENOMEM;
76946 }
76947 @@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76948 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76949 * vma is the last one with address > vma->vm_end. Have to extend vma.
76950 */
76951 +#ifndef CONFIG_IA64
76952 +static
76953 +#endif
76954 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76955 {
76956 int error;
76957 + bool locknext;
76958
76959 if (!(vma->vm_flags & VM_GROWSUP))
76960 return -EFAULT;
76961
76962 + /* Also guard against wrapping around to address 0. */
76963 + if (address < PAGE_ALIGN(address+1))
76964 + address = PAGE_ALIGN(address+1);
76965 + else
76966 + return -ENOMEM;
76967 +
76968 /*
76969 * We must make sure the anon_vma is allocated
76970 * so that the anon_vma locking is not a noop.
76971 */
76972 if (unlikely(anon_vma_prepare(vma)))
76973 return -ENOMEM;
76974 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
76975 + if (locknext && anon_vma_prepare(vma->vm_next))
76976 + return -ENOMEM;
76977 vma_lock_anon_vma(vma);
76978 + if (locknext)
76979 + vma_lock_anon_vma(vma->vm_next);
76980
76981 /*
76982 * vma->vm_start/vm_end cannot change under us because the caller
76983 * is required to hold the mmap_sem in read mode. We need the
76984 - * anon_vma lock to serialize against concurrent expand_stacks.
76985 - * Also guard against wrapping around to address 0.
76986 + * anon_vma locks to serialize against concurrent expand_stacks
76987 + * and expand_upwards.
76988 */
76989 - if (address < PAGE_ALIGN(address+4))
76990 - address = PAGE_ALIGN(address+4);
76991 - else {
76992 - vma_unlock_anon_vma(vma);
76993 - return -ENOMEM;
76994 - }
76995 error = 0;
76996
76997 /* Somebody else might have raced and expanded it already */
76998 - if (address > vma->vm_end) {
76999 + 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)
77000 + error = -ENOMEM;
77001 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77002 unsigned long size, grow;
77003
77004 size = address - vma->vm_start;
77005 @@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77006 }
77007 }
77008 }
77009 + if (locknext)
77010 + vma_unlock_anon_vma(vma->vm_next);
77011 vma_unlock_anon_vma(vma);
77012 khugepaged_enter_vma_merge(vma);
77013 validate_mm(vma->vm_mm);
77014 @@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
77015 unsigned long address)
77016 {
77017 int error;
77018 + bool lockprev = false;
77019 + struct vm_area_struct *prev;
77020
77021 /*
77022 * We must make sure the anon_vma is allocated
77023 @@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
77024 if (error)
77025 return error;
77026
77027 + prev = vma->vm_prev;
77028 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77029 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77030 +#endif
77031 + if (lockprev && anon_vma_prepare(prev))
77032 + return -ENOMEM;
77033 + if (lockprev)
77034 + vma_lock_anon_vma(prev);
77035 +
77036 vma_lock_anon_vma(vma);
77037
77038 /*
77039 @@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
77040 */
77041
77042 /* Somebody else might have raced and expanded it already */
77043 - if (address < vma->vm_start) {
77044 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77045 + error = -ENOMEM;
77046 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77047 unsigned long size, grow;
77048
77049 +#ifdef CONFIG_PAX_SEGMEXEC
77050 + struct vm_area_struct *vma_m;
77051 +
77052 + vma_m = pax_find_mirror_vma(vma);
77053 +#endif
77054 +
77055 size = vma->vm_end - address;
77056 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77057
77058 @@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
77059 vma->vm_pgoff -= grow;
77060 anon_vma_interval_tree_post_update_vma(vma);
77061 vma_gap_update(vma);
77062 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77063 +
77064 +#ifdef CONFIG_PAX_SEGMEXEC
77065 + if (vma_m) {
77066 + anon_vma_interval_tree_pre_update_vma(vma_m);
77067 + vma_m->vm_start -= grow << PAGE_SHIFT;
77068 + vma_m->vm_pgoff -= grow;
77069 + anon_vma_interval_tree_post_update_vma(vma_m);
77070 + vma_gap_update(vma_m);
77071 + }
77072 +#endif
77073 +
77074 spin_unlock(&vma->vm_mm->page_table_lock);
77075
77076 perf_event_mmap(vma);
77077 @@ -2236,6 +2544,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77078 do {
77079 long nrpages = vma_pages(vma);
77080
77081 +#ifdef CONFIG_PAX_SEGMEXEC
77082 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77083 + vma = remove_vma(vma);
77084 + continue;
77085 + }
77086 +#endif
77087 +
77088 if (vma->vm_flags & VM_ACCOUNT)
77089 nr_accounted += nrpages;
77090 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77091 @@ -2281,6 +2596,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77092 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77093 vma->vm_prev = NULL;
77094 do {
77095 +
77096 +#ifdef CONFIG_PAX_SEGMEXEC
77097 + if (vma->vm_mirror) {
77098 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77099 + vma->vm_mirror->vm_mirror = NULL;
77100 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
77101 + vma->vm_mirror = NULL;
77102 + }
77103 +#endif
77104 +
77105 vma_rb_erase(vma, &mm->mm_rb);
77106 mm->map_count--;
77107 tail_vma = vma;
77108 @@ -2312,14 +2637,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77109 struct vm_area_struct *new;
77110 int err = -ENOMEM;
77111
77112 +#ifdef CONFIG_PAX_SEGMEXEC
77113 + struct vm_area_struct *vma_m, *new_m = NULL;
77114 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77115 +#endif
77116 +
77117 if (is_vm_hugetlb_page(vma) && (addr &
77118 ~(huge_page_mask(hstate_vma(vma)))))
77119 return -EINVAL;
77120
77121 +#ifdef CONFIG_PAX_SEGMEXEC
77122 + vma_m = pax_find_mirror_vma(vma);
77123 +#endif
77124 +
77125 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77126 if (!new)
77127 goto out_err;
77128
77129 +#ifdef CONFIG_PAX_SEGMEXEC
77130 + if (vma_m) {
77131 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77132 + if (!new_m) {
77133 + kmem_cache_free(vm_area_cachep, new);
77134 + goto out_err;
77135 + }
77136 + }
77137 +#endif
77138 +
77139 /* most fields are the same, copy all, and then fixup */
77140 *new = *vma;
77141
77142 @@ -2332,6 +2676,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77143 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77144 }
77145
77146 +#ifdef CONFIG_PAX_SEGMEXEC
77147 + if (vma_m) {
77148 + *new_m = *vma_m;
77149 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
77150 + new_m->vm_mirror = new;
77151 + new->vm_mirror = new_m;
77152 +
77153 + if (new_below)
77154 + new_m->vm_end = addr_m;
77155 + else {
77156 + new_m->vm_start = addr_m;
77157 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77158 + }
77159 + }
77160 +#endif
77161 +
77162 pol = mpol_dup(vma_policy(vma));
77163 if (IS_ERR(pol)) {
77164 err = PTR_ERR(pol);
77165 @@ -2354,6 +2714,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77166 else
77167 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77168
77169 +#ifdef CONFIG_PAX_SEGMEXEC
77170 + if (!err && vma_m) {
77171 + if (anon_vma_clone(new_m, vma_m))
77172 + goto out_free_mpol;
77173 +
77174 + mpol_get(pol);
77175 + vma_set_policy(new_m, pol);
77176 +
77177 + if (new_m->vm_file)
77178 + get_file(new_m->vm_file);
77179 +
77180 + if (new_m->vm_ops && new_m->vm_ops->open)
77181 + new_m->vm_ops->open(new_m);
77182 +
77183 + if (new_below)
77184 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77185 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77186 + else
77187 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77188 +
77189 + if (err) {
77190 + if (new_m->vm_ops && new_m->vm_ops->close)
77191 + new_m->vm_ops->close(new_m);
77192 + if (new_m->vm_file)
77193 + fput(new_m->vm_file);
77194 + mpol_put(pol);
77195 + }
77196 + }
77197 +#endif
77198 +
77199 /* Success. */
77200 if (!err)
77201 return 0;
77202 @@ -2363,10 +2753,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77203 new->vm_ops->close(new);
77204 if (new->vm_file)
77205 fput(new->vm_file);
77206 - unlink_anon_vmas(new);
77207 out_free_mpol:
77208 mpol_put(pol);
77209 out_free_vma:
77210 +
77211 +#ifdef CONFIG_PAX_SEGMEXEC
77212 + if (new_m) {
77213 + unlink_anon_vmas(new_m);
77214 + kmem_cache_free(vm_area_cachep, new_m);
77215 + }
77216 +#endif
77217 +
77218 + unlink_anon_vmas(new);
77219 kmem_cache_free(vm_area_cachep, new);
77220 out_err:
77221 return err;
77222 @@ -2379,6 +2777,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77223 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77224 unsigned long addr, int new_below)
77225 {
77226 +
77227 +#ifdef CONFIG_PAX_SEGMEXEC
77228 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77229 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77230 + if (mm->map_count >= sysctl_max_map_count-1)
77231 + return -ENOMEM;
77232 + } else
77233 +#endif
77234 +
77235 if (mm->map_count >= sysctl_max_map_count)
77236 return -ENOMEM;
77237
77238 @@ -2390,11 +2797,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77239 * work. This now handles partial unmappings.
77240 * Jeremy Fitzhardinge <jeremy@goop.org>
77241 */
77242 +#ifdef CONFIG_PAX_SEGMEXEC
77243 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77244 {
77245 + int ret = __do_munmap(mm, start, len);
77246 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77247 + return ret;
77248 +
77249 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77250 +}
77251 +
77252 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77253 +#else
77254 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77255 +#endif
77256 +{
77257 unsigned long end;
77258 struct vm_area_struct *vma, *prev, *last;
77259
77260 + /*
77261 + * mm->mmap_sem is required to protect against another thread
77262 + * changing the mappings in case we sleep.
77263 + */
77264 + verify_mm_writelocked(mm);
77265 +
77266 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77267 return -EINVAL;
77268
77269 @@ -2469,6 +2895,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77270 /* Fix up all other VM information */
77271 remove_vma_list(mm, vma);
77272
77273 + track_exec_limit(mm, start, end, 0UL);
77274 +
77275 return 0;
77276 }
77277
77278 @@ -2477,6 +2905,13 @@ int vm_munmap(unsigned long start, size_t len)
77279 int ret;
77280 struct mm_struct *mm = current->mm;
77281
77282 +
77283 +#ifdef CONFIG_PAX_SEGMEXEC
77284 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77285 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
77286 + return -EINVAL;
77287 +#endif
77288 +
77289 down_write(&mm->mmap_sem);
77290 ret = do_munmap(mm, start, len);
77291 up_write(&mm->mmap_sem);
77292 @@ -2490,16 +2925,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77293 return vm_munmap(addr, len);
77294 }
77295
77296 -static inline void verify_mm_writelocked(struct mm_struct *mm)
77297 -{
77298 -#ifdef CONFIG_DEBUG_VM
77299 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77300 - WARN_ON(1);
77301 - up_read(&mm->mmap_sem);
77302 - }
77303 -#endif
77304 -}
77305 -
77306 /*
77307 * this is really a simplified "do_mmap". it only handles
77308 * anonymous maps. eventually we may be able to do some
77309 @@ -2513,6 +2938,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77310 struct rb_node ** rb_link, * rb_parent;
77311 pgoff_t pgoff = addr >> PAGE_SHIFT;
77312 int error;
77313 + unsigned long charged;
77314
77315 len = PAGE_ALIGN(len);
77316 if (!len)
77317 @@ -2520,16 +2946,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77318
77319 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77320
77321 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77322 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77323 + flags &= ~VM_EXEC;
77324 +
77325 +#ifdef CONFIG_PAX_MPROTECT
77326 + if (mm->pax_flags & MF_PAX_MPROTECT)
77327 + flags &= ~VM_MAYEXEC;
77328 +#endif
77329 +
77330 + }
77331 +#endif
77332 +
77333 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77334 if (error & ~PAGE_MASK)
77335 return error;
77336
77337 + charged = len >> PAGE_SHIFT;
77338 +
77339 /*
77340 * mlock MCL_FUTURE?
77341 */
77342 if (mm->def_flags & VM_LOCKED) {
77343 unsigned long locked, lock_limit;
77344 - locked = len >> PAGE_SHIFT;
77345 + locked = charged;
77346 locked += mm->locked_vm;
77347 lock_limit = rlimit(RLIMIT_MEMLOCK);
77348 lock_limit >>= PAGE_SHIFT;
77349 @@ -2546,21 +2986,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77350 /*
77351 * Clear old maps. this also does some error checking for us
77352 */
77353 - munmap_back:
77354 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
77355 if (do_munmap(mm, addr, len))
77356 return -ENOMEM;
77357 - goto munmap_back;
77358 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
77359 }
77360
77361 /* Check against address space limits *after* clearing old maps... */
77362 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77363 + if (!may_expand_vm(mm, charged))
77364 return -ENOMEM;
77365
77366 if (mm->map_count > sysctl_max_map_count)
77367 return -ENOMEM;
77368
77369 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
77370 + if (security_vm_enough_memory_mm(mm, charged))
77371 return -ENOMEM;
77372
77373 /* Can we just expand an old private anonymous mapping? */
77374 @@ -2574,7 +3013,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77375 */
77376 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77377 if (!vma) {
77378 - vm_unacct_memory(len >> PAGE_SHIFT);
77379 + vm_unacct_memory(charged);
77380 return -ENOMEM;
77381 }
77382
77383 @@ -2588,11 +3027,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77384 vma_link(mm, vma, prev, rb_link, rb_parent);
77385 out:
77386 perf_event_mmap(vma);
77387 - mm->total_vm += len >> PAGE_SHIFT;
77388 + mm->total_vm += charged;
77389 if (flags & VM_LOCKED) {
77390 if (!mlock_vma_pages_range(vma, addr, addr + len))
77391 - mm->locked_vm += (len >> PAGE_SHIFT);
77392 + mm->locked_vm += charged;
77393 }
77394 + track_exec_limit(mm, addr, addr + len, flags);
77395 return addr;
77396 }
77397
77398 @@ -2650,6 +3090,7 @@ void exit_mmap(struct mm_struct *mm)
77399 while (vma) {
77400 if (vma->vm_flags & VM_ACCOUNT)
77401 nr_accounted += vma_pages(vma);
77402 + vma->vm_mirror = NULL;
77403 vma = remove_vma(vma);
77404 }
77405 vm_unacct_memory(nr_accounted);
77406 @@ -2666,6 +3107,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77407 struct vm_area_struct *prev;
77408 struct rb_node **rb_link, *rb_parent;
77409
77410 +#ifdef CONFIG_PAX_SEGMEXEC
77411 + struct vm_area_struct *vma_m = NULL;
77412 +#endif
77413 +
77414 + if (security_mmap_addr(vma->vm_start))
77415 + return -EPERM;
77416 +
77417 /*
77418 * The vm_pgoff of a purely anonymous vma should be irrelevant
77419 * until its first write fault, when page's anon_vma and index
77420 @@ -2689,7 +3137,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77421 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77422 return -ENOMEM;
77423
77424 +#ifdef CONFIG_PAX_SEGMEXEC
77425 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77426 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77427 + if (!vma_m)
77428 + return -ENOMEM;
77429 + }
77430 +#endif
77431 +
77432 vma_link(mm, vma, prev, rb_link, rb_parent);
77433 +
77434 +#ifdef CONFIG_PAX_SEGMEXEC
77435 + if (vma_m)
77436 + BUG_ON(pax_mirror_vma(vma_m, vma));
77437 +#endif
77438 +
77439 return 0;
77440 }
77441
77442 @@ -2709,6 +3171,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77443 struct mempolicy *pol;
77444 bool faulted_in_anon_vma = true;
77445
77446 + BUG_ON(vma->vm_mirror);
77447 +
77448 /*
77449 * If anonymous vma has not yet been faulted, update new pgoff
77450 * to match new location, to increase its chance of merging.
77451 @@ -2775,6 +3239,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77452 return NULL;
77453 }
77454
77455 +#ifdef CONFIG_PAX_SEGMEXEC
77456 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77457 +{
77458 + struct vm_area_struct *prev_m;
77459 + struct rb_node **rb_link_m, *rb_parent_m;
77460 + struct mempolicy *pol_m;
77461 +
77462 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77463 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77464 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77465 + *vma_m = *vma;
77466 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
77467 + if (anon_vma_clone(vma_m, vma))
77468 + return -ENOMEM;
77469 + pol_m = vma_policy(vma_m);
77470 + mpol_get(pol_m);
77471 + vma_set_policy(vma_m, pol_m);
77472 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77473 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77474 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77475 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77476 + if (vma_m->vm_file)
77477 + get_file(vma_m->vm_file);
77478 + if (vma_m->vm_ops && vma_m->vm_ops->open)
77479 + vma_m->vm_ops->open(vma_m);
77480 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
77481 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77482 + vma_m->vm_mirror = vma;
77483 + vma->vm_mirror = vma_m;
77484 + return 0;
77485 +}
77486 +#endif
77487 +
77488 /*
77489 * Return true if the calling process may expand its vm space by the passed
77490 * number of pages
77491 @@ -2786,6 +3283,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77492
77493 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
77494
77495 +#ifdef CONFIG_PAX_RANDMMAP
77496 + if (mm->pax_flags & MF_PAX_RANDMMAP)
77497 + cur -= mm->brk_gap;
77498 +#endif
77499 +
77500 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77501 if (cur + npages > lim)
77502 return 0;
77503 return 1;
77504 @@ -2856,6 +3359,22 @@ int install_special_mapping(struct mm_struct *mm,
77505 vma->vm_start = addr;
77506 vma->vm_end = addr + len;
77507
77508 +#ifdef CONFIG_PAX_MPROTECT
77509 + if (mm->pax_flags & MF_PAX_MPROTECT) {
77510 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
77511 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77512 + return -EPERM;
77513 + if (!(vm_flags & VM_EXEC))
77514 + vm_flags &= ~VM_MAYEXEC;
77515 +#else
77516 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77517 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77518 +#endif
77519 + else
77520 + vm_flags &= ~VM_MAYWRITE;
77521 + }
77522 +#endif
77523 +
77524 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77525 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77526
77527 diff --git a/mm/mprotect.c b/mm/mprotect.c
77528 index 94722a4..9837984 100644
77529 --- a/mm/mprotect.c
77530 +++ b/mm/mprotect.c
77531 @@ -23,10 +23,17 @@
77532 #include <linux/mmu_notifier.h>
77533 #include <linux/migrate.h>
77534 #include <linux/perf_event.h>
77535 +
77536 +#ifdef CONFIG_PAX_MPROTECT
77537 +#include <linux/elf.h>
77538 +#include <linux/binfmts.h>
77539 +#endif
77540 +
77541 #include <asm/uaccess.h>
77542 #include <asm/pgtable.h>
77543 #include <asm/cacheflush.h>
77544 #include <asm/tlbflush.h>
77545 +#include <asm/mmu_context.h>
77546
77547 #ifndef pgprot_modify
77548 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77549 @@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
77550 return pages;
77551 }
77552
77553 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77554 +/* called while holding the mmap semaphor for writing except stack expansion */
77555 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77556 +{
77557 + unsigned long oldlimit, newlimit = 0UL;
77558 +
77559 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
77560 + return;
77561 +
77562 + spin_lock(&mm->page_table_lock);
77563 + oldlimit = mm->context.user_cs_limit;
77564 + if ((prot & VM_EXEC) && oldlimit < end)
77565 + /* USER_CS limit moved up */
77566 + newlimit = end;
77567 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77568 + /* USER_CS limit moved down */
77569 + newlimit = start;
77570 +
77571 + if (newlimit) {
77572 + mm->context.user_cs_limit = newlimit;
77573 +
77574 +#ifdef CONFIG_SMP
77575 + wmb();
77576 + cpus_clear(mm->context.cpu_user_cs_mask);
77577 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77578 +#endif
77579 +
77580 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77581 + }
77582 + spin_unlock(&mm->page_table_lock);
77583 + if (newlimit == end) {
77584 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
77585 +
77586 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
77587 + if (is_vm_hugetlb_page(vma))
77588 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77589 + else
77590 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
77591 + }
77592 +}
77593 +#endif
77594 +
77595 int
77596 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77597 unsigned long start, unsigned long end, unsigned long newflags)
77598 @@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77599 int error;
77600 int dirty_accountable = 0;
77601
77602 +#ifdef CONFIG_PAX_SEGMEXEC
77603 + struct vm_area_struct *vma_m = NULL;
77604 + unsigned long start_m, end_m;
77605 +
77606 + start_m = start + SEGMEXEC_TASK_SIZE;
77607 + end_m = end + SEGMEXEC_TASK_SIZE;
77608 +#endif
77609 +
77610 if (newflags == oldflags) {
77611 *pprev = vma;
77612 return 0;
77613 }
77614
77615 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77616 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77617 +
77618 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77619 + return -ENOMEM;
77620 +
77621 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77622 + return -ENOMEM;
77623 + }
77624 +
77625 /*
77626 * If we make a private mapping writable we increase our commit;
77627 * but (without finer accounting) cannot reduce our commit if we
77628 @@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77629 }
77630 }
77631
77632 +#ifdef CONFIG_PAX_SEGMEXEC
77633 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77634 + if (start != vma->vm_start) {
77635 + error = split_vma(mm, vma, start, 1);
77636 + if (error)
77637 + goto fail;
77638 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77639 + *pprev = (*pprev)->vm_next;
77640 + }
77641 +
77642 + if (end != vma->vm_end) {
77643 + error = split_vma(mm, vma, end, 0);
77644 + if (error)
77645 + goto fail;
77646 + }
77647 +
77648 + if (pax_find_mirror_vma(vma)) {
77649 + error = __do_munmap(mm, start_m, end_m - start_m);
77650 + if (error)
77651 + goto fail;
77652 + } else {
77653 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77654 + if (!vma_m) {
77655 + error = -ENOMEM;
77656 + goto fail;
77657 + }
77658 + vma->vm_flags = newflags;
77659 + error = pax_mirror_vma(vma_m, vma);
77660 + if (error) {
77661 + vma->vm_flags = oldflags;
77662 + goto fail;
77663 + }
77664 + }
77665 + }
77666 +#endif
77667 +
77668 /*
77669 * First try to merge with previous and/or next vma.
77670 */
77671 @@ -296,9 +399,21 @@ success:
77672 * vm_flags and vm_page_prot are protected by the mmap_sem
77673 * held in write mode.
77674 */
77675 +
77676 +#ifdef CONFIG_PAX_SEGMEXEC
77677 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77678 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77679 +#endif
77680 +
77681 vma->vm_flags = newflags;
77682 +
77683 +#ifdef CONFIG_PAX_MPROTECT
77684 + if (mm->binfmt && mm->binfmt->handle_mprotect)
77685 + mm->binfmt->handle_mprotect(vma, newflags);
77686 +#endif
77687 +
77688 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77689 - vm_get_page_prot(newflags));
77690 + vm_get_page_prot(vma->vm_flags));
77691
77692 if (vma_wants_writenotify(vma)) {
77693 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77694 @@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77695 end = start + len;
77696 if (end <= start)
77697 return -ENOMEM;
77698 +
77699 +#ifdef CONFIG_PAX_SEGMEXEC
77700 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77701 + if (end > SEGMEXEC_TASK_SIZE)
77702 + return -EINVAL;
77703 + } else
77704 +#endif
77705 +
77706 + if (end > TASK_SIZE)
77707 + return -EINVAL;
77708 +
77709 if (!arch_validate_prot(prot))
77710 return -EINVAL;
77711
77712 @@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77713 /*
77714 * Does the application expect PROT_READ to imply PROT_EXEC:
77715 */
77716 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77717 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77718 prot |= PROT_EXEC;
77719
77720 vm_flags = calc_vm_prot_bits(prot);
77721 @@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77722 if (start > vma->vm_start)
77723 prev = vma;
77724
77725 +#ifdef CONFIG_PAX_MPROTECT
77726 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
77727 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
77728 +#endif
77729 +
77730 for (nstart = start ; ; ) {
77731 unsigned long newflags;
77732
77733 @@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77734
77735 /* newflags >> 4 shift VM_MAY% in place of VM_% */
77736 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
77737 + if (prot & (PROT_WRITE | PROT_EXEC))
77738 + gr_log_rwxmprotect(vma->vm_file);
77739 +
77740 + error = -EACCES;
77741 + goto out;
77742 + }
77743 +
77744 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
77745 error = -EACCES;
77746 goto out;
77747 }
77748 @@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77749 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
77750 if (error)
77751 goto out;
77752 +
77753 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
77754 +
77755 nstart = tmp;
77756
77757 if (nstart < prev->vm_end)
77758 diff --git a/mm/mremap.c b/mm/mremap.c
77759 index e1031e1..1f2a0a1 100644
77760 --- a/mm/mremap.c
77761 +++ b/mm/mremap.c
77762 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
77763 continue;
77764 pte = ptep_get_and_clear(mm, old_addr, old_pte);
77765 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
77766 +
77767 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77768 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
77769 + pte = pte_exprotect(pte);
77770 +#endif
77771 +
77772 set_pte_at(mm, new_addr, new_pte, pte);
77773 }
77774
77775 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
77776 if (is_vm_hugetlb_page(vma))
77777 goto Einval;
77778
77779 +#ifdef CONFIG_PAX_SEGMEXEC
77780 + if (pax_find_mirror_vma(vma))
77781 + goto Einval;
77782 +#endif
77783 +
77784 /* We can't remap across vm area boundaries */
77785 if (old_len > vma->vm_end - addr)
77786 goto Efault;
77787 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
77788 unsigned long ret = -EINVAL;
77789 unsigned long charged = 0;
77790 unsigned long map_flags;
77791 + unsigned long pax_task_size = TASK_SIZE;
77792
77793 if (new_addr & ~PAGE_MASK)
77794 goto out;
77795
77796 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
77797 +#ifdef CONFIG_PAX_SEGMEXEC
77798 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
77799 + pax_task_size = SEGMEXEC_TASK_SIZE;
77800 +#endif
77801 +
77802 + pax_task_size -= PAGE_SIZE;
77803 +
77804 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
77805 goto out;
77806
77807 /* Check if the location we're moving into overlaps the
77808 * old location at all, and fail if it does.
77809 */
77810 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
77811 - goto out;
77812 -
77813 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
77814 + if (addr + old_len > new_addr && new_addr + new_len > addr)
77815 goto out;
77816
77817 ret = do_munmap(mm, new_addr, new_len);
77818 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77819 struct vm_area_struct *vma;
77820 unsigned long ret = -EINVAL;
77821 unsigned long charged = 0;
77822 + unsigned long pax_task_size = TASK_SIZE;
77823
77824 down_write(&current->mm->mmap_sem);
77825
77826 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77827 if (!new_len)
77828 goto out;
77829
77830 +#ifdef CONFIG_PAX_SEGMEXEC
77831 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
77832 + pax_task_size = SEGMEXEC_TASK_SIZE;
77833 +#endif
77834 +
77835 + pax_task_size -= PAGE_SIZE;
77836 +
77837 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
77838 + old_len > pax_task_size || addr > pax_task_size-old_len)
77839 + goto out;
77840 +
77841 if (flags & MREMAP_FIXED) {
77842 if (flags & MREMAP_MAYMOVE)
77843 ret = mremap_to(addr, old_len, new_addr, new_len);
77844 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77845 addr + new_len);
77846 }
77847 ret = addr;
77848 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
77849 goto out;
77850 }
77851 }
77852 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77853 goto out;
77854 }
77855
77856 + map_flags = vma->vm_flags;
77857 ret = move_vma(vma, addr, old_len, new_len, new_addr);
77858 + if (!(ret & ~PAGE_MASK)) {
77859 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
77860 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
77861 + }
77862 }
77863 out:
77864 if (ret & ~PAGE_MASK)
77865 diff --git a/mm/nommu.c b/mm/nommu.c
77866 index 79c3cac..4d357e0 100644
77867 --- a/mm/nommu.c
77868 +++ b/mm/nommu.c
77869 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77870 int sysctl_overcommit_ratio = 50; /* default is 50% */
77871 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77872 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77873 -int heap_stack_gap = 0;
77874
77875 atomic_long_t mmap_pages_allocated;
77876
77877 @@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77878 EXPORT_SYMBOL(find_vma);
77879
77880 /*
77881 - * find a VMA
77882 - * - we don't extend stack VMAs under NOMMU conditions
77883 - */
77884 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77885 -{
77886 - return find_vma(mm, addr);
77887 -}
77888 -
77889 -/*
77890 * expand a stack to a given address
77891 * - not supported under NOMMU conditions
77892 */
77893 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77894
77895 /* most fields are the same, copy all, and then fixup */
77896 *new = *vma;
77897 + INIT_LIST_HEAD(&new->anon_vma_chain);
77898 *region = *vma->vm_region;
77899 new->vm_region = region;
77900
77901 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
77902 index 0713bfb..e3774e0 100644
77903 --- a/mm/page-writeback.c
77904 +++ b/mm/page-writeback.c
77905 @@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
77906 }
77907 }
77908
77909 -static struct notifier_block __cpuinitdata ratelimit_nb = {
77910 +static struct notifier_block ratelimit_nb = {
77911 .notifier_call = ratelimit_handler,
77912 .next = NULL,
77913 };
77914 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
77915 index 6a83cd3..bc2dcb6 100644
77916 --- a/mm/page_alloc.c
77917 +++ b/mm/page_alloc.c
77918 @@ -338,7 +338,7 @@ out:
77919 * This usage means that zero-order pages may not be compound.
77920 */
77921
77922 -static void free_compound_page(struct page *page)
77923 +void free_compound_page(struct page *page)
77924 {
77925 __free_pages_ok(page, compound_order(page));
77926 }
77927 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77928 int i;
77929 int bad = 0;
77930
77931 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77932 + unsigned long index = 1UL << order;
77933 +#endif
77934 +
77935 trace_mm_page_free(page, order);
77936 kmemcheck_free_shadow(page, order);
77937
77938 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77939 debug_check_no_obj_freed(page_address(page),
77940 PAGE_SIZE << order);
77941 }
77942 +
77943 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77944 + for (; index; --index)
77945 + sanitize_highpage(page + index - 1);
77946 +#endif
77947 +
77948 arch_free_page(page, order);
77949 kernel_map_pages(page, 1 << order, 0);
77950
77951 @@ -861,8 +871,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
77952 arch_alloc_page(page, order);
77953 kernel_map_pages(page, 1 << order, 1);
77954
77955 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
77956 if (gfp_flags & __GFP_ZERO)
77957 prep_zero_page(page, order, gfp_flags);
77958 +#endif
77959
77960 if (order && (gfp_flags & __GFP_COMP))
77961 prep_compound_page(page, order);
77962 @@ -3752,7 +3764,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
77963 unsigned long pfn;
77964
77965 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
77966 +#ifdef CONFIG_X86_32
77967 + /* boot failures in VMware 8 on 32bit vanilla since
77968 + this change */
77969 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
77970 +#else
77971 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
77972 +#endif
77973 return 1;
77974 }
77975 return 0;
77976 diff --git a/mm/percpu.c b/mm/percpu.c
77977 index 8c8e08f..73a5cda 100644
77978 --- a/mm/percpu.c
77979 +++ b/mm/percpu.c
77980 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77981 static unsigned int pcpu_high_unit_cpu __read_mostly;
77982
77983 /* the address of the first chunk which starts with the kernel static area */
77984 -void *pcpu_base_addr __read_mostly;
77985 +void *pcpu_base_addr __read_only;
77986 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77987
77988 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77989 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
77990 index 926b466..b23df53 100644
77991 --- a/mm/process_vm_access.c
77992 +++ b/mm/process_vm_access.c
77993 @@ -13,6 +13,7 @@
77994 #include <linux/uio.h>
77995 #include <linux/sched.h>
77996 #include <linux/highmem.h>
77997 +#include <linux/security.h>
77998 #include <linux/ptrace.h>
77999 #include <linux/slab.h>
78000 #include <linux/syscalls.h>
78001 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78002 size_t iov_l_curr_offset = 0;
78003 ssize_t iov_len;
78004
78005 + return -ENOSYS; // PaX: until properly audited
78006 +
78007 /*
78008 * Work out how many pages of struct pages we're going to need
78009 * when eventually calling get_user_pages
78010 */
78011 for (i = 0; i < riovcnt; i++) {
78012 iov_len = rvec[i].iov_len;
78013 - if (iov_len > 0) {
78014 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
78015 - + iov_len)
78016 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
78017 - / PAGE_SIZE + 1;
78018 - nr_pages = max(nr_pages, nr_pages_iov);
78019 - }
78020 + if (iov_len <= 0)
78021 + continue;
78022 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
78023 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
78024 + nr_pages = max(nr_pages, nr_pages_iov);
78025 }
78026
78027 if (nr_pages == 0)
78028 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78029 goto free_proc_pages;
78030 }
78031
78032 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
78033 + rc = -EPERM;
78034 + goto put_task_struct;
78035 + }
78036 +
78037 mm = mm_access(task, PTRACE_MODE_ATTACH);
78038 if (!mm || IS_ERR(mm)) {
78039 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
78040 diff --git a/mm/rmap.c b/mm/rmap.c
78041 index 2c78f8c..9e9c624 100644
78042 --- a/mm/rmap.c
78043 +++ b/mm/rmap.c
78044 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78045 struct anon_vma *anon_vma = vma->anon_vma;
78046 struct anon_vma_chain *avc;
78047
78048 +#ifdef CONFIG_PAX_SEGMEXEC
78049 + struct anon_vma_chain *avc_m = NULL;
78050 +#endif
78051 +
78052 might_sleep();
78053 if (unlikely(!anon_vma)) {
78054 struct mm_struct *mm = vma->vm_mm;
78055 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78056 if (!avc)
78057 goto out_enomem;
78058
78059 +#ifdef CONFIG_PAX_SEGMEXEC
78060 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
78061 + if (!avc_m)
78062 + goto out_enomem_free_avc;
78063 +#endif
78064 +
78065 anon_vma = find_mergeable_anon_vma(vma);
78066 allocated = NULL;
78067 if (!anon_vma) {
78068 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78069 /* page_table_lock to protect against threads */
78070 spin_lock(&mm->page_table_lock);
78071 if (likely(!vma->anon_vma)) {
78072 +
78073 +#ifdef CONFIG_PAX_SEGMEXEC
78074 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78075 +
78076 + if (vma_m) {
78077 + BUG_ON(vma_m->anon_vma);
78078 + vma_m->anon_vma = anon_vma;
78079 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
78080 + avc_m = NULL;
78081 + }
78082 +#endif
78083 +
78084 vma->anon_vma = anon_vma;
78085 anon_vma_chain_link(vma, avc, anon_vma);
78086 allocated = NULL;
78087 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78088
78089 if (unlikely(allocated))
78090 put_anon_vma(allocated);
78091 +
78092 +#ifdef CONFIG_PAX_SEGMEXEC
78093 + if (unlikely(avc_m))
78094 + anon_vma_chain_free(avc_m);
78095 +#endif
78096 +
78097 if (unlikely(avc))
78098 anon_vma_chain_free(avc);
78099 }
78100 return 0;
78101
78102 out_enomem_free_avc:
78103 +
78104 +#ifdef CONFIG_PAX_SEGMEXEC
78105 + if (avc_m)
78106 + anon_vma_chain_free(avc_m);
78107 +#endif
78108 +
78109 anon_vma_chain_free(avc);
78110 out_enomem:
78111 return -ENOMEM;
78112 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
78113 * Attach the anon_vmas from src to dst.
78114 * Returns 0 on success, -ENOMEM on failure.
78115 */
78116 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78117 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
78118 {
78119 struct anon_vma_chain *avc, *pavc;
78120 struct anon_vma *root = NULL;
78121 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78122 * the corresponding VMA in the parent process is attached to.
78123 * Returns 0 on success, non-zero on failure.
78124 */
78125 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
78126 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
78127 {
78128 struct anon_vma_chain *avc;
78129 struct anon_vma *anon_vma;
78130 diff --git a/mm/shmem.c b/mm/shmem.c
78131 index 5dd56f6..994b702 100644
78132 --- a/mm/shmem.c
78133 +++ b/mm/shmem.c
78134 @@ -31,7 +31,7 @@
78135 #include <linux/export.h>
78136 #include <linux/swap.h>
78137
78138 -static struct vfsmount *shm_mnt;
78139 +struct vfsmount *shm_mnt;
78140
78141 #ifdef CONFIG_SHMEM
78142 /*
78143 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
78144 #define BOGO_DIRENT_SIZE 20
78145
78146 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
78147 -#define SHORT_SYMLINK_LEN 128
78148 +#define SHORT_SYMLINK_LEN 64
78149
78150 /*
78151 * shmem_fallocate and shmem_writepage communicate via inode->i_private
78152 @@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
78153 static int shmem_xattr_validate(const char *name)
78154 {
78155 struct { const char *prefix; size_t len; } arr[] = {
78156 +
78157 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78158 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
78159 +#endif
78160 +
78161 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
78162 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
78163 };
78164 @@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
78165 if (err)
78166 return err;
78167
78168 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78169 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
78170 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
78171 + return -EOPNOTSUPP;
78172 + if (size > 8)
78173 + return -EINVAL;
78174 + }
78175 +#endif
78176 +
78177 return simple_xattr_set(&info->xattrs, name, value, size, flags);
78178 }
78179
78180 @@ -2487,6 +2501,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
78181 unsigned long inodes;
78182 int error = -EINVAL;
78183
78184 + config.mpol = NULL;
78185 if (shmem_parse_options(data, &config, true))
78186 return error;
78187
78188 @@ -2511,8 +2526,13 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
78189 sbinfo->max_inodes = config.max_inodes;
78190 sbinfo->free_inodes = config.max_inodes - inodes;
78191
78192 - mpol_put(sbinfo->mpol);
78193 - sbinfo->mpol = config.mpol; /* transfers initial ref */
78194 + /*
78195 + * Preserve previous mempolicy unless mpol remount option was specified.
78196 + */
78197 + if (config.mpol) {
78198 + mpol_put(sbinfo->mpol);
78199 + sbinfo->mpol = config.mpol; /* transfers initial ref */
78200 + }
78201 out:
78202 spin_unlock(&sbinfo->stat_lock);
78203 return error;
78204 @@ -2556,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78205 int err = -ENOMEM;
78206
78207 /* Round up to L1_CACHE_BYTES to resist false sharing */
78208 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78209 - L1_CACHE_BYTES), GFP_KERNEL);
78210 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78211 if (!sbinfo)
78212 return -ENOMEM;
78213
78214 diff --git a/mm/slab.c b/mm/slab.c
78215 index e7667a3..b62c169 100644
78216 --- a/mm/slab.c
78217 +++ b/mm/slab.c
78218 @@ -306,7 +306,7 @@ struct kmem_list3 {
78219 * Need this for bootstrapping a per node allocator.
78220 */
78221 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78222 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78223 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78224 #define CACHE_CACHE 0
78225 #define SIZE_AC MAX_NUMNODES
78226 #define SIZE_L3 (2 * MAX_NUMNODES)
78227 @@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78228 if ((x)->max_freeable < i) \
78229 (x)->max_freeable = i; \
78230 } while (0)
78231 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78232 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78233 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78234 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78235 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78236 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78237 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78238 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78239 #else
78240 #define STATS_INC_ACTIVE(x) do { } while (0)
78241 #define STATS_DEC_ACTIVE(x) do { } while (0)
78242 @@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78243 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78244 */
78245 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78246 - const struct slab *slab, void *obj)
78247 + const struct slab *slab, const void *obj)
78248 {
78249 u32 offset = (obj - slab->s_mem);
78250 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78251 @@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
78252 struct cache_names {
78253 char *name;
78254 char *name_dma;
78255 + char *name_usercopy;
78256 };
78257
78258 static struct cache_names __initdata cache_names[] = {
78259 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
78260 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
78261 #include <linux/kmalloc_sizes.h>
78262 - {NULL,}
78263 + {NULL}
78264 #undef CACHE
78265 };
78266
78267 @@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
78268 if (unlikely(gfpflags & GFP_DMA))
78269 return csizep->cs_dmacachep;
78270 #endif
78271 +
78272 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78273 + if (unlikely(gfpflags & GFP_USERCOPY))
78274 + return csizep->cs_usercopycachep;
78275 +#endif
78276 +
78277 return csizep->cs_cachep;
78278 }
78279
78280 @@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
78281 return notifier_from_errno(err);
78282 }
78283
78284 -static struct notifier_block __cpuinitdata cpucache_notifier = {
78285 +static struct notifier_block cpucache_notifier = {
78286 &cpuup_callback, NULL, 0
78287 };
78288
78289 @@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
78290 */
78291
78292 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
78293 - sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
78294 + sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78295
78296 if (INDEX_AC != INDEX_L3)
78297 sizes[INDEX_L3].cs_cachep =
78298 create_kmalloc_cache(names[INDEX_L3].name,
78299 - sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
78300 + sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78301
78302 slab_early_init = 0;
78303
78304 @@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
78305 */
78306 if (!sizes->cs_cachep)
78307 sizes->cs_cachep = create_kmalloc_cache(names->name,
78308 - sizes->cs_size, ARCH_KMALLOC_FLAGS);
78309 + sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78310
78311 #ifdef CONFIG_ZONE_DMA
78312 sizes->cs_dmacachep = create_kmalloc_cache(
78313 names->name_dma, sizes->cs_size,
78314 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
78315 #endif
78316 +
78317 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78318 + sizes->cs_usercopycachep = create_kmalloc_cache(
78319 + names->name_usercopy, sizes->cs_size,
78320 + ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78321 +#endif
78322 +
78323 sizes++;
78324 names++;
78325 }
78326 @@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
78327 }
78328 /* cpu stats */
78329 {
78330 - unsigned long allochit = atomic_read(&cachep->allochit);
78331 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78332 - unsigned long freehit = atomic_read(&cachep->freehit);
78333 - unsigned long freemiss = atomic_read(&cachep->freemiss);
78334 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78335 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78336 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78337 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78338
78339 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78340 allochit, allocmiss, freehit, freemiss);
78341 @@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
78342 static int __init slab_proc_init(void)
78343 {
78344 #ifdef CONFIG_DEBUG_SLAB_LEAK
78345 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78346 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
78347 #endif
78348 return 0;
78349 }
78350 module_init(slab_proc_init);
78351 #endif
78352
78353 +bool is_usercopy_object(const void *ptr)
78354 +{
78355 + struct page *page;
78356 + struct kmem_cache *cachep;
78357 +
78358 + if (ZERO_OR_NULL_PTR(ptr))
78359 + return false;
78360 +
78361 + if (!slab_is_available())
78362 + return false;
78363 +
78364 + if (!virt_addr_valid(ptr))
78365 + return false;
78366 +
78367 + page = virt_to_head_page(ptr);
78368 +
78369 + if (!PageSlab(page))
78370 + return false;
78371 +
78372 + cachep = page->slab_cache;
78373 + return cachep->flags & SLAB_USERCOPY;
78374 +}
78375 +
78376 +#ifdef CONFIG_PAX_USERCOPY
78377 +const char *check_heap_object(const void *ptr, unsigned long n)
78378 +{
78379 + struct page *page;
78380 + struct kmem_cache *cachep;
78381 + struct slab *slabp;
78382 + unsigned int objnr;
78383 + unsigned long offset;
78384 +
78385 + if (ZERO_OR_NULL_PTR(ptr))
78386 + return "<null>";
78387 +
78388 + if (!virt_addr_valid(ptr))
78389 + return NULL;
78390 +
78391 + page = virt_to_head_page(ptr);
78392 +
78393 + if (!PageSlab(page))
78394 + return NULL;
78395 +
78396 + cachep = page->slab_cache;
78397 + if (!(cachep->flags & SLAB_USERCOPY))
78398 + return cachep->name;
78399 +
78400 + slabp = page->slab_page;
78401 + objnr = obj_to_index(cachep, slabp, ptr);
78402 + BUG_ON(objnr >= cachep->num);
78403 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78404 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
78405 + return NULL;
78406 +
78407 + return cachep->name;
78408 +}
78409 +#endif
78410 +
78411 /**
78412 * ksize - get the actual amount of memory allocated for a given object
78413 * @objp: Pointer to the object
78414 diff --git a/mm/slab.h b/mm/slab.h
78415 index 34a98d6..73633d1 100644
78416 --- a/mm/slab.h
78417 +++ b/mm/slab.h
78418 @@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78419
78420 /* Legal flag mask for kmem_cache_create(), for various configurations */
78421 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
78422 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
78423 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
78424
78425 #if defined(CONFIG_DEBUG_SLAB)
78426 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
78427 @@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
78428 return s;
78429
78430 page = virt_to_head_page(x);
78431 +
78432 + BUG_ON(!PageSlab(page));
78433 +
78434 cachep = page->slab_cache;
78435 if (slab_equal_or_root(cachep, s))
78436 return cachep;
78437 diff --git a/mm/slab_common.c b/mm/slab_common.c
78438 index 3f3cd97..e050794 100644
78439 --- a/mm/slab_common.c
78440 +++ b/mm/slab_common.c
78441 @@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
78442
78443 err = __kmem_cache_create(s, flags);
78444 if (!err) {
78445 - s->refcount = 1;
78446 + atomic_set(&s->refcount, 1);
78447 list_add(&s->list, &slab_caches);
78448 memcg_cache_list_add(memcg, s);
78449 } else {
78450 @@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
78451
78452 get_online_cpus();
78453 mutex_lock(&slab_mutex);
78454 - s->refcount--;
78455 - if (!s->refcount) {
78456 + if (atomic_dec_and_test(&s->refcount)) {
78457 list_del(&s->list);
78458
78459 if (!__kmem_cache_shutdown(s)) {
78460 @@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
78461 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
78462 name, size, err);
78463
78464 - s->refcount = -1; /* Exempt from merging for now */
78465 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
78466 }
78467
78468 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78469 @@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78470
78471 create_boot_cache(s, name, size, flags);
78472 list_add(&s->list, &slab_caches);
78473 - s->refcount = 1;
78474 + atomic_set(&s->refcount, 1);
78475 return s;
78476 }
78477
78478 diff --git a/mm/slob.c b/mm/slob.c
78479 index a99fdf7..f5b6577 100644
78480 --- a/mm/slob.c
78481 +++ b/mm/slob.c
78482 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78483 /*
78484 * Return the size of a slob block.
78485 */
78486 -static slobidx_t slob_units(slob_t *s)
78487 +static slobidx_t slob_units(const slob_t *s)
78488 {
78489 if (s->units > 0)
78490 return s->units;
78491 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
78492 /*
78493 * Return the next free slob block pointer after this one.
78494 */
78495 -static slob_t *slob_next(slob_t *s)
78496 +static slob_t *slob_next(const slob_t *s)
78497 {
78498 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78499 slobidx_t next;
78500 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
78501 /*
78502 * Returns true if s is the last free block in its page.
78503 */
78504 -static int slob_last(slob_t *s)
78505 +static int slob_last(const slob_t *s)
78506 {
78507 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78508 }
78509
78510 -static void *slob_new_pages(gfp_t gfp, int order, int node)
78511 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
78512 {
78513 - void *page;
78514 + struct page *page;
78515
78516 #ifdef CONFIG_NUMA
78517 if (node != NUMA_NO_NODE)
78518 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78519 if (!page)
78520 return NULL;
78521
78522 - return page_address(page);
78523 + __SetPageSlab(page);
78524 + return page;
78525 }
78526
78527 -static void slob_free_pages(void *b, int order)
78528 +static void slob_free_pages(struct page *sp, int order)
78529 {
78530 if (current->reclaim_state)
78531 current->reclaim_state->reclaimed_slab += 1 << order;
78532 - free_pages((unsigned long)b, order);
78533 + __ClearPageSlab(sp);
78534 + reset_page_mapcount(sp);
78535 + sp->private = 0;
78536 + __free_pages(sp, order);
78537 }
78538
78539 /*
78540 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78541
78542 /* Not enough space: must allocate a new page */
78543 if (!b) {
78544 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78545 - if (!b)
78546 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78547 + if (!sp)
78548 return NULL;
78549 - sp = virt_to_page(b);
78550 - __SetPageSlab(sp);
78551 + b = page_address(sp);
78552
78553 spin_lock_irqsave(&slob_lock, flags);
78554 sp->units = SLOB_UNITS(PAGE_SIZE);
78555 sp->freelist = b;
78556 + sp->private = 0;
78557 INIT_LIST_HEAD(&sp->list);
78558 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78559 set_slob_page_free(sp, slob_list);
78560 @@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
78561 if (slob_page_free(sp))
78562 clear_slob_page_free(sp);
78563 spin_unlock_irqrestore(&slob_lock, flags);
78564 - __ClearPageSlab(sp);
78565 - reset_page_mapcount(sp);
78566 - slob_free_pages(b, 0);
78567 + slob_free_pages(sp, 0);
78568 return;
78569 }
78570
78571 @@ -424,11 +426,10 @@ out:
78572 */
78573
78574 static __always_inline void *
78575 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78576 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
78577 {
78578 - unsigned int *m;
78579 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78580 - void *ret;
78581 + slob_t *m;
78582 + void *ret = NULL;
78583
78584 gfp &= gfp_allowed_mask;
78585
78586 @@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78587
78588 if (!m)
78589 return NULL;
78590 - *m = size;
78591 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78592 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78593 + m[0].units = size;
78594 + m[1].units = align;
78595 ret = (void *)m + align;
78596
78597 trace_kmalloc_node(caller, ret,
78598 size, size + align, gfp, node);
78599 } else {
78600 unsigned int order = get_order(size);
78601 + struct page *page;
78602
78603 if (likely(order))
78604 gfp |= __GFP_COMP;
78605 - ret = slob_new_pages(gfp, order, node);
78606 + page = slob_new_pages(gfp, order, node);
78607 + if (page) {
78608 + ret = page_address(page);
78609 + page->private = size;
78610 + }
78611
78612 trace_kmalloc_node(caller, ret,
78613 size, PAGE_SIZE << order, gfp, node);
78614 }
78615
78616 - kmemleak_alloc(ret, size, 1, gfp);
78617 + return ret;
78618 +}
78619 +
78620 +static __always_inline void *
78621 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78622 +{
78623 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78624 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
78625 +
78626 + if (!ZERO_OR_NULL_PTR(ret))
78627 + kmemleak_alloc(ret, size, 1, gfp);
78628 return ret;
78629 }
78630
78631 @@ -494,33 +513,110 @@ void kfree(const void *block)
78632 kmemleak_free(block);
78633
78634 sp = virt_to_page(block);
78635 - if (PageSlab(sp)) {
78636 + VM_BUG_ON(!PageSlab(sp));
78637 + if (!sp->private) {
78638 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78639 - unsigned int *m = (unsigned int *)(block - align);
78640 - slob_free(m, *m + align);
78641 - } else
78642 + slob_t *m = (slob_t *)(block - align);
78643 + slob_free(m, m[0].units + align);
78644 + } else {
78645 + __ClearPageSlab(sp);
78646 + reset_page_mapcount(sp);
78647 + sp->private = 0;
78648 __free_pages(sp, compound_order(sp));
78649 + }
78650 }
78651 EXPORT_SYMBOL(kfree);
78652
78653 +bool is_usercopy_object(const void *ptr)
78654 +{
78655 + if (!slab_is_available())
78656 + return false;
78657 +
78658 + // PAX: TODO
78659 +
78660 + return false;
78661 +}
78662 +
78663 +#ifdef CONFIG_PAX_USERCOPY
78664 +const char *check_heap_object(const void *ptr, unsigned long n)
78665 +{
78666 + struct page *page;
78667 + const slob_t *free;
78668 + const void *base;
78669 + unsigned long flags;
78670 +
78671 + if (ZERO_OR_NULL_PTR(ptr))
78672 + return "<null>";
78673 +
78674 + if (!virt_addr_valid(ptr))
78675 + return NULL;
78676 +
78677 + page = virt_to_head_page(ptr);
78678 + if (!PageSlab(page))
78679 + return NULL;
78680 +
78681 + if (page->private) {
78682 + base = page;
78683 + if (base <= ptr && n <= page->private - (ptr - base))
78684 + return NULL;
78685 + return "<slob>";
78686 + }
78687 +
78688 + /* some tricky double walking to find the chunk */
78689 + spin_lock_irqsave(&slob_lock, flags);
78690 + base = (void *)((unsigned long)ptr & PAGE_MASK);
78691 + free = page->freelist;
78692 +
78693 + while (!slob_last(free) && (void *)free <= ptr) {
78694 + base = free + slob_units(free);
78695 + free = slob_next(free);
78696 + }
78697 +
78698 + while (base < (void *)free) {
78699 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78700 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
78701 + int offset;
78702 +
78703 + if (ptr < base + align)
78704 + break;
78705 +
78706 + offset = ptr - base - align;
78707 + if (offset >= m) {
78708 + base += size;
78709 + continue;
78710 + }
78711 +
78712 + if (n > m - offset)
78713 + break;
78714 +
78715 + spin_unlock_irqrestore(&slob_lock, flags);
78716 + return NULL;
78717 + }
78718 +
78719 + spin_unlock_irqrestore(&slob_lock, flags);
78720 + return "<slob>";
78721 +}
78722 +#endif
78723 +
78724 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
78725 size_t ksize(const void *block)
78726 {
78727 struct page *sp;
78728 int align;
78729 - unsigned int *m;
78730 + slob_t *m;
78731
78732 BUG_ON(!block);
78733 if (unlikely(block == ZERO_SIZE_PTR))
78734 return 0;
78735
78736 sp = virt_to_page(block);
78737 - if (unlikely(!PageSlab(sp)))
78738 - return PAGE_SIZE << compound_order(sp);
78739 + VM_BUG_ON(!PageSlab(sp));
78740 + if (sp->private)
78741 + return sp->private;
78742
78743 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78744 - m = (unsigned int *)(block - align);
78745 - return SLOB_UNITS(*m) * SLOB_UNIT;
78746 + m = (slob_t *)(block - align);
78747 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
78748 }
78749 EXPORT_SYMBOL(ksize);
78750
78751 @@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
78752
78753 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
78754 {
78755 - void *b;
78756 + void *b = NULL;
78757
78758 flags &= gfp_allowed_mask;
78759
78760 lockdep_trace_alloc(flags);
78761
78762 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78763 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
78764 +#else
78765 if (c->size < PAGE_SIZE) {
78766 b = slob_alloc(c->size, flags, c->align, node);
78767 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
78768 SLOB_UNITS(c->size) * SLOB_UNIT,
78769 flags, node);
78770 } else {
78771 - b = slob_new_pages(flags, get_order(c->size), node);
78772 + struct page *sp;
78773 +
78774 + sp = slob_new_pages(flags, get_order(c->size), node);
78775 + if (sp) {
78776 + b = page_address(sp);
78777 + sp->private = c->size;
78778 + }
78779 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
78780 PAGE_SIZE << get_order(c->size),
78781 flags, node);
78782 }
78783 +#endif
78784
78785 if (c->ctor)
78786 c->ctor(b);
78787 @@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
78788
78789 static void __kmem_cache_free(void *b, int size)
78790 {
78791 - if (size < PAGE_SIZE)
78792 + struct page *sp;
78793 +
78794 + sp = virt_to_page(b);
78795 + BUG_ON(!PageSlab(sp));
78796 + if (!sp->private)
78797 slob_free(b, size);
78798 else
78799 - slob_free_pages(b, get_order(size));
78800 + slob_free_pages(sp, get_order(size));
78801 }
78802
78803 static void kmem_rcu_free(struct rcu_head *head)
78804 @@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
78805
78806 void kmem_cache_free(struct kmem_cache *c, void *b)
78807 {
78808 + int size = c->size;
78809 +
78810 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78811 + if (size + c->align < PAGE_SIZE) {
78812 + size += c->align;
78813 + b -= c->align;
78814 + }
78815 +#endif
78816 +
78817 kmemleak_free_recursive(b, c->flags);
78818 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
78819 struct slob_rcu *slob_rcu;
78820 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
78821 - slob_rcu->size = c->size;
78822 + slob_rcu = b + (size - sizeof(struct slob_rcu));
78823 + slob_rcu->size = size;
78824 call_rcu(&slob_rcu->head, kmem_rcu_free);
78825 } else {
78826 - __kmem_cache_free(b, c->size);
78827 + __kmem_cache_free(b, size);
78828 }
78829
78830 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78831 + trace_kfree(_RET_IP_, b);
78832 +#else
78833 trace_kmem_cache_free(_RET_IP_, b);
78834 +#endif
78835 +
78836 }
78837 EXPORT_SYMBOL(kmem_cache_free);
78838
78839 diff --git a/mm/slub.c b/mm/slub.c
78840 index ba2ca53..00b1f4e 100644
78841 --- a/mm/slub.c
78842 +++ b/mm/slub.c
78843 @@ -197,7 +197,7 @@ struct track {
78844
78845 enum track_item { TRACK_ALLOC, TRACK_FREE };
78846
78847 -#ifdef CONFIG_SYSFS
78848 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78849 static int sysfs_slab_add(struct kmem_cache *);
78850 static int sysfs_slab_alias(struct kmem_cache *, const char *);
78851 static void sysfs_slab_remove(struct kmem_cache *);
78852 @@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
78853 if (!t->addr)
78854 return;
78855
78856 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
78857 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
78858 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
78859 #ifdef CONFIG_STACKTRACE
78860 {
78861 @@ -2653,7 +2653,7 @@ static int slub_min_objects;
78862 * Merge control. If this is set then no merging of slab caches will occur.
78863 * (Could be removed. This was introduced to pacify the merge skeptics.)
78864 */
78865 -static int slub_nomerge;
78866 +static int slub_nomerge = 1;
78867
78868 /*
78869 * Calculate the order of allocation given an slab object size.
78870 @@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
78871 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
78872 #endif
78873
78874 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78875 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
78876 +#endif
78877 +
78878 static int __init setup_slub_min_order(char *str)
78879 {
78880 get_option(&str, &slub_min_order);
78881 @@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
78882 return kmalloc_dma_caches[index];
78883
78884 #endif
78885 +
78886 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78887 + if (flags & SLAB_USERCOPY)
78888 + return kmalloc_usercopy_caches[index];
78889 +
78890 +#endif
78891 +
78892 return kmalloc_caches[index];
78893 }
78894
78895 @@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78896 EXPORT_SYMBOL(__kmalloc_node);
78897 #endif
78898
78899 +bool is_usercopy_object(const void *ptr)
78900 +{
78901 + struct page *page;
78902 + struct kmem_cache *s;
78903 +
78904 + if (ZERO_OR_NULL_PTR(ptr))
78905 + return false;
78906 +
78907 + if (!slab_is_available())
78908 + return false;
78909 +
78910 + if (!virt_addr_valid(ptr))
78911 + return false;
78912 +
78913 + page = virt_to_head_page(ptr);
78914 +
78915 + if (!PageSlab(page))
78916 + return false;
78917 +
78918 + s = page->slab_cache;
78919 + return s->flags & SLAB_USERCOPY;
78920 +}
78921 +
78922 +#ifdef CONFIG_PAX_USERCOPY
78923 +const char *check_heap_object(const void *ptr, unsigned long n)
78924 +{
78925 + struct page *page;
78926 + struct kmem_cache *s;
78927 + unsigned long offset;
78928 +
78929 + if (ZERO_OR_NULL_PTR(ptr))
78930 + return "<null>";
78931 +
78932 + if (!virt_addr_valid(ptr))
78933 + return NULL;
78934 +
78935 + page = virt_to_head_page(ptr);
78936 +
78937 + if (!PageSlab(page))
78938 + return NULL;
78939 +
78940 + s = page->slab_cache;
78941 + if (!(s->flags & SLAB_USERCOPY))
78942 + return s->name;
78943 +
78944 + offset = (ptr - page_address(page)) % s->size;
78945 + if (offset <= s->object_size && n <= s->object_size - offset)
78946 + return NULL;
78947 +
78948 + return s->name;
78949 +}
78950 +#endif
78951 +
78952 size_t ksize(const void *object)
78953 {
78954 struct page *page;
78955 @@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
78956
78957 /* Caches that are not of the two-to-the-power-of size */
78958 if (KMALLOC_MIN_SIZE <= 32) {
78959 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
78960 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
78961 caches++;
78962 }
78963
78964 if (KMALLOC_MIN_SIZE <= 64) {
78965 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
78966 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
78967 caches++;
78968 }
78969
78970 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78971 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
78972 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
78973 caches++;
78974 }
78975
78976 @@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
78977 }
78978 }
78979 #endif
78980 +
78981 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78982 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
78983 + struct kmem_cache *s = kmalloc_caches[i];
78984 +
78985 + if (s && s->size) {
78986 + char *name = kasprintf(GFP_NOWAIT,
78987 + "usercopy-kmalloc-%d", s->object_size);
78988 +
78989 + BUG_ON(!name);
78990 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
78991 + s->object_size, SLAB_USERCOPY);
78992 + }
78993 + }
78994 +#endif
78995 +
78996 printk(KERN_INFO
78997 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
78998 " CPUs=%d, Nodes=%d\n",
78999 @@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
79000 /*
79001 * We may have set a slab to be unmergeable during bootstrap.
79002 */
79003 - if (s->refcount < 0)
79004 + if (atomic_read(&s->refcount) < 0)
79005 return 1;
79006
79007 return 0;
79008 @@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79009
79010 s = find_mergeable(memcg, size, align, flags, name, ctor);
79011 if (s) {
79012 - s->refcount++;
79013 + atomic_inc(&s->refcount);
79014 /*
79015 * Adjust the object sizes so that we clear
79016 * the complete object on kzalloc.
79017 @@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79018 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
79019
79020 if (sysfs_slab_alias(s, name)) {
79021 - s->refcount--;
79022 + atomic_dec(&s->refcount);
79023 s = NULL;
79024 }
79025 }
79026 @@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
79027 return NOTIFY_OK;
79028 }
79029
79030 -static struct notifier_block __cpuinitdata slab_notifier = {
79031 +static struct notifier_block slab_notifier = {
79032 .notifier_call = slab_cpuup_callback
79033 };
79034
79035 @@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
79036 }
79037 #endif
79038
79039 -#ifdef CONFIG_SYSFS
79040 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79041 static int count_inuse(struct page *page)
79042 {
79043 return page->inuse;
79044 @@ -4364,12 +4444,12 @@ static void resiliency_test(void)
79045 validate_slab_cache(kmalloc_caches[9]);
79046 }
79047 #else
79048 -#ifdef CONFIG_SYSFS
79049 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79050 static void resiliency_test(void) {};
79051 #endif
79052 #endif
79053
79054 -#ifdef CONFIG_SYSFS
79055 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79056 enum slab_stat_type {
79057 SL_ALL, /* All slabs */
79058 SL_PARTIAL, /* Only partially allocated slabs */
79059 @@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
79060
79061 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
79062 {
79063 - return sprintf(buf, "%d\n", s->refcount - 1);
79064 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
79065 }
79066 SLAB_ATTR_RO(aliases);
79067
79068 @@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
79069 return name;
79070 }
79071
79072 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79073 static int sysfs_slab_add(struct kmem_cache *s)
79074 {
79075 int err;
79076 @@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
79077 kobject_del(&s->kobj);
79078 kobject_put(&s->kobj);
79079 }
79080 +#endif
79081
79082 /*
79083 * Need to buffer aliases during bootup until sysfs becomes
79084 @@ -5336,6 +5418,7 @@ struct saved_alias {
79085
79086 static struct saved_alias *alias_list;
79087
79088 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79089 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79090 {
79091 struct saved_alias *al;
79092 @@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79093 alias_list = al;
79094 return 0;
79095 }
79096 +#endif
79097
79098 static int __init slab_sysfs_init(void)
79099 {
79100 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
79101 index 1b7e22a..3fcd4f3 100644
79102 --- a/mm/sparse-vmemmap.c
79103 +++ b/mm/sparse-vmemmap.c
79104 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
79105 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79106 if (!p)
79107 return NULL;
79108 - pud_populate(&init_mm, pud, p);
79109 + pud_populate_kernel(&init_mm, pud, p);
79110 }
79111 return pud;
79112 }
79113 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
79114 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79115 if (!p)
79116 return NULL;
79117 - pgd_populate(&init_mm, pgd, p);
79118 + pgd_populate_kernel(&init_mm, pgd, p);
79119 }
79120 return pgd;
79121 }
79122 diff --git a/mm/sparse.c b/mm/sparse.c
79123 index 6b5fb76..db0c190 100644
79124 --- a/mm/sparse.c
79125 +++ b/mm/sparse.c
79126 @@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
79127
79128 for (i = 0; i < PAGES_PER_SECTION; i++) {
79129 if (PageHWPoison(&memmap[i])) {
79130 - atomic_long_sub(1, &mce_bad_pages);
79131 + atomic_long_sub_unchecked(1, &mce_bad_pages);
79132 ClearPageHWPoison(&memmap[i]);
79133 }
79134 }
79135 diff --git a/mm/swap.c b/mm/swap.c
79136 index 6310dc2..3662b3f 100644
79137 --- a/mm/swap.c
79138 +++ b/mm/swap.c
79139 @@ -30,6 +30,7 @@
79140 #include <linux/backing-dev.h>
79141 #include <linux/memcontrol.h>
79142 #include <linux/gfp.h>
79143 +#include <linux/hugetlb.h>
79144
79145 #include "internal.h"
79146
79147 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
79148
79149 __page_cache_release(page);
79150 dtor = get_compound_page_dtor(page);
79151 + if (!PageHuge(page))
79152 + BUG_ON(dtor != free_compound_page);
79153 (*dtor)(page);
79154 }
79155
79156 diff --git a/mm/swapfile.c b/mm/swapfile.c
79157 index e97a0e5..b50e796 100644
79158 --- a/mm/swapfile.c
79159 +++ b/mm/swapfile.c
79160 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
79161
79162 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
79163 /* Activity counter to indicate that a swapon or swapoff has occurred */
79164 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
79165 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
79166
79167 static inline unsigned char swap_count(unsigned char ent)
79168 {
79169 @@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
79170 }
79171 filp_close(swap_file, NULL);
79172 err = 0;
79173 - atomic_inc(&proc_poll_event);
79174 + atomic_inc_unchecked(&proc_poll_event);
79175 wake_up_interruptible(&proc_poll_wait);
79176
79177 out_dput:
79178 @@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
79179
79180 poll_wait(file, &proc_poll_wait, wait);
79181
79182 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
79183 - seq->poll_event = atomic_read(&proc_poll_event);
79184 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
79185 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79186 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
79187 }
79188
79189 @@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
79190 return ret;
79191
79192 seq = file->private_data;
79193 - seq->poll_event = atomic_read(&proc_poll_event);
79194 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79195 return 0;
79196 }
79197
79198 @@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
79199 (frontswap_map) ? "FS" : "");
79200
79201 mutex_unlock(&swapon_mutex);
79202 - atomic_inc(&proc_poll_event);
79203 + atomic_inc_unchecked(&proc_poll_event);
79204 wake_up_interruptible(&proc_poll_wait);
79205
79206 if (S_ISREG(inode->i_mode))
79207 diff --git a/mm/util.c b/mm/util.c
79208 index c55e26b..3f913a9 100644
79209 --- a/mm/util.c
79210 +++ b/mm/util.c
79211 @@ -292,6 +292,12 @@ done:
79212 void arch_pick_mmap_layout(struct mm_struct *mm)
79213 {
79214 mm->mmap_base = TASK_UNMAPPED_BASE;
79215 +
79216 +#ifdef CONFIG_PAX_RANDMMAP
79217 + if (mm->pax_flags & MF_PAX_RANDMMAP)
79218 + mm->mmap_base += mm->delta_mmap;
79219 +#endif
79220 +
79221 mm->get_unmapped_area = arch_get_unmapped_area;
79222 mm->unmap_area = arch_unmap_area;
79223 }
79224 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79225 index 5123a16..f234a48 100644
79226 --- a/mm/vmalloc.c
79227 +++ b/mm/vmalloc.c
79228 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79229
79230 pte = pte_offset_kernel(pmd, addr);
79231 do {
79232 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79233 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79234 +
79235 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79236 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79237 + BUG_ON(!pte_exec(*pte));
79238 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79239 + continue;
79240 + }
79241 +#endif
79242 +
79243 + {
79244 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79245 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79246 + }
79247 } while (pte++, addr += PAGE_SIZE, addr != end);
79248 }
79249
79250 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79251 pte = pte_alloc_kernel(pmd, addr);
79252 if (!pte)
79253 return -ENOMEM;
79254 +
79255 + pax_open_kernel();
79256 do {
79257 struct page *page = pages[*nr];
79258
79259 - if (WARN_ON(!pte_none(*pte)))
79260 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79261 + if (pgprot_val(prot) & _PAGE_NX)
79262 +#endif
79263 +
79264 + if (!pte_none(*pte)) {
79265 + pax_close_kernel();
79266 + WARN_ON(1);
79267 return -EBUSY;
79268 - if (WARN_ON(!page))
79269 + }
79270 + if (!page) {
79271 + pax_close_kernel();
79272 + WARN_ON(1);
79273 return -ENOMEM;
79274 + }
79275 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79276 (*nr)++;
79277 } while (pte++, addr += PAGE_SIZE, addr != end);
79278 + pax_close_kernel();
79279 return 0;
79280 }
79281
79282 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79283 pmd_t *pmd;
79284 unsigned long next;
79285
79286 - pmd = pmd_alloc(&init_mm, pud, addr);
79287 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79288 if (!pmd)
79289 return -ENOMEM;
79290 do {
79291 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
79292 pud_t *pud;
79293 unsigned long next;
79294
79295 - pud = pud_alloc(&init_mm, pgd, addr);
79296 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
79297 if (!pud)
79298 return -ENOMEM;
79299 do {
79300 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
79301 * and fall back on vmalloc() if that fails. Others
79302 * just put it in the vmalloc space.
79303 */
79304 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79305 +#ifdef CONFIG_MODULES
79306 +#ifdef MODULES_VADDR
79307 unsigned long addr = (unsigned long)x;
79308 if (addr >= MODULES_VADDR && addr < MODULES_END)
79309 return 1;
79310 #endif
79311 +
79312 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79313 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79314 + return 1;
79315 +#endif
79316 +
79317 +#endif
79318 +
79319 return is_vmalloc_addr(x);
79320 }
79321
79322 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79323
79324 if (!pgd_none(*pgd)) {
79325 pud_t *pud = pud_offset(pgd, addr);
79326 +#ifdef CONFIG_X86
79327 + if (!pud_large(*pud))
79328 +#endif
79329 if (!pud_none(*pud)) {
79330 pmd_t *pmd = pmd_offset(pud, addr);
79331 +#ifdef CONFIG_X86
79332 + if (!pmd_large(*pmd))
79333 +#endif
79334 if (!pmd_none(*pmd)) {
79335 pte_t *ptep, pte;
79336
79337 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
79338 * Allocate a region of KVA of the specified size and alignment, within the
79339 * vstart and vend.
79340 */
79341 -static struct vmap_area *alloc_vmap_area(unsigned long size,
79342 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
79343 unsigned long align,
79344 unsigned long vstart, unsigned long vend,
79345 int node, gfp_t gfp_mask)
79346 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79347 struct vm_struct *area;
79348
79349 BUG_ON(in_interrupt());
79350 +
79351 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79352 + if (flags & VM_KERNEXEC) {
79353 + if (start != VMALLOC_START || end != VMALLOC_END)
79354 + return NULL;
79355 + start = (unsigned long)MODULES_EXEC_VADDR;
79356 + end = (unsigned long)MODULES_EXEC_END;
79357 + }
79358 +#endif
79359 +
79360 if (flags & VM_IOREMAP) {
79361 int bit = fls(size);
79362
79363 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
79364 if (count > totalram_pages)
79365 return NULL;
79366
79367 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79368 + if (!(pgprot_val(prot) & _PAGE_NX))
79369 + flags |= VM_KERNEXEC;
79370 +#endif
79371 +
79372 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79373 __builtin_return_address(0));
79374 if (!area)
79375 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
79376 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79377 goto fail;
79378
79379 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79380 + if (!(pgprot_val(prot) & _PAGE_NX))
79381 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79382 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
79383 + else
79384 +#endif
79385 +
79386 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79387 start, end, node, gfp_mask, caller);
79388 if (!area)
79389 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
79390 * For tight control over page level allocator and protection flags
79391 * use __vmalloc() instead.
79392 */
79393 -
79394 void *vmalloc_exec(unsigned long size)
79395 {
79396 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79397 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79398 -1, __builtin_return_address(0));
79399 }
79400
79401 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79402 unsigned long uaddr = vma->vm_start;
79403 unsigned long usize = vma->vm_end - vma->vm_start;
79404
79405 + BUG_ON(vma->vm_mirror);
79406 +
79407 if ((PAGE_SIZE-1) & (unsigned long)addr)
79408 return -EINVAL;
79409
79410 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
79411 v->addr, v->addr + v->size, v->size);
79412
79413 if (v->caller)
79414 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79415 + seq_printf(m, " %pK", v->caller);
79416 +#else
79417 seq_printf(m, " %pS", v->caller);
79418 +#endif
79419
79420 if (v->nr_pages)
79421 seq_printf(m, " pages=%d", v->nr_pages);
79422 diff --git a/mm/vmstat.c b/mm/vmstat.c
79423 index 9800306..76b4b27 100644
79424 --- a/mm/vmstat.c
79425 +++ b/mm/vmstat.c
79426 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
79427 *
79428 * vm_stat contains the global counters
79429 */
79430 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79431 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79432 EXPORT_SYMBOL(vm_stat);
79433
79434 #ifdef CONFIG_SMP
79435 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
79436 v = p->vm_stat_diff[i];
79437 p->vm_stat_diff[i] = 0;
79438 local_irq_restore(flags);
79439 - atomic_long_add(v, &zone->vm_stat[i]);
79440 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79441 global_diff[i] += v;
79442 #ifdef CONFIG_NUMA
79443 /* 3 seconds idle till flush */
79444 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
79445
79446 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79447 if (global_diff[i])
79448 - atomic_long_add(global_diff[i], &vm_stat[i]);
79449 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79450 }
79451
79452 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79453 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79454 if (pset->vm_stat_diff[i]) {
79455 int v = pset->vm_stat_diff[i];
79456 pset->vm_stat_diff[i] = 0;
79457 - atomic_long_add(v, &zone->vm_stat[i]);
79458 - atomic_long_add(v, &vm_stat[i]);
79459 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79460 + atomic_long_add_unchecked(v, &vm_stat[i]);
79461 }
79462 }
79463 #endif
79464 @@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
79465 return NOTIFY_OK;
79466 }
79467
79468 -static struct notifier_block __cpuinitdata vmstat_notifier =
79469 +static struct notifier_block vmstat_notifier =
79470 { &vmstat_cpuup_callback, NULL, 0 };
79471 #endif
79472
79473 @@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
79474 start_cpu_timer(cpu);
79475 #endif
79476 #ifdef CONFIG_PROC_FS
79477 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79478 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79479 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79480 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79481 + {
79482 + mode_t gr_mode = S_IRUGO;
79483 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
79484 + gr_mode = S_IRUSR;
79485 +#endif
79486 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79487 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79488 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79489 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79490 +#else
79491 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79492 +#endif
79493 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79494 + }
79495 #endif
79496 return 0;
79497 }
79498 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79499 index a292e80..785ee68 100644
79500 --- a/net/8021q/vlan.c
79501 +++ b/net/8021q/vlan.c
79502 @@ -485,7 +485,7 @@ out:
79503 return NOTIFY_DONE;
79504 }
79505
79506 -static struct notifier_block vlan_notifier_block __read_mostly = {
79507 +static struct notifier_block vlan_notifier_block = {
79508 .notifier_call = vlan_device_event,
79509 };
79510
79511 @@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79512 err = -EPERM;
79513 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
79514 break;
79515 - if ((args.u.name_type >= 0) &&
79516 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79517 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79518 struct vlan_net *vn;
79519
79520 vn = net_generic(net, vlan_net_id);
79521 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79522 index 02efb25..41541a9 100644
79523 --- a/net/9p/trans_fd.c
79524 +++ b/net/9p/trans_fd.c
79525 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79526 oldfs = get_fs();
79527 set_fs(get_ds());
79528 /* The cast to a user pointer is valid due to the set_fs() */
79529 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79530 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79531 set_fs(oldfs);
79532
79533 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79534 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79535 index 876fbe8..8bbea9f 100644
79536 --- a/net/atm/atm_misc.c
79537 +++ b/net/atm/atm_misc.c
79538 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
79539 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79540 return 1;
79541 atm_return(vcc, truesize);
79542 - atomic_inc(&vcc->stats->rx_drop);
79543 + atomic_inc_unchecked(&vcc->stats->rx_drop);
79544 return 0;
79545 }
79546 EXPORT_SYMBOL(atm_charge);
79547 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
79548 }
79549 }
79550 atm_return(vcc, guess);
79551 - atomic_inc(&vcc->stats->rx_drop);
79552 + atomic_inc_unchecked(&vcc->stats->rx_drop);
79553 return NULL;
79554 }
79555 EXPORT_SYMBOL(atm_alloc_charge);
79556 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
79557
79558 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79559 {
79560 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79561 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79562 __SONET_ITEMS
79563 #undef __HANDLE_ITEM
79564 }
79565 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
79566
79567 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79568 {
79569 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79570 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79571 __SONET_ITEMS
79572 #undef __HANDLE_ITEM
79573 }
79574 diff --git a/net/atm/lec.h b/net/atm/lec.h
79575 index a86aff9..3a0d6f6 100644
79576 --- a/net/atm/lec.h
79577 +++ b/net/atm/lec.h
79578 @@ -48,7 +48,7 @@ struct lane2_ops {
79579 const u8 *tlvs, u32 sizeoftlvs);
79580 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79581 const u8 *tlvs, u32 sizeoftlvs);
79582 -};
79583 +} __no_const;
79584
79585 /*
79586 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79587 diff --git a/net/atm/proc.c b/net/atm/proc.c
79588 index 0d020de..011c7bb 100644
79589 --- a/net/atm/proc.c
79590 +++ b/net/atm/proc.c
79591 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79592 const struct k_atm_aal_stats *stats)
79593 {
79594 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79595 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
79596 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
79597 - atomic_read(&stats->rx_drop));
79598 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79599 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79600 + atomic_read_unchecked(&stats->rx_drop));
79601 }
79602
79603 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79604 diff --git a/net/atm/resources.c b/net/atm/resources.c
79605 index 0447d5d..3cf4728 100644
79606 --- a/net/atm/resources.c
79607 +++ b/net/atm/resources.c
79608 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
79609 static void copy_aal_stats(struct k_atm_aal_stats *from,
79610 struct atm_aal_stats *to)
79611 {
79612 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79613 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79614 __AAL_STAT_ITEMS
79615 #undef __HANDLE_ITEM
79616 }
79617 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79618 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79619 struct atm_aal_stats *to)
79620 {
79621 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79622 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79623 __AAL_STAT_ITEMS
79624 #undef __HANDLE_ITEM
79625 }
79626 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
79627 index 7d02ebd..4d4cc01 100644
79628 --- a/net/batman-adv/bat_iv_ogm.c
79629 +++ b/net/batman-adv/bat_iv_ogm.c
79630 @@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
79631
79632 /* randomize initial seqno to avoid collision */
79633 get_random_bytes(&random_seqno, sizeof(random_seqno));
79634 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79635 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79636
79637 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
79638 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
79639 @@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
79640 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
79641
79642 /* change sequence number to network order */
79643 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
79644 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
79645 batadv_ogm_packet->seqno = htonl(seqno);
79646 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
79647 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
79648
79649 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
79650 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
79651 @@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
79652 return;
79653
79654 /* could be changed by schedule_own_packet() */
79655 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
79656 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
79657
79658 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
79659 has_directlink_flag = 1;
79660 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
79661 index f1d37cd..4190879 100644
79662 --- a/net/batman-adv/hard-interface.c
79663 +++ b/net/batman-adv/hard-interface.c
79664 @@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
79665 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
79666 dev_add_pack(&hard_iface->batman_adv_ptype);
79667
79668 - atomic_set(&hard_iface->frag_seqno, 1);
79669 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
79670 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
79671 hard_iface->net_dev->name);
79672
79673 @@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
79674 /* This can't be called via a bat_priv callback because
79675 * we have no bat_priv yet.
79676 */
79677 - atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
79678 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
79679 hard_iface->bat_iv.ogm_buff = NULL;
79680
79681 return hard_iface;
79682 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
79683 index 6b548fd..fc32c8d 100644
79684 --- a/net/batman-adv/soft-interface.c
79685 +++ b/net/batman-adv/soft-interface.c
79686 @@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
79687 primary_if->net_dev->dev_addr, ETH_ALEN);
79688
79689 /* set broadcast sequence number */
79690 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
79691 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
79692 bcast_packet->seqno = htonl(seqno);
79693
79694 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
79695 @@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
79696 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
79697
79698 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
79699 - atomic_set(&bat_priv->bcast_seqno, 1);
79700 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
79701 atomic_set(&bat_priv->tt.vn, 0);
79702 atomic_set(&bat_priv->tt.local_changes, 0);
79703 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
79704 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
79705 index ae9ac9a..11e0fe7 100644
79706 --- a/net/batman-adv/types.h
79707 +++ b/net/batman-adv/types.h
79708 @@ -48,7 +48,7 @@
79709 struct batadv_hard_iface_bat_iv {
79710 unsigned char *ogm_buff;
79711 int ogm_buff_len;
79712 - atomic_t ogm_seqno;
79713 + atomic_unchecked_t ogm_seqno;
79714 };
79715
79716 struct batadv_hard_iface {
79717 @@ -56,7 +56,7 @@ struct batadv_hard_iface {
79718 int16_t if_num;
79719 char if_status;
79720 struct net_device *net_dev;
79721 - atomic_t frag_seqno;
79722 + atomic_unchecked_t frag_seqno;
79723 struct kobject *hardif_obj;
79724 atomic_t refcount;
79725 struct packet_type batman_adv_ptype;
79726 @@ -284,7 +284,7 @@ struct batadv_priv {
79727 atomic_t orig_interval; /* uint */
79728 atomic_t hop_penalty; /* uint */
79729 atomic_t log_level; /* uint */
79730 - atomic_t bcast_seqno;
79731 + atomic_unchecked_t bcast_seqno;
79732 atomic_t bcast_queue_left;
79733 atomic_t batman_queue_left;
79734 char num_ifaces;
79735 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
79736 index 10aff49..ea8e021 100644
79737 --- a/net/batman-adv/unicast.c
79738 +++ b/net/batman-adv/unicast.c
79739 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
79740 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
79741 frag2->flags = large_tail;
79742
79743 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
79744 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
79745 frag1->seqno = htons(seqno - 1);
79746 frag2->seqno = htons(seqno);
79747
79748 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
79749 index 07f0739..3c42e34 100644
79750 --- a/net/bluetooth/hci_sock.c
79751 +++ b/net/bluetooth/hci_sock.c
79752 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
79753 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
79754 }
79755
79756 - len = min_t(unsigned int, len, sizeof(uf));
79757 + len = min((size_t)len, sizeof(uf));
79758 if (copy_from_user(&uf, optval, len)) {
79759 err = -EFAULT;
79760 break;
79761 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
79762 index 22e6583..426e2f3 100644
79763 --- a/net/bluetooth/l2cap_core.c
79764 +++ b/net/bluetooth/l2cap_core.c
79765 @@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
79766 break;
79767
79768 case L2CAP_CONF_RFC:
79769 - if (olen == sizeof(rfc))
79770 - memcpy(&rfc, (void *)val, olen);
79771 + if (olen != sizeof(rfc))
79772 + break;
79773 +
79774 + memcpy(&rfc, (void *)val, olen);
79775
79776 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
79777 rfc.mode != chan->mode)
79778 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
79779 index 1bcfb84..dad9f98 100644
79780 --- a/net/bluetooth/l2cap_sock.c
79781 +++ b/net/bluetooth/l2cap_sock.c
79782 @@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
79783 struct sock *sk = sock->sk;
79784 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
79785 struct l2cap_options opts;
79786 - int len, err = 0;
79787 + int err = 0;
79788 + size_t len = optlen;
79789 u32 opt;
79790
79791 BT_DBG("sk %p", sk);
79792 @@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
79793 opts.max_tx = chan->max_tx;
79794 opts.txwin_size = chan->tx_win;
79795
79796 - len = min_t(unsigned int, sizeof(opts), optlen);
79797 + len = min(sizeof(opts), len);
79798 if (copy_from_user((char *) &opts, optval, len)) {
79799 err = -EFAULT;
79800 break;
79801 @@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79802 struct bt_security sec;
79803 struct bt_power pwr;
79804 struct l2cap_conn *conn;
79805 - int len, err = 0;
79806 + int err = 0;
79807 + size_t len = optlen;
79808 u32 opt;
79809
79810 BT_DBG("sk %p", sk);
79811 @@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79812
79813 sec.level = BT_SECURITY_LOW;
79814
79815 - len = min_t(unsigned int, sizeof(sec), optlen);
79816 + len = min(sizeof(sec), len);
79817 if (copy_from_user((char *) &sec, optval, len)) {
79818 err = -EFAULT;
79819 break;
79820 @@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79821
79822 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
79823
79824 - len = min_t(unsigned int, sizeof(pwr), optlen);
79825 + len = min(sizeof(pwr), len);
79826 if (copy_from_user((char *) &pwr, optval, len)) {
79827 err = -EFAULT;
79828 break;
79829 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
79830 index ce3f665..2c7d08f 100644
79831 --- a/net/bluetooth/rfcomm/sock.c
79832 +++ b/net/bluetooth/rfcomm/sock.c
79833 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
79834 struct sock *sk = sock->sk;
79835 struct bt_security sec;
79836 int err = 0;
79837 - size_t len;
79838 + size_t len = optlen;
79839 u32 opt;
79840
79841 BT_DBG("sk %p", sk);
79842 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
79843
79844 sec.level = BT_SECURITY_LOW;
79845
79846 - len = min_t(unsigned int, sizeof(sec), optlen);
79847 + len = min(sizeof(sec), len);
79848 if (copy_from_user((char *) &sec, optval, len)) {
79849 err = -EFAULT;
79850 break;
79851 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
79852 index bd6fd0f..6492cba 100644
79853 --- a/net/bluetooth/rfcomm/tty.c
79854 +++ b/net/bluetooth/rfcomm/tty.c
79855 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
79856 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
79857
79858 spin_lock_irqsave(&dev->port.lock, flags);
79859 - if (dev->port.count > 0) {
79860 + if (atomic_read(&dev->port.count) > 0) {
79861 spin_unlock_irqrestore(&dev->port.lock, flags);
79862 return;
79863 }
79864 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
79865 return -ENODEV;
79866
79867 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
79868 - dev->channel, dev->port.count);
79869 + dev->channel, atomic_read(&dev->port.count));
79870
79871 spin_lock_irqsave(&dev->port.lock, flags);
79872 - if (++dev->port.count > 1) {
79873 + if (atomic_inc_return(&dev->port.count) > 1) {
79874 spin_unlock_irqrestore(&dev->port.lock, flags);
79875 return 0;
79876 }
79877 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
79878 return;
79879
79880 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
79881 - dev->port.count);
79882 + atomic_read(&dev->port.count));
79883
79884 spin_lock_irqsave(&dev->port.lock, flags);
79885 - if (!--dev->port.count) {
79886 + if (!atomic_dec_return(&dev->port.count)) {
79887 spin_unlock_irqrestore(&dev->port.lock, flags);
79888 if (dev->tty_dev->parent)
79889 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
79890 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79891 index 5fe2ff3..121d696 100644
79892 --- a/net/bridge/netfilter/ebtables.c
79893 +++ b/net/bridge/netfilter/ebtables.c
79894 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79895 tmp.valid_hooks = t->table->valid_hooks;
79896 }
79897 mutex_unlock(&ebt_mutex);
79898 - if (copy_to_user(user, &tmp, *len) != 0){
79899 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
79900 BUGPRINT("c2u Didn't work\n");
79901 ret = -EFAULT;
79902 break;
79903 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79904 goto out;
79905 tmp.valid_hooks = t->valid_hooks;
79906
79907 - if (copy_to_user(user, &tmp, *len) != 0) {
79908 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79909 ret = -EFAULT;
79910 break;
79911 }
79912 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79913 tmp.entries_size = t->table->entries_size;
79914 tmp.valid_hooks = t->table->valid_hooks;
79915
79916 - if (copy_to_user(user, &tmp, *len) != 0) {
79917 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79918 ret = -EFAULT;
79919 break;
79920 }
79921 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
79922 index a376ec1..1fbd6be 100644
79923 --- a/net/caif/cfctrl.c
79924 +++ b/net/caif/cfctrl.c
79925 @@ -10,6 +10,7 @@
79926 #include <linux/spinlock.h>
79927 #include <linux/slab.h>
79928 #include <linux/pkt_sched.h>
79929 +#include <linux/sched.h>
79930 #include <net/caif/caif_layer.h>
79931 #include <net/caif/cfpkt.h>
79932 #include <net/caif/cfctrl.h>
79933 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
79934 memset(&dev_info, 0, sizeof(dev_info));
79935 dev_info.id = 0xff;
79936 cfsrvl_init(&this->serv, 0, &dev_info, false);
79937 - atomic_set(&this->req_seq_no, 1);
79938 - atomic_set(&this->rsp_seq_no, 1);
79939 + atomic_set_unchecked(&this->req_seq_no, 1);
79940 + atomic_set_unchecked(&this->rsp_seq_no, 1);
79941 this->serv.layer.receive = cfctrl_recv;
79942 sprintf(this->serv.layer.name, "ctrl");
79943 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
79944 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
79945 struct cfctrl_request_info *req)
79946 {
79947 spin_lock_bh(&ctrl->info_list_lock);
79948 - atomic_inc(&ctrl->req_seq_no);
79949 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
79950 + atomic_inc_unchecked(&ctrl->req_seq_no);
79951 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
79952 list_add_tail(&req->list, &ctrl->list);
79953 spin_unlock_bh(&ctrl->info_list_lock);
79954 }
79955 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
79956 if (p != first)
79957 pr_warn("Requests are not received in order\n");
79958
79959 - atomic_set(&ctrl->rsp_seq_no,
79960 + atomic_set_unchecked(&ctrl->rsp_seq_no,
79961 p->sequence_no);
79962 list_del(&p->list);
79963 goto out;
79964 diff --git a/net/can/af_can.c b/net/can/af_can.c
79965 index ddac1ee..3ee0a78 100644
79966 --- a/net/can/af_can.c
79967 +++ b/net/can/af_can.c
79968 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
79969 };
79970
79971 /* notifier block for netdevice event */
79972 -static struct notifier_block can_netdev_notifier __read_mostly = {
79973 +static struct notifier_block can_netdev_notifier = {
79974 .notifier_call = can_notifier,
79975 };
79976
79977 diff --git a/net/can/gw.c b/net/can/gw.c
79978 index 574dda78e..3d2b3da 100644
79979 --- a/net/can/gw.c
79980 +++ b/net/can/gw.c
79981 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
79982 MODULE_ALIAS("can-gw");
79983
79984 static HLIST_HEAD(cgw_list);
79985 -static struct notifier_block notifier;
79986
79987 static struct kmem_cache *cgw_cache __read_mostly;
79988
79989 @@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
79990 return err;
79991 }
79992
79993 +static struct notifier_block notifier = {
79994 + .notifier_call = cgw_notifier
79995 +};
79996 +
79997 static __init int cgw_module_init(void)
79998 {
79999 printk(banner);
80000 @@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
80001 return -ENOMEM;
80002
80003 /* set notifier */
80004 - notifier.notifier_call = cgw_notifier;
80005 register_netdevice_notifier(&notifier);
80006
80007 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
80008 diff --git a/net/compat.c b/net/compat.c
80009 index 79ae884..17c5c09 100644
80010 --- a/net/compat.c
80011 +++ b/net/compat.c
80012 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
80013 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
80014 __get_user(kmsg->msg_flags, &umsg->msg_flags))
80015 return -EFAULT;
80016 - kmsg->msg_name = compat_ptr(tmp1);
80017 - kmsg->msg_iov = compat_ptr(tmp2);
80018 - kmsg->msg_control = compat_ptr(tmp3);
80019 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
80020 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
80021 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
80022 return 0;
80023 }
80024
80025 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80026
80027 if (kern_msg->msg_namelen) {
80028 if (mode == VERIFY_READ) {
80029 - int err = move_addr_to_kernel(kern_msg->msg_name,
80030 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
80031 kern_msg->msg_namelen,
80032 kern_address);
80033 if (err < 0)
80034 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80035 kern_msg->msg_name = NULL;
80036
80037 tot_len = iov_from_user_compat_to_kern(kern_iov,
80038 - (struct compat_iovec __user *)kern_msg->msg_iov,
80039 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
80040 kern_msg->msg_iovlen);
80041 if (tot_len >= 0)
80042 kern_msg->msg_iov = kern_iov;
80043 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80044
80045 #define CMSG_COMPAT_FIRSTHDR(msg) \
80046 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
80047 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
80048 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
80049 (struct compat_cmsghdr __user *)NULL)
80050
80051 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
80052 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
80053 (ucmlen) <= (unsigned long) \
80054 ((mhdr)->msg_controllen - \
80055 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
80056 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
80057
80058 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
80059 struct compat_cmsghdr __user *cmsg, int cmsg_len)
80060 {
80061 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
80062 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
80063 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
80064 msg->msg_controllen)
80065 return NULL;
80066 return (struct compat_cmsghdr __user *)ptr;
80067 @@ -219,7 +219,7 @@ Efault:
80068
80069 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
80070 {
80071 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80072 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80073 struct compat_cmsghdr cmhdr;
80074 struct compat_timeval ctv;
80075 struct compat_timespec cts[3];
80076 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80077
80078 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
80079 {
80080 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80081 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80082 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
80083 int fdnum = scm->fp->count;
80084 struct file **fp = scm->fp->fp;
80085 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
80086 return -EFAULT;
80087 old_fs = get_fs();
80088 set_fs(KERNEL_DS);
80089 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
80090 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
80091 set_fs(old_fs);
80092
80093 return err;
80094 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
80095 len = sizeof(ktime);
80096 old_fs = get_fs();
80097 set_fs(KERNEL_DS);
80098 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
80099 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
80100 set_fs(old_fs);
80101
80102 if (!err) {
80103 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80104 case MCAST_JOIN_GROUP:
80105 case MCAST_LEAVE_GROUP:
80106 {
80107 - struct compat_group_req __user *gr32 = (void *)optval;
80108 + struct compat_group_req __user *gr32 = (void __user *)optval;
80109 struct group_req __user *kgr =
80110 compat_alloc_user_space(sizeof(struct group_req));
80111 u32 interface;
80112 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80113 case MCAST_BLOCK_SOURCE:
80114 case MCAST_UNBLOCK_SOURCE:
80115 {
80116 - struct compat_group_source_req __user *gsr32 = (void *)optval;
80117 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80118 struct group_source_req __user *kgsr = compat_alloc_user_space(
80119 sizeof(struct group_source_req));
80120 u32 interface;
80121 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80122 }
80123 case MCAST_MSFILTER:
80124 {
80125 - struct compat_group_filter __user *gf32 = (void *)optval;
80126 + struct compat_group_filter __user *gf32 = (void __user *)optval;
80127 struct group_filter __user *kgf;
80128 u32 interface, fmode, numsrc;
80129
80130 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
80131 char __user *optval, int __user *optlen,
80132 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
80133 {
80134 - struct compat_group_filter __user *gf32 = (void *)optval;
80135 + struct compat_group_filter __user *gf32 = (void __user *)optval;
80136 struct group_filter __user *kgf;
80137 int __user *koptlen;
80138 u32 interface, fmode, numsrc;
80139 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
80140
80141 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
80142 return -EINVAL;
80143 - if (copy_from_user(a, args, nas[call]))
80144 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
80145 return -EFAULT;
80146 a0 = a[0];
80147 a1 = a[1];
80148 diff --git a/net/core/datagram.c b/net/core/datagram.c
80149 index 368f9c3..f82d4a3 100644
80150 --- a/net/core/datagram.c
80151 +++ b/net/core/datagram.c
80152 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
80153 }
80154
80155 kfree_skb(skb);
80156 - atomic_inc(&sk->sk_drops);
80157 + atomic_inc_unchecked(&sk->sk_drops);
80158 sk_mem_reclaim_partial(sk);
80159
80160 return err;
80161 diff --git a/net/core/dev.c b/net/core/dev.c
80162 index f64e439..8f959e6 100644
80163 --- a/net/core/dev.c
80164 +++ b/net/core/dev.c
80165 @@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
80166 if (no_module && capable(CAP_NET_ADMIN))
80167 no_module = request_module("netdev-%s", name);
80168 if (no_module && capable(CAP_SYS_MODULE)) {
80169 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
80170 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
80171 +#else
80172 if (!request_module("%s", name))
80173 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
80174 name);
80175 +#endif
80176 }
80177 }
80178 EXPORT_SYMBOL(dev_load);
80179 @@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80180 {
80181 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
80182 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
80183 - atomic_long_inc(&dev->rx_dropped);
80184 + atomic_long_inc_unchecked(&dev->rx_dropped);
80185 kfree_skb(skb);
80186 return NET_RX_DROP;
80187 }
80188 @@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80189 nf_reset(skb);
80190
80191 if (unlikely(!is_skb_forwardable(dev, skb))) {
80192 - atomic_long_inc(&dev->rx_dropped);
80193 + atomic_long_inc_unchecked(&dev->rx_dropped);
80194 kfree_skb(skb);
80195 return NET_RX_DROP;
80196 }
80197 @@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80198
80199 struct dev_gso_cb {
80200 void (*destructor)(struct sk_buff *skb);
80201 -};
80202 +} __no_const;
80203
80204 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80205
80206 @@ -3053,7 +3057,7 @@ enqueue:
80207
80208 local_irq_restore(flags);
80209
80210 - atomic_long_inc(&skb->dev->rx_dropped);
80211 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80212 kfree_skb(skb);
80213 return NET_RX_DROP;
80214 }
80215 @@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
80216 }
80217 EXPORT_SYMBOL(netif_rx_ni);
80218
80219 -static void net_tx_action(struct softirq_action *h)
80220 +static void net_tx_action(void)
80221 {
80222 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80223
80224 @@ -3456,7 +3460,7 @@ ncls:
80225 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
80226 } else {
80227 drop:
80228 - atomic_long_inc(&skb->dev->rx_dropped);
80229 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80230 kfree_skb(skb);
80231 /* Jamal, now you will not able to escape explaining
80232 * me how you were going to use this. :-)
80233 @@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
80234 }
80235 EXPORT_SYMBOL(netif_napi_del);
80236
80237 -static void net_rx_action(struct softirq_action *h)
80238 +static void net_rx_action(void)
80239 {
80240 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80241 unsigned long time_limit = jiffies + 2;
80242 @@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
80243 else
80244 seq_printf(seq, "%04x", ntohs(pt->type));
80245
80246 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80247 + seq_printf(seq, " %-8s %p\n",
80248 + pt->dev ? pt->dev->name : "", NULL);
80249 +#else
80250 seq_printf(seq, " %-8s %pF\n",
80251 pt->dev ? pt->dev->name : "", pt->func);
80252 +#endif
80253 }
80254
80255 return 0;
80256 @@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
80257 } else {
80258 netdev_stats_to_stats64(storage, &dev->stats);
80259 }
80260 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
80261 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
80262 return storage;
80263 }
80264 EXPORT_SYMBOL(dev_get_stats);
80265 diff --git a/net/core/flow.c b/net/core/flow.c
80266 index b0901ee..7d3c2ca 100644
80267 --- a/net/core/flow.c
80268 +++ b/net/core/flow.c
80269 @@ -61,7 +61,7 @@ struct flow_cache {
80270 struct timer_list rnd_timer;
80271 };
80272
80273 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
80274 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80275 EXPORT_SYMBOL(flow_cache_genid);
80276 static struct flow_cache flow_cache_global;
80277 static struct kmem_cache *flow_cachep __read_mostly;
80278 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
80279
80280 static int flow_entry_valid(struct flow_cache_entry *fle)
80281 {
80282 - if (atomic_read(&flow_cache_genid) != fle->genid)
80283 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
80284 return 0;
80285 if (fle->object && !fle->object->ops->check(fle->object))
80286 return 0;
80287 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
80288 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
80289 fcp->hash_count++;
80290 }
80291 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
80292 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
80293 flo = fle->object;
80294 if (!flo)
80295 goto ret_object;
80296 @@ -280,7 +280,7 @@ nocache:
80297 }
80298 flo = resolver(net, key, family, dir, flo, ctx);
80299 if (fle) {
80300 - fle->genid = atomic_read(&flow_cache_genid);
80301 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
80302 if (!IS_ERR(flo))
80303 fle->object = flo;
80304 else
80305 diff --git a/net/core/iovec.c b/net/core/iovec.c
80306 index 7e7aeb0..2a998cb 100644
80307 --- a/net/core/iovec.c
80308 +++ b/net/core/iovec.c
80309 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80310 if (m->msg_namelen) {
80311 if (mode == VERIFY_READ) {
80312 void __user *namep;
80313 - namep = (void __user __force *) m->msg_name;
80314 + namep = (void __force_user *) m->msg_name;
80315 err = move_addr_to_kernel(namep, m->msg_namelen,
80316 address);
80317 if (err < 0)
80318 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80319 }
80320
80321 size = m->msg_iovlen * sizeof(struct iovec);
80322 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
80323 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
80324 return -EFAULT;
80325
80326 m->msg_iov = iov;
80327 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80328 index 1868625..5f4de62 100644
80329 --- a/net/core/rtnetlink.c
80330 +++ b/net/core/rtnetlink.c
80331 @@ -58,7 +58,7 @@ struct rtnl_link {
80332 rtnl_doit_func doit;
80333 rtnl_dumpit_func dumpit;
80334 rtnl_calcit_func calcit;
80335 -};
80336 +} __no_const;
80337
80338 static DEFINE_MUTEX(rtnl_mutex);
80339
80340 diff --git a/net/core/scm.c b/net/core/scm.c
80341 index 905dcc6..14ee2d6 100644
80342 --- a/net/core/scm.c
80343 +++ b/net/core/scm.c
80344 @@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
80345 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80346 {
80347 struct cmsghdr __user *cm
80348 - = (__force struct cmsghdr __user *)msg->msg_control;
80349 + = (struct cmsghdr __force_user *)msg->msg_control;
80350 struct cmsghdr cmhdr;
80351 int cmlen = CMSG_LEN(len);
80352 int err;
80353 @@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80354 err = -EFAULT;
80355 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80356 goto out;
80357 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80358 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80359 goto out;
80360 cmlen = CMSG_SPACE(len);
80361 if (msg->msg_controllen < cmlen)
80362 @@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
80363 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80364 {
80365 struct cmsghdr __user *cm
80366 - = (__force struct cmsghdr __user*)msg->msg_control;
80367 + = (struct cmsghdr __force_user *)msg->msg_control;
80368
80369 int fdmax = 0;
80370 int fdnum = scm->fp->count;
80371 @@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80372 if (fdnum < fdmax)
80373 fdmax = fdnum;
80374
80375 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80376 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80377 i++, cmfptr++)
80378 {
80379 struct socket *sock;
80380 diff --git a/net/core/sock.c b/net/core/sock.c
80381 index bc131d4..029e378 100644
80382 --- a/net/core/sock.c
80383 +++ b/net/core/sock.c
80384 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80385 struct sk_buff_head *list = &sk->sk_receive_queue;
80386
80387 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
80388 - atomic_inc(&sk->sk_drops);
80389 + atomic_inc_unchecked(&sk->sk_drops);
80390 trace_sock_rcvqueue_full(sk, skb);
80391 return -ENOMEM;
80392 }
80393 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80394 return err;
80395
80396 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
80397 - atomic_inc(&sk->sk_drops);
80398 + atomic_inc_unchecked(&sk->sk_drops);
80399 return -ENOBUFS;
80400 }
80401
80402 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80403 skb_dst_force(skb);
80404
80405 spin_lock_irqsave(&list->lock, flags);
80406 - skb->dropcount = atomic_read(&sk->sk_drops);
80407 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80408 __skb_queue_tail(list, skb);
80409 spin_unlock_irqrestore(&list->lock, flags);
80410
80411 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80412 skb->dev = NULL;
80413
80414 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
80415 - atomic_inc(&sk->sk_drops);
80416 + atomic_inc_unchecked(&sk->sk_drops);
80417 goto discard_and_relse;
80418 }
80419 if (nested)
80420 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80421 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
80422 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
80423 bh_unlock_sock(sk);
80424 - atomic_inc(&sk->sk_drops);
80425 + atomic_inc_unchecked(&sk->sk_drops);
80426 goto discard_and_relse;
80427 }
80428
80429 @@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80430 struct timeval tm;
80431 } v;
80432
80433 - int lv = sizeof(int);
80434 - int len;
80435 + unsigned int lv = sizeof(int);
80436 + unsigned int len;
80437
80438 if (get_user(len, optlen))
80439 return -EFAULT;
80440 - if (len < 0)
80441 + if (len > INT_MAX)
80442 return -EINVAL;
80443
80444 memset(&v, 0, sizeof(v));
80445 @@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80446
80447 case SO_PEERNAME:
80448 {
80449 - char address[128];
80450 + char address[_K_SS_MAXSIZE];
80451
80452 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
80453 return -ENOTCONN;
80454 - if (lv < len)
80455 + if (lv < len || sizeof address < len)
80456 return -EINVAL;
80457 if (copy_to_user(optval, address, len))
80458 return -EFAULT;
80459 @@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80460
80461 if (len > lv)
80462 len = lv;
80463 - if (copy_to_user(optval, &v, len))
80464 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
80465 return -EFAULT;
80466 lenout:
80467 if (put_user(len, optlen))
80468 @@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80469 */
80470 smp_wmb();
80471 atomic_set(&sk->sk_refcnt, 1);
80472 - atomic_set(&sk->sk_drops, 0);
80473 + atomic_set_unchecked(&sk->sk_drops, 0);
80474 }
80475 EXPORT_SYMBOL(sock_init_data);
80476
80477 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
80478 index 602cd63..0a699b1 100644
80479 --- a/net/core/sock_diag.c
80480 +++ b/net/core/sock_diag.c
80481 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
80482
80483 int sock_diag_check_cookie(void *sk, __u32 *cookie)
80484 {
80485 +#ifndef CONFIG_GRKERNSEC_HIDESYM
80486 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
80487 cookie[1] != INET_DIAG_NOCOOKIE) &&
80488 ((u32)(unsigned long)sk != cookie[0] ||
80489 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
80490 return -ESTALE;
80491 else
80492 +#endif
80493 return 0;
80494 }
80495 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
80496
80497 void sock_diag_save_cookie(void *sk, __u32 *cookie)
80498 {
80499 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80500 + cookie[0] = 0;
80501 + cookie[1] = 0;
80502 +#else
80503 cookie[0] = (u32)(unsigned long)sk;
80504 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80505 +#endif
80506 }
80507 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
80508
80509 @@ -97,21 +104,6 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
80510 }
80511 EXPORT_SYMBOL_GPL(sock_diag_unregister);
80512
80513 -static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
80514 -{
80515 - if (sock_diag_handlers[family] == NULL)
80516 - request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80517 - NETLINK_SOCK_DIAG, family);
80518 -
80519 - mutex_lock(&sock_diag_table_mutex);
80520 - return sock_diag_handlers[family];
80521 -}
80522 -
80523 -static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
80524 -{
80525 - mutex_unlock(&sock_diag_table_mutex);
80526 -}
80527 -
80528 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80529 {
80530 int err;
80531 @@ -121,12 +113,20 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80532 if (nlmsg_len(nlh) < sizeof(*req))
80533 return -EINVAL;
80534
80535 - hndl = sock_diag_lock_handler(req->sdiag_family);
80536 + if (req->sdiag_family >= AF_MAX)
80537 + return -EINVAL;
80538 +
80539 + if (sock_diag_handlers[req->sdiag_family] == NULL)
80540 + request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80541 + NETLINK_SOCK_DIAG, req->sdiag_family);
80542 +
80543 + mutex_lock(&sock_diag_table_mutex);
80544 + hndl = sock_diag_handlers[req->sdiag_family];
80545 if (hndl == NULL)
80546 err = -ENOENT;
80547 else
80548 err = hndl->dump(skb, nlh);
80549 - sock_diag_unlock_handler(hndl);
80550 + mutex_unlock(&sock_diag_table_mutex);
80551
80552 return err;
80553 }
80554 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80555 index a55eecc..dd8428c 100644
80556 --- a/net/decnet/sysctl_net_decnet.c
80557 +++ b/net/decnet/sysctl_net_decnet.c
80558 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80559
80560 if (len > *lenp) len = *lenp;
80561
80562 - if (copy_to_user(buffer, addr, len))
80563 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
80564 return -EFAULT;
80565
80566 *lenp = len;
80567 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80568
80569 if (len > *lenp) len = *lenp;
80570
80571 - if (copy_to_user(buffer, devname, len))
80572 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
80573 return -EFAULT;
80574
80575 *lenp = len;
80576 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
80577 index a69b4e4..dbccba5 100644
80578 --- a/net/ipv4/ah4.c
80579 +++ b/net/ipv4/ah4.c
80580 @@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
80581 return;
80582
80583 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80584 - atomic_inc(&flow_cache_genid);
80585 + atomic_inc_unchecked(&flow_cache_genid);
80586 rt_genid_bump(net);
80587
80588 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
80589 diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
80590 index 3b4f0cd..8cb864c 100644
80591 --- a/net/ipv4/esp4.c
80592 +++ b/net/ipv4/esp4.c
80593 @@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
80594 return;
80595
80596 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80597 - atomic_inc(&flow_cache_genid);
80598 + atomic_inc_unchecked(&flow_cache_genid);
80599 rt_genid_bump(net);
80600
80601 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
80602 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
80603 index 5cd75e2..f57ef39 100644
80604 --- a/net/ipv4/fib_frontend.c
80605 +++ b/net/ipv4/fib_frontend.c
80606 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
80607 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80608 fib_sync_up(dev);
80609 #endif
80610 - atomic_inc(&net->ipv4.dev_addr_genid);
80611 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80612 rt_cache_flush(dev_net(dev));
80613 break;
80614 case NETDEV_DOWN:
80615 fib_del_ifaddr(ifa, NULL);
80616 - atomic_inc(&net->ipv4.dev_addr_genid);
80617 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80618 if (ifa->ifa_dev->ifa_list == NULL) {
80619 /* Last address was deleted from this interface.
80620 * Disable IP.
80621 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
80622 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80623 fib_sync_up(dev);
80624 #endif
80625 - atomic_inc(&net->ipv4.dev_addr_genid);
80626 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80627 rt_cache_flush(net);
80628 break;
80629 case NETDEV_DOWN:
80630 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
80631 index 4797a80..2bd54e9 100644
80632 --- a/net/ipv4/fib_semantics.c
80633 +++ b/net/ipv4/fib_semantics.c
80634 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
80635 nh->nh_saddr = inet_select_addr(nh->nh_dev,
80636 nh->nh_gw,
80637 nh->nh_parent->fib_scope);
80638 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
80639 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
80640
80641 return nh->nh_saddr;
80642 }
80643 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80644 index fa3ae81..0dbe6b8 100644
80645 --- a/net/ipv4/inet_hashtables.c
80646 +++ b/net/ipv4/inet_hashtables.c
80647 @@ -18,12 +18,15 @@
80648 #include <linux/sched.h>
80649 #include <linux/slab.h>
80650 #include <linux/wait.h>
80651 +#include <linux/security.h>
80652
80653 #include <net/inet_connection_sock.h>
80654 #include <net/inet_hashtables.h>
80655 #include <net/secure_seq.h>
80656 #include <net/ip.h>
80657
80658 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80659 +
80660 /*
80661 * Allocate and initialize a new local port bind bucket.
80662 * The bindhash mutex for snum's hash chain must be held here.
80663 @@ -540,6 +543,8 @@ ok:
80664 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
80665 spin_unlock(&head->lock);
80666
80667 + gr_update_task_in_ip_table(current, inet_sk(sk));
80668 +
80669 if (tw) {
80670 inet_twsk_deschedule(tw, death_row);
80671 while (twrefcnt) {
80672 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80673 index 000e3d2..5472da3 100644
80674 --- a/net/ipv4/inetpeer.c
80675 +++ b/net/ipv4/inetpeer.c
80676 @@ -503,8 +503,8 @@ relookup:
80677 if (p) {
80678 p->daddr = *daddr;
80679 atomic_set(&p->refcnt, 1);
80680 - atomic_set(&p->rid, 0);
80681 - atomic_set(&p->ip_id_count,
80682 + atomic_set_unchecked(&p->rid, 0);
80683 + atomic_set_unchecked(&p->ip_id_count,
80684 (daddr->family == AF_INET) ?
80685 secure_ip_id(daddr->addr.a4) :
80686 secure_ipv6_id(daddr->addr.a6));
80687 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80688 index eb9d63a..50babc1 100644
80689 --- a/net/ipv4/ip_fragment.c
80690 +++ b/net/ipv4/ip_fragment.c
80691 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80692 return 0;
80693
80694 start = qp->rid;
80695 - end = atomic_inc_return(&peer->rid);
80696 + end = atomic_inc_return_unchecked(&peer->rid);
80697 qp->rid = end;
80698
80699 rc = qp->q.fragments && (end - start) > max;
80700 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80701 index d9c4f11..02b82db 100644
80702 --- a/net/ipv4/ip_sockglue.c
80703 +++ b/net/ipv4/ip_sockglue.c
80704 @@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80705 len = min_t(unsigned int, len, opt->optlen);
80706 if (put_user(len, optlen))
80707 return -EFAULT;
80708 - if (copy_to_user(optval, opt->__data, len))
80709 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
80710 + copy_to_user(optval, opt->__data, len))
80711 return -EFAULT;
80712 return 0;
80713 }
80714 @@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80715 if (sk->sk_type != SOCK_STREAM)
80716 return -ENOPROTOOPT;
80717
80718 - msg.msg_control = optval;
80719 + msg.msg_control = (void __force_kernel *)optval;
80720 msg.msg_controllen = len;
80721 msg.msg_flags = flags;
80722
80723 diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
80724 index 9a46dae..5f793a0 100644
80725 --- a/net/ipv4/ipcomp.c
80726 +++ b/net/ipv4/ipcomp.c
80727 @@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
80728 return;
80729
80730 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80731 - atomic_inc(&flow_cache_genid);
80732 + atomic_inc_unchecked(&flow_cache_genid);
80733 rt_genid_bump(net);
80734
80735 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
80736 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80737 index a2e50ae..e152b7c 100644
80738 --- a/net/ipv4/ipconfig.c
80739 +++ b/net/ipv4/ipconfig.c
80740 @@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80741
80742 mm_segment_t oldfs = get_fs();
80743 set_fs(get_ds());
80744 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80745 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80746 set_fs(oldfs);
80747 return res;
80748 }
80749 @@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80750
80751 mm_segment_t oldfs = get_fs();
80752 set_fs(get_ds());
80753 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80754 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80755 set_fs(oldfs);
80756 return res;
80757 }
80758 @@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
80759
80760 mm_segment_t oldfs = get_fs();
80761 set_fs(get_ds());
80762 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
80763 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
80764 set_fs(oldfs);
80765 return res;
80766 }
80767 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
80768 index 3ea4127..849297b 100644
80769 --- a/net/ipv4/netfilter/arp_tables.c
80770 +++ b/net/ipv4/netfilter/arp_tables.c
80771 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
80772 #endif
80773
80774 static int get_info(struct net *net, void __user *user,
80775 - const int *len, int compat)
80776 + int len, int compat)
80777 {
80778 char name[XT_TABLE_MAXNAMELEN];
80779 struct xt_table *t;
80780 int ret;
80781
80782 - if (*len != sizeof(struct arpt_getinfo)) {
80783 - duprintf("length %u != %Zu\n", *len,
80784 + if (len != sizeof(struct arpt_getinfo)) {
80785 + duprintf("length %u != %Zu\n", len,
80786 sizeof(struct arpt_getinfo));
80787 return -EINVAL;
80788 }
80789 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
80790 info.size = private->size;
80791 strcpy(info.name, name);
80792
80793 - if (copy_to_user(user, &info, *len) != 0)
80794 + if (copy_to_user(user, &info, len) != 0)
80795 ret = -EFAULT;
80796 else
80797 ret = 0;
80798 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
80799
80800 switch (cmd) {
80801 case ARPT_SO_GET_INFO:
80802 - ret = get_info(sock_net(sk), user, len, 1);
80803 + ret = get_info(sock_net(sk), user, *len, 1);
80804 break;
80805 case ARPT_SO_GET_ENTRIES:
80806 ret = compat_get_entries(sock_net(sk), user, len);
80807 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
80808
80809 switch (cmd) {
80810 case ARPT_SO_GET_INFO:
80811 - ret = get_info(sock_net(sk), user, len, 0);
80812 + ret = get_info(sock_net(sk), user, *len, 0);
80813 break;
80814
80815 case ARPT_SO_GET_ENTRIES:
80816 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80817 index 17c5e06..1b91206 100644
80818 --- a/net/ipv4/netfilter/ip_tables.c
80819 +++ b/net/ipv4/netfilter/ip_tables.c
80820 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
80821 #endif
80822
80823 static int get_info(struct net *net, void __user *user,
80824 - const int *len, int compat)
80825 + int len, int compat)
80826 {
80827 char name[XT_TABLE_MAXNAMELEN];
80828 struct xt_table *t;
80829 int ret;
80830
80831 - if (*len != sizeof(struct ipt_getinfo)) {
80832 - duprintf("length %u != %zu\n", *len,
80833 + if (len != sizeof(struct ipt_getinfo)) {
80834 + duprintf("length %u != %zu\n", len,
80835 sizeof(struct ipt_getinfo));
80836 return -EINVAL;
80837 }
80838 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
80839 info.size = private->size;
80840 strcpy(info.name, name);
80841
80842 - if (copy_to_user(user, &info, *len) != 0)
80843 + if (copy_to_user(user, &info, len) != 0)
80844 ret = -EFAULT;
80845 else
80846 ret = 0;
80847 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80848
80849 switch (cmd) {
80850 case IPT_SO_GET_INFO:
80851 - ret = get_info(sock_net(sk), user, len, 1);
80852 + ret = get_info(sock_net(sk), user, *len, 1);
80853 break;
80854 case IPT_SO_GET_ENTRIES:
80855 ret = compat_get_entries(sock_net(sk), user, len);
80856 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80857
80858 switch (cmd) {
80859 case IPT_SO_GET_INFO:
80860 - ret = get_info(sock_net(sk), user, len, 0);
80861 + ret = get_info(sock_net(sk), user, *len, 0);
80862 break;
80863
80864 case IPT_SO_GET_ENTRIES:
80865 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
80866 index 6f9c072..38ea6c6 100644
80867 --- a/net/ipv4/ping.c
80868 +++ b/net/ipv4/ping.c
80869 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
80870 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80871 0, sock_i_ino(sp),
80872 atomic_read(&sp->sk_refcnt), sp,
80873 - atomic_read(&sp->sk_drops), len);
80874 + atomic_read_unchecked(&sp->sk_drops), len);
80875 }
80876
80877 static int ping_seq_show(struct seq_file *seq, void *v)
80878 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80879 index 6f08991..55867ad 100644
80880 --- a/net/ipv4/raw.c
80881 +++ b/net/ipv4/raw.c
80882 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
80883 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80884 {
80885 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80886 - atomic_inc(&sk->sk_drops);
80887 + atomic_inc_unchecked(&sk->sk_drops);
80888 kfree_skb(skb);
80889 return NET_RX_DROP;
80890 }
80891 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
80892
80893 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80894 {
80895 + struct icmp_filter filter;
80896 +
80897 if (optlen > sizeof(struct icmp_filter))
80898 optlen = sizeof(struct icmp_filter);
80899 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80900 + if (copy_from_user(&filter, optval, optlen))
80901 return -EFAULT;
80902 + raw_sk(sk)->filter = filter;
80903 return 0;
80904 }
80905
80906 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80907 {
80908 int len, ret = -EFAULT;
80909 + struct icmp_filter filter;
80910
80911 if (get_user(len, optlen))
80912 goto out;
80913 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80914 if (len > sizeof(struct icmp_filter))
80915 len = sizeof(struct icmp_filter);
80916 ret = -EFAULT;
80917 - if (put_user(len, optlen) ||
80918 - copy_to_user(optval, &raw_sk(sk)->filter, len))
80919 + filter = raw_sk(sk)->filter;
80920 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
80921 goto out;
80922 ret = 0;
80923 out: return ret;
80924 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80925 0, 0L, 0,
80926 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80927 0, sock_i_ino(sp),
80928 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80929 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80930 }
80931
80932 static int raw_seq_show(struct seq_file *seq, void *v)
80933 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80934 index a0fcc47..5949bba1 100644
80935 --- a/net/ipv4/route.c
80936 +++ b/net/ipv4/route.c
80937 @@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80938
80939 static __net_init int rt_genid_init(struct net *net)
80940 {
80941 - atomic_set(&net->rt_genid, 0);
80942 + atomic_set_unchecked(&net->rt_genid, 0);
80943 get_random_bytes(&net->ipv4.dev_addr_genid,
80944 sizeof(net->ipv4.dev_addr_genid));
80945 return 0;
80946 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
80947 index ad70a96..50cb55b 100644
80948 --- a/net/ipv4/tcp_input.c
80949 +++ b/net/ipv4/tcp_input.c
80950 @@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
80951 * simplifies code)
80952 */
80953 static void
80954 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80955 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80956 struct sk_buff *head, struct sk_buff *tail,
80957 u32 start, u32 end)
80958 {
80959 @@ -5850,6 +5850,7 @@ discard:
80960 tcp_paws_reject(&tp->rx_opt, 0))
80961 goto discard_and_undo;
80962
80963 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
80964 if (th->syn) {
80965 /* We see SYN without ACK. It is attempt of
80966 * simultaneous connect with crossed SYNs.
80967 @@ -5900,6 +5901,7 @@ discard:
80968 goto discard;
80969 #endif
80970 }
80971 +#endif
80972 /* "fifth, if neither of the SYN or RST bits is set then
80973 * drop the segment and return."
80974 */
80975 @@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80976 goto discard;
80977
80978 if (th->syn) {
80979 - if (th->fin)
80980 + if (th->fin || th->urg || th->psh)
80981 goto discard;
80982 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
80983 return 1;
80984 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80985 index eadb693..e8f7251 100644
80986 --- a/net/ipv4/tcp_ipv4.c
80987 +++ b/net/ipv4/tcp_ipv4.c
80988 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
80989 EXPORT_SYMBOL(sysctl_tcp_low_latency);
80990
80991
80992 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80993 +extern int grsec_enable_blackhole;
80994 +#endif
80995 +
80996 #ifdef CONFIG_TCP_MD5SIG
80997 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
80998 __be32 daddr, __be32 saddr, const struct tcphdr *th);
80999 @@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
81000 return 0;
81001
81002 reset:
81003 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81004 + if (!grsec_enable_blackhole)
81005 +#endif
81006 tcp_v4_send_reset(rsk, skb);
81007 discard:
81008 kfree_skb(skb);
81009 @@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
81010 TCP_SKB_CB(skb)->sacked = 0;
81011
81012 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81013 - if (!sk)
81014 + if (!sk) {
81015 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81016 + ret = 1;
81017 +#endif
81018 goto no_tcp_socket;
81019 -
81020 + }
81021 process:
81022 - if (sk->sk_state == TCP_TIME_WAIT)
81023 + if (sk->sk_state == TCP_TIME_WAIT) {
81024 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81025 + ret = 2;
81026 +#endif
81027 goto do_time_wait;
81028 + }
81029
81030 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
81031 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81032 @@ -2050,6 +2064,10 @@ no_tcp_socket:
81033 bad_packet:
81034 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81035 } else {
81036 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81037 + if (!grsec_enable_blackhole || (ret == 1 &&
81038 + (skb->dev->flags & IFF_LOOPBACK)))
81039 +#endif
81040 tcp_v4_send_reset(NULL, skb);
81041 }
81042
81043 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
81044 index f35f2df..ccb5ca6 100644
81045 --- a/net/ipv4/tcp_minisocks.c
81046 +++ b/net/ipv4/tcp_minisocks.c
81047 @@ -27,6 +27,10 @@
81048 #include <net/inet_common.h>
81049 #include <net/xfrm.h>
81050
81051 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81052 +extern int grsec_enable_blackhole;
81053 +#endif
81054 +
81055 int sysctl_tcp_syncookies __read_mostly = 1;
81056 EXPORT_SYMBOL(sysctl_tcp_syncookies);
81057
81058 @@ -742,7 +746,10 @@ embryonic_reset:
81059 * avoid becoming vulnerable to outside attack aiming at
81060 * resetting legit local connections.
81061 */
81062 - req->rsk_ops->send_reset(sk, skb);
81063 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81064 + if (!grsec_enable_blackhole)
81065 +#endif
81066 + req->rsk_ops->send_reset(sk, skb);
81067 } else if (fastopen) { /* received a valid RST pkt */
81068 reqsk_fastopen_remove(sk, req, true);
81069 tcp_reset(sk);
81070 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
81071 index 4526fe6..1a34e43 100644
81072 --- a/net/ipv4/tcp_probe.c
81073 +++ b/net/ipv4/tcp_probe.c
81074 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
81075 if (cnt + width >= len)
81076 break;
81077
81078 - if (copy_to_user(buf + cnt, tbuf, width))
81079 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
81080 return -EFAULT;
81081 cnt += width;
81082 }
81083 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
81084 index b78aac3..e18230b 100644
81085 --- a/net/ipv4/tcp_timer.c
81086 +++ b/net/ipv4/tcp_timer.c
81087 @@ -22,6 +22,10 @@
81088 #include <linux/gfp.h>
81089 #include <net/tcp.h>
81090
81091 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81092 +extern int grsec_lastack_retries;
81093 +#endif
81094 +
81095 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
81096 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
81097 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
81098 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
81099 }
81100 }
81101
81102 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81103 + if ((sk->sk_state == TCP_LAST_ACK) &&
81104 + (grsec_lastack_retries > 0) &&
81105 + (grsec_lastack_retries < retry_until))
81106 + retry_until = grsec_lastack_retries;
81107 +#endif
81108 +
81109 if (retransmits_timed_out(sk, retry_until,
81110 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
81111 /* Has it gone just too far? */
81112 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
81113 index 1f4d405..3524677 100644
81114 --- a/net/ipv4/udp.c
81115 +++ b/net/ipv4/udp.c
81116 @@ -87,6 +87,7 @@
81117 #include <linux/types.h>
81118 #include <linux/fcntl.h>
81119 #include <linux/module.h>
81120 +#include <linux/security.h>
81121 #include <linux/socket.h>
81122 #include <linux/sockios.h>
81123 #include <linux/igmp.h>
81124 @@ -111,6 +112,10 @@
81125 #include <trace/events/skb.h>
81126 #include "udp_impl.h"
81127
81128 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81129 +extern int grsec_enable_blackhole;
81130 +#endif
81131 +
81132 struct udp_table udp_table __read_mostly;
81133 EXPORT_SYMBOL(udp_table);
81134
81135 @@ -569,6 +574,9 @@ found:
81136 return s;
81137 }
81138
81139 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
81140 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
81141 +
81142 /*
81143 * This routine is called by the ICMP module when it gets some
81144 * sort of error condition. If err < 0 then the socket should
81145 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
81146 dport = usin->sin_port;
81147 if (dport == 0)
81148 return -EINVAL;
81149 +
81150 + err = gr_search_udp_sendmsg(sk, usin);
81151 + if (err)
81152 + return err;
81153 } else {
81154 if (sk->sk_state != TCP_ESTABLISHED)
81155 return -EDESTADDRREQ;
81156 +
81157 + err = gr_search_udp_sendmsg(sk, NULL);
81158 + if (err)
81159 + return err;
81160 +
81161 daddr = inet->inet_daddr;
81162 dport = inet->inet_dport;
81163 /* Open fast path for connected socket.
81164 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
81165 udp_lib_checksum_complete(skb)) {
81166 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81167 IS_UDPLITE(sk));
81168 - atomic_inc(&sk->sk_drops);
81169 + atomic_inc_unchecked(&sk->sk_drops);
81170 __skb_unlink(skb, rcvq);
81171 __skb_queue_tail(&list_kill, skb);
81172 }
81173 @@ -1194,6 +1211,10 @@ try_again:
81174 if (!skb)
81175 goto out;
81176
81177 + err = gr_search_udp_recvmsg(sk, skb);
81178 + if (err)
81179 + goto out_free;
81180 +
81181 ulen = skb->len - sizeof(struct udphdr);
81182 copied = len;
81183 if (copied > ulen)
81184 @@ -1227,7 +1248,7 @@ try_again:
81185 if (unlikely(err)) {
81186 trace_kfree_skb(skb, udp_recvmsg);
81187 if (!peeked) {
81188 - atomic_inc(&sk->sk_drops);
81189 + atomic_inc_unchecked(&sk->sk_drops);
81190 UDP_INC_STATS_USER(sock_net(sk),
81191 UDP_MIB_INERRORS, is_udplite);
81192 }
81193 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81194
81195 drop:
81196 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81197 - atomic_inc(&sk->sk_drops);
81198 + atomic_inc_unchecked(&sk->sk_drops);
81199 kfree_skb(skb);
81200 return -1;
81201 }
81202 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81203 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81204
81205 if (!skb1) {
81206 - atomic_inc(&sk->sk_drops);
81207 + atomic_inc_unchecked(&sk->sk_drops);
81208 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81209 IS_UDPLITE(sk));
81210 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81211 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81212 goto csum_error;
81213
81214 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81215 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81216 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81217 +#endif
81218 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
81219
81220 /*
81221 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
81222 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81223 0, sock_i_ino(sp),
81224 atomic_read(&sp->sk_refcnt), sp,
81225 - atomic_read(&sp->sk_drops), len);
81226 + atomic_read_unchecked(&sp->sk_drops), len);
81227 }
81228
81229 int udp4_seq_show(struct seq_file *seq, void *v)
81230 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81231 index 1b5d8cb..2e8c2d9 100644
81232 --- a/net/ipv6/addrconf.c
81233 +++ b/net/ipv6/addrconf.c
81234 @@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81235 p.iph.ihl = 5;
81236 p.iph.protocol = IPPROTO_IPV6;
81237 p.iph.ttl = 64;
81238 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81239 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81240
81241 if (ops->ndo_do_ioctl) {
81242 mm_segment_t oldfs = get_fs();
81243 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
81244 index 131dd09..7647ada 100644
81245 --- a/net/ipv6/ip6_gre.c
81246 +++ b/net/ipv6/ip6_gre.c
81247 @@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
81248 }
81249
81250
81251 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
81252 +static struct inet6_protocol ip6gre_protocol = {
81253 .handler = ip6gre_rcv,
81254 .err_handler = ip6gre_err,
81255 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
81256 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81257 index d1e2e8e..51c19ae 100644
81258 --- a/net/ipv6/ipv6_sockglue.c
81259 +++ b/net/ipv6/ipv6_sockglue.c
81260 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81261 if (sk->sk_type != SOCK_STREAM)
81262 return -ENOPROTOOPT;
81263
81264 - msg.msg_control = optval;
81265 + msg.msg_control = (void __force_kernel *)optval;
81266 msg.msg_controllen = len;
81267 msg.msg_flags = flags;
81268
81269 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81270 index 125a90d..2a11f36 100644
81271 --- a/net/ipv6/netfilter/ip6_tables.c
81272 +++ b/net/ipv6/netfilter/ip6_tables.c
81273 @@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
81274 #endif
81275
81276 static int get_info(struct net *net, void __user *user,
81277 - const int *len, int compat)
81278 + int len, int compat)
81279 {
81280 char name[XT_TABLE_MAXNAMELEN];
81281 struct xt_table *t;
81282 int ret;
81283
81284 - if (*len != sizeof(struct ip6t_getinfo)) {
81285 - duprintf("length %u != %zu\n", *len,
81286 + if (len != sizeof(struct ip6t_getinfo)) {
81287 + duprintf("length %u != %zu\n", len,
81288 sizeof(struct ip6t_getinfo));
81289 return -EINVAL;
81290 }
81291 @@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
81292 info.size = private->size;
81293 strcpy(info.name, name);
81294
81295 - if (copy_to_user(user, &info, *len) != 0)
81296 + if (copy_to_user(user, &info, len) != 0)
81297 ret = -EFAULT;
81298 else
81299 ret = 0;
81300 @@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81301
81302 switch (cmd) {
81303 case IP6T_SO_GET_INFO:
81304 - ret = get_info(sock_net(sk), user, len, 1);
81305 + ret = get_info(sock_net(sk), user, *len, 1);
81306 break;
81307 case IP6T_SO_GET_ENTRIES:
81308 ret = compat_get_entries(sock_net(sk), user, len);
81309 @@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81310
81311 switch (cmd) {
81312 case IP6T_SO_GET_INFO:
81313 - ret = get_info(sock_net(sk), user, len, 0);
81314 + ret = get_info(sock_net(sk), user, *len, 0);
81315 break;
81316
81317 case IP6T_SO_GET_ENTRIES:
81318 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81319 index 70fa814..d70c28c 100644
81320 --- a/net/ipv6/raw.c
81321 +++ b/net/ipv6/raw.c
81322 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
81323 {
81324 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
81325 skb_checksum_complete(skb)) {
81326 - atomic_inc(&sk->sk_drops);
81327 + atomic_inc_unchecked(&sk->sk_drops);
81328 kfree_skb(skb);
81329 return NET_RX_DROP;
81330 }
81331 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81332 struct raw6_sock *rp = raw6_sk(sk);
81333
81334 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81335 - atomic_inc(&sk->sk_drops);
81336 + atomic_inc_unchecked(&sk->sk_drops);
81337 kfree_skb(skb);
81338 return NET_RX_DROP;
81339 }
81340 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81341
81342 if (inet->hdrincl) {
81343 if (skb_checksum_complete(skb)) {
81344 - atomic_inc(&sk->sk_drops);
81345 + atomic_inc_unchecked(&sk->sk_drops);
81346 kfree_skb(skb);
81347 return NET_RX_DROP;
81348 }
81349 @@ -604,7 +604,7 @@ out:
81350 return err;
81351 }
81352
81353 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81354 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81355 struct flowi6 *fl6, struct dst_entry **dstp,
81356 unsigned int flags)
81357 {
81358 @@ -916,12 +916,15 @@ do_confirm:
81359 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81360 char __user *optval, int optlen)
81361 {
81362 + struct icmp6_filter filter;
81363 +
81364 switch (optname) {
81365 case ICMPV6_FILTER:
81366 if (optlen > sizeof(struct icmp6_filter))
81367 optlen = sizeof(struct icmp6_filter);
81368 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81369 + if (copy_from_user(&filter, optval, optlen))
81370 return -EFAULT;
81371 + raw6_sk(sk)->filter = filter;
81372 return 0;
81373 default:
81374 return -ENOPROTOOPT;
81375 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81376 char __user *optval, int __user *optlen)
81377 {
81378 int len;
81379 + struct icmp6_filter filter;
81380
81381 switch (optname) {
81382 case ICMPV6_FILTER:
81383 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81384 len = sizeof(struct icmp6_filter);
81385 if (put_user(len, optlen))
81386 return -EFAULT;
81387 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81388 + filter = raw6_sk(sk)->filter;
81389 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
81390 return -EFAULT;
81391 return 0;
81392 default:
81393 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81394 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81395 0,
81396 sock_i_ino(sp),
81397 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81398 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81399 }
81400
81401 static int raw6_seq_show(struct seq_file *seq, void *v)
81402 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81403 index 4f435371..5de9da7 100644
81404 --- a/net/ipv6/tcp_ipv6.c
81405 +++ b/net/ipv6/tcp_ipv6.c
81406 @@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
81407 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
81408 }
81409
81410 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81411 +extern int grsec_enable_blackhole;
81412 +#endif
81413 +
81414 static void tcp_v6_hash(struct sock *sk)
81415 {
81416 if (sk->sk_state != TCP_CLOSE) {
81417 @@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81418 return 0;
81419
81420 reset:
81421 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81422 + if (!grsec_enable_blackhole)
81423 +#endif
81424 tcp_v6_send_reset(sk, skb);
81425 discard:
81426 if (opt_skb)
81427 @@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81428 TCP_SKB_CB(skb)->sacked = 0;
81429
81430 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81431 - if (!sk)
81432 + if (!sk) {
81433 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81434 + ret = 1;
81435 +#endif
81436 goto no_tcp_socket;
81437 + }
81438
81439 process:
81440 - if (sk->sk_state == TCP_TIME_WAIT)
81441 + if (sk->sk_state == TCP_TIME_WAIT) {
81442 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81443 + ret = 2;
81444 +#endif
81445 goto do_time_wait;
81446 + }
81447
81448 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
81449 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81450 @@ -1568,6 +1583,10 @@ no_tcp_socket:
81451 bad_packet:
81452 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81453 } else {
81454 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81455 + if (!grsec_enable_blackhole || (ret == 1 &&
81456 + (skb->dev->flags & IFF_LOOPBACK)))
81457 +#endif
81458 tcp_v6_send_reset(NULL, skb);
81459 }
81460
81461 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81462 index fb08329..2d6919e 100644
81463 --- a/net/ipv6/udp.c
81464 +++ b/net/ipv6/udp.c
81465 @@ -51,6 +51,10 @@
81466 #include <trace/events/skb.h>
81467 #include "udp_impl.h"
81468
81469 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81470 +extern int grsec_enable_blackhole;
81471 +#endif
81472 +
81473 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81474 {
81475 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81476 @@ -395,7 +399,7 @@ try_again:
81477 if (unlikely(err)) {
81478 trace_kfree_skb(skb, udpv6_recvmsg);
81479 if (!peeked) {
81480 - atomic_inc(&sk->sk_drops);
81481 + atomic_inc_unchecked(&sk->sk_drops);
81482 if (is_udp4)
81483 UDP_INC_STATS_USER(sock_net(sk),
81484 UDP_MIB_INERRORS,
81485 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81486 return rc;
81487 drop:
81488 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81489 - atomic_inc(&sk->sk_drops);
81490 + atomic_inc_unchecked(&sk->sk_drops);
81491 kfree_skb(skb);
81492 return -1;
81493 }
81494 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81495 if (likely(skb1 == NULL))
81496 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81497 if (!skb1) {
81498 - atomic_inc(&sk->sk_drops);
81499 + atomic_inc_unchecked(&sk->sk_drops);
81500 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81501 IS_UDPLITE(sk));
81502 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81503 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81504 goto discard;
81505
81506 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81507 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81508 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81509 +#endif
81510 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
81511
81512 kfree_skb(skb);
81513 @@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81514 0,
81515 sock_i_ino(sp),
81516 atomic_read(&sp->sk_refcnt), sp,
81517 - atomic_read(&sp->sk_drops));
81518 + atomic_read_unchecked(&sp->sk_drops));
81519 }
81520
81521 int udp6_seq_show(struct seq_file *seq, void *v)
81522 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81523 index a68c88c..d55b0c5 100644
81524 --- a/net/irda/ircomm/ircomm_tty.c
81525 +++ b/net/irda/ircomm/ircomm_tty.c
81526 @@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81527 add_wait_queue(&port->open_wait, &wait);
81528
81529 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81530 - __FILE__, __LINE__, tty->driver->name, port->count);
81531 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81532
81533 spin_lock_irqsave(&port->lock, flags);
81534 if (!tty_hung_up_p(filp)) {
81535 extra_count = 1;
81536 - port->count--;
81537 + atomic_dec(&port->count);
81538 }
81539 spin_unlock_irqrestore(&port->lock, flags);
81540 port->blocked_open++;
81541 @@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81542 }
81543
81544 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81545 - __FILE__, __LINE__, tty->driver->name, port->count);
81546 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81547
81548 schedule();
81549 }
81550 @@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81551 if (extra_count) {
81552 /* ++ is not atomic, so this should be protected - Jean II */
81553 spin_lock_irqsave(&port->lock, flags);
81554 - port->count++;
81555 + atomic_inc(&port->count);
81556 spin_unlock_irqrestore(&port->lock, flags);
81557 }
81558 port->blocked_open--;
81559
81560 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81561 - __FILE__, __LINE__, tty->driver->name, port->count);
81562 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81563
81564 if (!retval)
81565 port->flags |= ASYNC_NORMAL_ACTIVE;
81566 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81567
81568 /* ++ is not atomic, so this should be protected - Jean II */
81569 spin_lock_irqsave(&self->port.lock, flags);
81570 - self->port.count++;
81571 + atomic_inc(&self->port.count);
81572 spin_unlock_irqrestore(&self->port.lock, flags);
81573 tty_port_tty_set(&self->port, tty);
81574
81575 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81576 - self->line, self->port.count);
81577 + self->line, atomic_read(&self->port.count));
81578
81579 /* Not really used by us, but lets do it anyway */
81580 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81581 @@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81582 tty_kref_put(port->tty);
81583 }
81584 port->tty = NULL;
81585 - port->count = 0;
81586 + atomic_set(&port->count, 0);
81587 spin_unlock_irqrestore(&port->lock, flags);
81588
81589 wake_up_interruptible(&port->open_wait);
81590 @@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81591 seq_putc(m, '\n');
81592
81593 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81594 - seq_printf(m, "Open count: %d\n", self->port.count);
81595 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
81596 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81597 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81598
81599 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81600 index cd6f7a9..e63fe89 100644
81601 --- a/net/iucv/af_iucv.c
81602 +++ b/net/iucv/af_iucv.c
81603 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
81604
81605 write_lock_bh(&iucv_sk_list.lock);
81606
81607 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81608 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81609 while (__iucv_get_sock_by_name(name)) {
81610 sprintf(name, "%08x",
81611 - atomic_inc_return(&iucv_sk_list.autobind_name));
81612 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81613 }
81614
81615 write_unlock_bh(&iucv_sk_list.lock);
81616 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
81617 index df08250..02021fe 100644
81618 --- a/net/iucv/iucv.c
81619 +++ b/net/iucv/iucv.c
81620 @@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
81621 return NOTIFY_OK;
81622 }
81623
81624 -static struct notifier_block __refdata iucv_cpu_notifier = {
81625 +static struct notifier_block iucv_cpu_notifier = {
81626 .notifier_call = iucv_cpu_notify,
81627 };
81628
81629 diff --git a/net/key/af_key.c b/net/key/af_key.c
81630 index 5b426a6..970032b 100644
81631 --- a/net/key/af_key.c
81632 +++ b/net/key/af_key.c
81633 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
81634 static u32 get_acqseq(void)
81635 {
81636 u32 res;
81637 - static atomic_t acqseq;
81638 + static atomic_unchecked_t acqseq;
81639
81640 do {
81641 - res = atomic_inc_return(&acqseq);
81642 + res = atomic_inc_return_unchecked(&acqseq);
81643 } while (!res);
81644 return res;
81645 }
81646 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81647 index 0479c64..d031db6 100644
81648 --- a/net/mac80211/cfg.c
81649 +++ b/net/mac80211/cfg.c
81650 @@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
81651 ret = ieee80211_vif_use_channel(sdata, chandef,
81652 IEEE80211_CHANCTX_EXCLUSIVE);
81653 }
81654 - } else if (local->open_count == local->monitors) {
81655 + } else if (local_read(&local->open_count) == local->monitors) {
81656 local->_oper_channel = chandef->chan;
81657 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
81658 ieee80211_hw_config(local, 0);
81659 @@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
81660 else
81661 local->probe_req_reg--;
81662
81663 - if (!local->open_count)
81664 + if (!local_read(&local->open_count))
81665 break;
81666
81667 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
81668 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81669 index 2ed065c..948177f 100644
81670 --- a/net/mac80211/ieee80211_i.h
81671 +++ b/net/mac80211/ieee80211_i.h
81672 @@ -28,6 +28,7 @@
81673 #include <net/ieee80211_radiotap.h>
81674 #include <net/cfg80211.h>
81675 #include <net/mac80211.h>
81676 +#include <asm/local.h>
81677 #include "key.h"
81678 #include "sta_info.h"
81679 #include "debug.h"
81680 @@ -909,7 +910,7 @@ struct ieee80211_local {
81681 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81682 spinlock_t queue_stop_reason_lock;
81683
81684 - int open_count;
81685 + local_t open_count;
81686 int monitors, cooked_mntrs;
81687 /* number of interfaces with corresponding FIF_ flags */
81688 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
81689 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81690 index 8be854e..ad72a69 100644
81691 --- a/net/mac80211/iface.c
81692 +++ b/net/mac80211/iface.c
81693 @@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81694 break;
81695 }
81696
81697 - if (local->open_count == 0) {
81698 + if (local_read(&local->open_count) == 0) {
81699 res = drv_start(local);
81700 if (res)
81701 goto err_del_bss;
81702 @@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81703 break;
81704 }
81705
81706 - if (local->monitors == 0 && local->open_count == 0) {
81707 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
81708 res = ieee80211_add_virtual_monitor(local);
81709 if (res)
81710 goto err_stop;
81711 @@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81712 mutex_unlock(&local->mtx);
81713
81714 if (coming_up)
81715 - local->open_count++;
81716 + local_inc(&local->open_count);
81717
81718 if (hw_reconf_flags)
81719 ieee80211_hw_config(local, hw_reconf_flags);
81720 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81721 err_del_interface:
81722 drv_remove_interface(local, sdata);
81723 err_stop:
81724 - if (!local->open_count)
81725 + if (!local_read(&local->open_count))
81726 drv_stop(local);
81727 err_del_bss:
81728 sdata->bss = NULL;
81729 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81730 }
81731
81732 if (going_down)
81733 - local->open_count--;
81734 + local_dec(&local->open_count);
81735
81736 switch (sdata->vif.type) {
81737 case NL80211_IFTYPE_AP_VLAN:
81738 @@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81739
81740 ieee80211_recalc_ps(local, -1);
81741
81742 - if (local->open_count == 0) {
81743 + if (local_read(&local->open_count) == 0) {
81744 if (local->ops->napi_poll)
81745 napi_disable(&local->napi);
81746 ieee80211_clear_tx_pending(local);
81747 @@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81748 }
81749 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
81750
81751 - if (local->monitors == local->open_count && local->monitors > 0)
81752 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
81753 ieee80211_add_virtual_monitor(local);
81754 }
81755
81756 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81757 index 1b087ff..bf600e9 100644
81758 --- a/net/mac80211/main.c
81759 +++ b/net/mac80211/main.c
81760 @@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81761 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
81762 IEEE80211_CONF_CHANGE_POWER);
81763
81764 - if (changed && local->open_count) {
81765 + if (changed && local_read(&local->open_count)) {
81766 ret = drv_config(local, changed);
81767 /*
81768 * Goal:
81769 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81770 index 79a48f3..5e185c9 100644
81771 --- a/net/mac80211/pm.c
81772 +++ b/net/mac80211/pm.c
81773 @@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81774 struct sta_info *sta;
81775 struct ieee80211_chanctx *ctx;
81776
81777 - if (!local->open_count)
81778 + if (!local_read(&local->open_count))
81779 goto suspend;
81780
81781 ieee80211_scan_cancel(local);
81782 @@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81783 cancel_work_sync(&local->dynamic_ps_enable_work);
81784 del_timer_sync(&local->dynamic_ps_timer);
81785
81786 - local->wowlan = wowlan && local->open_count;
81787 + local->wowlan = wowlan && local_read(&local->open_count);
81788 if (local->wowlan) {
81789 int err = drv_suspend(local, wowlan);
81790 if (err < 0) {
81791 @@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81792 mutex_unlock(&local->chanctx_mtx);
81793
81794 /* stop hardware - this must stop RX */
81795 - if (local->open_count)
81796 + if (local_read(&local->open_count))
81797 ieee80211_stop_device(local);
81798
81799 suspend:
81800 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
81801 index dd88381..eef4dd6 100644
81802 --- a/net/mac80211/rate.c
81803 +++ b/net/mac80211/rate.c
81804 @@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
81805
81806 ASSERT_RTNL();
81807
81808 - if (local->open_count)
81809 + if (local_read(&local->open_count))
81810 return -EBUSY;
81811
81812 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
81813 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
81814 index c97a065..ff61928 100644
81815 --- a/net/mac80211/rc80211_pid_debugfs.c
81816 +++ b/net/mac80211/rc80211_pid_debugfs.c
81817 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
81818
81819 spin_unlock_irqrestore(&events->lock, status);
81820
81821 - if (copy_to_user(buf, pb, p))
81822 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
81823 return -EFAULT;
81824
81825 return p;
81826 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
81827 index f11e8c5..08d0013 100644
81828 --- a/net/mac80211/util.c
81829 +++ b/net/mac80211/util.c
81830 @@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
81831 }
81832 #endif
81833 /* everything else happens only if HW was up & running */
81834 - if (!local->open_count)
81835 + if (!local_read(&local->open_count))
81836 goto wake_up;
81837
81838 /*
81839 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
81840 index 49e96df..63a51c3 100644
81841 --- a/net/netfilter/Kconfig
81842 +++ b/net/netfilter/Kconfig
81843 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
81844
81845 To compile it as a module, choose M here. If unsure, say N.
81846
81847 +config NETFILTER_XT_MATCH_GRADM
81848 + tristate '"gradm" match support'
81849 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
81850 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
81851 + ---help---
81852 + The gradm match allows to match on grsecurity RBAC being enabled.
81853 + It is useful when iptables rules are applied early on bootup to
81854 + prevent connections to the machine (except from a trusted host)
81855 + while the RBAC system is disabled.
81856 +
81857 config NETFILTER_XT_MATCH_HASHLIMIT
81858 tristate '"hashlimit" match support'
81859 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
81860 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
81861 index 3259697..54d5393 100644
81862 --- a/net/netfilter/Makefile
81863 +++ b/net/netfilter/Makefile
81864 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
81865 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
81866 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
81867 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
81868 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
81869 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
81870 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
81871 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
81872 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
81873 index 30e764a..c3b6a9d 100644
81874 --- a/net/netfilter/ipvs/ip_vs_conn.c
81875 +++ b/net/netfilter/ipvs/ip_vs_conn.c
81876 @@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
81877 /* Increase the refcnt counter of the dest */
81878 atomic_inc(&dest->refcnt);
81879
81880 - conn_flags = atomic_read(&dest->conn_flags);
81881 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
81882 if (cp->protocol != IPPROTO_UDP)
81883 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
81884 flags = cp->flags;
81885 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
81886 atomic_set(&cp->refcnt, 1);
81887
81888 atomic_set(&cp->n_control, 0);
81889 - atomic_set(&cp->in_pkts, 0);
81890 + atomic_set_unchecked(&cp->in_pkts, 0);
81891
81892 atomic_inc(&ipvs->conn_count);
81893 if (flags & IP_VS_CONN_F_NO_CPORT)
81894 @@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
81895
81896 /* Don't drop the entry if its number of incoming packets is not
81897 located in [0, 8] */
81898 - i = atomic_read(&cp->in_pkts);
81899 + i = atomic_read_unchecked(&cp->in_pkts);
81900 if (i > 8 || i < 0) return 0;
81901
81902 if (!todrop_rate[i]) return 0;
81903 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81904 index 47edf5a..235b07d 100644
81905 --- a/net/netfilter/ipvs/ip_vs_core.c
81906 +++ b/net/netfilter/ipvs/ip_vs_core.c
81907 @@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81908 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
81909 /* do not touch skb anymore */
81910
81911 - atomic_inc(&cp->in_pkts);
81912 + atomic_inc_unchecked(&cp->in_pkts);
81913 ip_vs_conn_put(cp);
81914 return ret;
81915 }
81916 @@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
81917 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
81918 pkts = sysctl_sync_threshold(ipvs);
81919 else
81920 - pkts = atomic_add_return(1, &cp->in_pkts);
81921 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81922
81923 if (ipvs->sync_state & IP_VS_STATE_MASTER)
81924 ip_vs_sync_conn(net, cp, pkts);
81925 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81926 index ec664cb..cd576ab 100644
81927 --- a/net/netfilter/ipvs/ip_vs_ctl.c
81928 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
81929 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
81930 ip_vs_rs_hash(ipvs, dest);
81931 write_unlock_bh(&ipvs->rs_lock);
81932 }
81933 - atomic_set(&dest->conn_flags, conn_flags);
81934 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
81935
81936 /* bind the service */
81937 if (!dest->svc) {
81938 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81939 " %-7s %-6d %-10d %-10d\n",
81940 &dest->addr.in6,
81941 ntohs(dest->port),
81942 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81943 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81944 atomic_read(&dest->weight),
81945 atomic_read(&dest->activeconns),
81946 atomic_read(&dest->inactconns));
81947 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81948 "%-7s %-6d %-10d %-10d\n",
81949 ntohl(dest->addr.ip),
81950 ntohs(dest->port),
81951 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81952 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81953 atomic_read(&dest->weight),
81954 atomic_read(&dest->activeconns),
81955 atomic_read(&dest->inactconns));
81956 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
81957
81958 entry.addr = dest->addr.ip;
81959 entry.port = dest->port;
81960 - entry.conn_flags = atomic_read(&dest->conn_flags);
81961 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81962 entry.weight = atomic_read(&dest->weight);
81963 entry.u_threshold = dest->u_threshold;
81964 entry.l_threshold = dest->l_threshold;
81965 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81966 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
81967 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
81968 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81969 - (atomic_read(&dest->conn_flags) &
81970 + (atomic_read_unchecked(&dest->conn_flags) &
81971 IP_VS_CONN_F_FWD_MASK)) ||
81972 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
81973 atomic_read(&dest->weight)) ||
81974 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81975 index 44fd10c..2a163b3 100644
81976 --- a/net/netfilter/ipvs/ip_vs_sync.c
81977 +++ b/net/netfilter/ipvs/ip_vs_sync.c
81978 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
81979 cp = cp->control;
81980 if (cp) {
81981 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81982 - pkts = atomic_add_return(1, &cp->in_pkts);
81983 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81984 else
81985 pkts = sysctl_sync_threshold(ipvs);
81986 ip_vs_sync_conn(net, cp->control, pkts);
81987 @@ -758,7 +758,7 @@ control:
81988 if (!cp)
81989 return;
81990 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81991 - pkts = atomic_add_return(1, &cp->in_pkts);
81992 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81993 else
81994 pkts = sysctl_sync_threshold(ipvs);
81995 goto sloop;
81996 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
81997
81998 if (opt)
81999 memcpy(&cp->in_seq, opt, sizeof(*opt));
82000 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82001 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82002 cp->state = state;
82003 cp->old_state = cp->state;
82004 /*
82005 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
82006 index ee6b7a9..f9a89f6 100644
82007 --- a/net/netfilter/ipvs/ip_vs_xmit.c
82008 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
82009 @@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
82010 else
82011 rc = NF_ACCEPT;
82012 /* do not touch skb anymore */
82013 - atomic_inc(&cp->in_pkts);
82014 + atomic_inc_unchecked(&cp->in_pkts);
82015 goto out;
82016 }
82017
82018 @@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
82019 else
82020 rc = NF_ACCEPT;
82021 /* do not touch skb anymore */
82022 - atomic_inc(&cp->in_pkts);
82023 + atomic_inc_unchecked(&cp->in_pkts);
82024 goto out;
82025 }
82026
82027 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
82028 index e4a0c4f..c263f28 100644
82029 --- a/net/netfilter/nf_conntrack_core.c
82030 +++ b/net/netfilter/nf_conntrack_core.c
82031 @@ -1529,6 +1529,10 @@ err_extend:
82032 #define DYING_NULLS_VAL ((1<<30)+1)
82033 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
82034
82035 +#ifdef CONFIG_GRKERNSEC_HIDESYM
82036 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
82037 +#endif
82038 +
82039 static int nf_conntrack_init_net(struct net *net)
82040 {
82041 int ret;
82042 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
82043 goto err_stat;
82044 }
82045
82046 +#ifdef CONFIG_GRKERNSEC_HIDESYM
82047 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
82048 +#else
82049 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
82050 +#endif
82051 if (!net->ct.slabname) {
82052 ret = -ENOMEM;
82053 goto err_slabname;
82054 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
82055 index 92fd8ec..3f6ea4b 100644
82056 --- a/net/netfilter/nfnetlink_log.c
82057 +++ b/net/netfilter/nfnetlink_log.c
82058 @@ -72,7 +72,7 @@ struct nfulnl_instance {
82059 };
82060
82061 static DEFINE_SPINLOCK(instances_lock);
82062 -static atomic_t global_seq;
82063 +static atomic_unchecked_t global_seq;
82064
82065 #define INSTANCE_BUCKETS 16
82066 static struct hlist_head instance_table[INSTANCE_BUCKETS];
82067 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
82068 /* global sequence number */
82069 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
82070 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
82071 - htonl(atomic_inc_return(&global_seq))))
82072 + htonl(atomic_inc_return_unchecked(&global_seq))))
82073 goto nla_put_failure;
82074
82075 if (data_len) {
82076 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
82077 new file mode 100644
82078 index 0000000..c566332
82079 --- /dev/null
82080 +++ b/net/netfilter/xt_gradm.c
82081 @@ -0,0 +1,51 @@
82082 +/*
82083 + * gradm match for netfilter
82084 + * Copyright © Zbigniew Krzystolik, 2010
82085 + *
82086 + * This program is free software; you can redistribute it and/or modify
82087 + * it under the terms of the GNU General Public License; either version
82088 + * 2 or 3 as published by the Free Software Foundation.
82089 + */
82090 +#include <linux/module.h>
82091 +#include <linux/moduleparam.h>
82092 +#include <linux/skbuff.h>
82093 +#include <linux/netfilter/x_tables.h>
82094 +#include <linux/grsecurity.h>
82095 +#include <linux/netfilter/xt_gradm.h>
82096 +
82097 +static bool
82098 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
82099 +{
82100 + const struct xt_gradm_mtinfo *info = par->matchinfo;
82101 + bool retval = false;
82102 + if (gr_acl_is_enabled())
82103 + retval = true;
82104 + return retval ^ info->invflags;
82105 +}
82106 +
82107 +static struct xt_match gradm_mt_reg __read_mostly = {
82108 + .name = "gradm",
82109 + .revision = 0,
82110 + .family = NFPROTO_UNSPEC,
82111 + .match = gradm_mt,
82112 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
82113 + .me = THIS_MODULE,
82114 +};
82115 +
82116 +static int __init gradm_mt_init(void)
82117 +{
82118 + return xt_register_match(&gradm_mt_reg);
82119 +}
82120 +
82121 +static void __exit gradm_mt_exit(void)
82122 +{
82123 + xt_unregister_match(&gradm_mt_reg);
82124 +}
82125 +
82126 +module_init(gradm_mt_init);
82127 +module_exit(gradm_mt_exit);
82128 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
82129 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
82130 +MODULE_LICENSE("GPL");
82131 +MODULE_ALIAS("ipt_gradm");
82132 +MODULE_ALIAS("ip6t_gradm");
82133 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
82134 index 4fe4fb4..87a89e5 100644
82135 --- a/net/netfilter/xt_statistic.c
82136 +++ b/net/netfilter/xt_statistic.c
82137 @@ -19,7 +19,7 @@
82138 #include <linux/module.h>
82139
82140 struct xt_statistic_priv {
82141 - atomic_t count;
82142 + atomic_unchecked_t count;
82143 } ____cacheline_aligned_in_smp;
82144
82145 MODULE_LICENSE("GPL");
82146 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
82147 break;
82148 case XT_STATISTIC_MODE_NTH:
82149 do {
82150 - oval = atomic_read(&info->master->count);
82151 + oval = atomic_read_unchecked(&info->master->count);
82152 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
82153 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
82154 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
82155 if (nval == 0)
82156 ret = !ret;
82157 break;
82158 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
82159 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
82160 if (info->master == NULL)
82161 return -ENOMEM;
82162 - atomic_set(&info->master->count, info->u.nth.count);
82163 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
82164
82165 return 0;
82166 }
82167 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
82168 index c0353d5..fcb0270 100644
82169 --- a/net/netlink/af_netlink.c
82170 +++ b/net/netlink/af_netlink.c
82171 @@ -785,7 +785,7 @@ static void netlink_overrun(struct sock *sk)
82172 sk->sk_error_report(sk);
82173 }
82174 }
82175 - atomic_inc(&sk->sk_drops);
82176 + atomic_inc_unchecked(&sk->sk_drops);
82177 }
82178
82179 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
82180 @@ -2071,7 +2071,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
82181 sk_wmem_alloc_get(s),
82182 nlk->cb,
82183 atomic_read(&s->sk_refcnt),
82184 - atomic_read(&s->sk_drops),
82185 + atomic_read_unchecked(&s->sk_drops),
82186 sock_i_ino(s)
82187 );
82188
82189 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
82190 index 7261eb8..44e8ac6 100644
82191 --- a/net/netrom/af_netrom.c
82192 +++ b/net/netrom/af_netrom.c
82193 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
82194 struct sock *sk = sock->sk;
82195 struct nr_sock *nr = nr_sk(sk);
82196
82197 + memset(sax, 0, sizeof(*sax));
82198 lock_sock(sk);
82199 if (peer != 0) {
82200 if (sk->sk_state != TCP_ESTABLISHED) {
82201 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
82202 *uaddr_len = sizeof(struct full_sockaddr_ax25);
82203 } else {
82204 sax->fsa_ax25.sax25_family = AF_NETROM;
82205 - sax->fsa_ax25.sax25_ndigis = 0;
82206 sax->fsa_ax25.sax25_call = nr->source_addr;
82207 *uaddr_len = sizeof(struct sockaddr_ax25);
82208 }
82209 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
82210 index c111bd0..7788ff7 100644
82211 --- a/net/packet/af_packet.c
82212 +++ b/net/packet/af_packet.c
82213 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
82214
82215 spin_lock(&sk->sk_receive_queue.lock);
82216 po->stats.tp_packets++;
82217 - skb->dropcount = atomic_read(&sk->sk_drops);
82218 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
82219 __skb_queue_tail(&sk->sk_receive_queue, skb);
82220 spin_unlock(&sk->sk_receive_queue.lock);
82221 sk->sk_data_ready(sk, skb->len);
82222 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
82223 drop_n_acct:
82224 spin_lock(&sk->sk_receive_queue.lock);
82225 po->stats.tp_drops++;
82226 - atomic_inc(&sk->sk_drops);
82227 + atomic_inc_unchecked(&sk->sk_drops);
82228 spin_unlock(&sk->sk_receive_queue.lock);
82229
82230 drop_n_restore:
82231 @@ -2565,6 +2565,7 @@ out:
82232
82233 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
82234 {
82235 + struct sock_extended_err ee;
82236 struct sock_exterr_skb *serr;
82237 struct sk_buff *skb, *skb2;
82238 int copied, err;
82239 @@ -2586,8 +2587,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
82240 sock_recv_timestamp(msg, sk, skb);
82241
82242 serr = SKB_EXT_ERR(skb);
82243 + ee = serr->ee;
82244 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
82245 - sizeof(serr->ee), &serr->ee);
82246 + sizeof ee, &ee);
82247
82248 msg->msg_flags |= MSG_ERRQUEUE;
82249 err = copied;
82250 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
82251 case PACKET_HDRLEN:
82252 if (len > sizeof(int))
82253 len = sizeof(int);
82254 - if (copy_from_user(&val, optval, len))
82255 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
82256 return -EFAULT;
82257 switch (val) {
82258 case TPACKET_V1:
82259 @@ -3254,7 +3256,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
82260 len = lv;
82261 if (put_user(len, optlen))
82262 return -EFAULT;
82263 - if (copy_to_user(optval, data, len))
82264 + if (len > sizeof(st) || copy_to_user(optval, data, len))
82265 return -EFAULT;
82266 return 0;
82267 }
82268 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
82269 index 5a940db..f0b9c12 100644
82270 --- a/net/phonet/af_phonet.c
82271 +++ b/net/phonet/af_phonet.c
82272 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
82273 {
82274 struct phonet_protocol *pp;
82275
82276 - if (protocol >= PHONET_NPROTO)
82277 + if (protocol < 0 || protocol >= PHONET_NPROTO)
82278 return NULL;
82279
82280 rcu_read_lock();
82281 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
82282 {
82283 int err = 0;
82284
82285 - if (protocol >= PHONET_NPROTO)
82286 + if (protocol < 0 || protocol >= PHONET_NPROTO)
82287 return -EINVAL;
82288
82289 err = proto_register(pp->prot, 1);
82290 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
82291 index 576f22c..bc7a71b 100644
82292 --- a/net/phonet/pep.c
82293 +++ b/net/phonet/pep.c
82294 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
82295
82296 case PNS_PEP_CTRL_REQ:
82297 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
82298 - atomic_inc(&sk->sk_drops);
82299 + atomic_inc_unchecked(&sk->sk_drops);
82300 break;
82301 }
82302 __skb_pull(skb, 4);
82303 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
82304 }
82305
82306 if (pn->rx_credits == 0) {
82307 - atomic_inc(&sk->sk_drops);
82308 + atomic_inc_unchecked(&sk->sk_drops);
82309 err = -ENOBUFS;
82310 break;
82311 }
82312 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
82313 }
82314
82315 if (pn->rx_credits == 0) {
82316 - atomic_inc(&sk->sk_drops);
82317 + atomic_inc_unchecked(&sk->sk_drops);
82318 err = NET_RX_DROP;
82319 break;
82320 }
82321 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
82322 index b7e9827..c264c85 100644
82323 --- a/net/phonet/socket.c
82324 +++ b/net/phonet/socket.c
82325 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
82326 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
82327 sock_i_ino(sk),
82328 atomic_read(&sk->sk_refcnt), sk,
82329 - atomic_read(&sk->sk_drops), &len);
82330 + atomic_read_unchecked(&sk->sk_drops), &len);
82331 }
82332 seq_printf(seq, "%*s\n", 127 - len, "");
82333 return 0;
82334 diff --git a/net/rds/cong.c b/net/rds/cong.c
82335 index e5b65ac..f3b6fb7 100644
82336 --- a/net/rds/cong.c
82337 +++ b/net/rds/cong.c
82338 @@ -78,7 +78,7 @@
82339 * finds that the saved generation number is smaller than the global generation
82340 * number, it wakes up the process.
82341 */
82342 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
82343 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
82344
82345 /*
82346 * Congestion monitoring
82347 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
82348 rdsdebug("waking map %p for %pI4\n",
82349 map, &map->m_addr);
82350 rds_stats_inc(s_cong_update_received);
82351 - atomic_inc(&rds_cong_generation);
82352 + atomic_inc_unchecked(&rds_cong_generation);
82353 if (waitqueue_active(&map->m_waitq))
82354 wake_up(&map->m_waitq);
82355 if (waitqueue_active(&rds_poll_waitq))
82356 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
82357
82358 int rds_cong_updated_since(unsigned long *recent)
82359 {
82360 - unsigned long gen = atomic_read(&rds_cong_generation);
82361 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
82362
82363 if (likely(*recent == gen))
82364 return 0;
82365 diff --git a/net/rds/ib.h b/net/rds/ib.h
82366 index 7280ab8..e04f4ea 100644
82367 --- a/net/rds/ib.h
82368 +++ b/net/rds/ib.h
82369 @@ -128,7 +128,7 @@ struct rds_ib_connection {
82370 /* sending acks */
82371 unsigned long i_ack_flags;
82372 #ifdef KERNEL_HAS_ATOMIC64
82373 - atomic64_t i_ack_next; /* next ACK to send */
82374 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
82375 #else
82376 spinlock_t i_ack_lock; /* protect i_ack_next */
82377 u64 i_ack_next; /* next ACK to send */
82378 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
82379 index 31b74f5..dc1fbfa 100644
82380 --- a/net/rds/ib_cm.c
82381 +++ b/net/rds/ib_cm.c
82382 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
82383 /* Clear the ACK state */
82384 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
82385 #ifdef KERNEL_HAS_ATOMIC64
82386 - atomic64_set(&ic->i_ack_next, 0);
82387 + atomic64_set_unchecked(&ic->i_ack_next, 0);
82388 #else
82389 ic->i_ack_next = 0;
82390 #endif
82391 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
82392 index 8eb9501..0c386ff 100644
82393 --- a/net/rds/ib_recv.c
82394 +++ b/net/rds/ib_recv.c
82395 @@ -597,7 +597,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
82396 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
82397 int ack_required)
82398 {
82399 - atomic64_set(&ic->i_ack_next, seq);
82400 + atomic64_set_unchecked(&ic->i_ack_next, seq);
82401 if (ack_required) {
82402 smp_mb__before_clear_bit();
82403 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82404 @@ -609,7 +609,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
82405 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82406 smp_mb__after_clear_bit();
82407
82408 - return atomic64_read(&ic->i_ack_next);
82409 + return atomic64_read_unchecked(&ic->i_ack_next);
82410 }
82411 #endif
82412
82413 diff --git a/net/rds/iw.h b/net/rds/iw.h
82414 index 04ce3b1..48119a6 100644
82415 --- a/net/rds/iw.h
82416 +++ b/net/rds/iw.h
82417 @@ -134,7 +134,7 @@ struct rds_iw_connection {
82418 /* sending acks */
82419 unsigned long i_ack_flags;
82420 #ifdef KERNEL_HAS_ATOMIC64
82421 - atomic64_t i_ack_next; /* next ACK to send */
82422 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
82423 #else
82424 spinlock_t i_ack_lock; /* protect i_ack_next */
82425 u64 i_ack_next; /* next ACK to send */
82426 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
82427 index a91e1db..cf3053f 100644
82428 --- a/net/rds/iw_cm.c
82429 +++ b/net/rds/iw_cm.c
82430 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
82431 /* Clear the ACK state */
82432 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
82433 #ifdef KERNEL_HAS_ATOMIC64
82434 - atomic64_set(&ic->i_ack_next, 0);
82435 + atomic64_set_unchecked(&ic->i_ack_next, 0);
82436 #else
82437 ic->i_ack_next = 0;
82438 #endif
82439 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
82440 index 4503335..db566b4 100644
82441 --- a/net/rds/iw_recv.c
82442 +++ b/net/rds/iw_recv.c
82443 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
82444 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
82445 int ack_required)
82446 {
82447 - atomic64_set(&ic->i_ack_next, seq);
82448 + atomic64_set_unchecked(&ic->i_ack_next, seq);
82449 if (ack_required) {
82450 smp_mb__before_clear_bit();
82451 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82452 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
82453 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82454 smp_mb__after_clear_bit();
82455
82456 - return atomic64_read(&ic->i_ack_next);
82457 + return atomic64_read_unchecked(&ic->i_ack_next);
82458 }
82459 #endif
82460
82461 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
82462 index edac9ef..16bcb98 100644
82463 --- a/net/rds/tcp.c
82464 +++ b/net/rds/tcp.c
82465 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
82466 int val = 1;
82467
82468 set_fs(KERNEL_DS);
82469 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
82470 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
82471 sizeof(val));
82472 set_fs(oldfs);
82473 }
82474 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
82475 index 81cf5a4..b5826ff 100644
82476 --- a/net/rds/tcp_send.c
82477 +++ b/net/rds/tcp_send.c
82478 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
82479
82480 oldfs = get_fs();
82481 set_fs(KERNEL_DS);
82482 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
82483 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
82484 sizeof(val));
82485 set_fs(oldfs);
82486 }
82487 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
82488 index 05996d0..5a1dfe0 100644
82489 --- a/net/rxrpc/af_rxrpc.c
82490 +++ b/net/rxrpc/af_rxrpc.c
82491 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
82492 __be32 rxrpc_epoch;
82493
82494 /* current debugging ID */
82495 -atomic_t rxrpc_debug_id;
82496 +atomic_unchecked_t rxrpc_debug_id;
82497
82498 /* count of skbs currently in use */
82499 atomic_t rxrpc_n_skbs;
82500 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
82501 index e4d9cbc..b229649 100644
82502 --- a/net/rxrpc/ar-ack.c
82503 +++ b/net/rxrpc/ar-ack.c
82504 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
82505
82506 _enter("{%d,%d,%d,%d},",
82507 call->acks_hard, call->acks_unacked,
82508 - atomic_read(&call->sequence),
82509 + atomic_read_unchecked(&call->sequence),
82510 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
82511
82512 stop = 0;
82513 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
82514
82515 /* each Tx packet has a new serial number */
82516 sp->hdr.serial =
82517 - htonl(atomic_inc_return(&call->conn->serial));
82518 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
82519
82520 hdr = (struct rxrpc_header *) txb->head;
82521 hdr->serial = sp->hdr.serial;
82522 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
82523 */
82524 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
82525 {
82526 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
82527 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
82528 }
82529
82530 /*
82531 @@ -629,7 +629,7 @@ process_further:
82532
82533 latest = ntohl(sp->hdr.serial);
82534 hard = ntohl(ack.firstPacket);
82535 - tx = atomic_read(&call->sequence);
82536 + tx = atomic_read_unchecked(&call->sequence);
82537
82538 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
82539 latest,
82540 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
82541 goto maybe_reschedule;
82542
82543 send_ACK_with_skew:
82544 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
82545 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
82546 ntohl(ack.serial));
82547 send_ACK:
82548 mtu = call->conn->trans->peer->if_mtu;
82549 @@ -1173,7 +1173,7 @@ send_ACK:
82550 ackinfo.rxMTU = htonl(5692);
82551 ackinfo.jumbo_max = htonl(4);
82552
82553 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
82554 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
82555 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
82556 ntohl(hdr.serial),
82557 ntohs(ack.maxSkew),
82558 @@ -1191,7 +1191,7 @@ send_ACK:
82559 send_message:
82560 _debug("send message");
82561
82562 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
82563 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
82564 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
82565 send_message_2:
82566
82567 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
82568 index a3bbb36..3341fb9 100644
82569 --- a/net/rxrpc/ar-call.c
82570 +++ b/net/rxrpc/ar-call.c
82571 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
82572 spin_lock_init(&call->lock);
82573 rwlock_init(&call->state_lock);
82574 atomic_set(&call->usage, 1);
82575 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
82576 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82577 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
82578
82579 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
82580 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
82581 index 4106ca9..a338d7a 100644
82582 --- a/net/rxrpc/ar-connection.c
82583 +++ b/net/rxrpc/ar-connection.c
82584 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
82585 rwlock_init(&conn->lock);
82586 spin_lock_init(&conn->state_lock);
82587 atomic_set(&conn->usage, 1);
82588 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
82589 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82590 conn->avail_calls = RXRPC_MAXCALLS;
82591 conn->size_align = 4;
82592 conn->header_size = sizeof(struct rxrpc_header);
82593 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
82594 index e7ed43a..6afa140 100644
82595 --- a/net/rxrpc/ar-connevent.c
82596 +++ b/net/rxrpc/ar-connevent.c
82597 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
82598
82599 len = iov[0].iov_len + iov[1].iov_len;
82600
82601 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
82602 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82603 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
82604
82605 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
82606 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
82607 index 529572f..c758ca7 100644
82608 --- a/net/rxrpc/ar-input.c
82609 +++ b/net/rxrpc/ar-input.c
82610 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
82611 /* track the latest serial number on this connection for ACK packet
82612 * information */
82613 serial = ntohl(sp->hdr.serial);
82614 - hi_serial = atomic_read(&call->conn->hi_serial);
82615 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
82616 while (serial > hi_serial)
82617 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
82618 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
82619 serial);
82620
82621 /* request ACK generation for any ACK or DATA packet that requests
82622 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
82623 index a693aca..81e7293 100644
82624 --- a/net/rxrpc/ar-internal.h
82625 +++ b/net/rxrpc/ar-internal.h
82626 @@ -272,8 +272,8 @@ struct rxrpc_connection {
82627 int error; /* error code for local abort */
82628 int debug_id; /* debug ID for printks */
82629 unsigned int call_counter; /* call ID counter */
82630 - atomic_t serial; /* packet serial number counter */
82631 - atomic_t hi_serial; /* highest serial number received */
82632 + atomic_unchecked_t serial; /* packet serial number counter */
82633 + atomic_unchecked_t hi_serial; /* highest serial number received */
82634 u8 avail_calls; /* number of calls available */
82635 u8 size_align; /* data size alignment (for security) */
82636 u8 header_size; /* rxrpc + security header size */
82637 @@ -346,7 +346,7 @@ struct rxrpc_call {
82638 spinlock_t lock;
82639 rwlock_t state_lock; /* lock for state transition */
82640 atomic_t usage;
82641 - atomic_t sequence; /* Tx data packet sequence counter */
82642 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
82643 u32 abort_code; /* local/remote abort code */
82644 enum { /* current state of call */
82645 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
82646 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
82647 */
82648 extern atomic_t rxrpc_n_skbs;
82649 extern __be32 rxrpc_epoch;
82650 -extern atomic_t rxrpc_debug_id;
82651 +extern atomic_unchecked_t rxrpc_debug_id;
82652 extern struct workqueue_struct *rxrpc_workqueue;
82653
82654 /*
82655 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
82656 index 87f7135..74d3703 100644
82657 --- a/net/rxrpc/ar-local.c
82658 +++ b/net/rxrpc/ar-local.c
82659 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
82660 spin_lock_init(&local->lock);
82661 rwlock_init(&local->services_lock);
82662 atomic_set(&local->usage, 1);
82663 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
82664 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82665 memcpy(&local->srx, srx, sizeof(*srx));
82666 }
82667
82668 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
82669 index e1ac183..b43e10e 100644
82670 --- a/net/rxrpc/ar-output.c
82671 +++ b/net/rxrpc/ar-output.c
82672 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
82673 sp->hdr.cid = call->cid;
82674 sp->hdr.callNumber = call->call_id;
82675 sp->hdr.seq =
82676 - htonl(atomic_inc_return(&call->sequence));
82677 + htonl(atomic_inc_return_unchecked(&call->sequence));
82678 sp->hdr.serial =
82679 - htonl(atomic_inc_return(&conn->serial));
82680 + htonl(atomic_inc_return_unchecked(&conn->serial));
82681 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
82682 sp->hdr.userStatus = 0;
82683 sp->hdr.securityIndex = conn->security_ix;
82684 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
82685 index bebaa43..2644591 100644
82686 --- a/net/rxrpc/ar-peer.c
82687 +++ b/net/rxrpc/ar-peer.c
82688 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
82689 INIT_LIST_HEAD(&peer->error_targets);
82690 spin_lock_init(&peer->lock);
82691 atomic_set(&peer->usage, 1);
82692 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
82693 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82694 memcpy(&peer->srx, srx, sizeof(*srx));
82695
82696 rxrpc_assess_MTU_size(peer);
82697 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
82698 index 38047f7..9f48511 100644
82699 --- a/net/rxrpc/ar-proc.c
82700 +++ b/net/rxrpc/ar-proc.c
82701 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
82702 atomic_read(&conn->usage),
82703 rxrpc_conn_states[conn->state],
82704 key_serial(conn->key),
82705 - atomic_read(&conn->serial),
82706 - atomic_read(&conn->hi_serial));
82707 + atomic_read_unchecked(&conn->serial),
82708 + atomic_read_unchecked(&conn->hi_serial));
82709
82710 return 0;
82711 }
82712 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
82713 index 92df566..87ec1bf 100644
82714 --- a/net/rxrpc/ar-transport.c
82715 +++ b/net/rxrpc/ar-transport.c
82716 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
82717 spin_lock_init(&trans->client_lock);
82718 rwlock_init(&trans->conn_lock);
82719 atomic_set(&trans->usage, 1);
82720 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
82721 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82722
82723 if (peer->srx.transport.family == AF_INET) {
82724 switch (peer->srx.transport_type) {
82725 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
82726 index f226709..0e735a8 100644
82727 --- a/net/rxrpc/rxkad.c
82728 +++ b/net/rxrpc/rxkad.c
82729 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
82730
82731 len = iov[0].iov_len + iov[1].iov_len;
82732
82733 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
82734 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82735 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
82736
82737 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
82738 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
82739
82740 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
82741
82742 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
82743 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82744 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
82745
82746 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
82747 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
82748 index 391a245..8f6a898 100644
82749 --- a/net/sctp/ipv6.c
82750 +++ b/net/sctp/ipv6.c
82751 @@ -1038,7 +1038,7 @@ void sctp_v6_pf_init(void)
82752
82753 void sctp_v6_pf_exit(void)
82754 {
82755 - list_del(&sctp_af_inet6.list);
82756 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
82757 }
82758
82759 /* Initialize IPv6 support and register with socket layer. */
82760 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
82761 index 8c19e97..16264b8 100644
82762 --- a/net/sctp/proc.c
82763 +++ b/net/sctp/proc.c
82764 @@ -338,7 +338,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
82765 seq_printf(seq,
82766 "%8pK %8pK %-3d %-3d %-2d %-4d "
82767 "%4d %8d %8d %7d %5lu %-5d %5d ",
82768 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
82769 + assoc, sk,
82770 + sctp_sk(sk)->type, sk->sk_state,
82771 assoc->state, hash,
82772 assoc->assoc_id,
82773 assoc->sndbuf_used,
82774 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
82775 index f898b1c..60bf8f2 100644
82776 --- a/net/sctp/protocol.c
82777 +++ b/net/sctp/protocol.c
82778 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
82779 return 0;
82780 }
82781
82782 - INIT_LIST_HEAD(&af->list);
82783 - list_add_tail(&af->list, &sctp_address_families);
82784 + pax_open_kernel();
82785 + INIT_LIST_HEAD((struct list_head *)&af->list);
82786 + pax_close_kernel();
82787 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
82788 return 1;
82789 }
82790
82791 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
82792
82793 static void sctp_v4_pf_exit(void)
82794 {
82795 - list_del(&sctp_af_inet.list);
82796 + pax_list_del((struct list_head *)&sctp_af_inet.list);
82797 }
82798
82799 static int sctp_v4_protosw_init(void)
82800 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
82801 index cedd9bf..b1fddeb 100644
82802 --- a/net/sctp/socket.c
82803 +++ b/net/sctp/socket.c
82804 @@ -4665,6 +4665,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
82805 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
82806 if (space_left < addrlen)
82807 return -ENOMEM;
82808 + if (addrlen > sizeof(temp) || addrlen < 0)
82809 + return -EFAULT;
82810 if (copy_to_user(to, &temp, addrlen))
82811 return -EFAULT;
82812 to += addrlen;
82813 diff --git a/net/socket.c b/net/socket.c
82814 index 2ca51c7..45d0b31 100644
82815 --- a/net/socket.c
82816 +++ b/net/socket.c
82817 @@ -89,6 +89,7 @@
82818 #include <linux/magic.h>
82819 #include <linux/slab.h>
82820 #include <linux/xattr.h>
82821 +#include <linux/in.h>
82822
82823 #include <asm/uaccess.h>
82824 #include <asm/unistd.h>
82825 @@ -106,6 +107,8 @@
82826 #include <linux/sockios.h>
82827 #include <linux/atalk.h>
82828
82829 +#include <linux/grsock.h>
82830 +
82831 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
82832 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
82833 unsigned long nr_segs, loff_t pos);
82834 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
82835 &sockfs_dentry_operations, SOCKFS_MAGIC);
82836 }
82837
82838 -static struct vfsmount *sock_mnt __read_mostly;
82839 +struct vfsmount *sock_mnt __read_mostly;
82840
82841 static struct file_system_type sock_fs_type = {
82842 .name = "sockfs",
82843 @@ -1270,6 +1273,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
82844 return -EAFNOSUPPORT;
82845 if (type < 0 || type >= SOCK_MAX)
82846 return -EINVAL;
82847 + if (protocol < 0)
82848 + return -EINVAL;
82849
82850 /* Compatibility.
82851
82852 @@ -1401,6 +1406,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
82853 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
82854 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
82855
82856 + if(!gr_search_socket(family, type, protocol)) {
82857 + retval = -EACCES;
82858 + goto out;
82859 + }
82860 +
82861 + if (gr_handle_sock_all(family, type, protocol)) {
82862 + retval = -EACCES;
82863 + goto out;
82864 + }
82865 +
82866 retval = sock_create(family, type, protocol, &sock);
82867 if (retval < 0)
82868 goto out;
82869 @@ -1528,6 +1543,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
82870 if (sock) {
82871 err = move_addr_to_kernel(umyaddr, addrlen, &address);
82872 if (err >= 0) {
82873 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
82874 + err = -EACCES;
82875 + goto error;
82876 + }
82877 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
82878 + if (err)
82879 + goto error;
82880 +
82881 err = security_socket_bind(sock,
82882 (struct sockaddr *)&address,
82883 addrlen);
82884 @@ -1536,6 +1559,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
82885 (struct sockaddr *)
82886 &address, addrlen);
82887 }
82888 +error:
82889 fput_light(sock->file, fput_needed);
82890 }
82891 return err;
82892 @@ -1559,10 +1583,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
82893 if ((unsigned int)backlog > somaxconn)
82894 backlog = somaxconn;
82895
82896 + if (gr_handle_sock_server_other(sock->sk)) {
82897 + err = -EPERM;
82898 + goto error;
82899 + }
82900 +
82901 + err = gr_search_listen(sock);
82902 + if (err)
82903 + goto error;
82904 +
82905 err = security_socket_listen(sock, backlog);
82906 if (!err)
82907 err = sock->ops->listen(sock, backlog);
82908
82909 +error:
82910 fput_light(sock->file, fput_needed);
82911 }
82912 return err;
82913 @@ -1606,6 +1640,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82914 newsock->type = sock->type;
82915 newsock->ops = sock->ops;
82916
82917 + if (gr_handle_sock_server_other(sock->sk)) {
82918 + err = -EPERM;
82919 + sock_release(newsock);
82920 + goto out_put;
82921 + }
82922 +
82923 + err = gr_search_accept(sock);
82924 + if (err) {
82925 + sock_release(newsock);
82926 + goto out_put;
82927 + }
82928 +
82929 /*
82930 * We don't need try_module_get here, as the listening socket (sock)
82931 * has the protocol module (sock->ops->owner) held.
82932 @@ -1651,6 +1697,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82933 fd_install(newfd, newfile);
82934 err = newfd;
82935
82936 + gr_attach_curr_ip(newsock->sk);
82937 +
82938 out_put:
82939 fput_light(sock->file, fput_needed);
82940 out:
82941 @@ -1683,6 +1731,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82942 int, addrlen)
82943 {
82944 struct socket *sock;
82945 + struct sockaddr *sck;
82946 struct sockaddr_storage address;
82947 int err, fput_needed;
82948
82949 @@ -1693,6 +1742,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82950 if (err < 0)
82951 goto out_put;
82952
82953 + sck = (struct sockaddr *)&address;
82954 +
82955 + if (gr_handle_sock_client(sck)) {
82956 + err = -EACCES;
82957 + goto out_put;
82958 + }
82959 +
82960 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
82961 + if (err)
82962 + goto out_put;
82963 +
82964 err =
82965 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
82966 if (err)
82967 @@ -2047,7 +2107,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
82968 * checking falls down on this.
82969 */
82970 if (copy_from_user(ctl_buf,
82971 - (void __user __force *)msg_sys->msg_control,
82972 + (void __force_user *)msg_sys->msg_control,
82973 ctl_len))
82974 goto out_freectl;
82975 msg_sys->msg_control = ctl_buf;
82976 @@ -2215,7 +2275,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
82977 * kernel msghdr to use the kernel address space)
82978 */
82979
82980 - uaddr = (__force void __user *)msg_sys->msg_name;
82981 + uaddr = (void __force_user *)msg_sys->msg_name;
82982 uaddr_len = COMPAT_NAMELEN(msg);
82983 if (MSG_CMSG_COMPAT & flags) {
82984 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
82985 @@ -2838,7 +2898,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82986 }
82987
82988 ifr = compat_alloc_user_space(buf_size);
82989 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
82990 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
82991
82992 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
82993 return -EFAULT;
82994 @@ -2862,12 +2922,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82995 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
82996
82997 if (copy_in_user(rxnfc, compat_rxnfc,
82998 - (void *)(&rxnfc->fs.m_ext + 1) -
82999 - (void *)rxnfc) ||
83000 + (void __user *)(&rxnfc->fs.m_ext + 1) -
83001 + (void __user *)rxnfc) ||
83002 copy_in_user(&rxnfc->fs.ring_cookie,
83003 &compat_rxnfc->fs.ring_cookie,
83004 - (void *)(&rxnfc->fs.location + 1) -
83005 - (void *)&rxnfc->fs.ring_cookie) ||
83006 + (void __user *)(&rxnfc->fs.location + 1) -
83007 + (void __user *)&rxnfc->fs.ring_cookie) ||
83008 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
83009 sizeof(rxnfc->rule_cnt)))
83010 return -EFAULT;
83011 @@ -2879,12 +2939,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
83012
83013 if (convert_out) {
83014 if (copy_in_user(compat_rxnfc, rxnfc,
83015 - (const void *)(&rxnfc->fs.m_ext + 1) -
83016 - (const void *)rxnfc) ||
83017 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
83018 + (const void __user *)rxnfc) ||
83019 copy_in_user(&compat_rxnfc->fs.ring_cookie,
83020 &rxnfc->fs.ring_cookie,
83021 - (const void *)(&rxnfc->fs.location + 1) -
83022 - (const void *)&rxnfc->fs.ring_cookie) ||
83023 + (const void __user *)(&rxnfc->fs.location + 1) -
83024 + (const void __user *)&rxnfc->fs.ring_cookie) ||
83025 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
83026 sizeof(rxnfc->rule_cnt)))
83027 return -EFAULT;
83028 @@ -2954,7 +3014,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
83029 old_fs = get_fs();
83030 set_fs(KERNEL_DS);
83031 err = dev_ioctl(net, cmd,
83032 - (struct ifreq __user __force *) &kifr);
83033 + (struct ifreq __force_user *) &kifr);
83034 set_fs(old_fs);
83035
83036 return err;
83037 @@ -3063,7 +3123,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
83038
83039 old_fs = get_fs();
83040 set_fs(KERNEL_DS);
83041 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
83042 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
83043 set_fs(old_fs);
83044
83045 if (cmd == SIOCGIFMAP && !err) {
83046 @@ -3168,7 +3228,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
83047 ret |= __get_user(rtdev, &(ur4->rt_dev));
83048 if (rtdev) {
83049 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
83050 - r4.rt_dev = (char __user __force *)devname;
83051 + r4.rt_dev = (char __force_user *)devname;
83052 devname[15] = 0;
83053 } else
83054 r4.rt_dev = NULL;
83055 @@ -3394,8 +3454,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
83056 int __user *uoptlen;
83057 int err;
83058
83059 - uoptval = (char __user __force *) optval;
83060 - uoptlen = (int __user __force *) optlen;
83061 + uoptval = (char __force_user *) optval;
83062 + uoptlen = (int __force_user *) optlen;
83063
83064 set_fs(KERNEL_DS);
83065 if (level == SOL_SOCKET)
83066 @@ -3415,7 +3475,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
83067 char __user *uoptval;
83068 int err;
83069
83070 - uoptval = (char __user __force *) optval;
83071 + uoptval = (char __force_user *) optval;
83072
83073 set_fs(KERNEL_DS);
83074 if (level == SOL_SOCKET)
83075 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
83076 index fb20f25..e3ba316 100644
83077 --- a/net/sunrpc/sched.c
83078 +++ b/net/sunrpc/sched.c
83079 @@ -259,9 +259,9 @@ static int rpc_wait_bit_killable(void *word)
83080 #ifdef RPC_DEBUG
83081 static void rpc_task_set_debuginfo(struct rpc_task *task)
83082 {
83083 - static atomic_t rpc_pid;
83084 + static atomic_unchecked_t rpc_pid;
83085
83086 - task->tk_pid = atomic_inc_return(&rpc_pid);
83087 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
83088 }
83089 #else
83090 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
83091 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
83092 index 8343737..677025e 100644
83093 --- a/net/sunrpc/xprtrdma/svc_rdma.c
83094 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
83095 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
83096 static unsigned int min_max_inline = 4096;
83097 static unsigned int max_max_inline = 65536;
83098
83099 -atomic_t rdma_stat_recv;
83100 -atomic_t rdma_stat_read;
83101 -atomic_t rdma_stat_write;
83102 -atomic_t rdma_stat_sq_starve;
83103 -atomic_t rdma_stat_rq_starve;
83104 -atomic_t rdma_stat_rq_poll;
83105 -atomic_t rdma_stat_rq_prod;
83106 -atomic_t rdma_stat_sq_poll;
83107 -atomic_t rdma_stat_sq_prod;
83108 +atomic_unchecked_t rdma_stat_recv;
83109 +atomic_unchecked_t rdma_stat_read;
83110 +atomic_unchecked_t rdma_stat_write;
83111 +atomic_unchecked_t rdma_stat_sq_starve;
83112 +atomic_unchecked_t rdma_stat_rq_starve;
83113 +atomic_unchecked_t rdma_stat_rq_poll;
83114 +atomic_unchecked_t rdma_stat_rq_prod;
83115 +atomic_unchecked_t rdma_stat_sq_poll;
83116 +atomic_unchecked_t rdma_stat_sq_prod;
83117
83118 /* Temporary NFS request map and context caches */
83119 struct kmem_cache *svc_rdma_map_cachep;
83120 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
83121 len -= *ppos;
83122 if (len > *lenp)
83123 len = *lenp;
83124 - if (len && copy_to_user(buffer, str_buf, len))
83125 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
83126 return -EFAULT;
83127 *lenp = len;
83128 *ppos += len;
83129 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
83130 {
83131 .procname = "rdma_stat_read",
83132 .data = &rdma_stat_read,
83133 - .maxlen = sizeof(atomic_t),
83134 + .maxlen = sizeof(atomic_unchecked_t),
83135 .mode = 0644,
83136 .proc_handler = read_reset_stat,
83137 },
83138 {
83139 .procname = "rdma_stat_recv",
83140 .data = &rdma_stat_recv,
83141 - .maxlen = sizeof(atomic_t),
83142 + .maxlen = sizeof(atomic_unchecked_t),
83143 .mode = 0644,
83144 .proc_handler = read_reset_stat,
83145 },
83146 {
83147 .procname = "rdma_stat_write",
83148 .data = &rdma_stat_write,
83149 - .maxlen = sizeof(atomic_t),
83150 + .maxlen = sizeof(atomic_unchecked_t),
83151 .mode = 0644,
83152 .proc_handler = read_reset_stat,
83153 },
83154 {
83155 .procname = "rdma_stat_sq_starve",
83156 .data = &rdma_stat_sq_starve,
83157 - .maxlen = sizeof(atomic_t),
83158 + .maxlen = sizeof(atomic_unchecked_t),
83159 .mode = 0644,
83160 .proc_handler = read_reset_stat,
83161 },
83162 {
83163 .procname = "rdma_stat_rq_starve",
83164 .data = &rdma_stat_rq_starve,
83165 - .maxlen = sizeof(atomic_t),
83166 + .maxlen = sizeof(atomic_unchecked_t),
83167 .mode = 0644,
83168 .proc_handler = read_reset_stat,
83169 },
83170 {
83171 .procname = "rdma_stat_rq_poll",
83172 .data = &rdma_stat_rq_poll,
83173 - .maxlen = sizeof(atomic_t),
83174 + .maxlen = sizeof(atomic_unchecked_t),
83175 .mode = 0644,
83176 .proc_handler = read_reset_stat,
83177 },
83178 {
83179 .procname = "rdma_stat_rq_prod",
83180 .data = &rdma_stat_rq_prod,
83181 - .maxlen = sizeof(atomic_t),
83182 + .maxlen = sizeof(atomic_unchecked_t),
83183 .mode = 0644,
83184 .proc_handler = read_reset_stat,
83185 },
83186 {
83187 .procname = "rdma_stat_sq_poll",
83188 .data = &rdma_stat_sq_poll,
83189 - .maxlen = sizeof(atomic_t),
83190 + .maxlen = sizeof(atomic_unchecked_t),
83191 .mode = 0644,
83192 .proc_handler = read_reset_stat,
83193 },
83194 {
83195 .procname = "rdma_stat_sq_prod",
83196 .data = &rdma_stat_sq_prod,
83197 - .maxlen = sizeof(atomic_t),
83198 + .maxlen = sizeof(atomic_unchecked_t),
83199 .mode = 0644,
83200 .proc_handler = read_reset_stat,
83201 },
83202 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83203 index 0ce7552..d074459 100644
83204 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83205 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83206 @@ -501,7 +501,7 @@ next_sge:
83207 svc_rdma_put_context(ctxt, 0);
83208 goto out;
83209 }
83210 - atomic_inc(&rdma_stat_read);
83211 + atomic_inc_unchecked(&rdma_stat_read);
83212
83213 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
83214 chl_map->ch[ch_no].count -= read_wr.num_sge;
83215 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
83216 dto_q);
83217 list_del_init(&ctxt->dto_q);
83218 } else {
83219 - atomic_inc(&rdma_stat_rq_starve);
83220 + atomic_inc_unchecked(&rdma_stat_rq_starve);
83221 clear_bit(XPT_DATA, &xprt->xpt_flags);
83222 ctxt = NULL;
83223 }
83224 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
83225 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
83226 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
83227 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
83228 - atomic_inc(&rdma_stat_recv);
83229 + atomic_inc_unchecked(&rdma_stat_recv);
83230
83231 /* Build up the XDR from the receive buffers. */
83232 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
83233 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83234 index c1d124d..acfc59e 100644
83235 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83236 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83237 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
83238 write_wr.wr.rdma.remote_addr = to;
83239
83240 /* Post It */
83241 - atomic_inc(&rdma_stat_write);
83242 + atomic_inc_unchecked(&rdma_stat_write);
83243 if (svc_rdma_send(xprt, &write_wr))
83244 goto err;
83245 return 0;
83246 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
83247 index 62e4f9b..dd3f2d7 100644
83248 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
83249 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
83250 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
83251 return;
83252
83253 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
83254 - atomic_inc(&rdma_stat_rq_poll);
83255 + atomic_inc_unchecked(&rdma_stat_rq_poll);
83256
83257 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
83258 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
83259 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
83260 }
83261
83262 if (ctxt)
83263 - atomic_inc(&rdma_stat_rq_prod);
83264 + atomic_inc_unchecked(&rdma_stat_rq_prod);
83265
83266 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
83267 /*
83268 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
83269 return;
83270
83271 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
83272 - atomic_inc(&rdma_stat_sq_poll);
83273 + atomic_inc_unchecked(&rdma_stat_sq_poll);
83274 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
83275 if (wc.status != IB_WC_SUCCESS)
83276 /* Close the transport */
83277 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
83278 }
83279
83280 if (ctxt)
83281 - atomic_inc(&rdma_stat_sq_prod);
83282 + atomic_inc_unchecked(&rdma_stat_sq_prod);
83283 }
83284
83285 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
83286 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
83287 spin_lock_bh(&xprt->sc_lock);
83288 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
83289 spin_unlock_bh(&xprt->sc_lock);
83290 - atomic_inc(&rdma_stat_sq_starve);
83291 + atomic_inc_unchecked(&rdma_stat_sq_starve);
83292
83293 /* See if we can opportunistically reap SQ WR to make room */
83294 sq_cq_reap(xprt);
83295 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
83296 index 9bc6db0..47ac8c0 100644
83297 --- a/net/sysctl_net.c
83298 +++ b/net/sysctl_net.c
83299 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
83300 kgid_t root_gid = make_kgid(net->user_ns, 0);
83301
83302 /* Allow network administrator to have same access as root. */
83303 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
83304 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
83305 uid_eq(root_uid, current_uid())) {
83306 int mode = (table->mode >> 6) & 7;
83307 return (mode << 6) | (mode << 3) | mode;
83308 diff --git a/net/tipc/link.c b/net/tipc/link.c
83309 index daa6080..02d357f 100644
83310 --- a/net/tipc/link.c
83311 +++ b/net/tipc/link.c
83312 @@ -1201,7 +1201,7 @@ static int link_send_sections_long(struct tipc_port *sender,
83313 struct tipc_msg fragm_hdr;
83314 struct sk_buff *buf, *buf_chain, *prev;
83315 u32 fragm_crs, fragm_rest, hsz, sect_rest;
83316 - const unchar *sect_crs;
83317 + const unchar __user *sect_crs;
83318 int curr_sect;
83319 u32 fragm_no;
83320
83321 @@ -1242,7 +1242,7 @@ again:
83322
83323 if (!sect_rest) {
83324 sect_rest = msg_sect[++curr_sect].iov_len;
83325 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
83326 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
83327 }
83328
83329 if (sect_rest < fragm_rest)
83330 @@ -1261,7 +1261,7 @@ error:
83331 }
83332 } else
83333 skb_copy_to_linear_data_offset(buf, fragm_crs,
83334 - sect_crs, sz);
83335 + (const void __force_kernel *)sect_crs, sz);
83336 sect_crs += sz;
83337 sect_rest -= sz;
83338 fragm_crs += sz;
83339 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
83340 index f2db8a8..9245aa4 100644
83341 --- a/net/tipc/msg.c
83342 +++ b/net/tipc/msg.c
83343 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
83344 msg_sect[cnt].iov_len);
83345 else
83346 skb_copy_to_linear_data_offset(*buf, pos,
83347 - msg_sect[cnt].iov_base,
83348 + (const void __force_kernel *)msg_sect[cnt].iov_base,
83349 msg_sect[cnt].iov_len);
83350 pos += msg_sect[cnt].iov_len;
83351 }
83352 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
83353 index 6b42d47..2ac24d5 100644
83354 --- a/net/tipc/subscr.c
83355 +++ b/net/tipc/subscr.c
83356 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
83357 {
83358 struct iovec msg_sect;
83359
83360 - msg_sect.iov_base = (void *)&sub->evt;
83361 + msg_sect.iov_base = (void __force_user *)&sub->evt;
83362 msg_sect.iov_len = sizeof(struct tipc_event);
83363
83364 sub->evt.event = htohl(event, sub->swap);
83365 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
83366 index 5b5c876..3127bf7 100644
83367 --- a/net/unix/af_unix.c
83368 +++ b/net/unix/af_unix.c
83369 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
83370 err = -ECONNREFUSED;
83371 if (!S_ISSOCK(inode->i_mode))
83372 goto put_fail;
83373 +
83374 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
83375 + err = -EACCES;
83376 + goto put_fail;
83377 + }
83378 +
83379 u = unix_find_socket_byinode(inode);
83380 if (!u)
83381 goto put_fail;
83382 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
83383 if (u) {
83384 struct dentry *dentry;
83385 dentry = unix_sk(u)->path.dentry;
83386 +
83387 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
83388 + err = -EPERM;
83389 + sock_put(u);
83390 + goto fail;
83391 + }
83392 +
83393 if (dentry)
83394 touch_atime(&unix_sk(u)->path);
83395 } else
83396 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
83397 */
83398 err = security_path_mknod(&path, dentry, mode, 0);
83399 if (!err) {
83400 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
83401 + err = -EACCES;
83402 + goto out;
83403 + }
83404 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
83405 if (!err) {
83406 res->mnt = mntget(path.mnt);
83407 res->dentry = dget(dentry);
83408 + gr_handle_create(dentry, path.mnt);
83409 }
83410 }
83411 +out:
83412 done_path_create(&path, dentry);
83413 return err;
83414 }
83415 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
83416 index c8717c1..08539f5 100644
83417 --- a/net/wireless/wext-core.c
83418 +++ b/net/wireless/wext-core.c
83419 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
83420 */
83421
83422 /* Support for very large requests */
83423 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
83424 - (user_length > descr->max_tokens)) {
83425 + if (user_length > descr->max_tokens) {
83426 /* Allow userspace to GET more than max so
83427 * we can support any size GET requests.
83428 * There is still a limit : -ENOMEM.
83429 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
83430 }
83431 }
83432
83433 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
83434 - /*
83435 - * If this is a GET, but not NOMAX, it means that the extra
83436 - * data is not bounded by userspace, but by max_tokens. Thus
83437 - * set the length to max_tokens. This matches the extra data
83438 - * allocation.
83439 - * The driver should fill it with the number of tokens it
83440 - * provided, and it may check iwp->length rather than having
83441 - * knowledge of max_tokens. If the driver doesn't change the
83442 - * iwp->length, this ioctl just copies back max_token tokens
83443 - * filled with zeroes. Hopefully the driver isn't claiming
83444 - * them to be valid data.
83445 - */
83446 - iwp->length = descr->max_tokens;
83447 - }
83448 -
83449 err = handler(dev, info, (union iwreq_data *) iwp, extra);
83450
83451 iwp->length += essid_compat;
83452 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
83453 index 07c5857..edc6dc0 100644
83454 --- a/net/xfrm/xfrm_policy.c
83455 +++ b/net/xfrm/xfrm_policy.c
83456 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
83457 {
83458 policy->walk.dead = 1;
83459
83460 - atomic_inc(&policy->genid);
83461 + atomic_inc_unchecked(&policy->genid);
83462
83463 if (del_timer(&policy->timer))
83464 xfrm_pol_put(policy);
83465 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
83466 hlist_add_head(&policy->bydst, chain);
83467 xfrm_pol_hold(policy);
83468 net->xfrm.policy_count[dir]++;
83469 - atomic_inc(&flow_cache_genid);
83470 + atomic_inc_unchecked(&flow_cache_genid);
83471 rt_genid_bump(net);
83472 if (delpol)
83473 __xfrm_policy_unlink(delpol, dir);
83474 @@ -1550,7 +1550,7 @@ free_dst:
83475 goto out;
83476 }
83477
83478 -static int inline
83479 +static inline int
83480 xfrm_dst_alloc_copy(void **target, const void *src, int size)
83481 {
83482 if (!*target) {
83483 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
83484 return 0;
83485 }
83486
83487 -static int inline
83488 +static inline int
83489 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
83490 {
83491 #ifdef CONFIG_XFRM_SUB_POLICY
83492 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
83493 #endif
83494 }
83495
83496 -static int inline
83497 +static inline int
83498 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
83499 {
83500 #ifdef CONFIG_XFRM_SUB_POLICY
83501 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
83502
83503 xdst->num_pols = num_pols;
83504 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
83505 - xdst->policy_genid = atomic_read(&pols[0]->genid);
83506 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
83507
83508 return xdst;
83509 }
83510 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
83511 if (xdst->xfrm_genid != dst->xfrm->genid)
83512 return 0;
83513 if (xdst->num_pols > 0 &&
83514 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
83515 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
83516 return 0;
83517
83518 mtu = dst_mtu(dst->child);
83519 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
83520 sizeof(pol->xfrm_vec[i].saddr));
83521 pol->xfrm_vec[i].encap_family = mp->new_family;
83522 /* flush bundles */
83523 - atomic_inc(&pol->genid);
83524 + atomic_inc_unchecked(&pol->genid);
83525 }
83526 }
83527
83528 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
83529 index 3459692..eefb515 100644
83530 --- a/net/xfrm/xfrm_state.c
83531 +++ b/net/xfrm/xfrm_state.c
83532 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
83533 if (!try_module_get(afinfo->owner))
83534 goto out;
83535
83536 - mode->afinfo = afinfo;
83537 + pax_open_kernel();
83538 + *(void **)&mode->afinfo = afinfo;
83539 + pax_close_kernel();
83540 modemap[mode->encap] = mode;
83541 err = 0;
83542
83543 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
83544 index 0e801c3..5c8ad3b 100644
83545 --- a/scripts/Makefile.build
83546 +++ b/scripts/Makefile.build
83547 @@ -111,7 +111,7 @@ endif
83548 endif
83549
83550 # Do not include host rules unless needed
83551 -ifneq ($(hostprogs-y)$(hostprogs-m),)
83552 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
83553 include scripts/Makefile.host
83554 endif
83555
83556 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
83557 index 686cb0d..9d653bf 100644
83558 --- a/scripts/Makefile.clean
83559 +++ b/scripts/Makefile.clean
83560 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
83561 __clean-files := $(extra-y) $(always) \
83562 $(targets) $(clean-files) \
83563 $(host-progs) \
83564 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
83565 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
83566 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
83567
83568 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
83569
83570 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
83571 index 1ac414f..38575f7 100644
83572 --- a/scripts/Makefile.host
83573 +++ b/scripts/Makefile.host
83574 @@ -31,6 +31,8 @@
83575 # Note: Shared libraries consisting of C++ files are not supported
83576
83577 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
83578 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
83579 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
83580
83581 # C code
83582 # Executables compiled from a single .c file
83583 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
83584 # Shared libaries (only .c supported)
83585 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
83586 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
83587 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
83588 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
83589 # Remove .so files from "xxx-objs"
83590 host-cobjs := $(filter-out %.so,$(host-cobjs))
83591 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
83592
83593 -#Object (.o) files used by the shared libaries
83594 +# Object (.o) files used by the shared libaries
83595 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
83596 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
83597
83598 # output directory for programs/.o files
83599 # hostprogs-y := tools/build may have been specified. Retrieve directory
83600 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
83601 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
83602 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
83603 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
83604 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
83605 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
83606 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
83607 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
83608
83609 obj-dirs += $(host-objdirs)
83610 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
83611 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
83612 $(call if_changed_dep,host-cshobjs)
83613
83614 +# Compile .c file, create position independent .o file
83615 +# host-cxxshobjs -> .o
83616 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
83617 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
83618 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
83619 + $(call if_changed_dep,host-cxxshobjs)
83620 +
83621 # Link a shared library, based on position independent .o files
83622 # *.o -> .so shared library (host-cshlib)
83623 quiet_cmd_host-cshlib = HOSTLLD -shared $@
83624 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
83625 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
83626 $(call if_changed,host-cshlib)
83627
83628 +# Link a shared library, based on position independent .o files
83629 +# *.o -> .so shared library (host-cxxshlib)
83630 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
83631 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
83632 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
83633 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
83634 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
83635 + $(call if_changed,host-cxxshlib)
83636 +
83637 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
83638 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
83639 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
83640
83641 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
83642 index cb1f50c..cef2a7c 100644
83643 --- a/scripts/basic/fixdep.c
83644 +++ b/scripts/basic/fixdep.c
83645 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
83646 /*
83647 * Lookup a value in the configuration string.
83648 */
83649 -static int is_defined_config(const char *name, int len, unsigned int hash)
83650 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
83651 {
83652 struct item *aux;
83653
83654 @@ -211,10 +211,10 @@ static void clear_config(void)
83655 /*
83656 * Record the use of a CONFIG_* word.
83657 */
83658 -static void use_config(const char *m, int slen)
83659 +static void use_config(const char *m, unsigned int slen)
83660 {
83661 unsigned int hash = strhash(m, slen);
83662 - int c, i;
83663 + unsigned int c, i;
83664
83665 if (is_defined_config(m, slen, hash))
83666 return;
83667 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
83668
83669 static void parse_config_file(const char *map, size_t len)
83670 {
83671 - const int *end = (const int *) (map + len);
83672 + const unsigned int *end = (const unsigned int *) (map + len);
83673 /* start at +1, so that p can never be < map */
83674 - const int *m = (const int *) map + 1;
83675 + const unsigned int *m = (const unsigned int *) map + 1;
83676 const char *p, *q;
83677
83678 for (; m < end; m++) {
83679 @@ -406,7 +406,7 @@ static void print_deps(void)
83680 static void traps(void)
83681 {
83682 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
83683 - int *p = (int *)test;
83684 + unsigned int *p = (unsigned int *)test;
83685
83686 if (*p != INT_CONF) {
83687 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
83688 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
83689 new file mode 100644
83690 index 0000000..5e0222d
83691 --- /dev/null
83692 +++ b/scripts/gcc-plugin.sh
83693 @@ -0,0 +1,17 @@
83694 +#!/bin/bash
83695 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
83696 +#include "gcc-plugin.h"
83697 +#include "tree.h"
83698 +#include "tm.h"
83699 +#include "rtl.h"
83700 +#ifdef ENABLE_BUILD_WITH_CXX
83701 +#warning $2
83702 +#else
83703 +#warning $1
83704 +#endif
83705 +EOF`
83706 +if [ $? -eq 0 ]
83707 +then
83708 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
83709 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
83710 +fi
83711 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
83712 index b3d907e..a4782ab 100644
83713 --- a/scripts/link-vmlinux.sh
83714 +++ b/scripts/link-vmlinux.sh
83715 @@ -152,7 +152,7 @@ else
83716 fi;
83717
83718 # final build of init/
83719 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
83720 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
83721
83722 kallsymso=""
83723 kallsyms_vmlinux=""
83724 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
83725 index df4fc23..0ea719d 100644
83726 --- a/scripts/mod/file2alias.c
83727 +++ b/scripts/mod/file2alias.c
83728 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
83729 unsigned long size, unsigned long id_size,
83730 void *symval)
83731 {
83732 - int i;
83733 + unsigned int i;
83734
83735 if (size % id_size || size < id_size) {
83736 if (cross_build != 0)
83737 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
83738 /* USB is special because the bcdDevice can be matched against a numeric range */
83739 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
83740 static void do_usb_entry(struct usb_device_id *id,
83741 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
83742 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
83743 unsigned char range_lo, unsigned char range_hi,
83744 unsigned char max, struct module *mod)
83745 {
83746 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
83747 {
83748 unsigned int devlo, devhi;
83749 unsigned char chi, clo, max;
83750 - int ndigits;
83751 + unsigned int ndigits;
83752
83753 id->match_flags = TO_NATIVE(id->match_flags);
83754 id->idVendor = TO_NATIVE(id->idVendor);
83755 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
83756 for (i = 0; i < count; i++) {
83757 const char *id = (char *)devs[i].id;
83758 char acpi_id[sizeof(devs[0].id)];
83759 - int j;
83760 + unsigned int j;
83761
83762 buf_printf(&mod->dev_table_buf,
83763 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
83764 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
83765
83766 for (j = 0; j < PNP_MAX_DEVICES; j++) {
83767 const char *id = (char *)card->devs[j].id;
83768 - int i2, j2;
83769 + unsigned int i2, j2;
83770 int dup = 0;
83771
83772 if (!id[0])
83773 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
83774 /* add an individual alias for every device entry */
83775 if (!dup) {
83776 char acpi_id[sizeof(card->devs[0].id)];
83777 - int k;
83778 + unsigned int k;
83779
83780 buf_printf(&mod->dev_table_buf,
83781 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
83782 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
83783 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
83784 char *alias)
83785 {
83786 - int i, j;
83787 + unsigned int i, j;
83788
83789 sprintf(alias, "dmi*");
83790
83791 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
83792 index ff36c50..7ab4fa9 100644
83793 --- a/scripts/mod/modpost.c
83794 +++ b/scripts/mod/modpost.c
83795 @@ -929,6 +929,7 @@ enum mismatch {
83796 ANY_INIT_TO_ANY_EXIT,
83797 ANY_EXIT_TO_ANY_INIT,
83798 EXPORT_TO_INIT_EXIT,
83799 + DATA_TO_TEXT
83800 };
83801
83802 struct sectioncheck {
83803 @@ -1043,6 +1044,12 @@ const struct sectioncheck sectioncheck[] = {
83804 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
83805 .mismatch = EXPORT_TO_INIT_EXIT,
83806 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
83807 +},
83808 +/* Do not reference code from writable data */
83809 +{
83810 + .fromsec = { DATA_SECTIONS, NULL },
83811 + .tosec = { TEXT_SECTIONS, NULL },
83812 + .mismatch = DATA_TO_TEXT
83813 }
83814 };
83815
83816 @@ -1165,10 +1172,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
83817 continue;
83818 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
83819 continue;
83820 - if (sym->st_value == addr)
83821 - return sym;
83822 /* Find a symbol nearby - addr are maybe negative */
83823 d = sym->st_value - addr;
83824 + if (d == 0)
83825 + return sym;
83826 if (d < 0)
83827 d = addr - sym->st_value;
83828 if (d < distance) {
83829 @@ -1447,6 +1454,14 @@ static void report_sec_mismatch(const char *modname,
83830 tosym, prl_to, prl_to, tosym);
83831 free(prl_to);
83832 break;
83833 + case DATA_TO_TEXT:
83834 +#if 0
83835 + fprintf(stderr,
83836 + "The %s %s:%s references\n"
83837 + "the %s %s:%s%s\n",
83838 + from, fromsec, fromsym, to, tosec, tosym, to_p);
83839 +#endif
83840 + break;
83841 }
83842 fprintf(stderr, "\n");
83843 }
83844 @@ -1681,7 +1696,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
83845 static void check_sec_ref(struct module *mod, const char *modname,
83846 struct elf_info *elf)
83847 {
83848 - int i;
83849 + unsigned int i;
83850 Elf_Shdr *sechdrs = elf->sechdrs;
83851
83852 /* Walk through all sections */
83853 @@ -1779,7 +1794,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
83854 va_end(ap);
83855 }
83856
83857 -void buf_write(struct buffer *buf, const char *s, int len)
83858 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
83859 {
83860 if (buf->size - buf->pos < len) {
83861 buf->size += len + SZ;
83862 @@ -1997,7 +2012,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
83863 if (fstat(fileno(file), &st) < 0)
83864 goto close_write;
83865
83866 - if (st.st_size != b->pos)
83867 + if (st.st_size != (off_t)b->pos)
83868 goto close_write;
83869
83870 tmp = NOFAIL(malloc(b->pos));
83871 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
83872 index 51207e4..f7d603d 100644
83873 --- a/scripts/mod/modpost.h
83874 +++ b/scripts/mod/modpost.h
83875 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
83876
83877 struct buffer {
83878 char *p;
83879 - int pos;
83880 - int size;
83881 + unsigned int pos;
83882 + unsigned int size;
83883 };
83884
83885 void __attribute__((format(printf, 2, 3)))
83886 buf_printf(struct buffer *buf, const char *fmt, ...);
83887
83888 void
83889 -buf_write(struct buffer *buf, const char *s, int len);
83890 +buf_write(struct buffer *buf, const char *s, unsigned int len);
83891
83892 struct module {
83893 struct module *next;
83894 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
83895 index 9dfcd6d..099068e 100644
83896 --- a/scripts/mod/sumversion.c
83897 +++ b/scripts/mod/sumversion.c
83898 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
83899 goto out;
83900 }
83901
83902 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
83903 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
83904 warn("writing sum in %s failed: %s\n",
83905 filename, strerror(errno));
83906 goto out;
83907 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
83908 index 68bb4ef..2f419e1 100644
83909 --- a/scripts/pnmtologo.c
83910 +++ b/scripts/pnmtologo.c
83911 @@ -244,14 +244,14 @@ static void write_header(void)
83912 fprintf(out, " * Linux logo %s\n", logoname);
83913 fputs(" */\n\n", out);
83914 fputs("#include <linux/linux_logo.h>\n\n", out);
83915 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
83916 + fprintf(out, "static unsigned char %s_data[] = {\n",
83917 logoname);
83918 }
83919
83920 static void write_footer(void)
83921 {
83922 fputs("\n};\n\n", out);
83923 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
83924 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
83925 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
83926 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
83927 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
83928 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
83929 fputs("\n};\n\n", out);
83930
83931 /* write logo clut */
83932 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
83933 + fprintf(out, "static unsigned char %s_clut[] = {\n",
83934 logoname);
83935 write_hex_cnt = 0;
83936 for (i = 0; i < logo_clutsize; i++) {
83937 diff --git a/security/Kconfig b/security/Kconfig
83938 index e9c6ac7..ab9590d 100644
83939 --- a/security/Kconfig
83940 +++ b/security/Kconfig
83941 @@ -4,6 +4,902 @@
83942
83943 menu "Security options"
83944
83945 +menu "Grsecurity"
83946 +
83947 + config ARCH_TRACK_EXEC_LIMIT
83948 + bool
83949 +
83950 + config PAX_KERNEXEC_PLUGIN
83951 + bool
83952 +
83953 + config PAX_PER_CPU_PGD
83954 + bool
83955 +
83956 + config TASK_SIZE_MAX_SHIFT
83957 + int
83958 + depends on X86_64
83959 + default 47 if !PAX_PER_CPU_PGD
83960 + default 42 if PAX_PER_CPU_PGD
83961 +
83962 + config PAX_ENABLE_PAE
83963 + bool
83964 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
83965 +
83966 + config PAX_USERCOPY_SLABS
83967 + bool
83968 +
83969 +config GRKERNSEC
83970 + bool "Grsecurity"
83971 + select CRYPTO
83972 + select CRYPTO_SHA256
83973 + select PROC_FS
83974 + select STOP_MACHINE
83975 + help
83976 + If you say Y here, you will be able to configure many features
83977 + that will enhance the security of your system. It is highly
83978 + recommended that you say Y here and read through the help
83979 + for each option so that you fully understand the features and
83980 + can evaluate their usefulness for your machine.
83981 +
83982 +choice
83983 + prompt "Configuration Method"
83984 + depends on GRKERNSEC
83985 + default GRKERNSEC_CONFIG_CUSTOM
83986 + help
83987 +
83988 +config GRKERNSEC_CONFIG_AUTO
83989 + bool "Automatic"
83990 + help
83991 + If you choose this configuration method, you'll be able to answer a small
83992 + number of simple questions about how you plan to use this kernel.
83993 + The settings of grsecurity and PaX will be automatically configured for
83994 + the highest commonly-used settings within the provided constraints.
83995 +
83996 + If you require additional configuration, custom changes can still be made
83997 + from the "custom configuration" menu.
83998 +
83999 +config GRKERNSEC_CONFIG_CUSTOM
84000 + bool "Custom"
84001 + help
84002 + If you choose this configuration method, you'll be able to configure all
84003 + grsecurity and PaX settings manually. Via this method, no options are
84004 + automatically enabled.
84005 +
84006 +endchoice
84007 +
84008 +choice
84009 + prompt "Usage Type"
84010 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
84011 + default GRKERNSEC_CONFIG_SERVER
84012 + help
84013 +
84014 +config GRKERNSEC_CONFIG_SERVER
84015 + bool "Server"
84016 + help
84017 + Choose this option if you plan to use this kernel on a server.
84018 +
84019 +config GRKERNSEC_CONFIG_DESKTOP
84020 + bool "Desktop"
84021 + help
84022 + Choose this option if you plan to use this kernel on a desktop.
84023 +
84024 +endchoice
84025 +
84026 +choice
84027 + prompt "Virtualization Type"
84028 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
84029 + default GRKERNSEC_CONFIG_VIRT_NONE
84030 + help
84031 +
84032 +config GRKERNSEC_CONFIG_VIRT_NONE
84033 + bool "None"
84034 + help
84035 + Choose this option if this kernel will be run on bare metal.
84036 +
84037 +config GRKERNSEC_CONFIG_VIRT_GUEST
84038 + bool "Guest"
84039 + help
84040 + Choose this option if this kernel will be run as a VM guest.
84041 +
84042 +config GRKERNSEC_CONFIG_VIRT_HOST
84043 + bool "Host"
84044 + help
84045 + Choose this option if this kernel will be run as a VM host.
84046 +
84047 +endchoice
84048 +
84049 +choice
84050 + prompt "Virtualization Hardware"
84051 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
84052 + help
84053 +
84054 +config GRKERNSEC_CONFIG_VIRT_EPT
84055 + bool "EPT/RVI Processor Support"
84056 + depends on X86
84057 + help
84058 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
84059 + hardware virtualization. This allows for additional kernel hardening protections
84060 + to operate without additional performance impact.
84061 +
84062 + To see if your Intel processor supports EPT, see:
84063 + http://ark.intel.com/Products/VirtualizationTechnology
84064 + (Most Core i3/5/7 support EPT)
84065 +
84066 + To see if your AMD processor supports RVI, see:
84067 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
84068 +
84069 +config GRKERNSEC_CONFIG_VIRT_SOFT
84070 + bool "First-gen/No Hardware Virtualization"
84071 + help
84072 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
84073 + support hardware virtualization or doesn't support the EPT/RVI extensions.
84074 +
84075 +endchoice
84076 +
84077 +choice
84078 + prompt "Virtualization Software"
84079 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
84080 + help
84081 +
84082 +config GRKERNSEC_CONFIG_VIRT_XEN
84083 + bool "Xen"
84084 + help
84085 + Choose this option if this kernel is running as a Xen guest or host.
84086 +
84087 +config GRKERNSEC_CONFIG_VIRT_VMWARE
84088 + bool "VMWare"
84089 + help
84090 + Choose this option if this kernel is running as a VMWare guest or host.
84091 +
84092 +config GRKERNSEC_CONFIG_VIRT_KVM
84093 + bool "KVM"
84094 + help
84095 + Choose this option if this kernel is running as a KVM guest or host.
84096 +
84097 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
84098 + bool "VirtualBox"
84099 + help
84100 + Choose this option if this kernel is running as a VirtualBox guest or host.
84101 +
84102 +endchoice
84103 +
84104 +choice
84105 + prompt "Required Priorities"
84106 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
84107 + default GRKERNSEC_CONFIG_PRIORITY_PERF
84108 + help
84109 +
84110 +config GRKERNSEC_CONFIG_PRIORITY_PERF
84111 + bool "Performance"
84112 + help
84113 + Choose this option if performance is of highest priority for this deployment
84114 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
84115 + and freed memory sanitizing will be disabled.
84116 +
84117 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
84118 + bool "Security"
84119 + help
84120 + Choose this option if security is of highest priority for this deployment of
84121 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
84122 + be enabled for this kernel. In a worst-case scenario, these features can
84123 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
84124 +
84125 +endchoice
84126 +
84127 +menu "Default Special Groups"
84128 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
84129 +
84130 +config GRKERNSEC_PROC_GID
84131 + int "GID exempted from /proc restrictions"
84132 + default 1001
84133 + help
84134 + Setting this GID determines which group will be exempted from
84135 + grsecurity's /proc restrictions, allowing users of the specified
84136 + group to view network statistics and the existence of other users'
84137 + processes on the system. This GID may also be chosen at boot time
84138 + via "grsec_proc_gid=" on the kernel commandline.
84139 +
84140 +config GRKERNSEC_TPE_UNTRUSTED_GID
84141 + int "GID for TPE-untrusted users"
84142 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
84143 + default 1005
84144 + help
84145 + Setting this GID determines which group untrusted users should
84146 + be added to. These users will be placed under grsecurity's Trusted Path
84147 + Execution mechanism, preventing them from executing their own binaries.
84148 + The users will only be able to execute binaries in directories owned and
84149 + writable only by the root user. If the sysctl option is enabled, a sysctl
84150 + option with name "tpe_gid" is created.
84151 +
84152 +config GRKERNSEC_TPE_TRUSTED_GID
84153 + int "GID for TPE-trusted users"
84154 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
84155 + default 1005
84156 + help
84157 + Setting this GID determines what group TPE restrictions will be
84158 + *disabled* for. If the sysctl option is enabled, a sysctl option
84159 + with name "tpe_gid" is created.
84160 +
84161 +config GRKERNSEC_SYMLINKOWN_GID
84162 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
84163 + depends on GRKERNSEC_CONFIG_SERVER
84164 + default 1006
84165 + help
84166 + Setting this GID determines what group kernel-enforced
84167 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
84168 + is enabled, a sysctl option with name "symlinkown_gid" is created.
84169 +
84170 +
84171 +endmenu
84172 +
84173 +menu "Customize Configuration"
84174 +depends on GRKERNSEC
84175 +
84176 +menu "PaX"
84177 +
84178 +config PAX
84179 + bool "Enable various PaX features"
84180 + default y if GRKERNSEC_CONFIG_AUTO
84181 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
84182 + help
84183 + This allows you to enable various PaX features. PaX adds
84184 + intrusion prevention mechanisms to the kernel that reduce
84185 + the risks posed by exploitable memory corruption bugs.
84186 +
84187 +menu "PaX Control"
84188 + depends on PAX
84189 +
84190 +config PAX_SOFTMODE
84191 + bool 'Support soft mode'
84192 + help
84193 + Enabling this option will allow you to run PaX in soft mode, that
84194 + is, PaX features will not be enforced by default, only on executables
84195 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
84196 + support as they are the only way to mark executables for soft mode use.
84197 +
84198 + Soft mode can be activated by using the "pax_softmode=1" kernel command
84199 + line option on boot. Furthermore you can control various PaX features
84200 + at runtime via the entries in /proc/sys/kernel/pax.
84201 +
84202 +config PAX_EI_PAX
84203 + bool 'Use legacy ELF header marking'
84204 + default y if GRKERNSEC_CONFIG_AUTO
84205 + help
84206 + Enabling this option will allow you to control PaX features on
84207 + a per executable basis via the 'chpax' utility available at
84208 + http://pax.grsecurity.net/. The control flags will be read from
84209 + an otherwise reserved part of the ELF header. This marking has
84210 + numerous drawbacks (no support for soft-mode, toolchain does not
84211 + know about the non-standard use of the ELF header) therefore it
84212 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
84213 + support.
84214 +
84215 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
84216 + support as well, they will override the legacy EI_PAX marks.
84217 +
84218 + If you enable none of the marking options then all applications
84219 + will run with PaX enabled on them by default.
84220 +
84221 +config PAX_PT_PAX_FLAGS
84222 + bool 'Use ELF program header marking'
84223 + default y if GRKERNSEC_CONFIG_AUTO
84224 + help
84225 + Enabling this option will allow you to control PaX features on
84226 + a per executable basis via the 'paxctl' utility available at
84227 + http://pax.grsecurity.net/. The control flags will be read from
84228 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
84229 + has the benefits of supporting both soft mode and being fully
84230 + integrated into the toolchain (the binutils patch is available
84231 + from http://pax.grsecurity.net).
84232 +
84233 + Note that if you enable the legacy EI_PAX marking support as well,
84234 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
84235 +
84236 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
84237 + must make sure that the marks are the same if a binary has both marks.
84238 +
84239 + If you enable none of the marking options then all applications
84240 + will run with PaX enabled on them by default.
84241 +
84242 +config PAX_XATTR_PAX_FLAGS
84243 + bool 'Use filesystem extended attributes marking'
84244 + default y if GRKERNSEC_CONFIG_AUTO
84245 + select CIFS_XATTR if CIFS
84246 + select EXT2_FS_XATTR if EXT2_FS
84247 + select EXT3_FS_XATTR if EXT3_FS
84248 + select EXT4_FS_XATTR if EXT4_FS
84249 + select JFFS2_FS_XATTR if JFFS2_FS
84250 + select REISERFS_FS_XATTR if REISERFS_FS
84251 + select SQUASHFS_XATTR if SQUASHFS
84252 + select TMPFS_XATTR if TMPFS
84253 + select UBIFS_FS_XATTR if UBIFS_FS
84254 + help
84255 + Enabling this option will allow you to control PaX features on
84256 + a per executable basis via the 'setfattr' utility. The control
84257 + flags will be read from the user.pax.flags extended attribute of
84258 + the file. This marking has the benefit of supporting binary-only
84259 + applications that self-check themselves (e.g., skype) and would
84260 + not tolerate chpax/paxctl changes. The main drawback is that
84261 + extended attributes are not supported by some filesystems (e.g.,
84262 + isofs, udf, vfat) so copying files through such filesystems will
84263 + lose the extended attributes and these PaX markings.
84264 +
84265 + Note that if you enable the legacy EI_PAX marking support as well,
84266 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
84267 +
84268 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
84269 + must make sure that the marks are the same if a binary has both marks.
84270 +
84271 + If you enable none of the marking options then all applications
84272 + will run with PaX enabled on them by default.
84273 +
84274 +choice
84275 + prompt 'MAC system integration'
84276 + default PAX_HAVE_ACL_FLAGS
84277 + help
84278 + Mandatory Access Control systems have the option of controlling
84279 + PaX flags on a per executable basis, choose the method supported
84280 + by your particular system.
84281 +
84282 + - "none": if your MAC system does not interact with PaX,
84283 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
84284 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
84285 +
84286 + NOTE: this option is for developers/integrators only.
84287 +
84288 + config PAX_NO_ACL_FLAGS
84289 + bool 'none'
84290 +
84291 + config PAX_HAVE_ACL_FLAGS
84292 + bool 'direct'
84293 +
84294 + config PAX_HOOK_ACL_FLAGS
84295 + bool 'hook'
84296 +endchoice
84297 +
84298 +endmenu
84299 +
84300 +menu "Non-executable pages"
84301 + depends on PAX
84302 +
84303 +config PAX_NOEXEC
84304 + bool "Enforce non-executable pages"
84305 + default y if GRKERNSEC_CONFIG_AUTO
84306 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
84307 + help
84308 + By design some architectures do not allow for protecting memory
84309 + pages against execution or even if they do, Linux does not make
84310 + use of this feature. In practice this means that if a page is
84311 + readable (such as the stack or heap) it is also executable.
84312 +
84313 + There is a well known exploit technique that makes use of this
84314 + fact and a common programming mistake where an attacker can
84315 + introduce code of his choice somewhere in the attacked program's
84316 + memory (typically the stack or the heap) and then execute it.
84317 +
84318 + If the attacked program was running with different (typically
84319 + higher) privileges than that of the attacker, then he can elevate
84320 + his own privilege level (e.g. get a root shell, write to files for
84321 + which he does not have write access to, etc).
84322 +
84323 + Enabling this option will let you choose from various features
84324 + that prevent the injection and execution of 'foreign' code in
84325 + a program.
84326 +
84327 + This will also break programs that rely on the old behaviour and
84328 + expect that dynamically allocated memory via the malloc() family
84329 + of functions is executable (which it is not). Notable examples
84330 + are the XFree86 4.x server, the java runtime and wine.
84331 +
84332 +config PAX_PAGEEXEC
84333 + bool "Paging based non-executable pages"
84334 + default y if GRKERNSEC_CONFIG_AUTO
84335 + 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)
84336 + select S390_SWITCH_AMODE if S390
84337 + select S390_EXEC_PROTECT if S390
84338 + select ARCH_TRACK_EXEC_LIMIT if X86_32
84339 + help
84340 + This implementation is based on the paging feature of the CPU.
84341 + On i386 without hardware non-executable bit support there is a
84342 + variable but usually low performance impact, however on Intel's
84343 + P4 core based CPUs it is very high so you should not enable this
84344 + for kernels meant to be used on such CPUs.
84345 +
84346 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
84347 + with hardware non-executable bit support there is no performance
84348 + impact, on ppc the impact is negligible.
84349 +
84350 + Note that several architectures require various emulations due to
84351 + badly designed userland ABIs, this will cause a performance impact
84352 + but will disappear as soon as userland is fixed. For example, ppc
84353 + userland MUST have been built with secure-plt by a recent toolchain.
84354 +
84355 +config PAX_SEGMEXEC
84356 + bool "Segmentation based non-executable pages"
84357 + default y if GRKERNSEC_CONFIG_AUTO
84358 + depends on PAX_NOEXEC && X86_32
84359 + help
84360 + This implementation is based on the segmentation feature of the
84361 + CPU and has a very small performance impact, however applications
84362 + will be limited to a 1.5 GB address space instead of the normal
84363 + 3 GB.
84364 +
84365 +config PAX_EMUTRAMP
84366 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
84367 + default y if PARISC
84368 + help
84369 + There are some programs and libraries that for one reason or
84370 + another attempt to execute special small code snippets from
84371 + non-executable memory pages. Most notable examples are the
84372 + signal handler return code generated by the kernel itself and
84373 + the GCC trampolines.
84374 +
84375 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
84376 + such programs will no longer work under your kernel.
84377 +
84378 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
84379 + utilities to enable trampoline emulation for the affected programs
84380 + yet still have the protection provided by the non-executable pages.
84381 +
84382 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
84383 + your system will not even boot.
84384 +
84385 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
84386 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
84387 + for the affected files.
84388 +
84389 + NOTE: enabling this feature *may* open up a loophole in the
84390 + protection provided by non-executable pages that an attacker
84391 + could abuse. Therefore the best solution is to not have any
84392 + files on your system that would require this option. This can
84393 + be achieved by not using libc5 (which relies on the kernel
84394 + signal handler return code) and not using or rewriting programs
84395 + that make use of the nested function implementation of GCC.
84396 + Skilled users can just fix GCC itself so that it implements
84397 + nested function calls in a way that does not interfere with PaX.
84398 +
84399 +config PAX_EMUSIGRT
84400 + bool "Automatically emulate sigreturn trampolines"
84401 + depends on PAX_EMUTRAMP && PARISC
84402 + default y
84403 + help
84404 + Enabling this option will have the kernel automatically detect
84405 + and emulate signal return trampolines executing on the stack
84406 + that would otherwise lead to task termination.
84407 +
84408 + This solution is intended as a temporary one for users with
84409 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
84410 + Modula-3 runtime, etc) or executables linked to such, basically
84411 + everything that does not specify its own SA_RESTORER function in
84412 + normal executable memory like glibc 2.1+ does.
84413 +
84414 + On parisc you MUST enable this option, otherwise your system will
84415 + not even boot.
84416 +
84417 + NOTE: this feature cannot be disabled on a per executable basis
84418 + and since it *does* open up a loophole in the protection provided
84419 + by non-executable pages, the best solution is to not have any
84420 + files on your system that would require this option.
84421 +
84422 +config PAX_MPROTECT
84423 + bool "Restrict mprotect()"
84424 + default y if GRKERNSEC_CONFIG_AUTO
84425 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
84426 + help
84427 + Enabling this option will prevent programs from
84428 + - changing the executable status of memory pages that were
84429 + not originally created as executable,
84430 + - making read-only executable pages writable again,
84431 + - creating executable pages from anonymous memory,
84432 + - making read-only-after-relocations (RELRO) data pages writable again.
84433 +
84434 + You should say Y here to complete the protection provided by
84435 + the enforcement of non-executable pages.
84436 +
84437 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
84438 + this feature on a per file basis.
84439 +
84440 +config PAX_MPROTECT_COMPAT
84441 + bool "Use legacy/compat protection demoting (read help)"
84442 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
84443 + depends on PAX_MPROTECT
84444 + help
84445 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
84446 + by sending the proper error code to the application. For some broken
84447 + userland, this can cause problems with Python or other applications. The
84448 + current implementation however allows for applications like clamav to
84449 + detect if JIT compilation/execution is allowed and to fall back gracefully
84450 + to an interpreter-based mode if it does not. While we encourage everyone
84451 + to use the current implementation as-is and push upstream to fix broken
84452 + userland (note that the RWX logging option can assist with this), in some
84453 + environments this may not be possible. Having to disable MPROTECT
84454 + completely on certain binaries reduces the security benefit of PaX,
84455 + so this option is provided for those environments to revert to the old
84456 + behavior.
84457 +
84458 +config PAX_ELFRELOCS
84459 + bool "Allow ELF text relocations (read help)"
84460 + depends on PAX_MPROTECT
84461 + default n
84462 + help
84463 + Non-executable pages and mprotect() restrictions are effective
84464 + in preventing the introduction of new executable code into an
84465 + attacked task's address space. There remain only two venues
84466 + for this kind of attack: if the attacker can execute already
84467 + existing code in the attacked task then he can either have it
84468 + create and mmap() a file containing his code or have it mmap()
84469 + an already existing ELF library that does not have position
84470 + independent code in it and use mprotect() on it to make it
84471 + writable and copy his code there. While protecting against
84472 + the former approach is beyond PaX, the latter can be prevented
84473 + by having only PIC ELF libraries on one's system (which do not
84474 + need to relocate their code). If you are sure this is your case,
84475 + as is the case with all modern Linux distributions, then leave
84476 + this option disabled. You should say 'n' here.
84477 +
84478 +config PAX_ETEXECRELOCS
84479 + bool "Allow ELF ET_EXEC text relocations"
84480 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
84481 + select PAX_ELFRELOCS
84482 + default y
84483 + help
84484 + On some architectures there are incorrectly created applications
84485 + that require text relocations and would not work without enabling
84486 + this option. If you are an alpha, ia64 or parisc user, you should
84487 + enable this option and disable it once you have made sure that
84488 + none of your applications need it.
84489 +
84490 +config PAX_EMUPLT
84491 + bool "Automatically emulate ELF PLT"
84492 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
84493 + default y
84494 + help
84495 + Enabling this option will have the kernel automatically detect
84496 + and emulate the Procedure Linkage Table entries in ELF files.
84497 + On some architectures such entries are in writable memory, and
84498 + become non-executable leading to task termination. Therefore
84499 + it is mandatory that you enable this option on alpha, parisc,
84500 + sparc and sparc64, otherwise your system would not even boot.
84501 +
84502 + NOTE: this feature *does* open up a loophole in the protection
84503 + provided by the non-executable pages, therefore the proper
84504 + solution is to modify the toolchain to produce a PLT that does
84505 + not need to be writable.
84506 +
84507 +config PAX_DLRESOLVE
84508 + bool 'Emulate old glibc resolver stub'
84509 + depends on PAX_EMUPLT && SPARC
84510 + default n
84511 + help
84512 + This option is needed if userland has an old glibc (before 2.4)
84513 + that puts a 'save' instruction into the runtime generated resolver
84514 + stub that needs special emulation.
84515 +
84516 +config PAX_KERNEXEC
84517 + bool "Enforce non-executable kernel pages"
84518 + 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))
84519 + depends on ((X86 && (!X86_32 || X86_WP_WORKS_OK)) || (ARM && (CPU_V6 || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
84520 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
84521 + select PAX_KERNEXEC_PLUGIN if X86_64
84522 + help
84523 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
84524 + that is, enabling this option will make it harder to inject
84525 + and execute 'foreign' code in kernel memory itself.
84526 +
84527 +choice
84528 + prompt "Return Address Instrumentation Method"
84529 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
84530 + depends on PAX_KERNEXEC_PLUGIN
84531 + help
84532 + Select the method used to instrument function pointer dereferences.
84533 + Note that binary modules cannot be instrumented by this approach.
84534 +
84535 + Note that the implementation requires a gcc with plugin support,
84536 + i.e., gcc 4.5 or newer. You may need to install the supporting
84537 + headers explicitly in addition to the normal gcc package.
84538 +
84539 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
84540 + bool "bts"
84541 + help
84542 + This method is compatible with binary only modules but has
84543 + a higher runtime overhead.
84544 +
84545 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
84546 + bool "or"
84547 + depends on !PARAVIRT
84548 + help
84549 + This method is incompatible with binary only modules but has
84550 + a lower runtime overhead.
84551 +endchoice
84552 +
84553 +config PAX_KERNEXEC_PLUGIN_METHOD
84554 + string
84555 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
84556 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
84557 + default ""
84558 +
84559 +config PAX_KERNEXEC_MODULE_TEXT
84560 + int "Minimum amount of memory reserved for module code"
84561 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
84562 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
84563 + depends on PAX_KERNEXEC && X86_32 && MODULES
84564 + help
84565 + Due to implementation details the kernel must reserve a fixed
84566 + amount of memory for module code at compile time that cannot be
84567 + changed at runtime. Here you can specify the minimum amount
84568 + in MB that will be reserved. Due to the same implementation
84569 + details this size will always be rounded up to the next 2/4 MB
84570 + boundary (depends on PAE) so the actually available memory for
84571 + module code will usually be more than this minimum.
84572 +
84573 + The default 4 MB should be enough for most users but if you have
84574 + an excessive number of modules (e.g., most distribution configs
84575 + compile many drivers as modules) or use huge modules such as
84576 + nvidia's kernel driver, you will need to adjust this amount.
84577 + A good rule of thumb is to look at your currently loaded kernel
84578 + modules and add up their sizes.
84579 +
84580 +endmenu
84581 +
84582 +menu "Address Space Layout Randomization"
84583 + depends on PAX
84584 +
84585 +config PAX_ASLR
84586 + bool "Address Space Layout Randomization"
84587 + default y if GRKERNSEC_CONFIG_AUTO
84588 + help
84589 + Many if not most exploit techniques rely on the knowledge of
84590 + certain addresses in the attacked program. The following options
84591 + will allow the kernel to apply a certain amount of randomization
84592 + to specific parts of the program thereby forcing an attacker to
84593 + guess them in most cases. Any failed guess will most likely crash
84594 + the attacked program which allows the kernel to detect such attempts
84595 + and react on them. PaX itself provides no reaction mechanisms,
84596 + instead it is strongly encouraged that you make use of Nergal's
84597 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
84598 + (http://www.grsecurity.net/) built-in crash detection features or
84599 + develop one yourself.
84600 +
84601 + By saying Y here you can choose to randomize the following areas:
84602 + - top of the task's kernel stack
84603 + - top of the task's userland stack
84604 + - base address for mmap() requests that do not specify one
84605 + (this includes all libraries)
84606 + - base address of the main executable
84607 +
84608 + It is strongly recommended to say Y here as address space layout
84609 + randomization has negligible impact on performance yet it provides
84610 + a very effective protection.
84611 +
84612 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
84613 + this feature on a per file basis.
84614 +
84615 +config PAX_RANDKSTACK
84616 + bool "Randomize kernel stack base"
84617 + default y if GRKERNSEC_CONFIG_AUTO
84618 + depends on X86_TSC && X86
84619 + help
84620 + By saying Y here the kernel will randomize every task's kernel
84621 + stack on every system call. This will not only force an attacker
84622 + to guess it but also prevent him from making use of possible
84623 + leaked information about it.
84624 +
84625 + Since the kernel stack is a rather scarce resource, randomization
84626 + may cause unexpected stack overflows, therefore you should very
84627 + carefully test your system. Note that once enabled in the kernel
84628 + configuration, this feature cannot be disabled on a per file basis.
84629 +
84630 +config PAX_RANDUSTACK
84631 + bool "Randomize user stack base"
84632 + default y if GRKERNSEC_CONFIG_AUTO
84633 + depends on PAX_ASLR
84634 + help
84635 + By saying Y here the kernel will randomize every task's userland
84636 + stack. The randomization is done in two steps where the second
84637 + one may apply a big amount of shift to the top of the stack and
84638 + cause problems for programs that want to use lots of memory (more
84639 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
84640 + For this reason the second step can be controlled by 'chpax' or
84641 + 'paxctl' on a per file basis.
84642 +
84643 +config PAX_RANDMMAP
84644 + bool "Randomize mmap() base"
84645 + default y if GRKERNSEC_CONFIG_AUTO
84646 + depends on PAX_ASLR
84647 + help
84648 + By saying Y here the kernel will use a randomized base address for
84649 + mmap() requests that do not specify one themselves. As a result
84650 + all dynamically loaded libraries will appear at random addresses
84651 + and therefore be harder to exploit by a technique where an attacker
84652 + attempts to execute library code for his purposes (e.g. spawn a
84653 + shell from an exploited program that is running at an elevated
84654 + privilege level).
84655 +
84656 + Furthermore, if a program is relinked as a dynamic ELF file, its
84657 + base address will be randomized as well, completing the full
84658 + randomization of the address space layout. Attacking such programs
84659 + becomes a guess game. You can find an example of doing this at
84660 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
84661 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
84662 +
84663 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
84664 + feature on a per file basis.
84665 +
84666 +endmenu
84667 +
84668 +menu "Miscellaneous hardening features"
84669 +
84670 +config PAX_MEMORY_SANITIZE
84671 + bool "Sanitize all freed memory"
84672 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
84673 + depends on !HIBERNATION
84674 + help
84675 + By saying Y here the kernel will erase memory pages as soon as they
84676 + are freed. This in turn reduces the lifetime of data stored in the
84677 + pages, making it less likely that sensitive information such as
84678 + passwords, cryptographic secrets, etc stay in memory for too long.
84679 +
84680 + This is especially useful for programs whose runtime is short, long
84681 + lived processes and the kernel itself benefit from this as long as
84682 + they operate on whole memory pages and ensure timely freeing of pages
84683 + that may hold sensitive information.
84684 +
84685 + The tradeoff is performance impact, on a single CPU system kernel
84686 + compilation sees a 3% slowdown, other systems and workloads may vary
84687 + and you are advised to test this feature on your expected workload
84688 + before deploying it.
84689 +
84690 + Note that this feature does not protect data stored in live pages,
84691 + e.g., process memory swapped to disk may stay there for a long time.
84692 +
84693 +config PAX_MEMORY_STACKLEAK
84694 + bool "Sanitize kernel stack"
84695 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
84696 + depends on X86
84697 + help
84698 + By saying Y here the kernel will erase the kernel stack before it
84699 + returns from a system call. This in turn reduces the information
84700 + that a kernel stack leak bug can reveal.
84701 +
84702 + Note that such a bug can still leak information that was put on
84703 + the stack by the current system call (the one eventually triggering
84704 + the bug) but traces of earlier system calls on the kernel stack
84705 + cannot leak anymore.
84706 +
84707 + The tradeoff is performance impact: on a single CPU system kernel
84708 + compilation sees a 1% slowdown, other systems and workloads may vary
84709 + and you are advised to test this feature on your expected workload
84710 + before deploying it.
84711 +
84712 + Note that the full feature requires a gcc with plugin support,
84713 + i.e., gcc 4.5 or newer. You may need to install the supporting
84714 + headers explicitly in addition to the normal gcc package. Using
84715 + older gcc versions means that functions with large enough stack
84716 + frames may leave uninitialized memory behind that may be exposed
84717 + to a later syscall leaking the stack.
84718 +
84719 +config PAX_MEMORY_UDEREF
84720 + bool "Prevent invalid userland pointer dereference"
84721 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
84722 + depends on (X86 || (ARM && (CPU_V6 || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
84723 + select PAX_PER_CPU_PGD if X86_64
84724 + help
84725 + By saying Y here the kernel will be prevented from dereferencing
84726 + userland pointers in contexts where the kernel expects only kernel
84727 + pointers. This is both a useful runtime debugging feature and a
84728 + security measure that prevents exploiting a class of kernel bugs.
84729 +
84730 + The tradeoff is that some virtualization solutions may experience
84731 + a huge slowdown and therefore you should not enable this feature
84732 + for kernels meant to run in such environments. Whether a given VM
84733 + solution is affected or not is best determined by simply trying it
84734 + out, the performance impact will be obvious right on boot as this
84735 + mechanism engages from very early on. A good rule of thumb is that
84736 + VMs running on CPUs without hardware virtualization support (i.e.,
84737 + the majority of IA-32 CPUs) will likely experience the slowdown.
84738 +
84739 +config PAX_REFCOUNT
84740 + bool "Prevent various kernel object reference counter overflows"
84741 + default y if GRKERNSEC_CONFIG_AUTO
84742 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
84743 + help
84744 + By saying Y here the kernel will detect and prevent overflowing
84745 + various (but not all) kinds of object reference counters. Such
84746 + overflows can normally occur due to bugs only and are often, if
84747 + not always, exploitable.
84748 +
84749 + The tradeoff is that data structures protected by an overflowed
84750 + refcount will never be freed and therefore will leak memory. Note
84751 + that this leak also happens even without this protection but in
84752 + that case the overflow can eventually trigger the freeing of the
84753 + data structure while it is still being used elsewhere, resulting
84754 + in the exploitable situation that this feature prevents.
84755 +
84756 + Since this has a negligible performance impact, you should enable
84757 + this feature.
84758 +
84759 +config PAX_USERCOPY
84760 + bool "Harden heap object copies between kernel and userland"
84761 + default y if GRKERNSEC_CONFIG_AUTO
84762 + depends on ARM || IA64 || PPC || SPARC || X86
84763 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
84764 + select PAX_USERCOPY_SLABS
84765 + help
84766 + By saying Y here the kernel will enforce the size of heap objects
84767 + when they are copied in either direction between the kernel and
84768 + userland, even if only a part of the heap object is copied.
84769 +
84770 + Specifically, this checking prevents information leaking from the
84771 + kernel heap during kernel to userland copies (if the kernel heap
84772 + object is otherwise fully initialized) and prevents kernel heap
84773 + overflows during userland to kernel copies.
84774 +
84775 + Note that the current implementation provides the strictest bounds
84776 + checks for the SLUB allocator.
84777 +
84778 + Enabling this option also enables per-slab cache protection against
84779 + data in a given cache being copied into/out of via userland
84780 + accessors. Though the whitelist of regions will be reduced over
84781 + time, it notably protects important data structures like task structs.
84782 +
84783 + If frame pointers are enabled on x86, this option will also restrict
84784 + copies into and out of the kernel stack to local variables within a
84785 + single frame.
84786 +
84787 + Since this has a negligible performance impact, you should enable
84788 + this feature.
84789 +
84790 +
84791 +config PAX_USERCOPY_DEBUG
84792 + bool
84793 + depends on X86 && PAX_USERCOPY
84794 + default n
84795 +
84796 +config PAX_SIZE_OVERFLOW
84797 + bool "Prevent various integer overflows in function size parameters"
84798 + default y if GRKERNSEC_CONFIG_AUTO
84799 + depends on X86
84800 + help
84801 + By saying Y here the kernel recomputes expressions of function
84802 + arguments marked by a size_overflow attribute with double integer
84803 + precision (DImode/TImode for 32/64 bit integer types).
84804 +
84805 + The recomputed argument is checked against TYPE_MAX and an event
84806 + is logged on overflow and the triggering process is killed.
84807 +
84808 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
84809 +
84810 + Note that the implementation requires a gcc with plugin support,
84811 + i.e., gcc 4.5 or newer. You may need to install the supporting
84812 + headers explicitly in addition to the normal gcc package.
84813 +
84814 +config PAX_LATENT_ENTROPY
84815 + bool "Generate some entropy during boot"
84816 + default y if GRKERNSEC_CONFIG_AUTO
84817 + help
84818 + By saying Y here the kernel will instrument early boot code to
84819 + extract some entropy from both original and artificially created
84820 + program state. This will help especially embedded systems where
84821 + there is little 'natural' source of entropy normally. The cost
84822 + is some slowdown of the boot process.
84823 +
84824 + Note that the implementation requires a gcc with plugin support,
84825 + i.e., gcc 4.5 or newer. You may need to install the supporting
84826 + headers explicitly in addition to the normal gcc package.
84827 +
84828 + Note that entropy extracted this way is not cryptographically
84829 + secure!
84830 +
84831 +endmenu
84832 +
84833 +endmenu
84834 +
84835 +source grsecurity/Kconfig
84836 +
84837 +endmenu
84838 +
84839 +endmenu
84840 +
84841 source security/keys/Kconfig
84842
84843 config SECURITY_DMESG_RESTRICT
84844 @@ -103,7 +999,7 @@ config INTEL_TXT
84845 config LSM_MMAP_MIN_ADDR
84846 int "Low address space for LSM to protect from user allocation"
84847 depends on SECURITY && SECURITY_SELINUX
84848 - default 32768 if ARM
84849 + default 32768 if ALPHA || ARM || PARISC || SPARC32
84850 default 65536
84851 help
84852 This is the portion of low virtual memory which should be protected
84853 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
84854 index 8c2a7f6..b133ac9 100644
84855 --- a/security/apparmor/lsm.c
84856 +++ b/security/apparmor/lsm.c
84857 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
84858 return error;
84859 }
84860
84861 -static struct security_operations apparmor_ops = {
84862 +static struct security_operations apparmor_ops __read_only = {
84863 .name = "apparmor",
84864
84865 .ptrace_access_check = apparmor_ptrace_access_check,
84866 diff --git a/security/commoncap.c b/security/commoncap.c
84867 index 7ee08c7..8d1a9d6 100644
84868 --- a/security/commoncap.c
84869 +++ b/security/commoncap.c
84870 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
84871 return 0;
84872 }
84873
84874 +/* returns:
84875 + 1 for suid privilege
84876 + 2 for sgid privilege
84877 + 3 for fscap privilege
84878 +*/
84879 +int is_privileged_binary(const struct dentry *dentry)
84880 +{
84881 + struct cpu_vfs_cap_data capdata;
84882 + struct inode *inode = dentry->d_inode;
84883 +
84884 + if (!inode || S_ISDIR(inode->i_mode))
84885 + return 0;
84886 +
84887 + if (inode->i_mode & S_ISUID)
84888 + return 1;
84889 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
84890 + return 2;
84891 +
84892 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
84893 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
84894 + return 3;
84895 + }
84896 +
84897 + return 0;
84898 +}
84899 +
84900 /*
84901 * Attempt to get the on-exec apply capability sets for an executable file from
84902 * its xattrs and, if present, apply them to the proposed credentials being
84903 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
84904 const struct cred *cred = current_cred();
84905 kuid_t root_uid = make_kuid(cred->user_ns, 0);
84906
84907 + if (gr_acl_enable_at_secure())
84908 + return 1;
84909 +
84910 if (!uid_eq(cred->uid, root_uid)) {
84911 if (bprm->cap_effective)
84912 return 1;
84913 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
84914 index 079a85d..12e93f8 100644
84915 --- a/security/integrity/ima/ima.h
84916 +++ b/security/integrity/ima/ima.h
84917 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84918 extern spinlock_t ima_queue_lock;
84919
84920 struct ima_h_table {
84921 - atomic_long_t len; /* number of stored measurements in the list */
84922 - atomic_long_t violations;
84923 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
84924 + atomic_long_unchecked_t violations;
84925 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
84926 };
84927 extern struct ima_h_table ima_htable;
84928 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
84929 index 0cea3db..2f0ef77 100644
84930 --- a/security/integrity/ima/ima_api.c
84931 +++ b/security/integrity/ima/ima_api.c
84932 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84933 int result;
84934
84935 /* can overflow, only indicator */
84936 - atomic_long_inc(&ima_htable.violations);
84937 + atomic_long_inc_unchecked(&ima_htable.violations);
84938
84939 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
84940 if (!entry) {
84941 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
84942 index 38477c9..87a60c7 100644
84943 --- a/security/integrity/ima/ima_fs.c
84944 +++ b/security/integrity/ima/ima_fs.c
84945 @@ -28,12 +28,12 @@
84946 static int valid_policy = 1;
84947 #define TMPBUFLEN 12
84948 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
84949 - loff_t *ppos, atomic_long_t *val)
84950 + loff_t *ppos, atomic_long_unchecked_t *val)
84951 {
84952 char tmpbuf[TMPBUFLEN];
84953 ssize_t len;
84954
84955 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
84956 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
84957 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
84958 }
84959
84960 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
84961 index 55a6271..ad829c3 100644
84962 --- a/security/integrity/ima/ima_queue.c
84963 +++ b/security/integrity/ima/ima_queue.c
84964 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
84965 INIT_LIST_HEAD(&qe->later);
84966 list_add_tail_rcu(&qe->later, &ima_measurements);
84967
84968 - atomic_long_inc(&ima_htable.len);
84969 + atomic_long_inc_unchecked(&ima_htable.len);
84970 key = ima_hash_key(entry->digest);
84971 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
84972 return 0;
84973 diff --git a/security/keys/compat.c b/security/keys/compat.c
84974 index 1c26176..64a1ba2 100644
84975 --- a/security/keys/compat.c
84976 +++ b/security/keys/compat.c
84977 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
84978 if (ret == 0)
84979 goto no_payload_free;
84980
84981 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
84982 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
84983
84984 if (iov != iovstack)
84985 kfree(iov);
84986 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
84987 index 4b5c948..2054dc1 100644
84988 --- a/security/keys/keyctl.c
84989 +++ b/security/keys/keyctl.c
84990 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
84991 /*
84992 * Copy the iovec data from userspace
84993 */
84994 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
84995 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
84996 unsigned ioc)
84997 {
84998 for (; ioc > 0; ioc--) {
84999 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
85000 * If successful, 0 will be returned.
85001 */
85002 long keyctl_instantiate_key_common(key_serial_t id,
85003 - const struct iovec *payload_iov,
85004 + const struct iovec __user *payload_iov,
85005 unsigned ioc,
85006 size_t plen,
85007 key_serial_t ringid)
85008 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
85009 [0].iov_len = plen
85010 };
85011
85012 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
85013 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
85014 }
85015
85016 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
85017 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
85018 if (ret == 0)
85019 goto no_payload_free;
85020
85021 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
85022 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
85023 err:
85024 if (iov != iovstack)
85025 kfree(iov);
85026 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
85027 index 6ece7f2..ecdb55c 100644
85028 --- a/security/keys/keyring.c
85029 +++ b/security/keys/keyring.c
85030 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
85031 ret = -EFAULT;
85032
85033 for (loop = 0; loop < klist->nkeys; loop++) {
85034 + key_serial_t serial;
85035 key = rcu_deref_link_locked(klist, loop,
85036 keyring);
85037 + serial = key->serial;
85038
85039 tmp = sizeof(key_serial_t);
85040 if (tmp > buflen)
85041 tmp = buflen;
85042
85043 - if (copy_to_user(buffer,
85044 - &key->serial,
85045 - tmp) != 0)
85046 + if (copy_to_user(buffer, &serial, tmp))
85047 goto error;
85048
85049 buflen -= tmp;
85050 diff --git a/security/min_addr.c b/security/min_addr.c
85051 index f728728..6457a0c 100644
85052 --- a/security/min_addr.c
85053 +++ b/security/min_addr.c
85054 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
85055 */
85056 static void update_mmap_min_addr(void)
85057 {
85058 +#ifndef SPARC
85059 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
85060 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
85061 mmap_min_addr = dac_mmap_min_addr;
85062 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
85063 #else
85064 mmap_min_addr = dac_mmap_min_addr;
85065 #endif
85066 +#endif
85067 }
85068
85069 /*
85070 diff --git a/security/security.c b/security/security.c
85071 index 7b88c6a..1e3ea8f 100644
85072 --- a/security/security.c
85073 +++ b/security/security.c
85074 @@ -20,6 +20,7 @@
85075 #include <linux/ima.h>
85076 #include <linux/evm.h>
85077 #include <linux/fsnotify.h>
85078 +#include <linux/mm.h>
85079 #include <linux/mman.h>
85080 #include <linux/mount.h>
85081 #include <linux/personality.h>
85082 @@ -32,8 +33,8 @@
85083 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
85084 CONFIG_DEFAULT_SECURITY;
85085
85086 -static struct security_operations *security_ops;
85087 -static struct security_operations default_security_ops = {
85088 +static struct security_operations *security_ops __read_only;
85089 +static struct security_operations default_security_ops __read_only = {
85090 .name = "default",
85091 };
85092
85093 @@ -74,7 +75,9 @@ int __init security_init(void)
85094
85095 void reset_security_ops(void)
85096 {
85097 + pax_open_kernel();
85098 security_ops = &default_security_ops;
85099 + pax_close_kernel();
85100 }
85101
85102 /* Save user chosen LSM */
85103 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
85104 index ef26e96..642fb78 100644
85105 --- a/security/selinux/hooks.c
85106 +++ b/security/selinux/hooks.c
85107 @@ -95,8 +95,6 @@
85108
85109 #define NUM_SEL_MNT_OPTS 5
85110
85111 -extern struct security_operations *security_ops;
85112 -
85113 /* SECMARK reference count */
85114 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
85115
85116 @@ -5501,7 +5499,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
85117
85118 #endif
85119
85120 -static struct security_operations selinux_ops = {
85121 +static struct security_operations selinux_ops __read_only = {
85122 .name = "selinux",
85123
85124 .ptrace_access_check = selinux_ptrace_access_check,
85125 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
85126 index 65f67cb..3f141ef 100644
85127 --- a/security/selinux/include/xfrm.h
85128 +++ b/security/selinux/include/xfrm.h
85129 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
85130
85131 static inline void selinux_xfrm_notify_policyload(void)
85132 {
85133 - atomic_inc(&flow_cache_genid);
85134 + atomic_inc_unchecked(&flow_cache_genid);
85135 rt_genid_bump(&init_net);
85136 }
85137 #else
85138 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
85139 index 38be92c..21f49ee 100644
85140 --- a/security/smack/smack_lsm.c
85141 +++ b/security/smack/smack_lsm.c
85142 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
85143 return 0;
85144 }
85145
85146 -struct security_operations smack_ops = {
85147 +struct security_operations smack_ops __read_only = {
85148 .name = "smack",
85149
85150 .ptrace_access_check = smack_ptrace_access_check,
85151 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
85152 index a2ee362..5754f34 100644
85153 --- a/security/tomoyo/tomoyo.c
85154 +++ b/security/tomoyo/tomoyo.c
85155 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
85156 * tomoyo_security_ops is a "struct security_operations" which is used for
85157 * registering TOMOYO.
85158 */
85159 -static struct security_operations tomoyo_security_ops = {
85160 +static struct security_operations tomoyo_security_ops __read_only = {
85161 .name = "tomoyo",
85162 .cred_alloc_blank = tomoyo_cred_alloc_blank,
85163 .cred_prepare = tomoyo_cred_prepare,
85164 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
85165 index 20ef514..4182bed 100644
85166 --- a/security/yama/Kconfig
85167 +++ b/security/yama/Kconfig
85168 @@ -1,6 +1,6 @@
85169 config SECURITY_YAMA
85170 bool "Yama support"
85171 - depends on SECURITY
85172 + depends on SECURITY && !GRKERNSEC
85173 select SECURITYFS
85174 select SECURITY_PATH
85175 default n
85176 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
85177 index 4cedc69..e59d8a3 100644
85178 --- a/sound/aoa/codecs/onyx.c
85179 +++ b/sound/aoa/codecs/onyx.c
85180 @@ -54,7 +54,7 @@ struct onyx {
85181 spdif_locked:1,
85182 analog_locked:1,
85183 original_mute:2;
85184 - int open_count;
85185 + local_t open_count;
85186 struct codec_info *codec_info;
85187
85188 /* mutex serializes concurrent access to the device
85189 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
85190 struct onyx *onyx = cii->codec_data;
85191
85192 mutex_lock(&onyx->mutex);
85193 - onyx->open_count++;
85194 + local_inc(&onyx->open_count);
85195 mutex_unlock(&onyx->mutex);
85196
85197 return 0;
85198 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
85199 struct onyx *onyx = cii->codec_data;
85200
85201 mutex_lock(&onyx->mutex);
85202 - onyx->open_count--;
85203 - if (!onyx->open_count)
85204 + if (local_dec_and_test(&onyx->open_count))
85205 onyx->spdif_locked = onyx->analog_locked = 0;
85206 mutex_unlock(&onyx->mutex);
85207
85208 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
85209 index ffd2025..df062c9 100644
85210 --- a/sound/aoa/codecs/onyx.h
85211 +++ b/sound/aoa/codecs/onyx.h
85212 @@ -11,6 +11,7 @@
85213 #include <linux/i2c.h>
85214 #include <asm/pmac_low_i2c.h>
85215 #include <asm/prom.h>
85216 +#include <asm/local.h>
85217
85218 /* PCM3052 register definitions */
85219
85220 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
85221 index 4c1cc51..16040040 100644
85222 --- a/sound/core/oss/pcm_oss.c
85223 +++ b/sound/core/oss/pcm_oss.c
85224 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
85225 if (in_kernel) {
85226 mm_segment_t fs;
85227 fs = snd_enter_user();
85228 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
85229 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
85230 snd_leave_user(fs);
85231 } else {
85232 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
85233 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
85234 }
85235 if (ret != -EPIPE && ret != -ESTRPIPE)
85236 break;
85237 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
85238 if (in_kernel) {
85239 mm_segment_t fs;
85240 fs = snd_enter_user();
85241 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
85242 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
85243 snd_leave_user(fs);
85244 } else {
85245 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
85246 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
85247 }
85248 if (ret == -EPIPE) {
85249 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
85250 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
85251 struct snd_pcm_plugin_channel *channels;
85252 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
85253 if (!in_kernel) {
85254 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
85255 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
85256 return -EFAULT;
85257 buf = runtime->oss.buffer;
85258 }
85259 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
85260 }
85261 } else {
85262 tmp = snd_pcm_oss_write2(substream,
85263 - (const char __force *)buf,
85264 + (const char __force_kernel *)buf,
85265 runtime->oss.period_bytes, 0);
85266 if (tmp <= 0)
85267 goto err;
85268 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
85269 struct snd_pcm_runtime *runtime = substream->runtime;
85270 snd_pcm_sframes_t frames, frames1;
85271 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
85272 - char __user *final_dst = (char __force __user *)buf;
85273 + char __user *final_dst = (char __force_user *)buf;
85274 if (runtime->oss.plugin_first) {
85275 struct snd_pcm_plugin_channel *channels;
85276 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
85277 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
85278 xfer += tmp;
85279 runtime->oss.buffer_used -= tmp;
85280 } else {
85281 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
85282 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
85283 runtime->oss.period_bytes, 0);
85284 if (tmp <= 0)
85285 goto err;
85286 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
85287 size1);
85288 size1 /= runtime->channels; /* frames */
85289 fs = snd_enter_user();
85290 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
85291 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
85292 snd_leave_user(fs);
85293 }
85294 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
85295 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
85296 index af49721..e85058e 100644
85297 --- a/sound/core/pcm_compat.c
85298 +++ b/sound/core/pcm_compat.c
85299 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
85300 int err;
85301
85302 fs = snd_enter_user();
85303 - err = snd_pcm_delay(substream, &delay);
85304 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
85305 snd_leave_user(fs);
85306 if (err < 0)
85307 return err;
85308 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
85309 index 09b4286..8620fac 100644
85310 --- a/sound/core/pcm_native.c
85311 +++ b/sound/core/pcm_native.c
85312 @@ -2806,11 +2806,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
85313 switch (substream->stream) {
85314 case SNDRV_PCM_STREAM_PLAYBACK:
85315 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
85316 - (void __user *)arg);
85317 + (void __force_user *)arg);
85318 break;
85319 case SNDRV_PCM_STREAM_CAPTURE:
85320 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
85321 - (void __user *)arg);
85322 + (void __force_user *)arg);
85323 break;
85324 default:
85325 result = -EINVAL;
85326 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
85327 index 040c60e..989a19a 100644
85328 --- a/sound/core/seq/seq_device.c
85329 +++ b/sound/core/seq/seq_device.c
85330 @@ -64,7 +64,7 @@ struct ops_list {
85331 int argsize; /* argument size */
85332
85333 /* operators */
85334 - struct snd_seq_dev_ops ops;
85335 + struct snd_seq_dev_ops *ops;
85336
85337 /* registered devices */
85338 struct list_head dev_list; /* list of devices */
85339 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
85340
85341 mutex_lock(&ops->reg_mutex);
85342 /* copy driver operators */
85343 - ops->ops = *entry;
85344 + ops->ops = entry;
85345 ops->driver |= DRIVER_LOADED;
85346 ops->argsize = argsize;
85347
85348 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
85349 dev->name, ops->id, ops->argsize, dev->argsize);
85350 return -EINVAL;
85351 }
85352 - if (ops->ops.init_device(dev) >= 0) {
85353 + if (ops->ops->init_device(dev) >= 0) {
85354 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
85355 ops->num_init_devices++;
85356 } else {
85357 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
85358 dev->name, ops->id, ops->argsize, dev->argsize);
85359 return -EINVAL;
85360 }
85361 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
85362 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
85363 dev->status = SNDRV_SEQ_DEVICE_FREE;
85364 dev->driver_data = NULL;
85365 ops->num_init_devices--;
85366 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
85367 index 4e0dd22..7a1f32c 100644
85368 --- a/sound/drivers/mts64.c
85369 +++ b/sound/drivers/mts64.c
85370 @@ -29,6 +29,7 @@
85371 #include <sound/initval.h>
85372 #include <sound/rawmidi.h>
85373 #include <sound/control.h>
85374 +#include <asm/local.h>
85375
85376 #define CARD_NAME "Miditerminal 4140"
85377 #define DRIVER_NAME "MTS64"
85378 @@ -67,7 +68,7 @@ struct mts64 {
85379 struct pardevice *pardev;
85380 int pardev_claimed;
85381
85382 - int open_count;
85383 + local_t open_count;
85384 int current_midi_output_port;
85385 int current_midi_input_port;
85386 u8 mode[MTS64_NUM_INPUT_PORTS];
85387 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
85388 {
85389 struct mts64 *mts = substream->rmidi->private_data;
85390
85391 - if (mts->open_count == 0) {
85392 + if (local_read(&mts->open_count) == 0) {
85393 /* We don't need a spinlock here, because this is just called
85394 if the device has not been opened before.
85395 So there aren't any IRQs from the device */
85396 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
85397
85398 msleep(50);
85399 }
85400 - ++(mts->open_count);
85401 + local_inc(&mts->open_count);
85402
85403 return 0;
85404 }
85405 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
85406 struct mts64 *mts = substream->rmidi->private_data;
85407 unsigned long flags;
85408
85409 - --(mts->open_count);
85410 - if (mts->open_count == 0) {
85411 + if (local_dec_return(&mts->open_count) == 0) {
85412 /* We need the spinlock_irqsave here because we can still
85413 have IRQs at this point */
85414 spin_lock_irqsave(&mts->lock, flags);
85415 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
85416
85417 msleep(500);
85418
85419 - } else if (mts->open_count < 0)
85420 - mts->open_count = 0;
85421 + } else if (local_read(&mts->open_count) < 0)
85422 + local_set(&mts->open_count, 0);
85423
85424 return 0;
85425 }
85426 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
85427 index b953fb4..1999c01 100644
85428 --- a/sound/drivers/opl4/opl4_lib.c
85429 +++ b/sound/drivers/opl4/opl4_lib.c
85430 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
85431 MODULE_DESCRIPTION("OPL4 driver");
85432 MODULE_LICENSE("GPL");
85433
85434 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
85435 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
85436 {
85437 int timeout = 10;
85438 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
85439 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
85440 index 991018d..8984740 100644
85441 --- a/sound/drivers/portman2x4.c
85442 +++ b/sound/drivers/portman2x4.c
85443 @@ -48,6 +48,7 @@
85444 #include <sound/initval.h>
85445 #include <sound/rawmidi.h>
85446 #include <sound/control.h>
85447 +#include <asm/local.h>
85448
85449 #define CARD_NAME "Portman 2x4"
85450 #define DRIVER_NAME "portman"
85451 @@ -85,7 +86,7 @@ struct portman {
85452 struct pardevice *pardev;
85453 int pardev_claimed;
85454
85455 - int open_count;
85456 + local_t open_count;
85457 int mode[PORTMAN_NUM_INPUT_PORTS];
85458 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
85459 };
85460 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
85461 index ea995af..f1bfa37 100644
85462 --- a/sound/firewire/amdtp.c
85463 +++ b/sound/firewire/amdtp.c
85464 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
85465 ptr = s->pcm_buffer_pointer + data_blocks;
85466 if (ptr >= pcm->runtime->buffer_size)
85467 ptr -= pcm->runtime->buffer_size;
85468 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
85469 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
85470
85471 s->pcm_period_pointer += data_blocks;
85472 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
85473 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
85474 */
85475 void amdtp_out_stream_update(struct amdtp_out_stream *s)
85476 {
85477 - ACCESS_ONCE(s->source_node_id_field) =
85478 + ACCESS_ONCE_RW(s->source_node_id_field) =
85479 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
85480 }
85481 EXPORT_SYMBOL(amdtp_out_stream_update);
85482 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
85483 index b680c5e..061b7a0 100644
85484 --- a/sound/firewire/amdtp.h
85485 +++ b/sound/firewire/amdtp.h
85486 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
85487 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
85488 struct snd_pcm_substream *pcm)
85489 {
85490 - ACCESS_ONCE(s->pcm) = pcm;
85491 + ACCESS_ONCE_RW(s->pcm) = pcm;
85492 }
85493
85494 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
85495 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
85496 index d428ffe..751ef78 100644
85497 --- a/sound/firewire/isight.c
85498 +++ b/sound/firewire/isight.c
85499 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
85500 ptr += count;
85501 if (ptr >= runtime->buffer_size)
85502 ptr -= runtime->buffer_size;
85503 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
85504 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
85505
85506 isight->period_counter += count;
85507 if (isight->period_counter >= runtime->period_size) {
85508 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
85509 if (err < 0)
85510 return err;
85511
85512 - ACCESS_ONCE(isight->pcm_active) = true;
85513 + ACCESS_ONCE_RW(isight->pcm_active) = true;
85514
85515 return 0;
85516 }
85517 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
85518 {
85519 struct isight *isight = substream->private_data;
85520
85521 - ACCESS_ONCE(isight->pcm_active) = false;
85522 + ACCESS_ONCE_RW(isight->pcm_active) = false;
85523
85524 mutex_lock(&isight->mutex);
85525 isight_stop_streaming(isight);
85526 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
85527
85528 switch (cmd) {
85529 case SNDRV_PCM_TRIGGER_START:
85530 - ACCESS_ONCE(isight->pcm_running) = true;
85531 + ACCESS_ONCE_RW(isight->pcm_running) = true;
85532 break;
85533 case SNDRV_PCM_TRIGGER_STOP:
85534 - ACCESS_ONCE(isight->pcm_running) = false;
85535 + ACCESS_ONCE_RW(isight->pcm_running) = false;
85536 break;
85537 default:
85538 return -EINVAL;
85539 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
85540 index 844a555..985ab83 100644
85541 --- a/sound/firewire/scs1x.c
85542 +++ b/sound/firewire/scs1x.c
85543 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
85544 {
85545 struct scs *scs = stream->rmidi->private_data;
85546
85547 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
85548 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
85549 if (up) {
85550 scs->output_idle = false;
85551 tasklet_schedule(&scs->tasklet);
85552 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
85553 {
85554 struct scs *scs = stream->rmidi->private_data;
85555
85556 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
85557 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
85558 }
85559
85560 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
85561 @@ -457,8 +457,8 @@ static int scs_remove(struct device *dev)
85562
85563 snd_card_disconnect(scs->card);
85564
85565 - ACCESS_ONCE(scs->output) = NULL;
85566 - ACCESS_ONCE(scs->input) = NULL;
85567 + ACCESS_ONCE_RW(scs->output) = NULL;
85568 + ACCESS_ONCE_RW(scs->input) = NULL;
85569
85570 wait_event(scs->idle_wait, scs->output_idle);
85571
85572 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
85573 index 048439a..3be9f6f 100644
85574 --- a/sound/oss/sb_audio.c
85575 +++ b/sound/oss/sb_audio.c
85576 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
85577 buf16 = (signed short *)(localbuf + localoffs);
85578 while (c)
85579 {
85580 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
85581 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
85582 if (copy_from_user(lbuf8,
85583 userbuf+useroffs + p,
85584 locallen))
85585 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
85586 index 7d8803a..559f8d0 100644
85587 --- a/sound/oss/swarm_cs4297a.c
85588 +++ b/sound/oss/swarm_cs4297a.c
85589 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
85590 {
85591 struct cs4297a_state *s;
85592 u32 pwr, id;
85593 - mm_segment_t fs;
85594 int rval;
85595 #ifndef CONFIG_BCM_CS4297A_CSWARM
85596 u64 cfg;
85597 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
85598 if (!rval) {
85599 char *sb1250_duart_present;
85600
85601 +#if 0
85602 + mm_segment_t fs;
85603 fs = get_fs();
85604 set_fs(KERNEL_DS);
85605 -#if 0
85606 val = SOUND_MASK_LINE;
85607 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
85608 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
85609 val = initvol[i].vol;
85610 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
85611 }
85612 + set_fs(fs);
85613 // cs4297a_write_ac97(s, 0x18, 0x0808);
85614 #else
85615 // cs4297a_write_ac97(s, 0x5e, 0x180);
85616 cs4297a_write_ac97(s, 0x02, 0x0808);
85617 cs4297a_write_ac97(s, 0x18, 0x0808);
85618 #endif
85619 - set_fs(fs);
85620
85621 list_add(&s->list, &cs4297a_devs);
85622
85623 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
85624 index 4631a23..001ae57 100644
85625 --- a/sound/pci/ymfpci/ymfpci.h
85626 +++ b/sound/pci/ymfpci/ymfpci.h
85627 @@ -358,7 +358,7 @@ struct snd_ymfpci {
85628 spinlock_t reg_lock;
85629 spinlock_t voice_lock;
85630 wait_queue_head_t interrupt_sleep;
85631 - atomic_t interrupt_sleep_count;
85632 + atomic_unchecked_t interrupt_sleep_count;
85633 struct snd_info_entry *proc_entry;
85634 const struct firmware *dsp_microcode;
85635 const struct firmware *controller_microcode;
85636 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
85637 index 22056c5..25d3244 100644
85638 --- a/sound/pci/ymfpci/ymfpci_main.c
85639 +++ b/sound/pci/ymfpci/ymfpci_main.c
85640 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
85641 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
85642 break;
85643 }
85644 - if (atomic_read(&chip->interrupt_sleep_count)) {
85645 - atomic_set(&chip->interrupt_sleep_count, 0);
85646 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
85647 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85648 wake_up(&chip->interrupt_sleep);
85649 }
85650 __end:
85651 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
85652 continue;
85653 init_waitqueue_entry(&wait, current);
85654 add_wait_queue(&chip->interrupt_sleep, &wait);
85655 - atomic_inc(&chip->interrupt_sleep_count);
85656 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
85657 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
85658 remove_wait_queue(&chip->interrupt_sleep, &wait);
85659 }
85660 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
85661 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
85662 spin_unlock(&chip->reg_lock);
85663
85664 - if (atomic_read(&chip->interrupt_sleep_count)) {
85665 - atomic_set(&chip->interrupt_sleep_count, 0);
85666 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
85667 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85668 wake_up(&chip->interrupt_sleep);
85669 }
85670 }
85671 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
85672 spin_lock_init(&chip->reg_lock);
85673 spin_lock_init(&chip->voice_lock);
85674 init_waitqueue_head(&chip->interrupt_sleep);
85675 - atomic_set(&chip->interrupt_sleep_count, 0);
85676 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85677 chip->card = card;
85678 chip->pci = pci;
85679 chip->irq = -1;
85680 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
85681 new file mode 100644
85682 index 0000000..50f2f2f
85683 --- /dev/null
85684 +++ b/tools/gcc/.gitignore
85685 @@ -0,0 +1 @@
85686 +size_overflow_hash.h
85687 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
85688 new file mode 100644
85689 index 0000000..1d09b7e
85690 --- /dev/null
85691 +++ b/tools/gcc/Makefile
85692 @@ -0,0 +1,43 @@
85693 +#CC := gcc
85694 +#PLUGIN_SOURCE_FILES := pax_plugin.c
85695 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
85696 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
85697 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
85698 +
85699 +ifeq ($(PLUGINCC),$(HOSTCC))
85700 +HOSTLIBS := hostlibs
85701 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
85702 +else
85703 +HOSTLIBS := hostcxxlibs
85704 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
85705 +endif
85706 +
85707 +$(HOSTLIBS)-y := constify_plugin.so
85708 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
85709 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
85710 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
85711 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
85712 +$(HOSTLIBS)-y += colorize_plugin.so
85713 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
85714 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
85715 +
85716 +always := $($(HOSTLIBS)-y)
85717 +
85718 +constify_plugin-objs := constify_plugin.o
85719 +stackleak_plugin-objs := stackleak_plugin.o
85720 +kallocstat_plugin-objs := kallocstat_plugin.o
85721 +kernexec_plugin-objs := kernexec_plugin.o
85722 +checker_plugin-objs := checker_plugin.o
85723 +colorize_plugin-objs := colorize_plugin.o
85724 +size_overflow_plugin-objs := size_overflow_plugin.o
85725 +latent_entropy_plugin-objs := latent_entropy_plugin.o
85726 +
85727 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
85728 +
85729 +quiet_cmd_build_size_overflow_hash = GENHASH $@
85730 + cmd_build_size_overflow_hash = \
85731 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
85732 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
85733 + $(call if_changed,build_size_overflow_hash)
85734 +
85735 +targets += size_overflow_hash.h
85736 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
85737 new file mode 100644
85738 index 0000000..d41b5af
85739 --- /dev/null
85740 +++ b/tools/gcc/checker_plugin.c
85741 @@ -0,0 +1,171 @@
85742 +/*
85743 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85744 + * Licensed under the GPL v2
85745 + *
85746 + * Note: the choice of the license means that the compilation process is
85747 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85748 + * but for the kernel it doesn't matter since it doesn't link against
85749 + * any of the gcc libraries
85750 + *
85751 + * gcc plugin to implement various sparse (source code checker) features
85752 + *
85753 + * TODO:
85754 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
85755 + *
85756 + * BUGS:
85757 + * - none known
85758 + */
85759 +#include "gcc-plugin.h"
85760 +#include "config.h"
85761 +#include "system.h"
85762 +#include "coretypes.h"
85763 +#include "tree.h"
85764 +#include "tree-pass.h"
85765 +#include "flags.h"
85766 +#include "intl.h"
85767 +#include "toplev.h"
85768 +#include "plugin.h"
85769 +//#include "expr.h" where are you...
85770 +#include "diagnostic.h"
85771 +#include "plugin-version.h"
85772 +#include "tm.h"
85773 +#include "function.h"
85774 +#include "basic-block.h"
85775 +#include "gimple.h"
85776 +#include "rtl.h"
85777 +#include "emit-rtl.h"
85778 +#include "tree-flow.h"
85779 +#include "target.h"
85780 +
85781 +extern void c_register_addr_space (const char *str, addr_space_t as);
85782 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
85783 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
85784 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
85785 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
85786 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
85787 +
85788 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85789 +extern rtx emit_move_insn(rtx x, rtx y);
85790 +
85791 +int plugin_is_GPL_compatible;
85792 +
85793 +static struct plugin_info checker_plugin_info = {
85794 + .version = "201111150100",
85795 +};
85796 +
85797 +#define ADDR_SPACE_KERNEL 0
85798 +#define ADDR_SPACE_FORCE_KERNEL 1
85799 +#define ADDR_SPACE_USER 2
85800 +#define ADDR_SPACE_FORCE_USER 3
85801 +#define ADDR_SPACE_IOMEM 0
85802 +#define ADDR_SPACE_FORCE_IOMEM 0
85803 +#define ADDR_SPACE_PERCPU 0
85804 +#define ADDR_SPACE_FORCE_PERCPU 0
85805 +#define ADDR_SPACE_RCU 0
85806 +#define ADDR_SPACE_FORCE_RCU 0
85807 +
85808 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
85809 +{
85810 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
85811 +}
85812 +
85813 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
85814 +{
85815 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
85816 +}
85817 +
85818 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
85819 +{
85820 + return default_addr_space_valid_pointer_mode(mode, as);
85821 +}
85822 +
85823 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
85824 +{
85825 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
85826 +}
85827 +
85828 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
85829 +{
85830 + return default_addr_space_legitimize_address(x, oldx, mode, as);
85831 +}
85832 +
85833 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
85834 +{
85835 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
85836 + return true;
85837 +
85838 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
85839 + return true;
85840 +
85841 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
85842 + return true;
85843 +
85844 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
85845 + return true;
85846 +
85847 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
85848 + return true;
85849 +
85850 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
85851 + return true;
85852 +
85853 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
85854 + return true;
85855 +
85856 + return subset == superset;
85857 +}
85858 +
85859 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
85860 +{
85861 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
85862 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
85863 +
85864 + return op;
85865 +}
85866 +
85867 +static void register_checker_address_spaces(void *event_data, void *data)
85868 +{
85869 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
85870 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
85871 + c_register_addr_space("__user", ADDR_SPACE_USER);
85872 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
85873 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
85874 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
85875 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
85876 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
85877 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
85878 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
85879 +
85880 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
85881 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
85882 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
85883 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
85884 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
85885 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
85886 + targetm.addr_space.convert = checker_addr_space_convert;
85887 +}
85888 +
85889 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85890 +{
85891 + const char * const plugin_name = plugin_info->base_name;
85892 + const int argc = plugin_info->argc;
85893 + const struct plugin_argument * const argv = plugin_info->argv;
85894 + int i;
85895 +
85896 + if (!plugin_default_version_check(version, &gcc_version)) {
85897 + error(G_("incompatible gcc/plugin versions"));
85898 + return 1;
85899 + }
85900 +
85901 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
85902 +
85903 + for (i = 0; i < argc; ++i)
85904 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85905 +
85906 + if (TARGET_64BIT == 0)
85907 + return 0;
85908 +
85909 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
85910 +
85911 + return 0;
85912 +}
85913 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
85914 new file mode 100644
85915 index 0000000..414fe5e
85916 --- /dev/null
85917 +++ b/tools/gcc/colorize_plugin.c
85918 @@ -0,0 +1,151 @@
85919 +/*
85920 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
85921 + * Licensed under the GPL v2
85922 + *
85923 + * Note: the choice of the license means that the compilation process is
85924 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85925 + * but for the kernel it doesn't matter since it doesn't link against
85926 + * any of the gcc libraries
85927 + *
85928 + * gcc plugin to colorize diagnostic output
85929 + *
85930 + */
85931 +
85932 +#include "gcc-plugin.h"
85933 +#include "config.h"
85934 +#include "system.h"
85935 +#include "coretypes.h"
85936 +#include "tree.h"
85937 +#include "tree-pass.h"
85938 +#include "flags.h"
85939 +#include "intl.h"
85940 +#include "toplev.h"
85941 +#include "plugin.h"
85942 +#include "diagnostic.h"
85943 +#include "plugin-version.h"
85944 +#include "tm.h"
85945 +
85946 +int plugin_is_GPL_compatible;
85947 +
85948 +static struct plugin_info colorize_plugin_info = {
85949 + .version = "201302112000",
85950 + .help = NULL,
85951 +};
85952 +
85953 +#define GREEN "\033[32m\033[2m"
85954 +#define LIGHTGREEN "\033[32m\033[1m"
85955 +#define YELLOW "\033[33m\033[2m"
85956 +#define LIGHTYELLOW "\033[33m\033[1m"
85957 +#define RED "\033[31m\033[2m"
85958 +#define LIGHTRED "\033[31m\033[1m"
85959 +#define BLUE "\033[34m\033[2m"
85960 +#define LIGHTBLUE "\033[34m\033[1m"
85961 +#define BRIGHT "\033[m\033[1m"
85962 +#define NORMAL "\033[m"
85963 +
85964 +static diagnostic_starter_fn old_starter;
85965 +static diagnostic_finalizer_fn old_finalizer;
85966 +
85967 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
85968 +{
85969 + const char *color;
85970 + char *newprefix;
85971 +
85972 + switch (diagnostic->kind) {
85973 + case DK_NOTE:
85974 + color = LIGHTBLUE;
85975 + break;
85976 +
85977 + case DK_PEDWARN:
85978 + case DK_WARNING:
85979 + color = LIGHTYELLOW;
85980 + break;
85981 +
85982 + case DK_ERROR:
85983 + case DK_FATAL:
85984 + case DK_ICE:
85985 + case DK_PERMERROR:
85986 + case DK_SORRY:
85987 + color = LIGHTRED;
85988 + break;
85989 +
85990 + default:
85991 + color = NORMAL;
85992 + }
85993 +
85994 + old_starter(context, diagnostic);
85995 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
85996 + return;
85997 + pp_destroy_prefix(context->printer);
85998 + pp_set_prefix(context->printer, newprefix);
85999 +}
86000 +
86001 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
86002 +{
86003 + old_finalizer(context, diagnostic);
86004 +}
86005 +
86006 +static void colorize_arm(void)
86007 +{
86008 + old_starter = diagnostic_starter(global_dc);
86009 + old_finalizer = diagnostic_finalizer(global_dc);
86010 +
86011 + diagnostic_starter(global_dc) = start_colorize;
86012 + diagnostic_finalizer(global_dc) = finalize_colorize;
86013 +}
86014 +
86015 +static unsigned int execute_colorize_rearm(void)
86016 +{
86017 + if (diagnostic_starter(global_dc) == start_colorize)
86018 + return 0;
86019 +
86020 + colorize_arm();
86021 + return 0;
86022 +}
86023 +
86024 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
86025 + .pass = {
86026 + .type = SIMPLE_IPA_PASS,
86027 + .name = "colorize_rearm",
86028 +#if BUILDING_GCC_VERSION >= 4008
86029 + .optinfo_flags = OPTGROUP_NONE,
86030 +#endif
86031 + .gate = NULL,
86032 + .execute = execute_colorize_rearm,
86033 + .sub = NULL,
86034 + .next = NULL,
86035 + .static_pass_number = 0,
86036 + .tv_id = TV_NONE,
86037 + .properties_required = 0,
86038 + .properties_provided = 0,
86039 + .properties_destroyed = 0,
86040 + .todo_flags_start = 0,
86041 + .todo_flags_finish = 0
86042 + }
86043 +};
86044 +
86045 +static void colorize_start_unit(void *gcc_data, void *user_data)
86046 +{
86047 + colorize_arm();
86048 +}
86049 +
86050 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86051 +{
86052 + const char * const plugin_name = plugin_info->base_name;
86053 + struct register_pass_info colorize_rearm_pass_info = {
86054 + .pass = &pass_ipa_colorize_rearm.pass,
86055 + .reference_pass_name = "*free_lang_data",
86056 + .ref_pass_instance_number = 1,
86057 + .pos_op = PASS_POS_INSERT_AFTER
86058 + };
86059 +
86060 + if (!plugin_default_version_check(version, &gcc_version)) {
86061 + error(G_("incompatible gcc/plugin versions"));
86062 + return 1;
86063 + }
86064 +
86065 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
86066 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
86067 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
86068 + return 0;
86069 +}
86070 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
86071 new file mode 100644
86072 index 0000000..8bd6f995
86073 --- /dev/null
86074 +++ b/tools/gcc/constify_plugin.c
86075 @@ -0,0 +1,359 @@
86076 +/*
86077 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
86078 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
86079 + * Licensed under the GPL v2, or (at your option) v3
86080 + *
86081 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
86082 + *
86083 + * Homepage:
86084 + * http://www.grsecurity.net/~ephox/const_plugin/
86085 + *
86086 + * Usage:
86087 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
86088 + * $ gcc -fplugin=constify_plugin.so test.c -O2
86089 + */
86090 +
86091 +#include "gcc-plugin.h"
86092 +#include "config.h"
86093 +#include "system.h"
86094 +#include "coretypes.h"
86095 +#include "tree.h"
86096 +#include "tree-pass.h"
86097 +#include "flags.h"
86098 +#include "intl.h"
86099 +#include "toplev.h"
86100 +#include "plugin.h"
86101 +#include "diagnostic.h"
86102 +#include "plugin-version.h"
86103 +#include "tm.h"
86104 +#include "function.h"
86105 +#include "basic-block.h"
86106 +#include "gimple.h"
86107 +#include "rtl.h"
86108 +#include "emit-rtl.h"
86109 +#include "tree-flow.h"
86110 +
86111 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
86112 +
86113 +int plugin_is_GPL_compatible;
86114 +
86115 +static struct plugin_info const_plugin_info = {
86116 + .version = "201302112000",
86117 + .help = "no-constify\tturn off constification\n",
86118 +};
86119 +
86120 +static tree get_field_type(tree field)
86121 +{
86122 + return strip_array_types(TREE_TYPE(field));
86123 +}
86124 +
86125 +static bool walk_struct(tree node, bool all);
86126 +static void deconstify_tree(tree node);
86127 +
86128 +static void deconstify_type(tree type)
86129 +{
86130 + tree field;
86131 +
86132 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
86133 + tree fieldtype = get_field_type(field);
86134 +
86135 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
86136 + continue;
86137 + if (!TYPE_READONLY(fieldtype))
86138 + continue;
86139 + if (!walk_struct(fieldtype, true))
86140 + continue;
86141 +
86142 + deconstify_tree(field);
86143 + TREE_READONLY(field) = 0;
86144 + }
86145 + TYPE_READONLY(type) = 0;
86146 + C_TYPE_FIELDS_READONLY(type) = 0;
86147 +}
86148 +
86149 +static void deconstify_tree(tree node)
86150 +{
86151 + tree old_type, new_type, field;
86152 +
86153 +// TREE_READONLY(node) = 0;
86154 + old_type = TREE_TYPE(node);
86155 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
86156 + node = old_type;
86157 + old_type = TREE_TYPE(old_type);
86158 + }
86159 +
86160 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
86161 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
86162 +
86163 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
86164 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
86165 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
86166 + DECL_FIELD_CONTEXT(field) = new_type;
86167 +
86168 + deconstify_type(new_type);
86169 +
86170 + TREE_TYPE(node) = new_type;
86171 +}
86172 +
86173 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86174 +{
86175 + tree type;
86176 +
86177 + *no_add_attrs = true;
86178 + if (TREE_CODE(*node) == FUNCTION_DECL) {
86179 + error("%qE attribute does not apply to functions", name);
86180 + return NULL_TREE;
86181 + }
86182 +
86183 + if (TREE_CODE(*node) == VAR_DECL) {
86184 + error("%qE attribute does not apply to variables", name);
86185 + return NULL_TREE;
86186 + }
86187 +
86188 + if (TYPE_P(*node)) {
86189 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
86190 + *no_add_attrs = false;
86191 + else
86192 + error("%qE attribute applies to struct and union types only", name);
86193 + return NULL_TREE;
86194 + }
86195 +
86196 + type = TREE_TYPE(*node);
86197 +
86198 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
86199 + error("%qE attribute applies to struct and union types only", name);
86200 + return NULL_TREE;
86201 + }
86202 +
86203 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
86204 + error("%qE attribute is already applied to the type", name);
86205 + return NULL_TREE;
86206 + }
86207 +
86208 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
86209 + error("%qE attribute used on type that is not constified", name);
86210 + return NULL_TREE;
86211 + }
86212 +
86213 + if (TREE_CODE(*node) == TYPE_DECL) {
86214 + deconstify_tree(*node);
86215 + return NULL_TREE;
86216 + }
86217 +
86218 + return NULL_TREE;
86219 +}
86220 +
86221 +static void constify_type(tree type)
86222 +{
86223 + TYPE_READONLY(type) = 1;
86224 + C_TYPE_FIELDS_READONLY(type) = 1;
86225 +}
86226 +
86227 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86228 +{
86229 + *no_add_attrs = true;
86230 + if (!TYPE_P(*node)) {
86231 + error("%qE attribute applies to types only", name);
86232 + return NULL_TREE;
86233 + }
86234 +
86235 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
86236 + error("%qE attribute applies to struct and union types only", name);
86237 + return NULL_TREE;
86238 + }
86239 +
86240 + *no_add_attrs = false;
86241 + constify_type(*node);
86242 + return NULL_TREE;
86243 +}
86244 +
86245 +static struct attribute_spec no_const_attr = {
86246 + .name = "no_const",
86247 + .min_length = 0,
86248 + .max_length = 0,
86249 + .decl_required = false,
86250 + .type_required = false,
86251 + .function_type_required = false,
86252 + .handler = handle_no_const_attribute,
86253 +#if BUILDING_GCC_VERSION >= 4007
86254 + .affects_type_identity = true
86255 +#endif
86256 +};
86257 +
86258 +static struct attribute_spec do_const_attr = {
86259 + .name = "do_const",
86260 + .min_length = 0,
86261 + .max_length = 0,
86262 + .decl_required = false,
86263 + .type_required = false,
86264 + .function_type_required = false,
86265 + .handler = handle_do_const_attribute,
86266 +#if BUILDING_GCC_VERSION >= 4007
86267 + .affects_type_identity = true
86268 +#endif
86269 +};
86270 +
86271 +static void register_attributes(void *event_data, void *data)
86272 +{
86273 + register_attribute(&no_const_attr);
86274 + register_attribute(&do_const_attr);
86275 +}
86276 +
86277 +static bool is_fptr(tree field)
86278 +{
86279 + tree ptr = get_field_type(field);
86280 +
86281 + if (TREE_CODE(ptr) != POINTER_TYPE)
86282 + return false;
86283 +
86284 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
86285 +}
86286 +
86287 +static bool walk_struct(tree node, bool all)
86288 +{
86289 + tree field;
86290 +
86291 + if (TYPE_FIELDS(node) == NULL_TREE)
86292 + return false;
86293 +
86294 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
86295 + return true;
86296 +
86297 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
86298 + gcc_assert(!TYPE_READONLY(node));
86299 + deconstify_type(node);
86300 + return false;
86301 + }
86302 +
86303 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
86304 + tree type = get_field_type(field);
86305 + enum tree_code code = TREE_CODE(type);
86306 +
86307 + if (node == type)
86308 + return false;
86309 + if (code == RECORD_TYPE || code == UNION_TYPE) {
86310 + if (!(walk_struct(type, all)))
86311 + return false;
86312 + } else if (!is_fptr(field) && (!all || !TREE_READONLY(field)))
86313 + return false;
86314 + }
86315 + return true;
86316 +}
86317 +
86318 +static void finish_type(void *event_data, void *data)
86319 +{
86320 + tree type = (tree)event_data;
86321 +
86322 + if (type == NULL_TREE || type == error_mark_node)
86323 + return;
86324 +
86325 + if (TYPE_READONLY(type))
86326 + return;
86327 +
86328 + if (walk_struct(type, true))
86329 + constify_type(type);
86330 + else
86331 + deconstify_type(type);
86332 +}
86333 +
86334 +static unsigned int check_local_variables(void)
86335 +{
86336 + unsigned int ret = 0;
86337 + tree var;
86338 +
86339 +#if BUILDING_GCC_VERSION == 4005
86340 + tree vars;
86341 +#else
86342 + unsigned int i;
86343 +#endif
86344 +
86345 +#if BUILDING_GCC_VERSION == 4005
86346 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
86347 + var = TREE_VALUE(vars);
86348 +#else
86349 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
86350 +#endif
86351 + tree type = TREE_TYPE(var);
86352 +
86353 + gcc_assert(DECL_P(var));
86354 + if (is_global_var(var))
86355 + continue;
86356 +
86357 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
86358 + continue;
86359 +
86360 + if (!TYPE_READONLY(type))
86361 + continue;
86362 +
86363 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
86364 +// continue;
86365 +
86366 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
86367 + continue;
86368 +
86369 + if (walk_struct(type, false)) {
86370 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
86371 + ret = 1;
86372 + }
86373 + }
86374 + return ret;
86375 +}
86376 +
86377 +struct gimple_opt_pass pass_local_variable = {
86378 + {
86379 + .type = GIMPLE_PASS,
86380 + .name = "check_local_variables",
86381 +#if BUILDING_GCC_VERSION >= 4008
86382 + .optinfo_flags = OPTGROUP_NONE,
86383 +#endif
86384 + .gate = NULL,
86385 + .execute = check_local_variables,
86386 + .sub = NULL,
86387 + .next = NULL,
86388 + .static_pass_number = 0,
86389 + .tv_id = TV_NONE,
86390 + .properties_required = 0,
86391 + .properties_provided = 0,
86392 + .properties_destroyed = 0,
86393 + .todo_flags_start = 0,
86394 + .todo_flags_finish = 0
86395 + }
86396 +};
86397 +
86398 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86399 +{
86400 + const char * const plugin_name = plugin_info->base_name;
86401 + const int argc = plugin_info->argc;
86402 + const struct plugin_argument * const argv = plugin_info->argv;
86403 + int i;
86404 + bool constify = true;
86405 +
86406 + struct register_pass_info local_variable_pass_info = {
86407 + .pass = &pass_local_variable.pass,
86408 + .reference_pass_name = "ssa",
86409 + .ref_pass_instance_number = 1,
86410 + .pos_op = PASS_POS_INSERT_BEFORE
86411 + };
86412 +
86413 + if (!plugin_default_version_check(version, &gcc_version)) {
86414 + error(G_("incompatible gcc/plugin versions"));
86415 + return 1;
86416 + }
86417 +
86418 + for (i = 0; i < argc; ++i) {
86419 + if (!(strcmp(argv[i].key, "no-constify"))) {
86420 + constify = false;
86421 + continue;
86422 + }
86423 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86424 + }
86425 +
86426 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
86427 + if (constify) {
86428 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
86429 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
86430 + }
86431 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86432 +
86433 + return 0;
86434 +}
86435 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
86436 new file mode 100644
86437 index 0000000..e518932
86438 --- /dev/null
86439 +++ b/tools/gcc/generate_size_overflow_hash.sh
86440 @@ -0,0 +1,94 @@
86441 +#!/bin/bash
86442 +
86443 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
86444 +
86445 +header1="size_overflow_hash.h"
86446 +database="size_overflow_hash.data"
86447 +n=65536
86448 +
86449 +usage() {
86450 +cat <<EOF
86451 +usage: $0 options
86452 +OPTIONS:
86453 + -h|--help help
86454 + -o header file
86455 + -d database file
86456 + -n hash array size
86457 +EOF
86458 + return 0
86459 +}
86460 +
86461 +while true
86462 +do
86463 + case "$1" in
86464 + -h|--help) usage && exit 0;;
86465 + -n) n=$2; shift 2;;
86466 + -o) header1="$2"; shift 2;;
86467 + -d) database="$2"; shift 2;;
86468 + --) shift 1; break ;;
86469 + *) break ;;
86470 + esac
86471 +done
86472 +
86473 +create_defines() {
86474 + for i in `seq 0 31`
86475 + do
86476 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
86477 + done
86478 + echo >> "$header1"
86479 +}
86480 +
86481 +create_structs() {
86482 + rm -f "$header1"
86483 +
86484 + create_defines
86485 +
86486 + cat "$database" | while read data
86487 + do
86488 + data_array=($data)
86489 + struct_hash_name="${data_array[0]}"
86490 + funcn="${data_array[1]}"
86491 + params="${data_array[2]}"
86492 + next="${data_array[4]}"
86493 +
86494 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
86495 +
86496 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
86497 + echo -en "\t.param\t= " >> "$header1"
86498 + line=
86499 + for param_num in ${params//-/ };
86500 + do
86501 + line="${line}PARAM"$param_num"|"
86502 + done
86503 +
86504 + echo -e "${line%?},\n};\n" >> "$header1"
86505 + done
86506 +}
86507 +
86508 +create_headers() {
86509 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
86510 +}
86511 +
86512 +create_array_elements() {
86513 + index=0
86514 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
86515 + do
86516 + data_array=($data)
86517 + i="${data_array[3]}"
86518 + hash="${data_array[0]}"
86519 + while [[ $index -lt $i ]]
86520 + do
86521 + echo -e "\t["$index"]\t= NULL," >> "$header1"
86522 + index=$(($index + 1))
86523 + done
86524 + index=$(($index + 1))
86525 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
86526 + done
86527 + echo '};' >> $header1
86528 +}
86529 +
86530 +create_structs
86531 +create_headers
86532 +create_array_elements
86533 +
86534 +exit 0
86535 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
86536 new file mode 100644
86537 index 0000000..568b360
86538 --- /dev/null
86539 +++ b/tools/gcc/kallocstat_plugin.c
86540 @@ -0,0 +1,170 @@
86541 +/*
86542 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
86543 + * Licensed under the GPL v2
86544 + *
86545 + * Note: the choice of the license means that the compilation process is
86546 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86547 + * but for the kernel it doesn't matter since it doesn't link against
86548 + * any of the gcc libraries
86549 + *
86550 + * gcc plugin to find the distribution of k*alloc sizes
86551 + *
86552 + * TODO:
86553 + *
86554 + * BUGS:
86555 + * - none known
86556 + */
86557 +#include "gcc-plugin.h"
86558 +#include "config.h"
86559 +#include "system.h"
86560 +#include "coretypes.h"
86561 +#include "tree.h"
86562 +#include "tree-pass.h"
86563 +#include "flags.h"
86564 +#include "intl.h"
86565 +#include "toplev.h"
86566 +#include "plugin.h"
86567 +//#include "expr.h" where are you...
86568 +#include "diagnostic.h"
86569 +#include "plugin-version.h"
86570 +#include "tm.h"
86571 +#include "function.h"
86572 +#include "basic-block.h"
86573 +#include "gimple.h"
86574 +#include "rtl.h"
86575 +#include "emit-rtl.h"
86576 +
86577 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86578 +
86579 +int plugin_is_GPL_compatible;
86580 +
86581 +static const char * const kalloc_functions[] = {
86582 + "__kmalloc",
86583 + "kmalloc",
86584 + "kmalloc_large",
86585 + "kmalloc_node",
86586 + "kmalloc_order",
86587 + "kmalloc_order_trace",
86588 + "kmalloc_slab",
86589 + "kzalloc",
86590 + "kzalloc_node",
86591 +};
86592 +
86593 +static struct plugin_info kallocstat_plugin_info = {
86594 + .version = "201302112000",
86595 +};
86596 +
86597 +static unsigned int execute_kallocstat(void);
86598 +
86599 +static struct gimple_opt_pass kallocstat_pass = {
86600 + .pass = {
86601 + .type = GIMPLE_PASS,
86602 + .name = "kallocstat",
86603 +#if BUILDING_GCC_VERSION >= 4008
86604 + .optinfo_flags = OPTGROUP_NONE,
86605 +#endif
86606 + .gate = NULL,
86607 + .execute = execute_kallocstat,
86608 + .sub = NULL,
86609 + .next = NULL,
86610 + .static_pass_number = 0,
86611 + .tv_id = TV_NONE,
86612 + .properties_required = 0,
86613 + .properties_provided = 0,
86614 + .properties_destroyed = 0,
86615 + .todo_flags_start = 0,
86616 + .todo_flags_finish = 0
86617 + }
86618 +};
86619 +
86620 +static bool is_kalloc(const char *fnname)
86621 +{
86622 + size_t i;
86623 +
86624 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
86625 + if (!strcmp(fnname, kalloc_functions[i]))
86626 + return true;
86627 + return false;
86628 +}
86629 +
86630 +static unsigned int execute_kallocstat(void)
86631 +{
86632 + basic_block bb;
86633 +
86634 + // 1. loop through BBs and GIMPLE statements
86635 + FOR_EACH_BB(bb) {
86636 + gimple_stmt_iterator gsi;
86637 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86638 + // gimple match:
86639 + tree fndecl, size;
86640 + gimple call_stmt;
86641 + const char *fnname;
86642 +
86643 + // is it a call
86644 + call_stmt = gsi_stmt(gsi);
86645 + if (!is_gimple_call(call_stmt))
86646 + continue;
86647 + fndecl = gimple_call_fndecl(call_stmt);
86648 + if (fndecl == NULL_TREE)
86649 + continue;
86650 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
86651 + continue;
86652 +
86653 + // is it a call to k*alloc
86654 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
86655 + if (!is_kalloc(fnname))
86656 + continue;
86657 +
86658 + // is the size arg the result of a simple const assignment
86659 + size = gimple_call_arg(call_stmt, 0);
86660 + while (true) {
86661 + gimple def_stmt;
86662 + expanded_location xloc;
86663 + size_t size_val;
86664 +
86665 + if (TREE_CODE(size) != SSA_NAME)
86666 + break;
86667 + def_stmt = SSA_NAME_DEF_STMT(size);
86668 + if (!def_stmt || !is_gimple_assign(def_stmt))
86669 + break;
86670 + if (gimple_num_ops(def_stmt) != 2)
86671 + break;
86672 + size = gimple_assign_rhs1(def_stmt);
86673 + if (!TREE_CONSTANT(size))
86674 + continue;
86675 + xloc = expand_location(gimple_location(def_stmt));
86676 + if (!xloc.file)
86677 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
86678 + size_val = TREE_INT_CST_LOW(size);
86679 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
86680 + break;
86681 + }
86682 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
86683 +//debug_tree(gimple_call_fn(call_stmt));
86684 +//print_node(stderr, "pax", fndecl, 4);
86685 + }
86686 + }
86687 +
86688 + return 0;
86689 +}
86690 +
86691 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86692 +{
86693 + const char * const plugin_name = plugin_info->base_name;
86694 + struct register_pass_info kallocstat_pass_info = {
86695 + .pass = &kallocstat_pass.pass,
86696 + .reference_pass_name = "ssa",
86697 + .ref_pass_instance_number = 1,
86698 + .pos_op = PASS_POS_INSERT_AFTER
86699 + };
86700 +
86701 + if (!plugin_default_version_check(version, &gcc_version)) {
86702 + error(G_("incompatible gcc/plugin versions"));
86703 + return 1;
86704 + }
86705 +
86706 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
86707 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
86708 +
86709 + return 0;
86710 +}
86711 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
86712 new file mode 100644
86713 index 0000000..0408e06
86714 --- /dev/null
86715 +++ b/tools/gcc/kernexec_plugin.c
86716 @@ -0,0 +1,465 @@
86717 +/*
86718 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
86719 + * Licensed under the GPL v2
86720 + *
86721 + * Note: the choice of the license means that the compilation process is
86722 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86723 + * but for the kernel it doesn't matter since it doesn't link against
86724 + * any of the gcc libraries
86725 + *
86726 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
86727 + *
86728 + * TODO:
86729 + *
86730 + * BUGS:
86731 + * - none known
86732 + */
86733 +#include "gcc-plugin.h"
86734 +#include "config.h"
86735 +#include "system.h"
86736 +#include "coretypes.h"
86737 +#include "tree.h"
86738 +#include "tree-pass.h"
86739 +#include "flags.h"
86740 +#include "intl.h"
86741 +#include "toplev.h"
86742 +#include "plugin.h"
86743 +//#include "expr.h" where are you...
86744 +#include "diagnostic.h"
86745 +#include "plugin-version.h"
86746 +#include "tm.h"
86747 +#include "function.h"
86748 +#include "basic-block.h"
86749 +#include "gimple.h"
86750 +#include "rtl.h"
86751 +#include "emit-rtl.h"
86752 +#include "tree-flow.h"
86753 +
86754 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86755 +extern rtx emit_move_insn(rtx x, rtx y);
86756 +
86757 +#if BUILDING_GCC_VERSION <= 4006
86758 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
86759 +#endif
86760 +
86761 +#if BUILDING_GCC_VERSION >= 4008
86762 +#define TODO_dump_func 0
86763 +#endif
86764 +
86765 +int plugin_is_GPL_compatible;
86766 +
86767 +static struct plugin_info kernexec_plugin_info = {
86768 + .version = "201302112000",
86769 + .help = "method=[bts|or]\tinstrumentation method\n"
86770 +};
86771 +
86772 +static unsigned int execute_kernexec_reload(void);
86773 +static unsigned int execute_kernexec_fptr(void);
86774 +static unsigned int execute_kernexec_retaddr(void);
86775 +static bool kernexec_cmodel_check(void);
86776 +
86777 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
86778 +static void (*kernexec_instrument_retaddr)(rtx);
86779 +
86780 +static struct gimple_opt_pass kernexec_reload_pass = {
86781 + .pass = {
86782 + .type = GIMPLE_PASS,
86783 + .name = "kernexec_reload",
86784 +#if BUILDING_GCC_VERSION >= 4008
86785 + .optinfo_flags = OPTGROUP_NONE,
86786 +#endif
86787 + .gate = kernexec_cmodel_check,
86788 + .execute = execute_kernexec_reload,
86789 + .sub = NULL,
86790 + .next = NULL,
86791 + .static_pass_number = 0,
86792 + .tv_id = TV_NONE,
86793 + .properties_required = 0,
86794 + .properties_provided = 0,
86795 + .properties_destroyed = 0,
86796 + .todo_flags_start = 0,
86797 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
86798 + }
86799 +};
86800 +
86801 +static struct gimple_opt_pass kernexec_fptr_pass = {
86802 + .pass = {
86803 + .type = GIMPLE_PASS,
86804 + .name = "kernexec_fptr",
86805 +#if BUILDING_GCC_VERSION >= 4008
86806 + .optinfo_flags = OPTGROUP_NONE,
86807 +#endif
86808 + .gate = kernexec_cmodel_check,
86809 + .execute = execute_kernexec_fptr,
86810 + .sub = NULL,
86811 + .next = NULL,
86812 + .static_pass_number = 0,
86813 + .tv_id = TV_NONE,
86814 + .properties_required = 0,
86815 + .properties_provided = 0,
86816 + .properties_destroyed = 0,
86817 + .todo_flags_start = 0,
86818 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
86819 + }
86820 +};
86821 +
86822 +static struct rtl_opt_pass kernexec_retaddr_pass = {
86823 + .pass = {
86824 + .type = RTL_PASS,
86825 + .name = "kernexec_retaddr",
86826 +#if BUILDING_GCC_VERSION >= 4008
86827 + .optinfo_flags = OPTGROUP_NONE,
86828 +#endif
86829 + .gate = kernexec_cmodel_check,
86830 + .execute = execute_kernexec_retaddr,
86831 + .sub = NULL,
86832 + .next = NULL,
86833 + .static_pass_number = 0,
86834 + .tv_id = TV_NONE,
86835 + .properties_required = 0,
86836 + .properties_provided = 0,
86837 + .properties_destroyed = 0,
86838 + .todo_flags_start = 0,
86839 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
86840 + }
86841 +};
86842 +
86843 +static bool kernexec_cmodel_check(void)
86844 +{
86845 + tree section;
86846 +
86847 + if (ix86_cmodel != CM_KERNEL)
86848 + return false;
86849 +
86850 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
86851 + if (!section || !TREE_VALUE(section))
86852 + return true;
86853 +
86854 + section = TREE_VALUE(TREE_VALUE(section));
86855 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
86856 + return true;
86857 +
86858 + return false;
86859 +}
86860 +
86861 +/*
86862 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
86863 + */
86864 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
86865 +{
86866 + gimple asm_movabs_stmt;
86867 +
86868 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
86869 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
86870 + gimple_asm_set_volatile(asm_movabs_stmt, true);
86871 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
86872 + update_stmt(asm_movabs_stmt);
86873 +}
86874 +
86875 +/*
86876 + * find all asm() stmts that clobber r10 and add a reload of r10
86877 + */
86878 +static unsigned int execute_kernexec_reload(void)
86879 +{
86880 + basic_block bb;
86881 +
86882 + // 1. loop through BBs and GIMPLE statements
86883 + FOR_EACH_BB(bb) {
86884 + gimple_stmt_iterator gsi;
86885 +
86886 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86887 + // gimple match: __asm__ ("" : : : "r10");
86888 + gimple asm_stmt;
86889 + size_t nclobbers;
86890 +
86891 + // is it an asm ...
86892 + asm_stmt = gsi_stmt(gsi);
86893 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
86894 + continue;
86895 +
86896 + // ... clobbering r10
86897 + nclobbers = gimple_asm_nclobbers(asm_stmt);
86898 + while (nclobbers--) {
86899 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
86900 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
86901 + continue;
86902 + kernexec_reload_fptr_mask(&gsi);
86903 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
86904 + break;
86905 + }
86906 + }
86907 + }
86908 +
86909 + return 0;
86910 +}
86911 +
86912 +/*
86913 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
86914 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
86915 + */
86916 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
86917 +{
86918 + gimple assign_intptr, assign_new_fptr, call_stmt;
86919 + tree intptr, old_fptr, new_fptr, kernexec_mask;
86920 +
86921 + call_stmt = gsi_stmt(*gsi);
86922 + old_fptr = gimple_call_fn(call_stmt);
86923 +
86924 + // create temporary unsigned long variable used for bitops and cast fptr to it
86925 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
86926 +#if BUILDING_GCC_VERSION <= 4007
86927 + add_referenced_var(intptr);
86928 + mark_sym_for_renaming(intptr);
86929 +#endif
86930 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
86931 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
86932 + update_stmt(assign_intptr);
86933 +
86934 + // apply logical or to temporary unsigned long and bitmask
86935 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
86936 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
86937 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
86938 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
86939 + update_stmt(assign_intptr);
86940 +
86941 + // cast temporary unsigned long back to a temporary fptr variable
86942 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
86943 +#if BUILDING_GCC_VERSION <= 4007
86944 + add_referenced_var(new_fptr);
86945 + mark_sym_for_renaming(new_fptr);
86946 +#endif
86947 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
86948 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
86949 + update_stmt(assign_new_fptr);
86950 +
86951 + // replace call stmt fn with the new fptr
86952 + gimple_call_set_fn(call_stmt, new_fptr);
86953 + update_stmt(call_stmt);
86954 +}
86955 +
86956 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
86957 +{
86958 + gimple asm_or_stmt, call_stmt;
86959 + tree old_fptr, new_fptr, input, output;
86960 +#if BUILDING_GCC_VERSION <= 4007
86961 + VEC(tree, gc) *inputs = NULL;
86962 + VEC(tree, gc) *outputs = NULL;
86963 +#else
86964 + vec<tree, va_gc> *inputs = NULL;
86965 + vec<tree, va_gc> *outputs = NULL;
86966 +#endif
86967 +
86968 + call_stmt = gsi_stmt(*gsi);
86969 + old_fptr = gimple_call_fn(call_stmt);
86970 +
86971 + // create temporary fptr variable
86972 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
86973 +#if BUILDING_GCC_VERSION <= 4007
86974 + add_referenced_var(new_fptr);
86975 + mark_sym_for_renaming(new_fptr);
86976 +#endif
86977 +
86978 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
86979 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
86980 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
86981 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
86982 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
86983 +#if BUILDING_GCC_VERSION <= 4007
86984 + VEC_safe_push(tree, gc, inputs, input);
86985 + VEC_safe_push(tree, gc, outputs, output);
86986 +#else
86987 + vec_safe_push(inputs, input);
86988 + vec_safe_push(outputs, output);
86989 +#endif
86990 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
86991 + gimple_asm_set_volatile(asm_or_stmt, true);
86992 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
86993 + update_stmt(asm_or_stmt);
86994 +
86995 + // replace call stmt fn with the new fptr
86996 + gimple_call_set_fn(call_stmt, new_fptr);
86997 + update_stmt(call_stmt);
86998 +}
86999 +
87000 +/*
87001 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
87002 + */
87003 +static unsigned int execute_kernexec_fptr(void)
87004 +{
87005 + basic_block bb;
87006 +
87007 + // 1. loop through BBs and GIMPLE statements
87008 + FOR_EACH_BB(bb) {
87009 + gimple_stmt_iterator gsi;
87010 +
87011 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
87012 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
87013 + tree fn;
87014 + gimple call_stmt;
87015 +
87016 + // is it a call ...
87017 + call_stmt = gsi_stmt(gsi);
87018 + if (!is_gimple_call(call_stmt))
87019 + continue;
87020 + fn = gimple_call_fn(call_stmt);
87021 + if (TREE_CODE(fn) == ADDR_EXPR)
87022 + continue;
87023 + if (TREE_CODE(fn) != SSA_NAME)
87024 + gcc_unreachable();
87025 +
87026 + // ... through a function pointer
87027 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
87028 + fn = SSA_NAME_VAR(fn);
87029 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
87030 + debug_tree(fn);
87031 + gcc_unreachable();
87032 + }
87033 + }
87034 + fn = TREE_TYPE(fn);
87035 + if (TREE_CODE(fn) != POINTER_TYPE)
87036 + continue;
87037 + fn = TREE_TYPE(fn);
87038 + if (TREE_CODE(fn) != FUNCTION_TYPE)
87039 + continue;
87040 +
87041 + kernexec_instrument_fptr(&gsi);
87042 +
87043 +//debug_tree(gimple_call_fn(call_stmt));
87044 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
87045 + }
87046 + }
87047 +
87048 + return 0;
87049 +}
87050 +
87051 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
87052 +static void kernexec_instrument_retaddr_bts(rtx insn)
87053 +{
87054 + rtx btsq;
87055 + rtvec argvec, constraintvec, labelvec;
87056 + int line;
87057 +
87058 + // create asm volatile("btsq $63,(%%rsp)":::)
87059 + argvec = rtvec_alloc(0);
87060 + constraintvec = rtvec_alloc(0);
87061 + labelvec = rtvec_alloc(0);
87062 + line = expand_location(RTL_LOCATION(insn)).line;
87063 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
87064 + MEM_VOLATILE_P(btsq) = 1;
87065 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
87066 + emit_insn_before(btsq, insn);
87067 +}
87068 +
87069 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
87070 +static void kernexec_instrument_retaddr_or(rtx insn)
87071 +{
87072 + rtx orq;
87073 + rtvec argvec, constraintvec, labelvec;
87074 + int line;
87075 +
87076 + // create asm volatile("orq %%r10,(%%rsp)":::)
87077 + argvec = rtvec_alloc(0);
87078 + constraintvec = rtvec_alloc(0);
87079 + labelvec = rtvec_alloc(0);
87080 + line = expand_location(RTL_LOCATION(insn)).line;
87081 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
87082 + MEM_VOLATILE_P(orq) = 1;
87083 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
87084 + emit_insn_before(orq, insn);
87085 +}
87086 +
87087 +/*
87088 + * find all asm level function returns and forcibly set the highest bit of the return address
87089 + */
87090 +static unsigned int execute_kernexec_retaddr(void)
87091 +{
87092 + rtx insn;
87093 +
87094 + // 1. find function returns
87095 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
87096 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
87097 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
87098 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
87099 + rtx body;
87100 +
87101 + // is it a retn
87102 + if (!JUMP_P(insn))
87103 + continue;
87104 + body = PATTERN(insn);
87105 + if (GET_CODE(body) == PARALLEL)
87106 + body = XVECEXP(body, 0, 0);
87107 + if (!ANY_RETURN_P(body))
87108 + continue;
87109 + kernexec_instrument_retaddr(insn);
87110 + }
87111 +
87112 +// print_simple_rtl(stderr, get_insns());
87113 +// print_rtl(stderr, get_insns());
87114 +
87115 + return 0;
87116 +}
87117 +
87118 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87119 +{
87120 + const char * const plugin_name = plugin_info->base_name;
87121 + const int argc = plugin_info->argc;
87122 + const struct plugin_argument * const argv = plugin_info->argv;
87123 + int i;
87124 + struct register_pass_info kernexec_reload_pass_info = {
87125 + .pass = &kernexec_reload_pass.pass,
87126 + .reference_pass_name = "ssa",
87127 + .ref_pass_instance_number = 1,
87128 + .pos_op = PASS_POS_INSERT_AFTER
87129 + };
87130 + struct register_pass_info kernexec_fptr_pass_info = {
87131 + .pass = &kernexec_fptr_pass.pass,
87132 + .reference_pass_name = "ssa",
87133 + .ref_pass_instance_number = 1,
87134 + .pos_op = PASS_POS_INSERT_AFTER
87135 + };
87136 + struct register_pass_info kernexec_retaddr_pass_info = {
87137 + .pass = &kernexec_retaddr_pass.pass,
87138 + .reference_pass_name = "pro_and_epilogue",
87139 + .ref_pass_instance_number = 1,
87140 + .pos_op = PASS_POS_INSERT_AFTER
87141 + };
87142 +
87143 + if (!plugin_default_version_check(version, &gcc_version)) {
87144 + error(G_("incompatible gcc/plugin versions"));
87145 + return 1;
87146 + }
87147 +
87148 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
87149 +
87150 + if (TARGET_64BIT == 0)
87151 + return 0;
87152 +
87153 + for (i = 0; i < argc; ++i) {
87154 + if (!strcmp(argv[i].key, "method")) {
87155 + if (!argv[i].value) {
87156 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87157 + continue;
87158 + }
87159 + if (!strcmp(argv[i].value, "bts")) {
87160 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
87161 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
87162 + } else if (!strcmp(argv[i].value, "or")) {
87163 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
87164 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
87165 + fix_register("r10", 1, 1);
87166 + } else
87167 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
87168 + continue;
87169 + }
87170 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87171 + }
87172 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
87173 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
87174 +
87175 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
87176 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
87177 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
87178 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
87179 +
87180 + return 0;
87181 +}
87182 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
87183 new file mode 100644
87184 index 0000000..1276616
87185 --- /dev/null
87186 +++ b/tools/gcc/latent_entropy_plugin.c
87187 @@ -0,0 +1,321 @@
87188 +/*
87189 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
87190 + * Licensed under the GPL v2
87191 + *
87192 + * Note: the choice of the license means that the compilation process is
87193 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
87194 + * but for the kernel it doesn't matter since it doesn't link against
87195 + * any of the gcc libraries
87196 + *
87197 + * gcc plugin to help generate a little bit of entropy from program state,
87198 + * used during boot in the kernel
87199 + *
87200 + * TODO:
87201 + * - add ipa pass to identify not explicitly marked candidate functions
87202 + * - mix in more program state (function arguments/return values, loop variables, etc)
87203 + * - more instrumentation control via attribute parameters
87204 + *
87205 + * BUGS:
87206 + * - LTO needs -flto-partition=none for now
87207 + */
87208 +#include "gcc-plugin.h"
87209 +#include "config.h"
87210 +#include "system.h"
87211 +#include "coretypes.h"
87212 +#include "tree.h"
87213 +#include "tree-pass.h"
87214 +#include "flags.h"
87215 +#include "intl.h"
87216 +#include "toplev.h"
87217 +#include "plugin.h"
87218 +//#include "expr.h" where are you...
87219 +#include "diagnostic.h"
87220 +#include "plugin-version.h"
87221 +#include "tm.h"
87222 +#include "function.h"
87223 +#include "basic-block.h"
87224 +#include "gimple.h"
87225 +#include "rtl.h"
87226 +#include "emit-rtl.h"
87227 +#include "tree-flow.h"
87228 +
87229 +#if BUILDING_GCC_VERSION >= 4008
87230 +#define TODO_dump_func 0
87231 +#endif
87232 +
87233 +int plugin_is_GPL_compatible;
87234 +
87235 +static tree latent_entropy_decl;
87236 +
87237 +static struct plugin_info latent_entropy_plugin_info = {
87238 + .version = "201302112000",
87239 + .help = NULL
87240 +};
87241 +
87242 +static unsigned int execute_latent_entropy(void);
87243 +static bool gate_latent_entropy(void);
87244 +
87245 +static struct gimple_opt_pass latent_entropy_pass = {
87246 + .pass = {
87247 + .type = GIMPLE_PASS,
87248 + .name = "latent_entropy",
87249 +#if BUILDING_GCC_VERSION >= 4008
87250 + .optinfo_flags = OPTGROUP_NONE,
87251 +#endif
87252 + .gate = gate_latent_entropy,
87253 + .execute = execute_latent_entropy,
87254 + .sub = NULL,
87255 + .next = NULL,
87256 + .static_pass_number = 0,
87257 + .tv_id = TV_NONE,
87258 + .properties_required = PROP_gimple_leh | PROP_cfg,
87259 + .properties_provided = 0,
87260 + .properties_destroyed = 0,
87261 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
87262 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
87263 + }
87264 +};
87265 +
87266 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
87267 +{
87268 + if (TREE_CODE(*node) != FUNCTION_DECL) {
87269 + *no_add_attrs = true;
87270 + error("%qE attribute only applies to functions", name);
87271 + }
87272 + return NULL_TREE;
87273 +}
87274 +
87275 +static struct attribute_spec latent_entropy_attr = {
87276 + .name = "latent_entropy",
87277 + .min_length = 0,
87278 + .max_length = 0,
87279 + .decl_required = true,
87280 + .type_required = false,
87281 + .function_type_required = false,
87282 + .handler = handle_latent_entropy_attribute,
87283 +#if BUILDING_GCC_VERSION >= 4007
87284 + .affects_type_identity = false
87285 +#endif
87286 +};
87287 +
87288 +static void register_attributes(void *event_data, void *data)
87289 +{
87290 + register_attribute(&latent_entropy_attr);
87291 +}
87292 +
87293 +static bool gate_latent_entropy(void)
87294 +{
87295 + tree latent_entropy_attr;
87296 +
87297 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
87298 + return latent_entropy_attr != NULL_TREE;
87299 +}
87300 +
87301 +static unsigned HOST_WIDE_INT seed;
87302 +static unsigned HOST_WIDE_INT get_random_const(void)
87303 +{
87304 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
87305 + return seed;
87306 +}
87307 +
87308 +static enum tree_code get_op(tree *rhs)
87309 +{
87310 + static enum tree_code op;
87311 + unsigned HOST_WIDE_INT random_const;
87312 +
87313 + random_const = get_random_const();
87314 +
87315 + switch (op) {
87316 + case BIT_XOR_EXPR:
87317 + op = PLUS_EXPR;
87318 + break;
87319 +
87320 + case PLUS_EXPR:
87321 + if (rhs) {
87322 + op = LROTATE_EXPR;
87323 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
87324 + break;
87325 + }
87326 +
87327 + case LROTATE_EXPR:
87328 + default:
87329 + op = BIT_XOR_EXPR;
87330 + break;
87331 + }
87332 + if (rhs)
87333 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
87334 + return op;
87335 +}
87336 +
87337 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
87338 +{
87339 + gimple_stmt_iterator gsi;
87340 + gimple assign;
87341 + tree addxorrol, rhs;
87342 + enum tree_code op;
87343 +
87344 + op = get_op(&rhs);
87345 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
87346 + assign = gimple_build_assign(local_entropy, addxorrol);
87347 +#if BUILDING_GCC_VERSION <= 4007
87348 + find_referenced_vars_in(assign);
87349 +#endif
87350 +//debug_bb(bb);
87351 + gsi = gsi_after_labels(bb);
87352 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
87353 + update_stmt(assign);
87354 +}
87355 +
87356 +static void perturb_latent_entropy(basic_block bb, tree rhs)
87357 +{
87358 + gimple_stmt_iterator gsi;
87359 + gimple assign;
87360 + tree addxorrol, temp;
87361 +
87362 + // 1. create temporary copy of latent_entropy
87363 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
87364 +#if BUILDING_GCC_VERSION <= 4007
87365 + add_referenced_var(temp);
87366 + mark_sym_for_renaming(temp);
87367 +#endif
87368 +
87369 + // 2. read...
87370 + assign = gimple_build_assign(temp, latent_entropy_decl);
87371 +#if BUILDING_GCC_VERSION <= 4007
87372 + find_referenced_vars_in(assign);
87373 +#endif
87374 + gsi = gsi_after_labels(bb);
87375 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87376 + update_stmt(assign);
87377 +
87378 + // 3. ...modify...
87379 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
87380 + assign = gimple_build_assign(temp, addxorrol);
87381 +#if BUILDING_GCC_VERSION <= 4007
87382 + find_referenced_vars_in(assign);
87383 +#endif
87384 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87385 + update_stmt(assign);
87386 +
87387 + // 4. ...write latent_entropy
87388 + assign = gimple_build_assign(latent_entropy_decl, temp);
87389 +#if BUILDING_GCC_VERSION <= 4007
87390 + find_referenced_vars_in(assign);
87391 +#endif
87392 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87393 + update_stmt(assign);
87394 +}
87395 +
87396 +static unsigned int execute_latent_entropy(void)
87397 +{
87398 + basic_block bb;
87399 + gimple assign;
87400 + gimple_stmt_iterator gsi;
87401 + tree local_entropy;
87402 +
87403 + if (!latent_entropy_decl) {
87404 + struct varpool_node *node;
87405 +
87406 +#if BUILDING_GCC_VERSION <= 4007
87407 + for (node = varpool_nodes; node; node = node->next) {
87408 + tree var = node->decl;
87409 +#else
87410 + FOR_EACH_VARIABLE(node) {
87411 + tree var = node->symbol.decl;
87412 +#endif
87413 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
87414 + continue;
87415 + latent_entropy_decl = var;
87416 +// debug_tree(var);
87417 + break;
87418 + }
87419 + if (!latent_entropy_decl) {
87420 +// debug_tree(current_function_decl);
87421 + return 0;
87422 + }
87423 + }
87424 +
87425 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
87426 +
87427 + // 1. create local entropy variable
87428 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
87429 +#if BUILDING_GCC_VERSION <= 4007
87430 + add_referenced_var(local_entropy);
87431 + mark_sym_for_renaming(local_entropy);
87432 +#endif
87433 +
87434 + // 2. initialize local entropy variable
87435 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87436 + if (dom_info_available_p(CDI_DOMINATORS))
87437 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
87438 + gsi = gsi_start_bb(bb);
87439 +
87440 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
87441 +// gimple_set_location(assign, loc);
87442 +#if BUILDING_GCC_VERSION <= 4007
87443 + find_referenced_vars_in(assign);
87444 +#endif
87445 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87446 + update_stmt(assign);
87447 + bb = bb->next_bb;
87448 +
87449 + // 3. instrument each BB with an operation on the local entropy variable
87450 + while (bb != EXIT_BLOCK_PTR) {
87451 + perturb_local_entropy(bb, local_entropy);
87452 + bb = bb->next_bb;
87453 + };
87454 +
87455 + // 4. mix local entropy into the global entropy variable
87456 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
87457 + return 0;
87458 +}
87459 +
87460 +static void start_unit_callback(void *gcc_data, void *user_data)
87461 +{
87462 +#if BUILDING_GCC_VERSION >= 4007
87463 + seed = get_random_seed(false);
87464 +#else
87465 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
87466 + seed *= seed;
87467 +#endif
87468 +
87469 + if (in_lto_p)
87470 + return;
87471 +
87472 + // extern u64 latent_entropy
87473 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
87474 +
87475 + TREE_STATIC(latent_entropy_decl) = 1;
87476 + TREE_PUBLIC(latent_entropy_decl) = 1;
87477 + TREE_USED(latent_entropy_decl) = 1;
87478 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
87479 + DECL_EXTERNAL(latent_entropy_decl) = 1;
87480 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
87481 + DECL_INITIAL(latent_entropy_decl) = NULL;
87482 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
87483 +// varpool_finalize_decl(latent_entropy_decl);
87484 +// varpool_mark_needed_node(latent_entropy_decl);
87485 +}
87486 +
87487 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87488 +{
87489 + const char * const plugin_name = plugin_info->base_name;
87490 + struct register_pass_info latent_entropy_pass_info = {
87491 + .pass = &latent_entropy_pass.pass,
87492 + .reference_pass_name = "optimized",
87493 + .ref_pass_instance_number = 1,
87494 + .pos_op = PASS_POS_INSERT_BEFORE
87495 + };
87496 +
87497 + if (!plugin_default_version_check(version, &gcc_version)) {
87498 + error(G_("incompatible gcc/plugin versions"));
87499 + return 1;
87500 + }
87501 +
87502 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
87503 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
87504 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
87505 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
87506 +
87507 + return 0;
87508 +}
87509 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
87510 new file mode 100644
87511 index 0000000..5921fd7
87512 --- /dev/null
87513 +++ b/tools/gcc/size_overflow_hash.data
87514 @@ -0,0 +1,3713 @@
87515 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
87516 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
87517 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
87518 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
87519 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
87520 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
87521 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
87522 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
87523 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
87524 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
87525 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
87526 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
87527 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
87528 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
87529 +create_log_8225 create_log 2 8225 NULL
87530 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
87531 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
87532 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
87533 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
87534 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
87535 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
87536 +padzero_55 padzero 1 55 &sel_read_policyvers_55
87537 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
87538 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
87539 +read_file_blob_57406 read_file_blob 3 57406 NULL
87540 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
87541 +enclosure_register_57412 enclosure_register 3 57412 NULL
87542 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
87543 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
87544 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
87545 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
87546 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
87547 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
87548 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
87549 +init_cdev_8274 init_cdev 1 8274 NULL
87550 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
87551 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
87552 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
87553 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
87554 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
87555 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
87556 +load_msg_95 load_msg 2 95 NULL
87557 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
87558 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
87559 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
87560 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
87561 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
87562 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
87563 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
87564 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
87565 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
87566 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
87567 +send_midi_async_57463 send_midi_async 3 57463 NULL
87568 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
87569 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
87570 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
87571 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
87572 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
87573 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
87574 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
87575 +init_q_132 init_q 4 132 NULL
87576 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
87577 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
87578 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
87579 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
87580 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
87581 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
87582 +uio_read_49300 uio_read 3 49300 NULL
87583 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
87584 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
87585 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
87586 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
87587 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
87588 +play_iframe_8219 play_iframe 3 8219 NULL
87589 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
87590 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
87591 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
87592 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
87593 +init_tag_map_57515 init_tag_map 3 57515 NULL
87594 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
87595 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
87596 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
87597 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
87598 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
87599 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
87600 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
87601 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
87602 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
87603 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
87604 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
87605 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
87606 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
87607 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
87608 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
87609 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
87610 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
87611 +cache_read_24790 cache_read 3 24790 NULL
87612 +px_raw_event_49371 px_raw_event 4 49371 NULL
87613 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
87614 +compat_filldir_32999 compat_filldir 3 32999 NULL
87615 +hci_si_event_1404 hci_si_event 3 1404 NULL
87616 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
87617 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
87618 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
87619 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
87620 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
87621 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
87622 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
87623 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
87624 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
87625 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
87626 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
87627 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
87628 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
87629 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
87630 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
87631 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
87632 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
87633 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
87634 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
87635 +mem_read_57631 mem_read 3 57631 NULL
87636 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
87637 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
87638 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
87639 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
87640 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
87641 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
87642 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
87643 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
87644 +queues_read_24877 queues_read 3 24877 NULL
87645 +__fprog_create_41263 __fprog_create 2 41263 NULL
87646 +syslog_print_307 syslog_print 2 307 NULL
87647 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
87648 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
87649 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
87650 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
87651 +r3964_write_57662 r3964_write 4 57662 NULL
87652 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
87653 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
87654 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
87655 +alloc_context_41283 alloc_context 1 41283 NULL
87656 +__lgwrite_57669 __lgwrite 4 57669 NULL
87657 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
87658 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
87659 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
87660 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
87661 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
87662 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
87663 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
87664 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
87665 +write_node_33121 write_node 4 33121 NULL
87666 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
87667 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
87668 +profile_remove_8556 profile_remove 3 8556 NULL
87669 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
87670 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
87671 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
87672 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
87673 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
87674 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
87675 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
87676 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
87677 +tower_write_8580 tower_write 3 8580 NULL
87678 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
87679 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
87680 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
87681 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
87682 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
87683 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
87684 +smk_write_access_49561 smk_write_access 3 49561 NULL
87685 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
87686 +kmp_init_41373 kmp_init 2 41373 NULL
87687 +context_alloc_24645 context_alloc 3 24645 NULL
87688 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
87689 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
87690 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
87691 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
87692 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
87693 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
87694 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
87695 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
87696 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
87697 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
87698 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
87699 +pp_read_33210 pp_read 3 33210 NULL
87700 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
87701 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
87702 +ivtv_read_57796 ivtv_read 3 57796 NULL
87703 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
87704 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
87705 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
87706 +heap_init_49617 heap_init 2 49617 NULL
87707 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
87708 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
87709 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
87710 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
87711 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
87712 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
87713 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
87714 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
87715 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
87716 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
87717 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
87718 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
87719 +st_write_16874 st_write 3 16874 NULL
87720 +copy_to_user_57835 copy_to_user 3 57835 NULL
87721 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
87722 +pidlist_resize_496 pidlist_resize 2 496 NULL
87723 +flash_read_57843 flash_read 3 57843 NULL
87724 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
87725 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
87726 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
87727 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
87728 +arcfb_write_8702 arcfb_write 3 8702 NULL
87729 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
87730 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
87731 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
87732 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
87733 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
87734 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
87735 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
87736 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
87737 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
87738 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
87739 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
87740 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
87741 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
87742 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
87743 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
87744 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
87745 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
87746 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
87747 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
87748 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
87749 +devres_alloc_551 devres_alloc 2 551 NULL
87750 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
87751 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
87752 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
87753 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
87754 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
87755 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
87756 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
87757 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
87758 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
87759 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
87760 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
87761 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
87762 +sys_prctl_8766 sys_prctl 4 8766 NULL
87763 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
87764 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
87765 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
87766 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
87767 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
87768 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
87769 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
87770 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
87771 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
87772 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
87773 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
87774 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
87775 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
87776 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
87777 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
87778 +gserial_setup_41558 gserial_setup 2 41558 NULL
87779 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
87780 +rx_57944 rx 4 57944 NULL
87781 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
87782 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
87783 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
87784 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
87785 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
87786 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
87787 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
87788 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
87789 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
87790 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
87791 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
87792 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
87793 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
87794 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
87795 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
87796 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
87797 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
87798 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
87799 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
87800 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
87801 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
87802 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
87803 +a2mp_send_41615 a2mp_send 4 41615 NULL
87804 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
87805 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
87806 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
87807 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
87808 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
87809 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
87810 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
87811 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
87812 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
87813 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
87814 +add_uuid_49831 add_uuid 4 49831 NULL
87815 +send_pages_8872 send_pages 3 8872 NULL
87816 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
87817 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
87818 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
87819 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
87820 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
87821 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
87822 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
87823 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
87824 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
87825 +vfs_writev_25278 vfs_writev 3 25278 NULL
87826 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
87827 +alloc_async_14208 alloc_async 1 14208 NULL
87828 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
87829 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
87830 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
87831 +create_entry_33479 create_entry 2 33479 NULL
87832 +mce_async_out_58056 mce_async_out 3 58056 NULL
87833 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
87834 +sys_preadv_17100 sys_preadv 3 17100 NULL
87835 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
87836 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
87837 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
87838 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
87839 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
87840 +res_counter_read_33499 res_counter_read 4 33499 NULL
87841 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
87842 +cm4040_write_58079 cm4040_write 3 58079 NULL
87843 +fb_read_33506 fb_read 3 33506 NULL
87844 +help_25316 help 5 25316 NULL nohasharray
87845 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
87846 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
87847 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
87848 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
87849 +ddp_set_map_751 ddp_set_map 4 751 NULL
87850 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
87851 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
87852 +dvb_video_write_754 dvb_video_write 3 754 NULL
87853 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
87854 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
87855 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
87856 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
87857 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
87858 +udi_log_event_58105 udi_log_event 3 58105 NULL
87859 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
87860 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
87861 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
87862 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
87863 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
87864 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
87865 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
87866 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
87867 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
87868 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
87869 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
87870 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
87871 +sep_read_17161 sep_read 3 17161 NULL
87872 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
87873 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
87874 +dup_array_33551 dup_array 3 33551 NULL
87875 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
87876 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
87877 +fillonedir_41746 fillonedir 3 41746 NULL
87878 +init_bch_64130 init_bch 1-2 64130 NULL
87879 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
87880 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
87881 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
87882 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
87883 +savemem_58129 savemem 3 58129 NULL
87884 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
87885 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
87886 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
87887 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
87888 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
87889 +if_writecmd_815 if_writecmd 2 815 NULL
87890 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
87891 +read_fifo_826 read_fifo 3 826 NULL
87892 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
87893 +scsi_execute_33596 scsi_execute 5 33596 NULL
87894 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
87895 +ms_rw_17220 ms_rw 3-4 17220 NULL
87896 +read_tree_block_841 read_tree_block 3 841 NULL
87897 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
87898 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
87899 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
87900 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
87901 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
87902 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
87903 +um_idi_read_850 um_idi_read 3 850 NULL
87904 +__module_alloc_50004 __module_alloc 1 50004 NULL
87905 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
87906 +ts_read_44687 ts_read 3 44687 NULL
87907 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
87908 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
87909 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
87910 +provide_user_output_41105 provide_user_output 3 41105 NULL
87911 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
87912 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
87913 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
87914 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
87915 +alloc_ep_17269 alloc_ep 1 17269 NULL
87916 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
87917 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
87918 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
87919 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
87920 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
87921 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
87922 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
87923 +create_queues_9088 create_queues 2-3 9088 NULL
87924 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
87925 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
87926 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
87927 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
87928 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
87929 +read_file_debug_58256 read_file_debug 3 58256 NULL
87930 +skb_pad_17302 skb_pad 2 17302 NULL
87931 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
87932 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
87933 +profile_load_58267 profile_load 3 58267 NULL
87934 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
87935 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
87936 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
87937 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
87938 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
87939 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
87940 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
87941 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
87942 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
87943 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
87944 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
87945 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
87946 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
87947 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
87948 +get_packet_41914 get_packet 3 41914 NULL
87949 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
87950 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
87951 +read_file_slot_50111 read_file_slot 3 50111 NULL
87952 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
87953 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
87954 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
87955 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
87956 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
87957 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
87958 +copy_items_50140 copy_items 6 50140 NULL
87959 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
87960 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
87961 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
87962 +map_addr_56144 map_addr 7 56144 NULL
87963 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
87964 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
87965 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
87966 +portnames_read_41958 portnames_read 3 41958 NULL
87967 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
87968 +hashtab_create_33769 hashtab_create 3 33769 NULL
87969 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
87970 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
87971 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
87972 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
87973 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
87974 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
87975 +odev_update_50169 odev_update 2 50169 NULL
87976 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
87977 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
87978 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
87979 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
87980 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
87981 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
87982 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
87983 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
87984 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
87985 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
87986 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
87987 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
87988 +lguest_map_42008 lguest_map 1-2 42008 NULL
87989 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
87990 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
87991 +pool_allocate_42012 pool_allocate 3 42012 NULL
87992 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
87993 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
87994 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
87995 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
87996 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
87997 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
87998 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
87999 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
88000 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
88001 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
88002 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
88003 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
88004 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
88005 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
88006 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
88007 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
88008 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
88009 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
88010 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
88011 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
88012 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
88013 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
88014 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
88015 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
88016 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
88017 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
88018 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
88019 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
88020 +config_proc_write_33878 config_proc_write 3 33878 NULL
88021 +capabilities_read_58457 capabilities_read 3 58457 NULL
88022 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
88023 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
88024 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
88025 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
88026 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
88027 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
88028 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
88029 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
88030 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
88031 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
88032 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
88033 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
88034 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
88035 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
88036 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
88037 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
88038 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
88039 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
88040 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
88041 +vme_user_write_15587 vme_user_write 3 15587 NULL
88042 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
88043 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
88044 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
88045 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
88046 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
88047 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
88048 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
88049 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
88050 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
88051 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
88052 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
88053 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
88054 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
88055 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
88056 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
88057 +read_9397 read 3 9397 NULL
88058 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
88059 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
88060 +printer_write_60276 printer_write 3 60276 NULL
88061 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
88062 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
88063 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
88064 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
88065 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
88066 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
88067 +osst_execute_17607 osst_execute 7-6 17607 NULL
88068 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
88069 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
88070 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
88071 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
88072 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
88073 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
88074 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
88075 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
88076 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
88077 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
88078 +xip_file_read_58592 xip_file_read 3 58592 NULL
88079 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
88080 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
88081 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
88082 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
88083 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
88084 +ppp_write_34034 ppp_write 3 34034 NULL
88085 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
88086 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
88087 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
88088 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
88089 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
88090 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
88091 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
88092 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
88093 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
88094 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
88095 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
88096 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
88097 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
88098 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
88099 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
88100 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
88101 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
88102 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
88103 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
88104 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
88105 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
88106 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
88107 +lp_write_9511 lp_write 3 9511 NULL
88108 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
88109 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
88110 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
88111 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
88112 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
88113 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
88114 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
88115 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
88116 +read_file_dma_9530 read_file_dma 3 9530 NULL
88117 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
88118 +rcname_read_25919 rcname_read 3 25919 NULL
88119 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
88120 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
88121 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
88122 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
88123 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
88124 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
88125 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
88126 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
88127 +key_flags_read_25931 key_flags_read 3 25931 NULL
88128 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
88129 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
88130 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
88131 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
88132 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
88133 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
88134 +fw_node_create_9559 fw_node_create 2 9559 NULL
88135 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
88136 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
88137 +kobj_map_9566 kobj_map 2-3 9566 NULL
88138 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
88139 +acpi_map_58725 acpi_map 1-2 58725 NULL
88140 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
88141 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
88142 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
88143 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
88144 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
88145 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
88146 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
88147 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
88148 +file_read_actor_1401 file_read_actor 4 1401 NULL
88149 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
88150 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
88151 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
88152 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
88153 +do_sync_9604 do_sync 1 9604 NULL
88154 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
88155 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
88156 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
88157 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
88158 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
88159 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
88160 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
88161 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
88162 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
88163 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
88164 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
88165 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
88166 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
88167 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
88168 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
88169 +sge_rx_50594 sge_rx 3 50594 NULL
88170 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
88171 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
88172 +skb_padto_50759 skb_padto 2 50759 NULL
88173 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
88174 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
88175 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
88176 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
88177 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
88178 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
88179 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
88180 +ep_read_58813 ep_read 3 58813 NULL
88181 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
88182 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
88183 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
88184 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
88185 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
88186 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
88187 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
88188 +dns_query_9676 dns_query 3 9676 NULL
88189 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
88190 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
88191 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
88192 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
88193 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
88194 +command_write_58841 command_write 3 58841 NULL
88195 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
88196 +dev_config_8506 dev_config 3 8506 NULL
88197 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
88198 +sys_readv_50664 sys_readv 3 50664 NULL
88199 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
88200 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
88201 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
88202 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
88203 +recover_head_17904 recover_head 3 17904 NULL
88204 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
88205 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
88206 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
88207 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
88208 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
88209 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
88210 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
88211 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
88212 +skb_cow_26138 skb_cow 2 26138 NULL
88213 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
88214 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
88215 +do_sigpending_9766 do_sigpending 2 9766 NULL
88216 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
88217 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
88218 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
88219 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
88220 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
88221 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
88222 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
88223 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
88224 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
88225 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
88226 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
88227 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
88228 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
88229 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
88230 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
88231 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
88232 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
88233 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
88234 +get_registers_26187 get_registers 3 26187 NULL
88235 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
88236 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
88237 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
88238 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
88239 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
88240 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
88241 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
88242 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
88243 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
88244 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
88245 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
88246 +mce_write_26201 mce_write 3 26201 NULL
88247 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
88248 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
88249 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
88250 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
88251 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
88252 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
88253 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
88254 +tpm_write_50798 tpm_write 3 50798 NULL
88255 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
88256 +tun_do_read_50800 tun_do_read 4 50800 NULL
88257 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
88258 +write_flush_50803 write_flush 3 50803 NULL
88259 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
88260 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
88261 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
88262 +dvb_play_50814 dvb_play 3 50814 NULL
88263 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
88264 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
88265 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
88266 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
88267 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
88268 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
88269 +dma_attach_50831 dma_attach 6-7 50831 NULL
88270 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
88271 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
88272 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
88273 +packet_came_18072 packet_came 3 18072 NULL
88274 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
88275 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
88276 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
88277 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
88278 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
88279 +get_vm_area_18080 get_vm_area 1 18080 NULL
88280 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
88281 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
88282 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
88283 +self_check_write_50856 self_check_write 5 50856 NULL
88284 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
88285 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
88286 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
88287 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
88288 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
88289 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
88290 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
88291 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
88292 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
88293 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
88294 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
88295 +vb2_read_42703 vb2_read 3 42703 NULL
88296 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
88297 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
88298 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
88299 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
88300 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
88301 +read_file_misc_9948 read_file_misc 3 9948 NULL
88302 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
88303 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
88304 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
88305 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
88306 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
88307 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
88308 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
88309 +cosa_write_1774 cosa_write 3 1774 NULL
88310 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
88311 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
88312 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
88313 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
88314 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
88315 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
88316 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
88317 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
88318 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
88319 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
88320 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
88321 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
88322 +mld_newpack_50950 mld_newpack 2 50950 NULL
88323 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
88324 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
88325 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
88326 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
88327 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
88328 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
88329 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
88330 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
88331 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
88332 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
88333 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
88334 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
88335 +handle_request_10024 handle_request 9 10024 NULL
88336 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
88337 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
88338 +timeout_write_50991 timeout_write 3 50991 NULL
88339 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
88340 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
88341 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
88342 +proc_write_51003 proc_write 3 51003 NULL
88343 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
88344 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
88345 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
88346 +set_arg_42824 set_arg 3 42824 NULL
88347 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
88348 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
88349 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
88350 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
88351 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
88352 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
88353 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
88354 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
88355 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
88356 +dt3155_read_59226 dt3155_read 3 59226 NULL
88357 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
88358 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
88359 +dump_midi_51040 dump_midi 3 51040 NULL
88360 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
88361 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
88362 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
88363 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
88364 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
88365 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
88366 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
88367 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
88368 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
88369 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
88370 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
88371 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
88372 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
88373 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
88374 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
88375 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
88376 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
88377 +read_vmcore_26501 read_vmcore 3 26501 NULL
88378 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
88379 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
88380 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
88381 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
88382 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
88383 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
88384 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
88385 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
88386 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
88387 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
88388 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
88389 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
88390 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
88391 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
88392 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
88393 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
88394 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
88395 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
88396 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
88397 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
88398 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
88399 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
88400 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
88401 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
88402 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
88403 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
88404 +fd_copyout_59323 fd_copyout 3 59323 NULL
88405 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
88406 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
88407 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
88408 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
88409 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
88410 +solos_param_store_34755 solos_param_store 4 34755 NULL
88411 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
88412 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
88413 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
88414 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
88415 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
88416 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
88417 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
88418 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
88419 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
88420 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
88421 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
88422 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
88423 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
88424 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
88425 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
88426 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
88427 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
88428 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
88429 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
88430 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
88431 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
88432 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
88433 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
88434 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
88435 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
88436 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
88437 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
88438 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
88439 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
88440 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
88441 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
88442 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
88443 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
88444 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
88445 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
88446 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
88447 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
88448 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
88449 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
88450 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
88451 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
88452 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
88453 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
88454 +tipc_send_51238 tipc_send 4 51238 NULL
88455 +drm_property_create_51239 drm_property_create 4 51239 NULL
88456 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
88457 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
88458 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
88459 +audit_expand_2098 audit_expand 2 2098 NULL
88460 +st_read_51251 st_read 3 51251 NULL
88461 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
88462 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
88463 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
88464 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
88465 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
88466 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
88467 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
88468 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
88469 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
88470 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
88471 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
88472 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
88473 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
88474 +c4_add_card_54968 c4_add_card 3 54968 NULL
88475 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
88476 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
88477 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
88478 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
88479 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
88480 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
88481 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
88482 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
88483 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
88484 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
88485 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
88486 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
88487 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
88488 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
88489 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
88490 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
88491 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
88492 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
88493 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
88494 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
88495 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
88496 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
88497 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
88498 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
88499 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
88500 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
88501 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
88502 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
88503 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
88504 +debug_output_18575 debug_output 3 18575 NULL
88505 +Realloc_34961 Realloc 2 34961 NULL
88506 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
88507 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
88508 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
88509 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
88510 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
88511 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
88512 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
88513 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
88514 +vhci_write_2224 vhci_write 3 2224 NULL
88515 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
88516 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
88517 +rb_alloc_3102 rb_alloc 1 3102 NULL
88518 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
88519 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
88520 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
88521 +write_pbl_59583 write_pbl 4 59583 NULL
88522 +from_buffer_18625 from_buffer 3 18625 NULL
88523 +uio_write_43202 uio_write 3 43202 NULL
88524 +memdup_user_59590 memdup_user 2 59590 NULL
88525 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
88526 +iso_callback_43208 iso_callback 3 43208 NULL
88527 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
88528 +smk_write_load_26829 smk_write_load 3 26829 NULL
88529 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
88530 +do_update_counters_2259 do_update_counters 4 2259 NULL
88531 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
88532 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
88533 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
88534 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
88535 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
88536 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
88537 +mtrr_write_59622 mtrr_write 3 59622 NULL
88538 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
88539 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
88540 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
88541 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
88542 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
88543 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
88544 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
88545 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
88546 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
88547 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
88548 +fixup_leb_43256 fixup_leb 3 43256 NULL
88549 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
88550 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
88551 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
88552 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
88553 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
88554 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
88555 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
88556 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
88557 +evtchn_write_43278 evtchn_write 3 43278 NULL
88558 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
88559 +store_ifalias_35088 store_ifalias 4 35088 NULL
88560 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
88561 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
88562 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
88563 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
88564 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
88565 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
88566 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
88567 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
88568 +capi_write_35104 capi_write 3 35104 NULL nohasharray
88569 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
88570 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
88571 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
88572 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
88573 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
88574 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
88575 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
88576 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
88577 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
88578 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
88579 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
88580 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
88581 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
88582 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
88583 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
88584 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
88585 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
88586 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
88587 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
88588 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
88589 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
88590 +do_trimming_26952 do_trimming 3 26952 NULL
88591 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
88592 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
88593 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
88594 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
88595 +alloc_buf_34532 alloc_buf 1 34532 NULL
88596 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
88597 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
88598 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
88599 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
88600 +otp_read_10594 otp_read 2-4-5 10594 NULL
88601 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
88602 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
88603 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
88604 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
88605 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
88606 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
88607 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
88608 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
88609 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
88610 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
88611 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
88612 +venus_remove_59781 venus_remove 4 59781 NULL
88613 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
88614 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
88615 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
88616 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
88617 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
88618 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
88619 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
88620 +xenfb_write_43412 xenfb_write 3 43412 NULL
88621 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
88622 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
88623 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
88624 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
88625 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
88626 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
88627 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
88628 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
88629 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
88630 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
88631 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
88632 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
88633 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
88634 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
88635 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
88636 +cmd_complete_51629 cmd_complete 6 51629 NULL
88637 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
88638 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
88639 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
88640 +set_fd_set_35249 set_fd_set 1 35249 NULL
88641 +wiphy_new_2482 wiphy_new 2 2482 NULL
88642 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
88643 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
88644 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
88645 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
88646 +tcp_push_10680 tcp_push 3 10680 NULL
88647 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
88648 +c101_run_37279 c101_run 2 37279 NULL
88649 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
88650 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
88651 +tun_put_user_59849 tun_put_user 4 59849 NULL
88652 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
88653 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
88654 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
88655 +dm_write_2513 dm_write 3 2513 NULL
88656 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
88657 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
88658 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
88659 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
88660 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
88661 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
88662 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
88663 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
88664 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
88665 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
88666 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
88667 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
88668 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
88669 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
88670 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
88671 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
88672 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
88673 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
88674 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
88675 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
88676 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
88677 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
88678 +sel_write_access_51704 sel_write_access 3 51704 NULL
88679 +sys_syslog_10746 sys_syslog 3 10746 NULL
88680 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
88681 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
88682 +do_readlink_43518 do_readlink 2 43518 NULL
88683 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
88684 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
88685 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
88686 +read_file_reset_52310 read_file_reset 3 52310 NULL
88687 +pms_capture_27142 pms_capture 4 27142 NULL
88688 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
88689 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
88690 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
88691 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
88692 +msg_set_51725 msg_set 3 51725 NULL
88693 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
88694 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
88695 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
88696 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
88697 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
88698 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
88699 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
88700 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
88701 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
88702 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
88703 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
88704 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
88705 +sys_bind_10799 sys_bind 3 10799 NULL
88706 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
88707 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
88708 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
88709 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
88710 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
88711 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
88712 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
88713 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
88714 +send_command_10832 send_command 4 10832 NULL
88715 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
88716 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
88717 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
88718 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
88719 +proc_read_43614 proc_read 3 43614 NULL
88720 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
88721 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
88722 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
88723 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
88724 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
88725 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
88726 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
88727 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
88728 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
88729 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
88730 +vmalloc_15464 vmalloc 1 15464 NULL
88731 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
88732 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
88733 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
88734 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
88735 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
88736 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
88737 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
88738 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
88739 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
88740 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
88741 +adu_write_30487 adu_write 3 30487 NULL
88742 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
88743 +get_scq_10897 get_scq 2 10897 NULL
88744 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
88745 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
88746 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
88747 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
88748 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
88749 +load_module_60056 load_module 2 60056 NULL nohasharray
88750 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
88751 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
88752 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
88753 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
88754 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
88755 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
88756 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
88757 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
88758 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
88759 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
88760 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
88761 +user_read_51881 user_read 3 51881 NULL
88762 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
88763 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
88764 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
88765 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
88766 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
88767 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
88768 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
88769 +async_setkey_35521 async_setkey 3 35521 NULL
88770 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
88771 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
88772 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
88773 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
88774 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
88775 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
88776 +add_tty_40055 add_tty 1 40055 NULL nohasharray
88777 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
88778 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
88779 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
88780 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
88781 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
88782 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
88783 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
88784 +alloc_context_3194 alloc_context 1 3194 NULL
88785 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
88786 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
88787 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
88788 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
88789 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
88790 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
88791 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
88792 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
88793 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
88794 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
88795 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
88796 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
88797 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
88798 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
88799 +init_state_60165 init_state 2 60165 NULL
88800 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
88801 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
88802 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
88803 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
88804 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
88805 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
88806 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
88807 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
88808 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
88809 +calc_hmac_32010 calc_hmac 3 32010 NULL
88810 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
88811 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
88812 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
88813 +kernel_readv_35617 kernel_readv 3 35617 NULL
88814 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
88815 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
88816 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
88817 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
88818 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
88819 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
88820 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
88821 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
88822 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
88823 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
88824 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
88825 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
88826 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
88827 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
88828 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
88829 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
88830 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
88831 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
88832 +store_debug_level_35652 store_debug_level 3 35652 NULL
88833 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
88834 +read_flush_43851 read_flush 3 43851 NULL
88835 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
88836 +cmm_write_2896 cmm_write 3 2896 NULL
88837 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
88838 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
88839 +tunables_write_59563 tunables_write 3 59563 NULL
88840 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
88841 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
88842 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
88843 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
88844 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
88845 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
88846 +dm_table_create_35687 dm_table_create 3 35687 NULL
88847 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
88848 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
88849 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
88850 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
88851 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
88852 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
88853 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
88854 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
88855 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
88856 +debug_read_19322 debug_read 3 19322 NULL
88857 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
88858 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
88859 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
88860 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
88861 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
88862 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
88863 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
88864 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
88865 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
88866 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
88867 +doc_probe_23285 doc_probe 1 23285 NULL
88868 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
88869 +SendString_43928 SendString 3 43928 NULL
88870 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
88871 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
88872 +retry_count_read_52129 retry_count_read 3 52129 NULL
88873 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
88874 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
88875 +read_zero_19366 read_zero 3 19366 NULL
88876 +bch_alloc_4593 bch_alloc 1 4593 NULL
88877 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
88878 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
88879 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
88880 +raid5_resize_63306 raid5_resize 2 63306 NULL
88881 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
88882 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
88883 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
88884 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
88885 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
88886 +depth_write_3021 depth_write 3 3021 NULL
88887 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
88888 +read_file_stations_35795 read_file_stations 3 35795 NULL
88889 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
88890 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
88891 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
88892 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
88893 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
88894 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
88895 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
88896 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
88897 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
88898 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
88899 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
88900 +driver_names_read_60399 driver_names_read 3 60399 NULL
88901 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
88902 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
88903 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
88904 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
88905 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
88906 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
88907 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
88908 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
88909 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
88910 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
88911 +rx_data_60442 rx_data 4 60442 NULL
88912 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
88913 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
88914 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
88915 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
88916 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
88917 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
88918 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
88919 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
88920 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
88921 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
88922 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
88923 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
88924 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
88925 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
88926 +construct_key_11329 construct_key 3 11329 NULL
88927 +evm_write_key_27715 evm_write_key 3 27715 NULL
88928 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
88929 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
88930 +filldir_55137 filldir 3 55137 NULL
88931 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
88932 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
88933 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
88934 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
88935 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
88936 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
88937 +sel_write_create_11353 sel_write_create 3 11353 NULL
88938 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
88939 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
88940 +hwflags_read_52318 hwflags_read 3 52318 NULL
88941 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
88942 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
88943 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
88944 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
88945 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
88946 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
88947 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
88948 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
88949 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
88950 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
88951 +nfsd_read_19568 nfsd_read 5 19568 NULL
88952 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
88953 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
88954 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
88955 +kcalloc_27770 kcalloc 1-2 27770 NULL
88956 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
88957 +bm_status_read_19583 bm_status_read 3 19583 NULL
88958 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
88959 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
88960 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
88961 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
88962 +acl_alloc_35979 acl_alloc 1 35979 NULL
88963 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
88964 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
88965 +str_to_user_11411 str_to_user 2 11411 NULL
88966 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
88967 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
88968 +trace_options_read_11419 trace_options_read 3 11419 NULL
88969 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
88970 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
88971 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
88972 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
88973 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
88974 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
88975 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
88976 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
88977 +console_store_36007 console_store 4 36007 NULL
88978 +bttv_read_11432 bttv_read 3 11432 NULL
88979 +key_key_read_3241 key_key_read 3 3241 NULL
88980 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
88981 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
88982 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
88983 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
88984 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
88985 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
88986 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
88987 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
88988 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
88989 +um_idi_write_18293 um_idi_write 3 18293 NULL
88990 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
88991 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
88992 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
88993 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
88994 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
88995 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
88996 +sys_init_module_36047 sys_init_module 2 36047 NULL
88997 +read_profile_27859 read_profile 3 27859 NULL
88998 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
88999 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
89000 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
89001 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
89002 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
89003 +refill_pool_19477 refill_pool 2 19477 NULL
89004 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
89005 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
89006 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
89007 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
89008 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
89009 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
89010 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
89011 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
89012 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
89013 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
89014 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
89015 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
89016 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
89017 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
89018 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
89019 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
89020 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
89021 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
89022 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
89023 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
89024 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
89025 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
89026 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
89027 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
89028 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
89029 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
89030 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
89031 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
89032 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
89033 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
89034 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
89035 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
89036 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
89037 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
89038 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
89039 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
89040 +init_data_container_60709 init_data_container 1 60709 NULL
89041 +p9_client_read_19750 p9_client_read 5 19750 NULL
89042 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
89043 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
89044 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
89045 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
89046 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
89047 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
89048 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
89049 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
89050 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
89051 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
89052 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
89053 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
89054 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
89055 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
89056 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
89057 +send_stream_3397 send_stream 4 3397 NULL
89058 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
89059 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
89060 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
89061 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
89062 +msix_map_region_3411 msix_map_region 3 3411 NULL
89063 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
89064 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
89065 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
89066 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
89067 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
89068 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
89069 +opticon_write_60775 opticon_write 4 60775 NULL
89070 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
89071 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
89072 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
89073 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
89074 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
89075 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
89076 +vip_read_19832 vip_read 3 19832 NULL
89077 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
89078 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
89079 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
89080 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
89081 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
89082 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
89083 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
89084 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
89085 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
89086 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
89087 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
89088 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
89089 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
89090 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
89091 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
89092 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
89093 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
89094 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
89095 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
89096 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
89097 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
89098 +split_11691 split 2 11691 NULL
89099 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
89100 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
89101 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
89102 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
89103 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
89104 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
89105 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
89106 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
89107 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
89108 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
89109 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
89110 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
89111 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
89112 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
89113 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
89114 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
89115 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
89116 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
89117 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
89118 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
89119 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
89120 +spidev_write_44510 spidev_write 3 44510 NULL
89121 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
89122 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
89123 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
89124 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
89125 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
89126 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
89127 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
89128 +kone_receive_4690 kone_receive 4 4690 NULL
89129 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
89130 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
89131 +evtchn_read_3569 evtchn_read 3 3569 NULL
89132 +video_read_28148 video_read 3 28148 NULL
89133 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
89134 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
89135 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
89136 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
89137 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
89138 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
89139 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
89140 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
89141 +vc_resize_3585 vc_resize 2-3 3585 NULL
89142 +gluebi_write_27905 gluebi_write 3 27905 NULL
89143 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
89144 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
89145 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
89146 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
89147 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
89148 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
89149 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
89150 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
89151 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
89152 +pti_char_write_60960 pti_char_write 3 60960 NULL
89153 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
89154 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
89155 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
89156 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
89157 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
89158 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
89159 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
89160 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
89161 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
89162 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
89163 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
89164 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
89165 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
89166 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
89167 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
89168 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
89169 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
89170 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
89171 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
89172 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
89173 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
89174 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
89175 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
89176 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
89177 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
89178 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
89179 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
89180 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
89181 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
89182 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
89183 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
89184 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
89185 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
89186 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
89187 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
89188 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
89189 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
89190 +symtab_init_61050 symtab_init 2 61050 NULL
89191 +team_options_register_20091 team_options_register 3 20091 NULL
89192 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
89193 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
89194 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
89195 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
89196 +mpi_resize_44674 mpi_resize 2 44674 NULL
89197 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
89198 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
89199 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
89200 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
89201 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
89202 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
89203 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
89204 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
89205 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
89206 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
89207 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
89208 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
89209 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
89210 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
89211 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
89212 +pms_read_53873 pms_read 3 53873 NULL
89213 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
89214 +get_derived_key_61100 get_derived_key 4 61100 NULL
89215 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
89216 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
89217 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
89218 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
89219 +dm_read_15674 dm_read 3 15674 NULL
89220 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
89221 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
89222 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
89223 +kone_send_63435 kone_send 4 63435 NULL
89224 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
89225 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
89226 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
89227 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
89228 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
89229 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
89230 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
89231 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
89232 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
89233 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
89234 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
89235 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
89236 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
89237 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
89238 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
89239 +send_packet_52960 send_packet 4 52960 NULL
89240 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
89241 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
89242 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
89243 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
89244 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
89245 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
89246 +put_cmsg_36589 put_cmsg 4 36589 NULL
89247 +__vmalloc_61168 __vmalloc 1 61168 NULL
89248 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
89249 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
89250 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
89251 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
89252 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
89253 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
89254 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
89255 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
89256 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
89257 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
89258 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
89259 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
89260 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
89261 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
89262 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
89263 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
89264 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
89265 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
89266 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
89267 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
89268 +get_fd_set_3866 get_fd_set 1 3866 NULL
89269 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
89270 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
89271 +unlink_queued_645 unlink_queued 3-4 645 NULL
89272 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
89273 +sisusb_write_44834 sisusb_write 3 44834 NULL
89274 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
89275 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
89276 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
89277 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
89278 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
89279 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
89280 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
89281 +nvram_write_3894 nvram_write 3 3894 NULL
89282 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
89283 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
89284 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
89285 +vcs_write_3910 vcs_write 3 3910 NULL
89286 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
89287 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
89288 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
89289 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
89290 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
89291 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
89292 +do_tty_write_44896 do_tty_write 5 44896 NULL
89293 +set_powered_12129 set_powered 4 12129 NULL
89294 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
89295 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
89296 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
89297 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
89298 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
89299 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
89300 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
89301 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
89302 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
89303 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
89304 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
89305 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
89306 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
89307 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
89308 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
89309 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
89310 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
89311 +gather_array_56641 gather_array 3 56641 NULL
89312 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
89313 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
89314 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
89315 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
89316 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
89317 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
89318 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
89319 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
89320 +do_add_counters_3992 do_add_counters 3 3992 NULL
89321 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
89322 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
89323 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
89324 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
89325 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
89326 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
89327 +mei_write_4005 mei_write 3 4005 NULL
89328 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
89329 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
89330 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
89331 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
89332 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
89333 +receive_copy_12216 receive_copy 3 12216 NULL
89334 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
89335 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
89336 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
89337 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
89338 +change_xattr_61390 change_xattr 5 61390 NULL
89339 +find_skb_20431 find_skb 2 20431 NULL
89340 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
89341 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
89342 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
89343 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
89344 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
89345 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
89346 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
89347 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
89348 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
89349 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
89350 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
89351 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
89352 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
89353 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
89354 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
89355 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
89356 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
89357 +read_buf_20469 read_buf 2 20469 NULL
89358 +cm_write_36858 cm_write 3 36858 NULL
89359 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
89360 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
89361 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
89362 +sel_write_user_45060 sel_write_user 3 45060 NULL
89363 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
89364 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
89365 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
89366 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
89367 +fast_user_write_20494 fast_user_write 5 20494 NULL
89368 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
89369 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
89370 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
89371 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
89372 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
89373 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
89374 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
89375 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
89376 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
89377 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
89378 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
89379 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
89380 +osst_read_40237 osst_read 3 40237 NULL
89381 +tm6000_read_4151 tm6000_read 3 4151 NULL
89382 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
89383 +usbdev_read_45114 usbdev_read 3 45114 NULL
89384 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
89385 +spi_execute_28736 spi_execute 5 28736 NULL
89386 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
89387 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
89388 +get_alua_req_4166 get_alua_req 3 4166 NULL
89389 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
89390 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
89391 +venus_create_20555 venus_create 4 20555 NULL
89392 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
89393 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
89394 +receive_packet_12367 receive_packet 2 12367 NULL
89395 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
89396 +mem_write_22232 mem_write 3 22232 NULL
89397 +read_file_bool_4180 read_file_bool 3 4180 NULL
89398 +send_to_tty_45141 send_to_tty 3 45141 NULL
89399 +fops_read_40672 fops_read 3 40672 NULL
89400 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
89401 +write_leb_36957 write_leb 5 36957 NULL
89402 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
89403 +device_write_45156 device_write 3 45156 NULL
89404 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
89405 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
89406 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
89407 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
89408 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
89409 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
89410 +isp1760_register_628 isp1760_register 1-2 628 NULL
89411 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
89412 +lirc_write_20604 lirc_write 3 20604 NULL
89413 +sel_write_member_28800 sel_write_member 3 28800 NULL
89414 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
89415 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
89416 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
89417 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
89418 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
89419 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
89420 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
89421 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
89422 +setxattr_37006 setxattr 4 37006 NULL
89423 +add_child_45201 add_child 4 45201 NULL
89424 +seq_open_private_61589 seq_open_private 3 61589 NULL
89425 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
89426 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
89427 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
89428 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
89429 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
89430 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
89431 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
89432 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
89433 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
89434 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
89435 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
89436 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
89437 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
89438 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
89439 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
89440 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
89441 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
89442 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
89443 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
89444 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
89445 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
89446 +resize_stripes_61650 resize_stripes 2 61650 NULL
89447 +n2_run_53459 n2_run 3 53459 NULL
89448 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
89449 +parse_command_37079 parse_command 2 37079 NULL
89450 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
89451 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
89452 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
89453 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
89454 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
89455 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
89456 +insert_one_name_61668 insert_one_name 7 61668 NULL
89457 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
89458 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
89459 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
89460 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
89461 +lock_loop_61681 lock_loop 1 61681 NULL
89462 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
89463 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
89464 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
89465 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
89466 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
89467 +push_rx_28939 push_rx 3 28939 NULL
89468 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
89469 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
89470 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
89471 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
89472 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
89473 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
89474 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
89475 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
89476 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
89477 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
89478 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
89479 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
89480 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
89481 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
89482 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
89483 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
89484 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
89485 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
89486 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
89487 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
89488 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
89489 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
89490 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
89491 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
89492 +bin_uuid_28999 bin_uuid 3 28999 NULL
89493 +sys_sendto_20809 sys_sendto 6 20809 NULL
89494 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
89495 +set_registers_53582 set_registers 3 53582 NULL
89496 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
89497 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
89498 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
89499 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
89500 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
89501 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
89502 +keymap_store_45406 keymap_store 4 45406 NULL
89503 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
89504 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
89505 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
89506 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
89507 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
89508 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
89509 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
89510 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
89511 +__do_replace_37227 __do_replace 5 37227 NULL
89512 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
89513 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
89514 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
89515 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
89516 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
89517 +tso_fragment_29050 tso_fragment 3 29050 NULL
89518 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
89519 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
89520 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
89521 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
89522 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
89523 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
89524 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
89525 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
89526 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
89527 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
89528 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
89529 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
89530 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
89531 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
89532 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
89533 +set_link_security_4502 set_link_security 4 4502 NULL
89534 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
89535 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
89536 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
89537 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
89538 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
89539 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
89540 +mmio_read_40348 mmio_read 4 40348 NULL
89541 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
89542 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
89543 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
89544 +ivtv_write_12721 ivtv_write 3 12721 NULL
89545 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
89546 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
89547 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
89548 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
89549 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
89550 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
89551 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
89552 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
89553 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
89554 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
89555 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
89556 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
89557 +send_msg_37323 send_msg 4 37323 NULL
89558 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
89559 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
89560 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
89561 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
89562 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
89563 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
89564 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
89565 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
89566 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
89567 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
89568 +reshape_ring_29147 reshape_ring 2 29147 NULL
89569 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
89570 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
89571 +copy_macs_45534 copy_macs 4 45534 NULL
89572 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
89573 +listxattr_12769 listxattr 3 12769 NULL
89574 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
89575 +wdm_write_53735 wdm_write 3 53735 NULL
89576 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
89577 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
89578 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
89579 +mempool_create_29437 mempool_create 1 29437 NULL
89580 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
89581 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
89582 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
89583 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
89584 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
89585 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
89586 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
89587 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
89588 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
89589 +mgmt_event_12810 mgmt_event 4 12810 NULL
89590 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
89591 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
89592 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
89593 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
89594 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
89595 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
89596 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
89597 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
89598 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
89599 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
89600 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
89601 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
89602 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
89603 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
89604 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
89605 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
89606 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
89607 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
89608 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
89609 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
89610 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
89611 +recover_peb_29238 recover_peb 6-7 29238 NULL
89612 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
89613 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
89614 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
89615 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
89616 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
89617 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
89618 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
89619 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
89620 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
89621 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
89622 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
89623 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
89624 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
89625 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
89626 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
89627 +do_pselect_62061 do_pselect 1 62061 NULL
89628 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
89629 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
89630 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
89631 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
89632 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
89633 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
89634 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
89635 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
89636 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
89637 +sg_read_25799 sg_read 3 25799 NULL
89638 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
89639 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
89640 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
89641 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
89642 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
89643 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
89644 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
89645 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
89646 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
89647 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
89648 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
89649 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
89650 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
89651 +new_skb_21148 new_skb 1 21148 NULL
89652 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
89653 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
89654 +bm_status_write_12964 bm_status_write 3 12964 NULL
89655 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
89656 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
89657 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
89658 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
89659 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
89660 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
89661 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
89662 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
89663 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
89664 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
89665 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
89666 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
89667 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
89668 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
89669 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
89670 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
89671 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
89672 +video_usercopy_62151 video_usercopy 2 62151 NULL
89673 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
89674 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
89675 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
89676 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
89677 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
89678 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
89679 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
89680 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
89681 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
89682 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
89683 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
89684 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
89685 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
89686 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
89687 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
89688 +input_ff_create_21240 input_ff_create 2 21240 NULL
89689 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
89690 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
89691 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
89692 +amthi_read_45831 amthi_read 4 45831 NULL
89693 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
89694 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
89695 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
89696 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
89697 +sys_ipc_4889 sys_ipc 3 4889 NULL
89698 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
89699 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
89700 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
89701 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
89702 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
89703 +do_register_entry_29478 do_register_entry 4 29478 NULL
89704 +isdn_write_45863 isdn_write 3 45863 NULL
89705 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
89706 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
89707 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
89708 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
89709 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
89710 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
89711 +_malloc_54077 _malloc 1 54077 NULL
89712 +add_res_range_21310 add_res_range 4 21310 NULL
89713 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
89714 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
89715 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
89716 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
89717 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
89718 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
89719 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
89720 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
89721 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
89722 +create_xattr_54106 create_xattr 5 54106 NULL
89723 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
89724 +ep_write_59008 ep_write 3 59008 NULL
89725 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
89726 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
89727 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
89728 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
89729 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
89730 +alloc_mr_45935 alloc_mr 1 45935 NULL
89731 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
89732 +isku_receive_54130 isku_receive 4 54130 NULL
89733 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
89734 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
89735 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
89736 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
89737 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
89738 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
89739 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
89740 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
89741 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
89742 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
89743 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
89744 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
89745 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
89746 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
89747 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
89748 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
89749 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
89750 +comedi_read_13199 comedi_read 3 13199 NULL
89751 +flash_write_62354 flash_write 3 62354 NULL
89752 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
89753 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
89754 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
89755 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
89756 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
89757 +proc_file_read_53905 proc_file_read 3 53905 NULL
89758 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
89759 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
89760 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
89761 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
89762 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
89763 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
89764 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
89765 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
89766 +cru_detect_11272 cru_detect 1 11272 NULL
89767 +altera_irscan_62396 altera_irscan 2 62396 NULL
89768 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
89769 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
89770 +fw_download_code_13249 fw_download_code 3 13249 NULL
89771 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
89772 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
89773 +set_ssp_62411 set_ssp 4 62411 NULL
89774 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
89775 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
89776 +get_free_entries_46030 get_free_entries 1 46030 NULL
89777 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
89778 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
89779 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
89780 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
89781 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
89782 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
89783 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
89784 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
89785 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
89786 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
89787 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
89788 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
89789 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
89790 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
89791 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
89792 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
89793 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
89794 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
89795 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
89796 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
89797 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
89798 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
89799 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
89800 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
89801 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
89802 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
89803 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
89804 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
89805 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
89806 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
89807 +probes_write_29711 probes_write 3 29711 NULL
89808 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
89809 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
89810 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
89811 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
89812 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
89813 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
89814 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
89815 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
89816 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
89817 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
89818 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
89819 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
89820 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
89821 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
89822 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
89823 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
89824 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
89825 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
89826 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
89827 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
89828 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
89829 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
89830 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
89831 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
89832 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
89833 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
89834 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
89835 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
89836 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
89837 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
89838 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
89839 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
89840 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
89841 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
89842 +isdn_read_50021 isdn_read 3 50021 NULL
89843 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
89844 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
89845 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
89846 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
89847 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
89848 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
89849 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
89850 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
89851 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
89852 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
89853 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
89854 +get_subdir_62581 get_subdir 3 62581 NULL
89855 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
89856 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
89857 +vfs_readv_38011 vfs_readv 3 38011 NULL
89858 +keyring_read_13438 keyring_read 3 13438 NULL
89859 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
89860 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
89861 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
89862 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
89863 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
89864 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
89865 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
89866 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
89867 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
89868 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
89869 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
89870 +ftrace_write_29551 ftrace_write 3 29551 NULL
89871 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
89872 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
89873 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
89874 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
89875 +dev_write_7708 dev_write 3 7708 NULL
89876 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
89877 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
89878 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
89879 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
89880 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
89881 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
89882 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
89883 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
89884 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
89885 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
89886 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
89887 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
89888 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
89889 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
89890 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
89891 +bm_init_13529 bm_init 2 13529 NULL
89892 +check586_29914 check586 2 29914 NULL
89893 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
89894 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
89895 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
89896 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
89897 +pg_read_17276 pg_read 3 17276 NULL
89898 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
89899 +ep0_read_38095 ep0_read 3 38095 NULL
89900 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
89901 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
89902 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
89903 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
89904 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
89905 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
89906 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
89907 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
89908 +l2down_create_21755 l2down_create 4 21755 NULL
89909 +alloc_tio_13564 alloc_tio 3 13564 NULL
89910 +viacam_read_54526 viacam_read 3 54526 NULL
89911 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
89912 +tunables_read_36385 tunables_read 3 36385 NULL
89913 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
89914 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
89915 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
89916 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
89917 +setsockopt_54539 setsockopt 5 54539 NULL
89918 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
89919 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
89920 +tty_register_device_4544 tty_register_device 2 4544 NULL
89921 +cache_write_13589 cache_write 3 13589 NULL
89922 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
89923 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
89924 +key_replays_read_62746 key_replays_read 3 62746 NULL
89925 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
89926 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
89927 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
89928 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
89929 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
89930 +cdev_add_38176 cdev_add 2-3 38176 NULL
89931 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
89932 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
89933 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
89934 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
89935 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
89936 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
89937 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
89938 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
89939 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
89940 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
89941 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
89942 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
89943 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
89944 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
89945 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
89946 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
89947 +packet_snd_13634 packet_snd 3 13634 NULL
89948 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
89949 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
89950 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
89951 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
89952 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
89953 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
89954 +drp_wmove_30043 drp_wmove 4 30043 NULL
89955 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
89956 +cache_downcall_13666 cache_downcall 3 13666 NULL
89957 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
89958 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
89959 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
89960 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
89961 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
89962 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
89963 +tty_write_5494 tty_write 3 5494 NULL
89964 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
89965 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
89966 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
89967 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
89968 +teiup_create_43201 teiup_create 3 43201 NULL
89969 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
89970 +filldir64_46469 filldir64 3 46469 NULL
89971 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
89972 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
89973 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
89974 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
89975 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
89976 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
89977 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
89978 +spidev_message_5518 spidev_message 3 5518 NULL
89979 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
89980 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
89981 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
89982 +evm_read_key_54674 evm_read_key 3 54674 NULL
89983 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
89984 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
89985 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
89986 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
89987 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
89988 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
89989 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
89990 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
89991 +u32_array_read_2219 u32_array_read 3 2219 NULL
89992 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
89993 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
89994 +sys_add_key_61288 sys_add_key 4 61288 NULL
89995 +kmsg_read_46514 kmsg_read 3 46514 NULL
89996 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
89997 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
89998 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
89999 +recv_stream_30138 recv_stream 4 30138 NULL
90000 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
90001 +getdqbuf_62908 getdqbuf 1 62908 NULL
90002 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
90003 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
90004 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
90005 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
90006 +fir16_create_5574 fir16_create 3 5574 NULL
90007 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
90008 +pt_write_40159 pt_write 3 40159 NULL
90009 +bioset_create_5580 bioset_create 1 5580 NULL
90010 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
90011 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
90012 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
90013 +kzalloc_54740 kzalloc 1 54740 NULL
90014 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
90015 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
90016 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
90017 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
90018 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
90019 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
90020 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
90021 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
90022 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
90023 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
90024 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
90025 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
90026 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
90027 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
90028 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
90029 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
90030 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
90031 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
90032 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
90033 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
90034 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
90035 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
90036 +ti_recv_22027 ti_recv 4 22027 NULL
90037 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
90038 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
90039 +nfsd_write_54809 nfsd_write 6 54809 NULL
90040 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
90041 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
90042 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
90043 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
90044 +get_skb_63008 get_skb 2 63008 NULL
90045 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
90046 +netlink_send_38434 netlink_send 5 38434 NULL
90047 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
90048 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
90049 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
90050 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
90051 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
90052 +write_rio_54837 write_rio 3 54837 NULL
90053 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
90054 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
90055 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
90056 +get_arg_5694 get_arg 3 5694 NULL
90057 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
90058 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
90059 +compat_readv_30273 compat_readv 3 30273 NULL
90060 +printer_read_54851 printer_read 3 54851 NULL
90061 +mem_rw_22085 mem_rw 3 22085 NULL
90062 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
90063 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
90064 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
90065 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
90066 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
90067 +unlink1_63059 unlink1 3 63059 NULL
90068 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
90069 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
90070 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
90071 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
90072 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
90073 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
90074 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
90075 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
90076 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
90077 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
90078 +dev_names_read_38509 dev_names_read 3 38509 NULL
90079 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
90080 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
90081 +get_packet_5747 get_packet 3 5747 NULL
90082 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
90083 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
90084 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
90085 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
90086 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
90087 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
90088 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
90089 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
90090 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
90091 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
90092 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
90093 +resource_from_user_30341 resource_from_user 3 30341 NULL
90094 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
90095 +sound_write_5102 sound_write 3 5102 NULL
90096 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
90097 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
90098 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
90099 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
90100 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
90101 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
90102 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
90103 +com90xx_found_13974 com90xx_found 3 13974 NULL
90104 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
90105 +qcam_read_13977 qcam_read 3 13977 NULL
90106 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
90107 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
90108 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
90109 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
90110 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
90111 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
90112 +generic_readlink_32654 generic_readlink 3 32654 NULL
90113 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
90114 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
90115 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
90116 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
90117 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
90118 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
90119 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
90120 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
90121 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
90122 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
90123 +concat_writev_21451 concat_writev 3 21451 NULL
90124 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
90125 +_queue_data_54983 _queue_data 4 54983 NULL
90126 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
90127 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
90128 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
90129 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
90130 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
90131 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
90132 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
90133 +setup_req_5848 setup_req 3 5848 NULL
90134 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
90135 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
90136 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
90137 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
90138 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
90139 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
90140 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
90141 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
90142 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
90143 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
90144 +cma_create_area_38642 cma_create_area 2 38642 NULL
90145 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
90146 +sriov_enable_59689 sriov_enable 2 59689 NULL
90147 +enable_write_30456 enable_write 3 30456 NULL
90148 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
90149 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
90150 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
90151 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
90152 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
90153 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
90154 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
90155 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
90156 +port_show_regs_5904 port_show_regs 3 5904 NULL
90157 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
90158 +ptp_read_63251 ptp_read 4 63251 NULL
90159 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
90160 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
90161 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
90162 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
90163 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
90164 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
90165 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
90166 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
90167 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
90168 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
90169 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
90170 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
90171 +read_dma_55086 read_dma 3 55086 NULL
90172 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
90173 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
90174 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
90175 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
90176 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
90177 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
90178 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
90179 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
90180 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
90181 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
90182 +em_canid_change_14150 em_canid_change 3 14150 NULL
90183 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
90184 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
90185 +fb_write_46924 fb_write 3 46924 NULL
90186 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
90187 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
90188 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
90189 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
90190 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
90191 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
90192 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
90193 +udf_readpages_38761 udf_readpages 4 38761 NULL
90194 +reada_add_block_54247 reada_add_block 2 54247 NULL
90195 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
90196 +proc_info_read_63344 proc_info_read 3 63344 NULL
90197 +pep_indicate_38611 pep_indicate 5 38611 NULL
90198 +set_le_30581 set_le 4 30581 NULL
90199 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
90200 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
90201 +alloc_private_22399 alloc_private 2 22399 NULL
90202 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
90203 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
90204 +zoran_write_22404 zoran_write 3 22404 NULL
90205 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
90206 +idmouse_read_63374 idmouse_read 3 63374 NULL
90207 +queue_reply_22416 queue_reply 3 22416 NULL
90208 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
90209 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
90210 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
90211 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
90212 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
90213 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
90214 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
90215 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
90216 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
90217 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
90218 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
90219 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
90220 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
90221 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
90222 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
90223 +sys_select_38827 sys_select 1 38827 NULL
90224 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
90225 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
90226 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
90227 +direct_entry_38836 direct_entry 3 38836 NULL
90228 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
90229 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
90230 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
90231 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
90232 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
90233 +write_head_30481 write_head 4 30481 NULL
90234 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
90235 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
90236 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
90237 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
90238 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
90239 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
90240 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
90241 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
90242 +agp_remap_30665 agp_remap 2 30665 NULL
90243 +interfaces_38859 interfaces 2 38859 NULL
90244 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
90245 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
90246 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
90247 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
90248 +qc_capture_19298 qc_capture 3 19298 NULL
90249 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
90250 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
90251 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
90252 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
90253 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
90254 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
90255 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
90256 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
90257 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
90258 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
90259 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
90260 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
90261 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
90262 +read_kcore_63488 read_kcore 3 63488 NULL
90263 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
90264 +__skb_cow_39254 __skb_cow 2 39254 NULL
90265 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
90266 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
90267 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
90268 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
90269 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
90270 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
90271 +mousedev_read_47123 mousedev_read 3 47123 NULL
90272 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
90273 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
90274 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
90275 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
90276 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
90277 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
90278 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
90279 +vme_user_read_55338 vme_user_read 3 55338 NULL
90280 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
90281 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
90282 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
90283 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
90284 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
90285 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
90286 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
90287 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
90288 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
90289 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
90290 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
90291 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
90292 +snapshot_read_22601 snapshot_read 3 22601 NULL
90293 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
90294 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
90295 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
90296 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
90297 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
90298 +__send_to_port_55383 __send_to_port 3 55383 NULL
90299 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
90300 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
90301 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
90302 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
90303 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
90304 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
90305 +get_nodes_39012 get_nodes 3 39012 NULL
90306 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
90307 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
90308 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
90309 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
90310 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
90311 +create_subvol_30836 create_subvol 4 30836 NULL
90312 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
90313 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
90314 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
90315 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
90316 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
90317 +read_oldmem_55658 read_oldmem 3 55658 NULL
90318 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
90319 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
90320 +options_write_47243 options_write 3 47243 NULL
90321 +module_alloc_63630 module_alloc 1 63630 NULL
90322 +alloc_skb_55439 alloc_skb 1 55439 NULL
90323 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
90324 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
90325 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
90326 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
90327 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
90328 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
90329 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
90330 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
90331 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
90332 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
90333 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
90334 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
90335 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
90336 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
90337 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
90338 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
90339 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
90340 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
90341 +vbi_read_63673 vbi_read 3 63673 NULL
90342 +tun_get_user_39099 tun_get_user 4 39099 NULL
90343 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
90344 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
90345 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
90346 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
90347 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
90348 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
90349 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
90350 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
90351 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
90352 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
90353 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
90354 +ax25_output_22736 ax25_output 2 22736 NULL
90355 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
90356 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
90357 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
90358 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
90359 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
90360 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
90361 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
90362 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
90363 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
90364 +hid_input_report_32458 hid_input_report 4 32458 NULL
90365 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
90366 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
90367 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
90368 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
90369 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
90370 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
90371 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
90372 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
90373 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
90374 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
90375 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
90376 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
90377 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
90378 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
90379 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
90380 +get_info_55681 get_info 3 55681 NULL
90381 +setkey_14987 setkey 3 14987 NULL
90382 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
90383 +init_list_set_39188 init_list_set 2-3 39188 NULL
90384 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
90385 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
90386 +l2up_create_6430 l2up_create 3 6430 NULL
90387 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
90388 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
90389 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
90390 +add_partition_55588 add_partition 2 55588 NULL
90391 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
90392 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
90393 +depth_read_31112 depth_read 3 31112 NULL
90394 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
90395 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
90396 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
90397 +profile_replace_14652 profile_replace 3 14652 NULL
90398 +vzalloc_47421 vzalloc 1 47421 NULL
90399 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
90400 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
90401 +sys_writev_28384 sys_writev 3 28384 NULL
90402 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
90403 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
90404 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
90405 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
90406 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
90407 +create_attr_set_22861 create_attr_set 1 22861 NULL
90408 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
90409 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
90410 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
90411 +sel_write_load_63830 sel_write_load 3 63830 NULL
90412 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
90413 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
90414 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
90415 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
90416 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
90417 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
90418 +probe_bios_17467 probe_bios 1 17467 NULL
90419 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
90420 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
90421 +mei_read_6507 mei_read 3 6507 NULL
90422 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
90423 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
90424 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
90425 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
90426 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
90427 +SetArea_50835 SetArea 4 50835 NULL
90428 +tpm_read_50344 tpm_read 3 50344 NULL
90429 +newpart_47485 newpart 6 47485 NULL
90430 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
90431 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
90432 +core_sys_select_47494 core_sys_select 1 47494 NULL
90433 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
90434 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
90435 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
90436 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
90437 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
90438 +unlink_simple_47506 unlink_simple 3 47506 NULL
90439 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
90440 +wdm_read_6549 wdm_read 3 6549 NULL
90441 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
90442 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
90443 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
90444 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
90445 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
90446 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
90447 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
90448 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
90449 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
90450 +filter_read_61692 filter_read 3 61692 NULL
90451 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
90452 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
90453 +debugfs_read_62535 debugfs_read 3 62535 NULL
90454 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
90455 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
90456 +divas_write_63901 divas_write 3 63901 NULL
90457 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
90458 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
90459 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
90460 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
90461 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
90462 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
90463 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
90464 +ipw_write_59807 ipw_write 3 59807 NULL
90465 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
90466 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
90467 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
90468 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
90469 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
90470 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
90471 +cycx_setup_47562 cycx_setup 4 47562 NULL
90472 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
90473 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
90474 +set_local_name_55757 set_local_name 4 55757 NULL
90475 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
90476 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
90477 +read_ldt_47570 read_ldt 2 47570 NULL
90478 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
90479 +pci_iomap_47575 pci_iomap 3 47575 NULL
90480 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
90481 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
90482 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
90483 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
90484 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
90485 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
90486 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
90487 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
90488 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
90489 +conf_read_55786 conf_read 3 55786 NULL
90490 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
90491 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
90492 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
90493 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
90494 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
90495 +user_power_read_39414 user_power_read 3 39414 NULL
90496 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
90497 +uea_request_47613 uea_request 4 47613 NULL
90498 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
90499 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
90500 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
90501 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
90502 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
90503 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
90504 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
90505 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
90506 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
90507 +kmemdup_64015 kmemdup 2 64015 NULL
90508 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
90509 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
90510 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
90511 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
90512 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
90513 +oz_events_read_47535 oz_events_read 3 47535 NULL
90514 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
90515 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
90516 +sys_semop_39457 sys_semop 3 39457 NULL
90517 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
90518 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
90519 +update_pmkid_2481 update_pmkid 4 2481 NULL
90520 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
90521 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
90522 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
90523 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
90524 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
90525 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
90526 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
90527 +mpeg_read_6708 mpeg_read 3 6708 NULL
90528 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
90529 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
90530 +sky2_receive_13407 sky2_receive 2 13407 NULL
90531 +krealloc_14908 krealloc 2 14908 NULL
90532 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
90533 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
90534 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
90535 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
90536 +video_proc_write_6724 video_proc_write 3 6724 NULL
90537 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
90538 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
90539 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
90540 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
90541 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
90542 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
90543 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
90544 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
90545 +command_file_write_31318 command_file_write 3 31318 NULL
90546 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
90547 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
90548 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
90549 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
90550 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
90551 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
90552 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
90553 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
90554 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
90555 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
90556 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
90557 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
90558 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
90559 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
90560 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
90561 +int_proc_write_39542 int_proc_write 3 39542 NULL
90562 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
90563 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
90564 +read_file_ani_23161 read_file_ani 3 23161 NULL
90565 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
90566 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
90567 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
90568 +pp_write_39554 pp_write 3 39554 NULL
90569 +ioremap_23172 ioremap 1-2 23172 NULL
90570 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
90571 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
90572 +usblp_write_23178 usblp_write 3 23178 NULL
90573 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
90574 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
90575 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
90576 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
90577 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
90578 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
90579 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
90580 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
90581 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
90582 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
90583 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
90584 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
90585 +__team_options_register_63941 __team_options_register 3 63941 NULL
90586 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
90587 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
90588 +rvmalloc_46873 rvmalloc 1 46873 NULL
90589 +vmap_15025 vmap 2 15025 NULL
90590 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
90591 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
90592 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
90593 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
90594 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
90595 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
90596 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
90597 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
90598 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
90599 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
90600 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
90601 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
90602 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
90603 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
90604 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
90605 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
90606 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
90607 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
90608 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
90609 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
90610 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
90611 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
90612 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
90613 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
90614 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
90615 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
90616 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
90617 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
90618 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
90619 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
90620 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
90621 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
90622 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
90623 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
90624 +alg_setkey_31485 alg_setkey 3 31485 NULL
90625 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
90626 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
90627 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
90628 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
90629 +vhci_read_47878 vhci_read 3 47878 NULL
90630 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
90631 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
90632 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
90633 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
90634 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
90635 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
90636 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
90637 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
90638 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
90639 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
90640 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
90641 +timeout_read_47915 timeout_read 3 47915 NULL
90642 +hidraw_write_31536 hidraw_write 3 31536 NULL
90643 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
90644 +page_readlink_23346 page_readlink 3 23346 NULL
90645 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
90646 +comedi_write_47926 comedi_write 3 47926 NULL
90647 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
90648 +dsp_write_46218 dsp_write 2 46218 NULL
90649 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
90650 +usbvision_read_31555 usbvision_read 3 31555 NULL
90651 +pd_video_read_24510 pd_video_read 3 24510 NULL
90652 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
90653 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
90654 +request_key_async_6990 request_key_async 4 6990 NULL
90655 +ts_write_64336 ts_write 3 64336 NULL
90656 +handle_response_55951 handle_response 5 55951 NULL
90657 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
90658 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
90659 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
90660 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
90661 +osst_write_31581 osst_write 3 31581 NULL
90662 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
90663 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
90664 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
90665 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
90666 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
90667 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
90668 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
90669 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
90670 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
90671 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
90672 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
90673 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
90674 +ilo_write_64378 ilo_write 3 64378 NULL
90675 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
90676 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
90677 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
90678 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
90679 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
90680 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
90681 +copy_from_user_17559 copy_from_user 3 17559 NULL
90682 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
90683 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
90684 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
90685 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
90686 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
90687 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
90688 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
90689 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
90690 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
90691 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
90692 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
90693 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
90694 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
90695 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
90696 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
90697 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
90698 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
90699 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
90700 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
90701 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
90702 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
90703 +__lgread_31668 __lgread 4 31668 NULL
90704 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
90705 +fd_copyin_56247 fd_copyin 3 56247 NULL
90706 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
90707 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
90708 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
90709 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
90710 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
90711 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
90712 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
90713 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
90714 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
90715 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
90716 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
90717 +event_filter_read_23494 event_filter_read 3 23494 NULL
90718 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
90719 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
90720 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
90721 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
90722 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
90723 +pkt_add_39897 pkt_add 3 39897 NULL
90724 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
90725 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
90726 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
90727 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
90728 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
90729 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
90730 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
90731 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
90732 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
90733 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
90734 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
90735 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
90736 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
90737 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
90738 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
90739 +remove_uuid_64505 remove_uuid 4 64505 NULL
90740 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
90741 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
90742 +create_table_16213 create_table 2 16213 NULL
90743 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
90744 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
90745 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
90746 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
90747 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
90748 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
90749 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
90750 +set_discoverable_48141 set_discoverable 4 48141 NULL
90751 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
90752 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
90753 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
90754 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
90755 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
90756 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
90757 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
90758 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
90759 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
90760 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
90761 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
90762 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
90763 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
90764 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
90765 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
90766 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
90767 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
90768 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
90769 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
90770 +dev_read_56369 dev_read 3 56369 NULL
90771 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
90772 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
90773 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
90774 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
90775 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
90776 +init_ipath_48187 init_ipath 1 48187 NULL
90777 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
90778 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
90779 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
90780 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
90781 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
90782 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
90783 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
90784 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
90785 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
90786 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
90787 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
90788 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
90789 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
90790 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
90791 +use_pool_64607 use_pool 2 64607 NULL
90792 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
90793 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
90794 +store_msg_56417 store_msg 3 56417 NULL
90795 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
90796 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
90797 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
90798 +read_file_recv_48232 read_file_recv 3 48232 NULL
90799 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
90800 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
90801 +fanotify_write_64623 fanotify_write 3 64623 NULL
90802 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
90803 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
90804 +fl_create_56435 fl_create 5 56435 NULL
90805 +gnttab_map_56439 gnttab_map 2 56439 NULL
90806 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
90807 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
90808 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
90809 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
90810 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
90811 +set_connectable_56458 set_connectable 4 56458 NULL
90812 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
90813 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
90814 +add_port_54941 add_port 2 54941 NULL
90815 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
90816 +cx18_read_23699 cx18_read 3 23699 NULL
90817 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
90818 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
90819 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
90820 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
90821 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
90822 +send_set_info_48288 send_set_info 7 48288 NULL
90823 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
90824 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
90825 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
90826 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
90827 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
90828 +new_dir_31919 new_dir 3 31919 NULL
90829 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
90830 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
90831 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
90832 +mgmt_control_7349 mgmt_control 3 7349 NULL
90833 +hash_setkey_48310 hash_setkey 3 48310 NULL
90834 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
90835 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
90836 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
90837 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
90838 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
90839 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
90840 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
90841 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
90842 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
90843 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
90844 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
90845 +vb2_write_31948 vb2_write 3 31948 NULL
90846 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
90847 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
90848 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
90849 +ip_options_get_56538 ip_options_get 4 56538 NULL
90850 +write_62671 write 3 62671 NULL
90851 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
90852 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
90853 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
90854 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
90855 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
90856 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
90857 +skb_add_data_48363 skb_add_data 3 48363 NULL
90858 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
90859 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
90860 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
90861 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
90862 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
90863 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
90864 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
90865 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
90866 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
90867 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
90868 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
90869 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
90870 +system_enable_read_25815 system_enable_read 3 25815 NULL
90871 +allocate_probes_40204 allocate_probes 1 40204 NULL
90872 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
90873 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
90874 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
90875 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
90876 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
90877 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
90878 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
90879 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
90880 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
90881 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
90882 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
90883 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
90884 +fs_path_add_15648 fs_path_add 3 15648 NULL
90885 +event_filter_write_56609 event_filter_write 3 56609 NULL
90886 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
90887 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
90888 +xsd_read_15653 xsd_read 3 15653 NULL
90889 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
90890 +p54_init_common_23850 p54_init_common 1 23850 NULL
90891 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
90892 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
90893 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
90894 +garp_request_join_7471 garp_request_join 4 7471 NULL
90895 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
90896 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
90897 +unifi_read_14899 unifi_read 3 14899 NULL
90898 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
90899 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
90900 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
90901 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
90902 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
90903 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
90904 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
90905 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
90906 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
90907 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
90908 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
90909 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
90910 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
90911 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
90912 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
90913 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
90914 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
90915 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
90916 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
90917 +bio_alloc_32095 bio_alloc 2 32095 NULL
90918 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
90919 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
90920 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
90921 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
90922 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
90923 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
90924 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
90925 +send_control_msg_48498 send_control_msg 6 48498 NULL
90926 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
90927 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
90928 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
90929 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
90930 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
90931 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
90932 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
90933 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
90934 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
90935 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
90936 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
90937 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
90938 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
90939 +alloc_tx_32143 alloc_tx 2 32143 NULL
90940 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
90941 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
90942 +hsc_write_55875 hsc_write 3 55875 NULL
90943 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
90944 +do_test_15766 do_test 1 15766 NULL
90945 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
90946 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
90947 +named_distribute_48544 named_distribute 4 48544 NULL
90948 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
90949 +venus_link_32165 venus_link 5 32165 NULL
90950 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
90951 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
90952 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
90953 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
90954 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
90955 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
90956 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
90957 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
90958 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
90959 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
90960 +groups_alloc_7614 groups_alloc 1 7614 NULL
90961 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
90962 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
90963 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
90964 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
90965 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
90966 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
90967 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
90968 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
90969 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
90970 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
90971 +snapshot_write_28351 snapshot_write 3 28351 NULL
90972 +event_enable_read_7074 event_enable_read 3 7074 NULL
90973 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
90974 +do_syslog_56807 do_syslog 3 56807 NULL
90975 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
90976 +pskb_pull_65005 pskb_pull 2 65005 NULL
90977 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
90978 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
90979 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
90980 +unifi_write_65012 unifi_write 3 65012 NULL
90981 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
90982 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
90983 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
90984 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
90985 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
90986 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
90987 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
90988 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
90989 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
90990 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
90991 +if_write_51756 if_write 3 51756 NULL
90992 +insert_dent_65034 insert_dent 7 65034 NULL
90993 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
90994 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
90995 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
90996 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
90997 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
90998 +lc_create_48662 lc_create 3 48662 NULL
90999 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
91000 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
91001 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
91002 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
91003 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
91004 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
91005 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
91006 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
91007 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
91008 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
91009 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
91010 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
91011 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
91012 +altera_drscan_48698 altera_drscan 2 48698 NULL
91013 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
91014 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
91015 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
91016 +power_read_15939 power_read 3 15939 NULL
91017 +recv_msg_48709 recv_msg 4 48709 NULL
91018 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
91019 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
91020 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
91021 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
91022 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
91023 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
91024 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
91025 +revalidate_19043 revalidate 2 19043 NULL
91026 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
91027 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
91028 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
91029 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
91030 +check_header_56930 check_header 2 56930 NULL
91031 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
91032 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
91033 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
91034 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
91035 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
91036 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
91037 +frame_alloc_15981 frame_alloc 4 15981 NULL
91038 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
91039 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
91040 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
91041 +adu_read_24177 adu_read 3 24177 NULL
91042 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
91043 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
91044 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
91045 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
91046 +vfd_write_14717 vfd_write 3 14717 NULL
91047 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
91048 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
91049 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
91050 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
91051 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
91052 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
91053 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
91054 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
91055 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
91056 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
91057 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
91058 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
91059 +register_device_60015 register_device 2-3 60015 NULL
91060 +got_frame_16028 got_frame 2 16028 NULL
91061 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
91062 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
91063 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
91064 +scsi_register_49094 scsi_register 2 49094 NULL
91065 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
91066 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
91067 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
91068 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
91069 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
91070 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
91071 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
91072 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
91073 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
91074 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
91075 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
91076 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
91077 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
91078 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
91079 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
91080 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
91081 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
91082 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
91083 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
91084 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
91085 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
91086 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
91087 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
91088 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
91089 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
91090 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
91091 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
91092 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
91093 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
91094 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
91095 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
91096 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
91097 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
91098 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
91099 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
91100 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
91101 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
91102 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
91103 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
91104 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
91105 +fsm_init_16134 fsm_init 2 16134 NULL
91106 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
91107 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
91108 +disconnect_32521 disconnect 4 32521 NULL
91109 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
91110 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
91111 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
91112 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
91113 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
91114 +ilo_read_32531 ilo_read 3 32531 NULL
91115 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
91116 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
91117 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
91118 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
91119 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
91120 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
91121 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
91122 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
91123 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
91124 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
91125 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
91126 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
91127 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
91128 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
91129 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
91130 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
91131 +card_send_command_40757 card_send_command 3 40757 NULL
91132 +sys_mbind_7990 sys_mbind 5 7990 NULL
91133 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
91134 +pg_write_40766 pg_write 3 40766 NULL
91135 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
91136 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
91137 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
91138 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
91139 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
91140 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
91141 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
91142 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
91143 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
91144 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
91145 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
91146 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
91147 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
91148 +vcs_read_8017 vcs_read 3 8017 NULL
91149 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
91150 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
91151 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
91152 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
91153 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
91154 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
91155 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
91156 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
91157 +copy_and_check_19089 copy_and_check 3 19089 NULL
91158 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
91159 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
91160 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
91161 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
91162 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
91163 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
91164 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
91165 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
91166 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
91167 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
91168 +smk_user_access_24440 smk_user_access 3 24440 NULL
91169 +xd_rw_49020 xd_rw 3-4 49020 NULL
91170 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
91171 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
91172 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
91173 +kvmalloc_32646 kvmalloc 1 32646 NULL
91174 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
91175 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
91176 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
91177 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
91178 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
91179 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
91180 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
91181 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
91182 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
91183 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
91184 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
91185 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
91186 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
91187 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
91188 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
91189 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
91190 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
91191 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
91192 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
91193 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
91194 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
91195 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
91196 +venus_lookup_8121 venus_lookup 4 8121 NULL
91197 +compat_writev_60063 compat_writev 3 60063 NULL
91198 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
91199 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
91200 +read_file_queue_40895 read_file_queue 3 40895 NULL
91201 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
91202 +waiters_read_40902 waiters_read 3 40902 NULL
91203 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
91204 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
91205 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
91206 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
91207 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
91208 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
91209 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
91210 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
91211 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
91212 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
91213 +alloc_dr_65495 alloc_dr 2 65495 NULL
91214 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
91215 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
91216 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
91217 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
91218 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
91219 +rbd_add_16366 rbd_add 3 16366 NULL
91220 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
91221 +pt_read_49136 pt_read 3 49136 NULL
91222 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
91223 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
91224 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
91225 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
91226 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
91227 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
91228 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
91229 new file mode 100644
91230 index 0000000..d52f2ee
91231 --- /dev/null
91232 +++ b/tools/gcc/size_overflow_plugin.c
91233 @@ -0,0 +1,1941 @@
91234 +/*
91235 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
91236 + * Licensed under the GPL v2, or (at your option) v3
91237 + *
91238 + * Homepage:
91239 + * http://www.grsecurity.net/~ephox/overflow_plugin/
91240 + *
91241 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
91242 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
91243 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
91244 + *
91245 + * Usage:
91246 + * $ 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
91247 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
91248 + */
91249 +
91250 +#include "gcc-plugin.h"
91251 +#include "config.h"
91252 +#include "system.h"
91253 +#include "coretypes.h"
91254 +#include "tree.h"
91255 +#include "tree-pass.h"
91256 +#include "intl.h"
91257 +#include "plugin-version.h"
91258 +#include "tm.h"
91259 +#include "toplev.h"
91260 +#include "function.h"
91261 +#include "tree-flow.h"
91262 +#include "plugin.h"
91263 +#include "gimple.h"
91264 +#include "c-common.h"
91265 +#include "diagnostic.h"
91266 +#include "cfgloop.h"
91267 +
91268 +#if BUILDING_GCC_VERSION >= 4007
91269 +#include "c-tree.h"
91270 +#else
91271 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
91272 +#endif
91273 +
91274 +#if BUILDING_GCC_VERSION >= 4008
91275 +#define TODO_dump_func 0
91276 +#endif
91277 +
91278 +struct size_overflow_hash {
91279 + const struct size_overflow_hash * const next;
91280 + const char * const name;
91281 + const unsigned int param;
91282 +};
91283 +
91284 +#include "size_overflow_hash.h"
91285 +
91286 +enum marked {
91287 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
91288 +};
91289 +
91290 +static unsigned int call_count = 0;
91291 +
91292 +#define __unused __attribute__((__unused__))
91293 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
91294 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
91295 +#define BEFORE_STMT true
91296 +#define AFTER_STMT false
91297 +#define CREATE_NEW_VAR NULL_TREE
91298 +#define CODES_LIMIT 32
91299 +#define MAX_PARAM 32
91300 +#define MY_STMT GF_PLF_1
91301 +#define NO_CAST_CHECK GF_PLF_2
91302 +
91303 +#if BUILDING_GCC_VERSION == 4005
91304 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
91305 +#endif
91306 +
91307 +int plugin_is_GPL_compatible;
91308 +void debug_gimple_stmt(gimple gs);
91309 +
91310 +static tree expand(struct pointer_set_t *visited, tree lhs);
91311 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
91312 +static tree report_size_overflow_decl;
91313 +static const_tree const_char_ptr_type_node;
91314 +static unsigned int handle_function(void);
91315 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
91316 +static tree get_size_overflow_type(gimple stmt, const_tree node);
91317 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
91318 +
91319 +static struct plugin_info size_overflow_plugin_info = {
91320 + .version = "20130109beta",
91321 + .help = "no-size-overflow\tturn off size overflow checking\n",
91322 +};
91323 +
91324 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
91325 +{
91326 + unsigned int arg_count;
91327 + enum tree_code code = TREE_CODE(*node);
91328 +
91329 + switch (code) {
91330 + case FUNCTION_DECL:
91331 + arg_count = type_num_arguments(TREE_TYPE(*node));
91332 + break;
91333 + case FUNCTION_TYPE:
91334 + case METHOD_TYPE:
91335 + arg_count = type_num_arguments(*node);
91336 + break;
91337 + default:
91338 + *no_add_attrs = true;
91339 + error("%s: %qE attribute only applies to functions", __func__, name);
91340 + return NULL_TREE;
91341 + }
91342 +
91343 + for (; args; args = TREE_CHAIN(args)) {
91344 + tree position = TREE_VALUE(args);
91345 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
91346 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
91347 + *no_add_attrs = true;
91348 + }
91349 + }
91350 + return NULL_TREE;
91351 +}
91352 +
91353 +static const char* get_asm_name(tree node)
91354 +{
91355 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
91356 +}
91357 +
91358 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
91359 +{
91360 + unsigned int arg_count, arg_num;
91361 + enum tree_code code = TREE_CODE(*node);
91362 +
91363 + switch (code) {
91364 + case FUNCTION_DECL:
91365 + arg_count = type_num_arguments(TREE_TYPE(*node));
91366 + break;
91367 + case FUNCTION_TYPE:
91368 + case METHOD_TYPE:
91369 + arg_count = type_num_arguments(*node);
91370 + break;
91371 + case FIELD_DECL:
91372 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
91373 + if (arg_num != 0) {
91374 + *no_add_attrs = true;
91375 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
91376 + }
91377 + return NULL_TREE;
91378 + default:
91379 + *no_add_attrs = true;
91380 + error("%qE attribute only applies to functions", name);
91381 + return NULL_TREE;
91382 + }
91383 +
91384 + for (; args; args = TREE_CHAIN(args)) {
91385 + tree position = TREE_VALUE(args);
91386 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
91387 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
91388 + *no_add_attrs = true;
91389 + }
91390 + }
91391 + return NULL_TREE;
91392 +}
91393 +
91394 +static struct attribute_spec size_overflow_attr = {
91395 + .name = "size_overflow",
91396 + .min_length = 1,
91397 + .max_length = -1,
91398 + .decl_required = true,
91399 + .type_required = false,
91400 + .function_type_required = false,
91401 + .handler = handle_size_overflow_attribute,
91402 +#if BUILDING_GCC_VERSION >= 4007
91403 + .affects_type_identity = false
91404 +#endif
91405 +};
91406 +
91407 +static struct attribute_spec intentional_overflow_attr = {
91408 + .name = "intentional_overflow",
91409 + .min_length = 1,
91410 + .max_length = -1,
91411 + .decl_required = true,
91412 + .type_required = false,
91413 + .function_type_required = false,
91414 + .handler = handle_intentional_overflow_attribute,
91415 +#if BUILDING_GCC_VERSION >= 4007
91416 + .affects_type_identity = false
91417 +#endif
91418 +};
91419 +
91420 +static void register_attributes(void __unused *event_data, void __unused *data)
91421 +{
91422 + register_attribute(&size_overflow_attr);
91423 + register_attribute(&intentional_overflow_attr);
91424 +}
91425 +
91426 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
91427 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
91428 +{
91429 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
91430 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
91431 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
91432 +
91433 + unsigned int m = 0x57559429;
91434 + unsigned int n = 0x5052acdb;
91435 + const unsigned int *key4 = (const unsigned int *)key;
91436 + unsigned int h = len;
91437 + unsigned int k = len + seed + n;
91438 + unsigned long long p;
91439 +
91440 + while (len >= 8) {
91441 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
91442 + len -= 8;
91443 + }
91444 + if (len >= 4) {
91445 + cwmixb(key4[0]) key4 += 1;
91446 + len -= 4;
91447 + }
91448 + if (len)
91449 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
91450 + cwmixb(h ^ (k + n));
91451 + return k ^ h;
91452 +
91453 +#undef cwfold
91454 +#undef cwmixa
91455 +#undef cwmixb
91456 +}
91457 +
91458 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
91459 +{
91460 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
91461 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
91462 + return fn ^ codes;
91463 +}
91464 +
91465 +static inline tree get_original_function_decl(tree fndecl)
91466 +{
91467 + if (DECL_ABSTRACT_ORIGIN(fndecl))
91468 + return DECL_ABSTRACT_ORIGIN(fndecl);
91469 + return fndecl;
91470 +}
91471 +
91472 +static inline gimple get_def_stmt(const_tree node)
91473 +{
91474 + gcc_assert(node != NULL_TREE);
91475 + gcc_assert(TREE_CODE(node) == SSA_NAME);
91476 + return SSA_NAME_DEF_STMT(node);
91477 +}
91478 +
91479 +static unsigned char get_tree_code(const_tree type)
91480 +{
91481 + switch (TREE_CODE(type)) {
91482 + case ARRAY_TYPE:
91483 + return 0;
91484 + case BOOLEAN_TYPE:
91485 + return 1;
91486 + case ENUMERAL_TYPE:
91487 + return 2;
91488 + case FUNCTION_TYPE:
91489 + return 3;
91490 + case INTEGER_TYPE:
91491 + return 4;
91492 + case POINTER_TYPE:
91493 + return 5;
91494 + case RECORD_TYPE:
91495 + return 6;
91496 + case UNION_TYPE:
91497 + return 7;
91498 + case VOID_TYPE:
91499 + return 8;
91500 + case REAL_TYPE:
91501 + return 9;
91502 + case VECTOR_TYPE:
91503 + return 10;
91504 + case REFERENCE_TYPE:
91505 + return 11;
91506 + case OFFSET_TYPE:
91507 + return 12;
91508 + case COMPLEX_TYPE:
91509 + return 13;
91510 + default:
91511 + debug_tree((tree)type);
91512 + gcc_unreachable();
91513 + }
91514 +}
91515 +
91516 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
91517 +{
91518 + gcc_assert(type != NULL_TREE);
91519 +
91520 + while (type && len < CODES_LIMIT) {
91521 + tree_codes[len] = get_tree_code(type);
91522 + len++;
91523 + type = TREE_TYPE(type);
91524 + }
91525 + return len;
91526 +}
91527 +
91528 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
91529 +{
91530 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
91531 + enum tree_code code = TREE_CODE(type);
91532 + size_t len = 0;
91533 +
91534 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
91535 +
91536 + arg = TYPE_ARG_TYPES(type);
91537 + // skip builtins __builtin_constant_p
91538 + if (!arg && DECL_BUILT_IN(fndecl))
91539 + return 0;
91540 +
91541 + if (TREE_CODE_CLASS(code) == tcc_type)
91542 + result = type;
91543 + else
91544 + result = DECL_RESULT(fndecl);
91545 +
91546 + gcc_assert(result != NULL_TREE);
91547 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
91548 +
91549 + if (arg == NULL_TREE) {
91550 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
91551 + arg_field = DECL_ARGUMENT_FLD(fndecl);
91552 + if (arg_field == NULL_TREE)
91553 + return 0;
91554 + arg = TREE_TYPE(arg_field);
91555 + len = add_type_codes(arg, tree_codes, len);
91556 + gcc_assert(len != 0);
91557 + return len;
91558 + }
91559 +
91560 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
91561 + while (arg && len < CODES_LIMIT) {
91562 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
91563 + arg = TREE_CHAIN(arg);
91564 + }
91565 +
91566 + gcc_assert(len != 0);
91567 + return len;
91568 +}
91569 +
91570 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
91571 +{
91572 + unsigned int hash;
91573 + const struct size_overflow_hash *entry;
91574 + unsigned char tree_codes[CODES_LIMIT];
91575 + size_t len;
91576 + const char *func_name = get_asm_name(fndecl);
91577 +
91578 + len = get_function_decl(fndecl, tree_codes);
91579 + if (len == 0)
91580 + return NULL;
91581 +
91582 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
91583 +
91584 + entry = size_overflow_hash[hash];
91585 + while (entry) {
91586 + if (!strcmp(entry->name, func_name))
91587 + return entry;
91588 + entry = entry->next;
91589 + }
91590 +
91591 + return NULL;
91592 +}
91593 +
91594 +static void check_arg_type(const_tree arg)
91595 +{
91596 + const_tree type = TREE_TYPE(arg);
91597 + enum tree_code code = TREE_CODE(type);
91598 +
91599 + if (code == BOOLEAN_TYPE)
91600 + return;
91601 +
91602 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
91603 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
91604 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
91605 +}
91606 +
91607 +static unsigned int find_arg_number(const_tree arg, tree func)
91608 +{
91609 + tree var;
91610 + unsigned int argnum = 1;
91611 +
91612 + if (TREE_CODE(arg) == SSA_NAME)
91613 + arg = SSA_NAME_VAR(arg);
91614 +
91615 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
91616 + if (strcmp(NAME(arg), NAME(var))) {
91617 + argnum++;
91618 + continue;
91619 + }
91620 + check_arg_type(var);
91621 + return argnum;
91622 + }
91623 + gcc_unreachable();
91624 +}
91625 +
91626 +static tree create_new_var(tree type)
91627 +{
91628 + tree new_var = create_tmp_var(type, "cicus");
91629 +
91630 +#if BUILDING_GCC_VERSION <= 4007
91631 + add_referenced_var(new_var);
91632 + mark_sym_for_renaming(new_var);
91633 +#endif
91634 + return new_var;
91635 +}
91636 +
91637 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
91638 +{
91639 + gimple assign;
91640 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91641 + tree type = TREE_TYPE(rhs1);
91642 + tree lhs = create_new_var(type);
91643 +
91644 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
91645 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
91646 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
91647 +
91648 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
91649 + update_stmt(assign);
91650 + gimple_set_plf(assign, MY_STMT, true);
91651 + return assign;
91652 +}
91653 +
91654 +static bool is_bool(const_tree node)
91655 +{
91656 + const_tree type;
91657 +
91658 + if (node == NULL_TREE)
91659 + return false;
91660 +
91661 + type = TREE_TYPE(node);
91662 + if (!INTEGRAL_TYPE_P(type))
91663 + return false;
91664 + if (TREE_CODE(type) == BOOLEAN_TYPE)
91665 + return true;
91666 + if (TYPE_PRECISION(type) == 1)
91667 + return true;
91668 + return false;
91669 +}
91670 +
91671 +static tree cast_a_tree(tree type, tree var)
91672 +{
91673 + gcc_assert(type != NULL_TREE);
91674 + gcc_assert(var != NULL_TREE);
91675 + gcc_assert(fold_convertible_p(type, var));
91676 +
91677 + return fold_convert(type, var);
91678 +}
91679 +
91680 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
91681 +{
91682 + gimple assign;
91683 +
91684 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
91685 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
91686 + gcc_unreachable();
91687 +
91688 + if (lhs == CREATE_NEW_VAR)
91689 + lhs = create_new_var(dst_type);
91690 +
91691 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
91692 +
91693 + if (!gsi_end_p(*gsi)) {
91694 + location_t loc = gimple_location(gsi_stmt(*gsi));
91695 + gimple_set_location(assign, loc);
91696 + }
91697 +
91698 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
91699 +
91700 + if (before)
91701 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
91702 + else
91703 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
91704 + update_stmt(assign);
91705 + gimple_set_plf(assign, MY_STMT, true);
91706 +
91707 + return assign;
91708 +}
91709 +
91710 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
91711 +{
91712 + gimple assign;
91713 + gimple_stmt_iterator gsi;
91714 +
91715 + if (rhs == NULL_TREE)
91716 + return NULL_TREE;
91717 +
91718 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
91719 + return rhs;
91720 +
91721 + gsi = gsi_for_stmt(stmt);
91722 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
91723 + gimple_set_plf(assign, MY_STMT, true);
91724 + return gimple_get_lhs(assign);
91725 +}
91726 +
91727 +static tree cast_to_TI_type(gimple stmt, tree node)
91728 +{
91729 + gimple_stmt_iterator gsi;
91730 + gimple cast_stmt;
91731 + tree type = TREE_TYPE(node);
91732 +
91733 + if (types_compatible_p(type, intTI_type_node))
91734 + return node;
91735 +
91736 + gsi = gsi_for_stmt(stmt);
91737 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91738 + gimple_set_plf(cast_stmt, MY_STMT, true);
91739 + return gimple_get_lhs(cast_stmt);
91740 +}
91741 +
91742 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
91743 +{
91744 + tree lhs;
91745 + gimple_stmt_iterator gsi;
91746 +
91747 + if (rhs1 == NULL_TREE) {
91748 + debug_gimple_stmt(oldstmt);
91749 + error("%s: rhs1 is NULL_TREE", __func__);
91750 + gcc_unreachable();
91751 + }
91752 +
91753 + switch (gimple_code(oldstmt)) {
91754 + case GIMPLE_ASM:
91755 + lhs = rhs1;
91756 + break;
91757 + case GIMPLE_CALL:
91758 + lhs = gimple_call_lhs(oldstmt);
91759 + break;
91760 + case GIMPLE_ASSIGN:
91761 + lhs = gimple_get_lhs(oldstmt);
91762 + break;
91763 + default:
91764 + debug_gimple_stmt(oldstmt);
91765 + gcc_unreachable();
91766 + }
91767 +
91768 + gsi = gsi_for_stmt(oldstmt);
91769 + pointer_set_insert(visited, oldstmt);
91770 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
91771 + basic_block next_bb, cur_bb;
91772 + const_edge e;
91773 +
91774 + gcc_assert(before == false);
91775 + gcc_assert(stmt_can_throw_internal(oldstmt));
91776 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
91777 + gcc_assert(!gsi_end_p(gsi));
91778 +
91779 + cur_bb = gimple_bb(oldstmt);
91780 + next_bb = cur_bb->next_bb;
91781 + e = find_edge(cur_bb, next_bb);
91782 + gcc_assert(e != NULL);
91783 + gcc_assert(e->flags & EDGE_FALLTHRU);
91784 +
91785 + gsi = gsi_after_labels(next_bb);
91786 + gcc_assert(!gsi_end_p(gsi));
91787 +
91788 + before = true;
91789 + oldstmt = gsi_stmt(gsi);
91790 + }
91791 +
91792 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
91793 +}
91794 +
91795 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
91796 +{
91797 + gimple stmt;
91798 + gimple_stmt_iterator gsi;
91799 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
91800 +
91801 + if (gimple_plf(oldstmt, MY_STMT))
91802 + return lhs;
91803 +
91804 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
91805 + rhs1 = gimple_assign_rhs1(oldstmt);
91806 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
91807 + }
91808 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
91809 + rhs2 = gimple_assign_rhs2(oldstmt);
91810 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
91811 + }
91812 +
91813 + stmt = gimple_copy(oldstmt);
91814 + gimple_set_location(stmt, gimple_location(oldstmt));
91815 + gimple_set_plf(stmt, MY_STMT, true);
91816 +
91817 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
91818 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
91819 +
91820 + size_overflow_type = get_size_overflow_type(oldstmt, node);
91821 +
91822 + if (is_bool(lhs))
91823 + new_var = SSA_NAME_VAR(lhs);
91824 + else
91825 + new_var = create_new_var(size_overflow_type);
91826 + new_var = make_ssa_name(new_var, stmt);
91827 + gimple_set_lhs(stmt, new_var);
91828 +
91829 + if (rhs1 != NULL_TREE)
91830 + gimple_assign_set_rhs1(stmt, rhs1);
91831 +
91832 + if (rhs2 != NULL_TREE)
91833 + gimple_assign_set_rhs2(stmt, rhs2);
91834 +#if BUILDING_GCC_VERSION >= 4007
91835 + if (rhs3 != NULL_TREE)
91836 + gimple_assign_set_rhs3(stmt, rhs3);
91837 +#endif
91838 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
91839 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
91840 +
91841 + gsi = gsi_for_stmt(oldstmt);
91842 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
91843 + update_stmt(stmt);
91844 + pointer_set_insert(visited, oldstmt);
91845 + return gimple_get_lhs(stmt);
91846 +}
91847 +
91848 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
91849 +{
91850 + basic_block bb;
91851 + gimple phi;
91852 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
91853 + gimple_seq seq;
91854 +
91855 + bb = gsi_bb(gsi);
91856 +
91857 + phi = create_phi_node(result, bb);
91858 + seq = phi_nodes(bb);
91859 + gsi = gsi_last(seq);
91860 + gsi_remove(&gsi, false);
91861 +
91862 + gsi = gsi_for_stmt(oldstmt);
91863 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
91864 + gimple_set_bb(phi, bb);
91865 + gimple_set_plf(phi, MY_STMT, true);
91866 + return phi;
91867 +}
91868 +
91869 +static basic_block create_a_first_bb(void)
91870 +{
91871 + basic_block first_bb;
91872 +
91873 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
91874 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
91875 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
91876 + return first_bb;
91877 +}
91878 +
91879 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
91880 +{
91881 + basic_block bb;
91882 + const_gimple newstmt;
91883 + gimple_stmt_iterator gsi;
91884 + bool before = BEFORE_STMT;
91885 +
91886 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
91887 + gsi = gsi_for_stmt(get_def_stmt(arg));
91888 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
91889 + return gimple_get_lhs(newstmt);
91890 + }
91891 +
91892 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
91893 + gsi = gsi_after_labels(bb);
91894 + if (bb->index == 0) {
91895 + bb = create_a_first_bb();
91896 + gsi = gsi_start_bb(bb);
91897 + }
91898 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
91899 + return gimple_get_lhs(newstmt);
91900 +}
91901 +
91902 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
91903 +{
91904 + gimple newstmt;
91905 + gimple_stmt_iterator gsi;
91906 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
91907 + gimple def_newstmt = get_def_stmt(new_rhs);
91908 +
91909 + gsi_insert = gsi_insert_after;
91910 + gsi = gsi_for_stmt(def_newstmt);
91911 +
91912 + switch (gimple_code(get_def_stmt(arg))) {
91913 + case GIMPLE_PHI:
91914 + newstmt = gimple_build_assign(new_var, new_rhs);
91915 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
91916 + gsi_insert = gsi_insert_before;
91917 + break;
91918 + case GIMPLE_ASM:
91919 + case GIMPLE_CALL:
91920 + newstmt = gimple_build_assign(new_var, new_rhs);
91921 + break;
91922 + case GIMPLE_ASSIGN:
91923 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
91924 + break;
91925 + default:
91926 + /* unknown gimple_code (handle_build_new_phi_arg) */
91927 + gcc_unreachable();
91928 + }
91929 +
91930 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
91931 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
91932 + gimple_set_plf(newstmt, MY_STMT, true);
91933 + update_stmt(newstmt);
91934 + return newstmt;
91935 +}
91936 +
91937 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
91938 +{
91939 + const_gimple newstmt;
91940 + gimple def_stmt;
91941 + tree new_rhs;
91942 +
91943 + new_rhs = expand(visited, arg);
91944 + if (new_rhs == NULL_TREE)
91945 + return NULL_TREE;
91946 +
91947 + def_stmt = get_def_stmt(new_rhs);
91948 + if (gimple_code(def_stmt) == GIMPLE_NOP)
91949 + return NULL_TREE;
91950 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
91951 +
91952 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
91953 + return gimple_get_lhs(newstmt);
91954 +}
91955 +
91956 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
91957 +{
91958 + gimple phi, oldstmt = get_def_stmt(orig_result);
91959 + tree new_result, size_overflow_type;
91960 + unsigned int i;
91961 + unsigned int n = gimple_phi_num_args(oldstmt);
91962 +
91963 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
91964 +
91965 + new_result = create_new_var(size_overflow_type);
91966 +
91967 + pointer_set_insert(visited, oldstmt);
91968 + phi = overflow_create_phi_node(oldstmt, new_result);
91969 + for (i = 0; i < n; i++) {
91970 + tree arg, lhs;
91971 +
91972 + arg = gimple_phi_arg_def(oldstmt, i);
91973 + if (is_gimple_constant(arg))
91974 + arg = cast_a_tree(size_overflow_type, arg);
91975 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
91976 + if (lhs == NULL_TREE)
91977 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
91978 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
91979 + }
91980 +
91981 + update_stmt(phi);
91982 + return gimple_phi_result(phi);
91983 +}
91984 +
91985 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
91986 +{
91987 + const_gimple assign;
91988 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91989 + tree origtype = TREE_TYPE(orig_rhs);
91990 +
91991 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
91992 +
91993 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91994 + return gimple_get_lhs(assign);
91995 +}
91996 +
91997 +static void change_rhs1(gimple stmt, tree new_rhs1)
91998 +{
91999 + tree assign_rhs;
92000 + const_tree rhs = gimple_assign_rhs1(stmt);
92001 +
92002 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
92003 + gimple_assign_set_rhs1(stmt, assign_rhs);
92004 + update_stmt(stmt);
92005 +}
92006 +
92007 +static bool check_mode_type(const_gimple stmt)
92008 +{
92009 + const_tree lhs = gimple_get_lhs(stmt);
92010 + const_tree lhs_type = TREE_TYPE(lhs);
92011 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
92012 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
92013 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
92014 +
92015 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
92016 + return false;
92017 +
92018 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
92019 + return false;
92020 +
92021 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
92022 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
92023 + return false;
92024 +
92025 + return true;
92026 +}
92027 +
92028 +static bool check_undefined_integer_operation(const_gimple stmt)
92029 +{
92030 + const_gimple def_stmt;
92031 + const_tree lhs = gimple_get_lhs(stmt);
92032 + const_tree rhs1 = gimple_assign_rhs1(stmt);
92033 + const_tree rhs1_type = TREE_TYPE(rhs1);
92034 + const_tree lhs_type = TREE_TYPE(lhs);
92035 +
92036 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
92037 + return false;
92038 +
92039 + def_stmt = get_def_stmt(rhs1);
92040 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
92041 + return false;
92042 +
92043 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
92044 + return false;
92045 + return true;
92046 +}
92047 +
92048 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
92049 +{
92050 + const_tree rhs1, lhs, rhs1_type, lhs_type;
92051 + enum machine_mode lhs_mode, rhs_mode;
92052 + gimple def_stmt = get_def_stmt(no_const_rhs);
92053 +
92054 + if (!gimple_assign_cast_p(def_stmt))
92055 + return false;
92056 +
92057 + rhs1 = gimple_assign_rhs1(def_stmt);
92058 + lhs = gimple_get_lhs(def_stmt);
92059 + rhs1_type = TREE_TYPE(rhs1);
92060 + lhs_type = TREE_TYPE(lhs);
92061 + rhs_mode = TYPE_MODE(rhs1_type);
92062 + lhs_mode = TYPE_MODE(lhs_type);
92063 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
92064 + return false;
92065 +
92066 + return true;
92067 +}
92068 +
92069 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
92070 +{
92071 + tree rhs1 = gimple_assign_rhs1(stmt);
92072 + tree lhs = gimple_get_lhs(stmt);
92073 + const_tree rhs1_type = TREE_TYPE(rhs1);
92074 + const_tree lhs_type = TREE_TYPE(lhs);
92075 +
92076 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
92077 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92078 +
92079 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
92080 +}
92081 +
92082 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
92083 +{
92084 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
92085 + tree new_rhs1 = NULL_TREE;
92086 + tree rhs1 = gimple_assign_rhs1(stmt);
92087 + const_tree rhs1_type = TREE_TYPE(rhs1);
92088 + const_tree lhs_type = TREE_TYPE(lhs);
92089 +
92090 + if (gimple_plf(stmt, MY_STMT))
92091 + return lhs;
92092 +
92093 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
92094 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92095 +
92096 + new_rhs1 = expand(visited, rhs1);
92097 +
92098 + if (new_rhs1 == NULL_TREE)
92099 + return create_cast_assign(visited, stmt);
92100 +
92101 + if (gimple_plf(stmt, NO_CAST_CHECK))
92102 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
92103 +
92104 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
92105 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
92106 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
92107 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
92108 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92109 + }
92110 +
92111 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
92112 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
92113 +
92114 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
92115 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
92116 +
92117 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
92118 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
92119 +
92120 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
92121 +
92122 + change_rhs1(stmt, new_rhs1);
92123 +
92124 + if (!check_mode_type(stmt))
92125 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92126 +
92127 + size_overflow_type = get_size_overflow_type(stmt, lhs);
92128 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
92129 +
92130 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
92131 +
92132 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92133 +}
92134 +
92135 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
92136 +{
92137 + tree rhs1, lhs = gimple_get_lhs(stmt);
92138 + gimple def_stmt = get_def_stmt(lhs);
92139 +
92140 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
92141 + rhs1 = gimple_assign_rhs1(def_stmt);
92142 +
92143 + if (is_gimple_constant(rhs1))
92144 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92145 +
92146 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
92147 + switch (TREE_CODE(rhs1)) {
92148 + case SSA_NAME:
92149 + return handle_unary_rhs(visited, def_stmt);
92150 + case ARRAY_REF:
92151 + case BIT_FIELD_REF:
92152 + case ADDR_EXPR:
92153 + case COMPONENT_REF:
92154 + case INDIRECT_REF:
92155 +#if BUILDING_GCC_VERSION >= 4006
92156 + case MEM_REF:
92157 +#endif
92158 + case TARGET_MEM_REF:
92159 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92160 + case PARM_DECL:
92161 + case VAR_DECL:
92162 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92163 +
92164 + default:
92165 + debug_gimple_stmt(def_stmt);
92166 + debug_tree(rhs1);
92167 + gcc_unreachable();
92168 + }
92169 +}
92170 +
92171 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
92172 +{
92173 + gimple cond_stmt;
92174 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
92175 +
92176 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
92177 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
92178 + update_stmt(cond_stmt);
92179 +}
92180 +
92181 +static tree create_string_param(tree string)
92182 +{
92183 + tree i_type, a_type;
92184 + const int length = TREE_STRING_LENGTH(string);
92185 +
92186 + gcc_assert(length > 0);
92187 +
92188 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
92189 + a_type = build_array_type(char_type_node, i_type);
92190 +
92191 + TREE_TYPE(string) = a_type;
92192 + TREE_CONSTANT(string) = 1;
92193 + TREE_READONLY(string) = 1;
92194 +
92195 + return build1(ADDR_EXPR, ptr_type_node, string);
92196 +}
92197 +
92198 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
92199 +{
92200 + gimple func_stmt;
92201 + const_gimple def_stmt;
92202 + const_tree loc_line;
92203 + tree loc_file, ssa_name, current_func;
92204 + expanded_location xloc;
92205 + char *ssa_name_buf;
92206 + int len;
92207 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
92208 +
92209 + def_stmt = get_def_stmt(arg);
92210 + xloc = expand_location(gimple_location(def_stmt));
92211 +
92212 + if (!gimple_has_location(def_stmt)) {
92213 + xloc = expand_location(gimple_location(stmt));
92214 + if (!gimple_has_location(stmt))
92215 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
92216 + }
92217 +
92218 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
92219 +
92220 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
92221 + loc_file = create_string_param(loc_file);
92222 +
92223 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
92224 + current_func = create_string_param(current_func);
92225 +
92226 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
92227 + call_count++;
92228 + 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);
92229 + gcc_assert(len > 0);
92230 + ssa_name = build_string(len + 1, ssa_name_buf);
92231 + free(ssa_name_buf);
92232 + ssa_name = create_string_param(ssa_name);
92233 +
92234 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
92235 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
92236 +
92237 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
92238 +}
92239 +
92240 +static void __unused print_the_code_insertions(const_gimple stmt)
92241 +{
92242 + location_t loc = gimple_location(stmt);
92243 +
92244 + inform(loc, "Integer size_overflow check applied here.");
92245 +}
92246 +
92247 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
92248 +{
92249 + basic_block cond_bb, join_bb, bb_true;
92250 + edge e;
92251 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
92252 +
92253 + cond_bb = gimple_bb(stmt);
92254 + if (before)
92255 + gsi_prev(&gsi);
92256 + if (gsi_end_p(gsi))
92257 + e = split_block_after_labels(cond_bb);
92258 + else
92259 + e = split_block(cond_bb, gsi_stmt(gsi));
92260 + cond_bb = e->src;
92261 + join_bb = e->dest;
92262 + e->flags = EDGE_FALSE_VALUE;
92263 + e->probability = REG_BR_PROB_BASE;
92264 +
92265 + bb_true = create_empty_bb(cond_bb);
92266 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
92267 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
92268 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
92269 +
92270 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
92271 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
92272 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
92273 +
92274 + if (current_loops != NULL) {
92275 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
92276 + add_bb_to_loop(bb_true, cond_bb->loop_father);
92277 + }
92278 +
92279 + insert_cond(cond_bb, arg, cond_code, type_value);
92280 + insert_cond_result(bb_true, stmt, arg, min);
92281 +
92282 +// print_the_code_insertions(stmt);
92283 +}
92284 +
92285 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
92286 +{
92287 + const_tree rhs_type = TREE_TYPE(rhs);
92288 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
92289 +
92290 + gcc_assert(rhs_type != NULL_TREE);
92291 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
92292 + return;
92293 +
92294 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
92295 +
92296 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
92297 + // typemax (-1) < typemin (0)
92298 + if (TREE_OVERFLOW(type_max))
92299 + return;
92300 +
92301 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
92302 +
92303 + cast_rhs_type = TREE_TYPE(cast_rhs);
92304 + type_max_type = TREE_TYPE(type_max);
92305 + type_min_type = TREE_TYPE(type_min);
92306 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
92307 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
92308 +
92309 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
92310 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
92311 +}
92312 +
92313 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
92314 +{
92315 + gimple change_rhs_def_stmt;
92316 + tree lhs = gimple_get_lhs(def_stmt);
92317 + tree lhs_type = TREE_TYPE(lhs);
92318 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
92319 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
92320 +
92321 + if (change_rhs == NULL_TREE)
92322 + return get_size_overflow_type(def_stmt, lhs);
92323 +
92324 + change_rhs_def_stmt = get_def_stmt(change_rhs);
92325 +
92326 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
92327 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92328 +
92329 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
92330 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92331 +
92332 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
92333 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92334 +
92335 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
92336 + debug_gimple_stmt(def_stmt);
92337 + gcc_unreachable();
92338 + }
92339 +
92340 + return get_size_overflow_type(def_stmt, lhs);
92341 +}
92342 +
92343 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
92344 +{
92345 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
92346 + return false;
92347 + if (!is_gimple_constant(rhs))
92348 + return false;
92349 + return true;
92350 +}
92351 +
92352 +static bool is_subtraction_special(const_gimple stmt)
92353 +{
92354 + gimple rhs1_def_stmt, rhs2_def_stmt;
92355 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
92356 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
92357 + const_tree rhs1 = gimple_assign_rhs1(stmt);
92358 + const_tree rhs2 = gimple_assign_rhs2(stmt);
92359 +
92360 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
92361 + return false;
92362 +
92363 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
92364 +
92365 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
92366 + return false;
92367 +
92368 + rhs1_def_stmt = get_def_stmt(rhs1);
92369 + rhs2_def_stmt = get_def_stmt(rhs2);
92370 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
92371 + return false;
92372 +
92373 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
92374 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
92375 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
92376 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
92377 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
92378 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
92379 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
92380 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
92381 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
92382 + return false;
92383 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
92384 + return false;
92385 +
92386 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
92387 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
92388 + return true;
92389 +}
92390 +
92391 +static tree get_def_stmt_rhs(const_tree var)
92392 +{
92393 + tree rhs1, def_stmt_rhs1;
92394 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
92395 +
92396 + def_stmt = get_def_stmt(var);
92397 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
92398 +
92399 + rhs1 = gimple_assign_rhs1(def_stmt);
92400 + rhs1_def_stmt = get_def_stmt(rhs1);
92401 + if (!gimple_assign_cast_p(rhs1_def_stmt))
92402 + return rhs1;
92403 +
92404 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
92405 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
92406 +
92407 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
92408 + case GIMPLE_CALL:
92409 + case GIMPLE_NOP:
92410 + case GIMPLE_ASM:
92411 + return def_stmt_rhs1;
92412 + case GIMPLE_ASSIGN:
92413 + return rhs1;
92414 + default:
92415 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
92416 + gcc_unreachable();
92417 + }
92418 +}
92419 +
92420 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
92421 +{
92422 + tree new_rhs1, new_rhs2;
92423 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
92424 + gimple assign, stmt = get_def_stmt(lhs);
92425 + tree rhs1 = gimple_assign_rhs1(stmt);
92426 + tree rhs2 = gimple_assign_rhs2(stmt);
92427 +
92428 + if (!is_subtraction_special(stmt))
92429 + return NULL_TREE;
92430 +
92431 + new_rhs1 = expand(visited, rhs1);
92432 + new_rhs2 = expand(visited, rhs2);
92433 +
92434 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
92435 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
92436 +
92437 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
92438 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
92439 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
92440 + }
92441 +
92442 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
92443 + new_lhs = gimple_get_lhs(assign);
92444 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
92445 +
92446 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
92447 +}
92448 +
92449 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
92450 +{
92451 + const_gimple def_stmt;
92452 +
92453 + if (TREE_CODE(rhs) != SSA_NAME)
92454 + return false;
92455 +
92456 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
92457 + return false;
92458 +
92459 + def_stmt = get_def_stmt(rhs);
92460 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
92461 + return false;
92462 +
92463 + return true;
92464 +}
92465 +
92466 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
92467 +{
92468 + tree new_rhs, size_overflow_type, orig_rhs;
92469 + void (*gimple_assign_set_rhs)(gimple, tree);
92470 + tree rhs1 = gimple_assign_rhs1(stmt);
92471 + tree rhs2 = gimple_assign_rhs2(stmt);
92472 + tree lhs = gimple_get_lhs(stmt);
92473 +
92474 + if (change_rhs == NULL_TREE)
92475 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92476 +
92477 + if (new_rhs2 == NULL_TREE) {
92478 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
92479 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
92480 + orig_rhs = rhs1;
92481 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
92482 + } else {
92483 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
92484 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
92485 + orig_rhs = rhs2;
92486 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
92487 + }
92488 +
92489 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
92490 +
92491 + if (check_overflow)
92492 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
92493 +
92494 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
92495 + gimple_assign_set_rhs(stmt, new_rhs);
92496 + update_stmt(stmt);
92497 +
92498 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92499 +}
92500 +
92501 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
92502 +{
92503 + tree rhs1, rhs2, new_lhs;
92504 + gimple def_stmt = get_def_stmt(lhs);
92505 + tree new_rhs1 = NULL_TREE;
92506 + tree new_rhs2 = NULL_TREE;
92507 +
92508 + rhs1 = gimple_assign_rhs1(def_stmt);
92509 + rhs2 = gimple_assign_rhs2(def_stmt);
92510 +
92511 + /* no DImode/TImode division in the 32/64 bit kernel */
92512 + switch (gimple_assign_rhs_code(def_stmt)) {
92513 + case RDIV_EXPR:
92514 + case TRUNC_DIV_EXPR:
92515 + case CEIL_DIV_EXPR:
92516 + case FLOOR_DIV_EXPR:
92517 + case ROUND_DIV_EXPR:
92518 + case TRUNC_MOD_EXPR:
92519 + case CEIL_MOD_EXPR:
92520 + case FLOOR_MOD_EXPR:
92521 + case ROUND_MOD_EXPR:
92522 + case EXACT_DIV_EXPR:
92523 + case POINTER_PLUS_EXPR:
92524 + case BIT_AND_EXPR:
92525 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92526 + default:
92527 + break;
92528 + }
92529 +
92530 + new_lhs = handle_integer_truncation(visited, lhs);
92531 + if (new_lhs != NULL_TREE)
92532 + return new_lhs;
92533 +
92534 + if (TREE_CODE(rhs1) == SSA_NAME)
92535 + new_rhs1 = expand(visited, rhs1);
92536 + if (TREE_CODE(rhs2) == SSA_NAME)
92537 + new_rhs2 = expand(visited, rhs2);
92538 +
92539 + if (is_a_neg_overflow(def_stmt, rhs2))
92540 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
92541 + if (is_a_neg_overflow(def_stmt, rhs1))
92542 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
92543 +
92544 + if (is_a_constant_overflow(def_stmt, rhs2))
92545 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
92546 + if (is_a_constant_overflow(def_stmt, rhs1))
92547 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
92548 +
92549 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
92550 +}
92551 +
92552 +#if BUILDING_GCC_VERSION >= 4007
92553 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
92554 +{
92555 + if (is_gimple_constant(rhs))
92556 + return cast_a_tree(size_overflow_type, rhs);
92557 + if (TREE_CODE(rhs) != SSA_NAME)
92558 + return NULL_TREE;
92559 + return expand(visited, rhs);
92560 +}
92561 +
92562 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
92563 +{
92564 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
92565 + gimple def_stmt = get_def_stmt(lhs);
92566 +
92567 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
92568 +
92569 + rhs1 = gimple_assign_rhs1(def_stmt);
92570 + rhs2 = gimple_assign_rhs2(def_stmt);
92571 + rhs3 = gimple_assign_rhs3(def_stmt);
92572 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
92573 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
92574 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
92575 +
92576 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
92577 +}
92578 +#endif
92579 +
92580 +static tree get_size_overflow_type(gimple stmt, const_tree node)
92581 +{
92582 + const_tree type;
92583 + tree new_type;
92584 +
92585 + gcc_assert(node != NULL_TREE);
92586 +
92587 + type = TREE_TYPE(node);
92588 +
92589 + if (gimple_plf(stmt, MY_STMT))
92590 + return TREE_TYPE(node);
92591 +
92592 + switch (TYPE_MODE(type)) {
92593 + case QImode:
92594 + new_type = intHI_type_node;
92595 + break;
92596 + case HImode:
92597 + new_type = intSI_type_node;
92598 + break;
92599 + case SImode:
92600 + new_type = intDI_type_node;
92601 + break;
92602 + case DImode:
92603 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
92604 + new_type = intDI_type_node;
92605 + else
92606 + new_type = intTI_type_node;
92607 + break;
92608 + default:
92609 + debug_tree((tree)node);
92610 + error("%s: unsupported gcc configuration.", __func__);
92611 + gcc_unreachable();
92612 + }
92613 +
92614 + if (TYPE_QUALS(type) != 0)
92615 + return build_qualified_type(new_type, TYPE_QUALS(type));
92616 + return new_type;
92617 +}
92618 +
92619 +static tree expand_visited(gimple def_stmt)
92620 +{
92621 + const_gimple next_stmt;
92622 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
92623 +
92624 + gsi_next(&gsi);
92625 + next_stmt = gsi_stmt(gsi);
92626 +
92627 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
92628 +
92629 + switch (gimple_code(next_stmt)) {
92630 + case GIMPLE_ASSIGN:
92631 + return gimple_get_lhs(next_stmt);
92632 + case GIMPLE_PHI:
92633 + return gimple_phi_result(next_stmt);
92634 + case GIMPLE_CALL:
92635 + return gimple_call_lhs(next_stmt);
92636 + default:
92637 + return NULL_TREE;
92638 + }
92639 +}
92640 +
92641 +static tree expand(struct pointer_set_t *visited, tree lhs)
92642 +{
92643 + gimple def_stmt;
92644 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
92645 +
92646 + if (is_gimple_constant(lhs))
92647 + return NULL_TREE;
92648 +
92649 + if (TREE_CODE(lhs) == ADDR_EXPR)
92650 + return NULL_TREE;
92651 +
92652 + if (code == REAL_TYPE)
92653 + return NULL_TREE;
92654 +
92655 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
92656 +
92657 + def_stmt = get_def_stmt(lhs);
92658 +
92659 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
92660 + return NULL_TREE;
92661 +
92662 + if (gimple_plf(def_stmt, MY_STMT))
92663 + return lhs;
92664 +
92665 + if (pointer_set_contains(visited, def_stmt))
92666 + return expand_visited(def_stmt);
92667 +
92668 + switch (gimple_code(def_stmt)) {
92669 + case GIMPLE_PHI:
92670 + return build_new_phi(visited, lhs);
92671 + case GIMPLE_CALL:
92672 + case GIMPLE_ASM:
92673 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92674 + case GIMPLE_ASSIGN:
92675 + switch (gimple_num_ops(def_stmt)) {
92676 + case 2:
92677 + return handle_unary_ops(visited, def_stmt);
92678 + case 3:
92679 + return handle_binary_ops(visited, lhs);
92680 +#if BUILDING_GCC_VERSION >= 4007
92681 + case 4:
92682 + return handle_ternary_ops(visited, lhs);
92683 +#endif
92684 + }
92685 + default:
92686 + debug_gimple_stmt(def_stmt);
92687 + error("%s: unknown gimple code", __func__);
92688 + gcc_unreachable();
92689 + }
92690 +}
92691 +
92692 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
92693 +{
92694 + const_gimple assign;
92695 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
92696 + tree origtype = TREE_TYPE(origarg);
92697 +
92698 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
92699 +
92700 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
92701 +
92702 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
92703 + update_stmt(stmt);
92704 +}
92705 +
92706 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
92707 +{
92708 + const char *origid;
92709 + tree arg;
92710 + const_tree origarg;
92711 +
92712 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
92713 + return true;
92714 +
92715 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
92716 + while (origarg && *argnum) {
92717 + (*argnum)--;
92718 + origarg = TREE_CHAIN(origarg);
92719 + }
92720 +
92721 + gcc_assert(*argnum == 0);
92722 +
92723 + gcc_assert(origarg != NULL_TREE);
92724 + origid = NAME(origarg);
92725 + *argnum = 0;
92726 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
92727 + if (!strcmp(origid, NAME(arg)))
92728 + return true;
92729 + (*argnum)++;
92730 + }
92731 + return false;
92732 +}
92733 +
92734 +static bool skip_types(const_tree var)
92735 +{
92736 + const_tree type;
92737 +
92738 + switch (TREE_CODE(var)) {
92739 + case ADDR_EXPR:
92740 +#if BUILDING_GCC_VERSION >= 4006
92741 + case MEM_REF:
92742 +#endif
92743 + case ARRAY_REF:
92744 + case BIT_FIELD_REF:
92745 + case INDIRECT_REF:
92746 + case TARGET_MEM_REF:
92747 + case VAR_DECL:
92748 + return true;
92749 + default:
92750 + break;
92751 + }
92752 +
92753 + type = TREE_TYPE(TREE_TYPE(var));
92754 + if (!type)
92755 + return false;
92756 + switch (TREE_CODE(type)) {
92757 + case RECORD_TYPE:
92758 + return true;
92759 + default:
92760 + break;
92761 + }
92762 +
92763 + return false;
92764 +}
92765 +
92766 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
92767 +{
92768 + gimple phi = get_def_stmt(result);
92769 + unsigned int i, n = gimple_phi_num_args(phi);
92770 +
92771 + if (!phi)
92772 + return false;
92773 +
92774 + pointer_set_insert(visited, phi);
92775 + for (i = 0; i < n; i++) {
92776 + const_tree arg = gimple_phi_arg_def(phi, i);
92777 + if (pre_expand(visited, arg))
92778 + return true;
92779 + }
92780 + return false;
92781 +}
92782 +
92783 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
92784 +{
92785 + gimple def_stmt = get_def_stmt(lhs);
92786 + const_tree rhs;
92787 +
92788 + if (!def_stmt)
92789 + return false;
92790 +
92791 + rhs = gimple_assign_rhs1(def_stmt);
92792 + if (pre_expand(visited, rhs))
92793 + return true;
92794 + return false;
92795 +}
92796 +
92797 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
92798 +{
92799 + bool rhs1_found, rhs2_found;
92800 + gimple def_stmt = get_def_stmt(lhs);
92801 + const_tree rhs1, rhs2;
92802 +
92803 + if (!def_stmt)
92804 + return false;
92805 +
92806 + rhs1 = gimple_assign_rhs1(def_stmt);
92807 + rhs2 = gimple_assign_rhs2(def_stmt);
92808 + rhs1_found = pre_expand(visited, rhs1);
92809 + rhs2_found = pre_expand(visited, rhs2);
92810 +
92811 + return rhs1_found || rhs2_found;
92812 +}
92813 +
92814 +static const_tree search_field_decl(const_tree comp_ref)
92815 +{
92816 + const_tree field = NULL_TREE;
92817 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
92818 +
92819 + for (i = 0; i < len; i++) {
92820 + field = TREE_OPERAND(comp_ref, i);
92821 + if (TREE_CODE(field) == FIELD_DECL)
92822 + break;
92823 + }
92824 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
92825 + return field;
92826 +}
92827 +
92828 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
92829 +{
92830 + const_tree attr, p;
92831 +
92832 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
92833 + if (!attr || !TREE_VALUE(attr))
92834 + return MARKED_NO;
92835 +
92836 + p = TREE_VALUE(attr);
92837 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
92838 + return MARKED_NOT_INTENTIONAL;
92839 +
92840 + do {
92841 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
92842 + return MARKED_YES;
92843 + p = TREE_CHAIN(p);
92844 + } while (p);
92845 +
92846 + return MARKED_NO;
92847 +}
92848 +
92849 +static void print_missing_msg(tree func, unsigned int argnum)
92850 +{
92851 + unsigned int new_hash;
92852 + size_t len;
92853 + unsigned char tree_codes[CODES_LIMIT];
92854 + location_t loc = DECL_SOURCE_LOCATION(func);
92855 + const char *curfunc = get_asm_name(func);
92856 +
92857 + len = get_function_decl(func, tree_codes);
92858 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
92859 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
92860 +}
92861 +
92862 +static unsigned int search_missing_attribute(const_tree arg)
92863 +{
92864 + const_tree type = TREE_TYPE(arg);
92865 + tree func = get_original_function_decl(current_function_decl);
92866 + unsigned int argnum;
92867 + const struct size_overflow_hash *hash;
92868 +
92869 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
92870 +
92871 + if (TREE_CODE(type) == POINTER_TYPE)
92872 + return 0;
92873 +
92874 + argnum = find_arg_number(arg, func);
92875 + if (argnum == 0)
92876 + return 0;
92877 +
92878 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
92879 + return argnum;
92880 +
92881 + hash = get_function_hash(func);
92882 + if (!hash || !(hash->param & (1U << argnum))) {
92883 + print_missing_msg(func, argnum);
92884 + return 0;
92885 + }
92886 + return argnum;
92887 +}
92888 +
92889 +static bool is_already_marked(const_tree lhs)
92890 +{
92891 + unsigned int argnum;
92892 + const_tree fndecl;
92893 +
92894 + argnum = search_missing_attribute(lhs);
92895 + fndecl = get_original_function_decl(current_function_decl);
92896 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
92897 + return true;
92898 + return false;
92899 +}
92900 +
92901 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
92902 +{
92903 + const_gimple def_stmt;
92904 +
92905 + if (is_gimple_constant(lhs))
92906 + return false;
92907 +
92908 + if (skip_types(lhs))
92909 + return false;
92910 +
92911 + // skip char type (FIXME: only kernel)
92912 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
92913 + return false;
92914 +
92915 + if (TREE_CODE(lhs) == PARM_DECL)
92916 + return is_already_marked(lhs);
92917 +
92918 + if (TREE_CODE(lhs) == COMPONENT_REF) {
92919 + const_tree field, attr;
92920 +
92921 + field = search_field_decl(lhs);
92922 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
92923 + if (!attr || !TREE_VALUE(attr))
92924 + return false;
92925 + return true;
92926 + }
92927 +
92928 + def_stmt = get_def_stmt(lhs);
92929 +
92930 + if (!def_stmt)
92931 + return false;
92932 +
92933 + if (pointer_set_contains(visited, def_stmt))
92934 + return false;
92935 +
92936 + switch (gimple_code(def_stmt)) {
92937 + case GIMPLE_NOP:
92938 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
92939 + return is_already_marked(lhs);
92940 + return false;
92941 + case GIMPLE_PHI:
92942 + return walk_phi(visited, lhs);
92943 + case GIMPLE_CALL:
92944 + case GIMPLE_ASM:
92945 + return false;
92946 + case GIMPLE_ASSIGN:
92947 + switch (gimple_num_ops(def_stmt)) {
92948 + case 2:
92949 + return walk_unary_ops(visited, lhs);
92950 + case 3:
92951 + return walk_binary_ops(visited, lhs);
92952 + }
92953 + default:
92954 + debug_gimple_stmt((gimple)def_stmt);
92955 + error("%s: unknown gimple code", __func__);
92956 + gcc_unreachable();
92957 + }
92958 +}
92959 +
92960 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
92961 +{
92962 + struct pointer_set_t *visited;
92963 + bool is_found;
92964 + enum marked is_marked;
92965 + location_t loc;
92966 +
92967 + visited = pointer_set_create();
92968 + is_found = pre_expand(visited, arg);
92969 + pointer_set_destroy(visited);
92970 +
92971 + is_marked = mark_status(fndecl, argnum + 1);
92972 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
92973 + return true;
92974 +
92975 + if (is_found) {
92976 + loc = DECL_SOURCE_LOCATION(fndecl);
92977 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
92978 + return true;
92979 + }
92980 + return false;
92981 +}
92982 +
92983 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
92984 +{
92985 + struct pointer_set_t *visited;
92986 + tree arg, newarg;
92987 + bool match;
92988 +
92989 + match = get_function_arg(&argnum, fndecl);
92990 + if (!match)
92991 + return;
92992 + gcc_assert(gimple_call_num_args(stmt) > argnum);
92993 + arg = gimple_call_arg(stmt, argnum);
92994 + if (arg == NULL_TREE)
92995 + return;
92996 +
92997 + if (is_gimple_constant(arg))
92998 + return;
92999 +
93000 + if (search_attributes(fndecl, arg, argnum))
93001 + return;
93002 +
93003 + if (TREE_CODE(arg) != SSA_NAME)
93004 + return;
93005 +
93006 + check_arg_type(arg);
93007 +
93008 + visited = pointer_set_create();
93009 + newarg = expand(visited, arg);
93010 + pointer_set_destroy(visited);
93011 +
93012 + if (newarg == NULL_TREE)
93013 + return;
93014 +
93015 + change_function_arg(stmt, arg, argnum, newarg);
93016 +
93017 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
93018 +}
93019 +
93020 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
93021 +{
93022 + tree p = TREE_VALUE(attr);
93023 + do {
93024 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
93025 + p = TREE_CHAIN(p);
93026 + } while (p);
93027 +}
93028 +
93029 +static void handle_function_by_hash(gimple stmt, tree fndecl)
93030 +{
93031 + tree orig_fndecl;
93032 + unsigned int num;
93033 + const struct size_overflow_hash *hash;
93034 +
93035 + orig_fndecl = get_original_function_decl(fndecl);
93036 + if (C_DECL_IMPLICIT(orig_fndecl))
93037 + return;
93038 + hash = get_function_hash(orig_fndecl);
93039 + if (!hash)
93040 + return;
93041 +
93042 + for (num = 1; num <= MAX_PARAM; num++)
93043 + if (hash->param & (1U << num))
93044 + handle_function_arg(stmt, fndecl, num - 1);
93045 +}
93046 +
93047 +static void set_plf_false(void)
93048 +{
93049 + basic_block bb;
93050 +
93051 + FOR_ALL_BB(bb) {
93052 + gimple_stmt_iterator si;
93053 +
93054 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
93055 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
93056 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
93057 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
93058 + }
93059 +}
93060 +
93061 +static unsigned int handle_function(void)
93062 +{
93063 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
93064 +
93065 + set_plf_false();
93066 +
93067 + do {
93068 + gimple_stmt_iterator gsi;
93069 + next = bb->next_bb;
93070 +
93071 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
93072 + tree fndecl, attr;
93073 + gimple stmt = gsi_stmt(gsi);
93074 +
93075 + if (!(is_gimple_call(stmt)))
93076 + continue;
93077 + fndecl = gimple_call_fndecl(stmt);
93078 + if (fndecl == NULL_TREE)
93079 + continue;
93080 + if (gimple_call_num_args(stmt) == 0)
93081 + continue;
93082 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
93083 + if (!attr || !TREE_VALUE(attr))
93084 + handle_function_by_hash(stmt, fndecl);
93085 + else
93086 + handle_function_by_attribute(stmt, attr, fndecl);
93087 + gsi = gsi_for_stmt(stmt);
93088 + next = gimple_bb(stmt)->next_bb;
93089 + }
93090 + bb = next;
93091 + } while (bb);
93092 + return 0;
93093 +}
93094 +
93095 +static struct gimple_opt_pass size_overflow_pass = {
93096 + .pass = {
93097 + .type = GIMPLE_PASS,
93098 + .name = "size_overflow",
93099 +#if BUILDING_GCC_VERSION >= 4008
93100 + .optinfo_flags = OPTGROUP_NONE,
93101 +#endif
93102 + .gate = NULL,
93103 + .execute = handle_function,
93104 + .sub = NULL,
93105 + .next = NULL,
93106 + .static_pass_number = 0,
93107 + .tv_id = TV_NONE,
93108 + .properties_required = PROP_cfg,
93109 + .properties_provided = 0,
93110 + .properties_destroyed = 0,
93111 + .todo_flags_start = 0,
93112 + .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
93113 + }
93114 +};
93115 +
93116 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
93117 +{
93118 + tree fntype;
93119 +
93120 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
93121 +
93122 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
93123 + fntype = build_function_type_list(void_type_node,
93124 + const_char_ptr_type_node,
93125 + unsigned_type_node,
93126 + const_char_ptr_type_node,
93127 + const_char_ptr_type_node,
93128 + NULL_TREE);
93129 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
93130 +
93131 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
93132 + TREE_PUBLIC(report_size_overflow_decl) = 1;
93133 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
93134 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
93135 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
93136 +}
93137 +
93138 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93139 +{
93140 + int i;
93141 + const char * const plugin_name = plugin_info->base_name;
93142 + const int argc = plugin_info->argc;
93143 + const struct plugin_argument * const argv = plugin_info->argv;
93144 + bool enable = true;
93145 +
93146 + struct register_pass_info size_overflow_pass_info = {
93147 + .pass = &size_overflow_pass.pass,
93148 + .reference_pass_name = "ssa",
93149 + .ref_pass_instance_number = 1,
93150 + .pos_op = PASS_POS_INSERT_AFTER
93151 + };
93152 +
93153 + if (!plugin_default_version_check(version, &gcc_version)) {
93154 + error(G_("incompatible gcc/plugin versions"));
93155 + return 1;
93156 + }
93157 +
93158 + for (i = 0; i < argc; ++i) {
93159 + if (!strcmp(argv[i].key, "no-size-overflow")) {
93160 + enable = false;
93161 + continue;
93162 + }
93163 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93164 + }
93165 +
93166 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
93167 + if (enable) {
93168 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
93169 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
93170 + }
93171 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
93172 +
93173 + return 0;
93174 +}
93175 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
93176 new file mode 100644
93177 index 0000000..ac2901e
93178 --- /dev/null
93179 +++ b/tools/gcc/stackleak_plugin.c
93180 @@ -0,0 +1,327 @@
93181 +/*
93182 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
93183 + * Licensed under the GPL v2
93184 + *
93185 + * Note: the choice of the license means that the compilation process is
93186 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
93187 + * but for the kernel it doesn't matter since it doesn't link against
93188 + * any of the gcc libraries
93189 + *
93190 + * gcc plugin to help implement various PaX features
93191 + *
93192 + * - track lowest stack pointer
93193 + *
93194 + * TODO:
93195 + * - initialize all local variables
93196 + *
93197 + * BUGS:
93198 + * - none known
93199 + */
93200 +#include "gcc-plugin.h"
93201 +#include "config.h"
93202 +#include "system.h"
93203 +#include "coretypes.h"
93204 +#include "tree.h"
93205 +#include "tree-pass.h"
93206 +#include "flags.h"
93207 +#include "intl.h"
93208 +#include "toplev.h"
93209 +#include "plugin.h"
93210 +//#include "expr.h" where are you...
93211 +#include "diagnostic.h"
93212 +#include "plugin-version.h"
93213 +#include "tm.h"
93214 +#include "function.h"
93215 +#include "basic-block.h"
93216 +#include "gimple.h"
93217 +#include "rtl.h"
93218 +#include "emit-rtl.h"
93219 +
93220 +#if BUILDING_GCC_VERSION >= 4008
93221 +#define TODO_dump_func 0
93222 +#endif
93223 +
93224 +extern void print_gimple_stmt(FILE *, gimple, int, int);
93225 +
93226 +int plugin_is_GPL_compatible;
93227 +
93228 +static int track_frame_size = -1;
93229 +static const char track_function[] = "pax_track_stack";
93230 +static const char check_function[] = "pax_check_alloca";
93231 +static bool init_locals;
93232 +
93233 +static struct plugin_info stackleak_plugin_info = {
93234 + .version = "201302112000",
93235 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
93236 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
93237 +};
93238 +
93239 +static bool gate_stackleak_track_stack(void);
93240 +static unsigned int execute_stackleak_tree_instrument(void);
93241 +static unsigned int execute_stackleak_final(void);
93242 +
93243 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
93244 + .pass = {
93245 + .type = GIMPLE_PASS,
93246 + .name = "stackleak_tree_instrument",
93247 +#if BUILDING_GCC_VERSION >= 4008
93248 + .optinfo_flags = OPTGROUP_NONE,
93249 +#endif
93250 + .gate = gate_stackleak_track_stack,
93251 + .execute = execute_stackleak_tree_instrument,
93252 + .sub = NULL,
93253 + .next = NULL,
93254 + .static_pass_number = 0,
93255 + .tv_id = TV_NONE,
93256 + .properties_required = PROP_gimple_leh | PROP_cfg,
93257 + .properties_provided = 0,
93258 + .properties_destroyed = 0,
93259 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
93260 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
93261 + }
93262 +};
93263 +
93264 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
93265 + .pass = {
93266 + .type = RTL_PASS,
93267 + .name = "stackleak_final",
93268 +#if BUILDING_GCC_VERSION >= 4008
93269 + .optinfo_flags = OPTGROUP_NONE,
93270 +#endif
93271 + .gate = gate_stackleak_track_stack,
93272 + .execute = execute_stackleak_final,
93273 + .sub = NULL,
93274 + .next = NULL,
93275 + .static_pass_number = 0,
93276 + .tv_id = TV_NONE,
93277 + .properties_required = 0,
93278 + .properties_provided = 0,
93279 + .properties_destroyed = 0,
93280 + .todo_flags_start = 0,
93281 + .todo_flags_finish = TODO_dump_func
93282 + }
93283 +};
93284 +
93285 +static bool gate_stackleak_track_stack(void)
93286 +{
93287 + return track_frame_size >= 0;
93288 +}
93289 +
93290 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
93291 +{
93292 + gimple check_alloca;
93293 + tree fntype, fndecl, alloca_size;
93294 +
93295 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
93296 + fndecl = build_fn_decl(check_function, fntype);
93297 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
93298 +
93299 + // insert call to void pax_check_alloca(unsigned long size)
93300 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
93301 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
93302 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
93303 +}
93304 +
93305 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
93306 +{
93307 + gimple track_stack;
93308 + tree fntype, fndecl;
93309 +
93310 + fntype = build_function_type_list(void_type_node, NULL_TREE);
93311 + fndecl = build_fn_decl(track_function, fntype);
93312 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
93313 +
93314 + // insert call to void pax_track_stack(void)
93315 + track_stack = gimple_build_call(fndecl, 0);
93316 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
93317 +}
93318 +
93319 +#if BUILDING_GCC_VERSION == 4005
93320 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
93321 +{
93322 + tree fndecl;
93323 +
93324 + if (!is_gimple_call(stmt))
93325 + return false;
93326 + fndecl = gimple_call_fndecl(stmt);
93327 + if (!fndecl)
93328 + return false;
93329 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
93330 + return false;
93331 +// print_node(stderr, "pax", fndecl, 4);
93332 + return DECL_FUNCTION_CODE(fndecl) == code;
93333 +}
93334 +#endif
93335 +
93336 +static bool is_alloca(gimple stmt)
93337 +{
93338 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
93339 + return true;
93340 +
93341 +#if BUILDING_GCC_VERSION >= 4007
93342 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
93343 + return true;
93344 +#endif
93345 +
93346 + return false;
93347 +}
93348 +
93349 +static unsigned int execute_stackleak_tree_instrument(void)
93350 +{
93351 + basic_block bb, entry_bb;
93352 + bool prologue_instrumented = false, is_leaf = true;
93353 +
93354 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
93355 +
93356 + // 1. loop through BBs and GIMPLE statements
93357 + FOR_EACH_BB(bb) {
93358 + gimple_stmt_iterator gsi;
93359 +
93360 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
93361 + gimple stmt;
93362 +
93363 + stmt = gsi_stmt(gsi);
93364 +
93365 + if (is_gimple_call(stmt))
93366 + is_leaf = false;
93367 +
93368 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
93369 + if (!is_alloca(stmt))
93370 + continue;
93371 +
93372 + // 2. insert stack overflow check before each __builtin_alloca call
93373 + stackleak_check_alloca(&gsi);
93374 +
93375 + // 3. insert track call after each __builtin_alloca call
93376 + stackleak_add_instrumentation(&gsi);
93377 + if (bb == entry_bb)
93378 + prologue_instrumented = true;
93379 + }
93380 + }
93381 +
93382 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
93383 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
93384 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
93385 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
93386 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
93387 + return 0;
93388 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
93389 + return 0;
93390 +
93391 + // 4. insert track call at the beginning
93392 + if (!prologue_instrumented) {
93393 + gimple_stmt_iterator gsi;
93394 +
93395 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
93396 + if (dom_info_available_p(CDI_DOMINATORS))
93397 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
93398 + gsi = gsi_start_bb(bb);
93399 + stackleak_add_instrumentation(&gsi);
93400 + }
93401 +
93402 + return 0;
93403 +}
93404 +
93405 +static unsigned int execute_stackleak_final(void)
93406 +{
93407 + rtx insn, next;
93408 +
93409 + if (cfun->calls_alloca)
93410 + return 0;
93411 +
93412 + // keep calls only if function frame is big enough
93413 + if (get_frame_size() >= track_frame_size)
93414 + return 0;
93415 +
93416 + // 1. find pax_track_stack calls
93417 + for (insn = get_insns(); insn; insn = next) {
93418 + // 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))
93419 + rtx body;
93420 +
93421 + next = NEXT_INSN(insn);
93422 + if (!CALL_P(insn))
93423 + continue;
93424 + body = PATTERN(insn);
93425 + if (GET_CODE(body) != CALL)
93426 + continue;
93427 + body = XEXP(body, 0);
93428 + if (GET_CODE(body) != MEM)
93429 + continue;
93430 + body = XEXP(body, 0);
93431 + if (GET_CODE(body) != SYMBOL_REF)
93432 + continue;
93433 + if (strcmp(XSTR(body, 0), track_function))
93434 + continue;
93435 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
93436 + // 2. delete call
93437 + delete_insn_and_edges(insn);
93438 +#if BUILDING_GCC_VERSION >= 4007
93439 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
93440 + insn = next;
93441 + next = NEXT_INSN(insn);
93442 + delete_insn_and_edges(insn);
93443 + }
93444 +#endif
93445 + }
93446 +
93447 +// print_simple_rtl(stderr, get_insns());
93448 +// print_rtl(stderr, get_insns());
93449 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
93450 +
93451 + return 0;
93452 +}
93453 +
93454 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93455 +{
93456 + const char * const plugin_name = plugin_info->base_name;
93457 + const int argc = plugin_info->argc;
93458 + const struct plugin_argument * const argv = plugin_info->argv;
93459 + int i;
93460 + struct register_pass_info stackleak_tree_instrument_pass_info = {
93461 + .pass = &stackleak_tree_instrument_pass.pass,
93462 +// .reference_pass_name = "tree_profile",
93463 + .reference_pass_name = "optimized",
93464 + .ref_pass_instance_number = 1,
93465 + .pos_op = PASS_POS_INSERT_BEFORE
93466 + };
93467 + struct register_pass_info stackleak_final_pass_info = {
93468 + .pass = &stackleak_final_rtl_opt_pass.pass,
93469 + .reference_pass_name = "final",
93470 + .ref_pass_instance_number = 1,
93471 + .pos_op = PASS_POS_INSERT_BEFORE
93472 + };
93473 +
93474 + if (!plugin_default_version_check(version, &gcc_version)) {
93475 + error(G_("incompatible gcc/plugin versions"));
93476 + return 1;
93477 + }
93478 +
93479 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
93480 +
93481 + for (i = 0; i < argc; ++i) {
93482 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
93483 + if (!argv[i].value) {
93484 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93485 + continue;
93486 + }
93487 + track_frame_size = atoi(argv[i].value);
93488 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
93489 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
93490 + continue;
93491 + }
93492 + if (!strcmp(argv[i].key, "initialize-locals")) {
93493 + if (argv[i].value) {
93494 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
93495 + continue;
93496 + }
93497 + init_locals = true;
93498 + continue;
93499 + }
93500 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93501 + }
93502 +
93503 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
93504 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
93505 +
93506 + return 0;
93507 +}
93508 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
93509 index 6789d78..4afd019e 100644
93510 --- a/tools/perf/util/include/asm/alternative-asm.h
93511 +++ b/tools/perf/util/include/asm/alternative-asm.h
93512 @@ -5,4 +5,7 @@
93513
93514 #define altinstruction_entry #
93515
93516 + .macro pax_force_retaddr rip=0, reload=0
93517 + .endm
93518 +
93519 #endif
93520 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
93521 index 1cd693a..f4a7b20 100644
93522 --- a/virt/kvm/kvm_main.c
93523 +++ b/virt/kvm/kvm_main.c
93524 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
93525
93526 static cpumask_var_t cpus_hardware_enabled;
93527 static int kvm_usage_count = 0;
93528 -static atomic_t hardware_enable_failed;
93529 +static atomic_unchecked_t hardware_enable_failed;
93530
93531 struct kmem_cache *kvm_vcpu_cache;
93532 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
93533
93534 -static __read_mostly struct preempt_ops kvm_preempt_ops;
93535 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
93536 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
93537 +static struct preempt_ops kvm_preempt_ops = {
93538 + .sched_in = kvm_sched_in,
93539 + .sched_out = kvm_sched_out,
93540 +};
93541
93542 struct dentry *kvm_debugfs_dir;
93543
93544 @@ -731,7 +736,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
93545 /* We can read the guest memory with __xxx_user() later on. */
93546 if (user_alloc &&
93547 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
93548 - !access_ok(VERIFY_WRITE,
93549 + !__access_ok(VERIFY_WRITE,
93550 (void __user *)(unsigned long)mem->userspace_addr,
93551 mem->memory_size)))
93552 goto out;
93553 @@ -1783,7 +1788,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
93554 return 0;
93555 }
93556
93557 -static struct file_operations kvm_vcpu_fops = {
93558 +static file_operations_no_const kvm_vcpu_fops __read_only = {
93559 .release = kvm_vcpu_release,
93560 .unlocked_ioctl = kvm_vcpu_ioctl,
93561 #ifdef CONFIG_COMPAT
93562 @@ -2304,7 +2309,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
93563 return 0;
93564 }
93565
93566 -static struct file_operations kvm_vm_fops = {
93567 +static file_operations_no_const kvm_vm_fops __read_only = {
93568 .release = kvm_vm_release,
93569 .unlocked_ioctl = kvm_vm_ioctl,
93570 #ifdef CONFIG_COMPAT
93571 @@ -2402,7 +2407,7 @@ out:
93572 return r;
93573 }
93574
93575 -static struct file_operations kvm_chardev_ops = {
93576 +static file_operations_no_const kvm_chardev_ops __read_only = {
93577 .unlocked_ioctl = kvm_dev_ioctl,
93578 .compat_ioctl = kvm_dev_ioctl,
93579 .llseek = noop_llseek,
93580 @@ -2428,7 +2433,7 @@ static void hardware_enable_nolock(void *junk)
93581
93582 if (r) {
93583 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
93584 - atomic_inc(&hardware_enable_failed);
93585 + atomic_inc_unchecked(&hardware_enable_failed);
93586 printk(KERN_INFO "kvm: enabling virtualization on "
93587 "CPU%d failed\n", cpu);
93588 }
93589 @@ -2482,10 +2487,10 @@ static int hardware_enable_all(void)
93590
93591 kvm_usage_count++;
93592 if (kvm_usage_count == 1) {
93593 - atomic_set(&hardware_enable_failed, 0);
93594 + atomic_set_unchecked(&hardware_enable_failed, 0);
93595 on_each_cpu(hardware_enable_nolock, NULL, 1);
93596
93597 - if (atomic_read(&hardware_enable_failed)) {
93598 + if (atomic_read_unchecked(&hardware_enable_failed)) {
93599 hardware_disable_all_nolock();
93600 r = -EBUSY;
93601 }
93602 @@ -2843,7 +2848,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
93603 kvm_arch_vcpu_put(vcpu);
93604 }
93605
93606 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93607 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93608 struct module *module)
93609 {
93610 int r;
93611 @@ -2879,7 +2884,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93612 if (!vcpu_align)
93613 vcpu_align = __alignof__(struct kvm_vcpu);
93614 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
93615 - 0, NULL);
93616 + SLAB_USERCOPY, NULL);
93617 if (!kvm_vcpu_cache) {
93618 r = -ENOMEM;
93619 goto out_free_3;
93620 @@ -2889,9 +2894,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93621 if (r)
93622 goto out_free;
93623
93624 + pax_open_kernel();
93625 kvm_chardev_ops.owner = module;
93626 kvm_vm_fops.owner = module;
93627 kvm_vcpu_fops.owner = module;
93628 + pax_close_kernel();
93629
93630 r = misc_register(&kvm_dev);
93631 if (r) {
93632 @@ -2901,9 +2908,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93633
93634 register_syscore_ops(&kvm_syscore_ops);
93635
93636 - kvm_preempt_ops.sched_in = kvm_sched_in;
93637 - kvm_preempt_ops.sched_out = kvm_sched_out;
93638 -
93639 r = kvm_init_debug();
93640 if (r) {
93641 printk(KERN_ERR "kvm: create debugfs files failed\n");