]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.8.0-201302231124.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.0-201302231124.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..22e9a03 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,6 +1237,9 @@ 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 @@ -2282,6 +2288,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50837 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50838 MS_STRICTATIME);
50839
50840 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50841 + retval = -EPERM;
50842 + goto dput_out;
50843 + }
50844 +
50845 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50846 + retval = -EPERM;
50847 + goto dput_out;
50848 + }
50849 +
50850 if (flags & MS_REMOUNT)
50851 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50852 data_page);
50853 @@ -2296,6 +2312,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50854 dev_name, data_page);
50855 dput_out:
50856 path_put(&path);
50857 +
50858 + gr_log_mount(dev_name, dir_name, retval);
50859 +
50860 return retval;
50861 }
50862
50863 @@ -2582,6 +2601,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50864 if (error)
50865 goto out2;
50866
50867 + if (gr_handle_chroot_pivot()) {
50868 + error = -EPERM;
50869 + goto out2;
50870 + }
50871 +
50872 get_fs_root(current->fs, &root);
50873 error = lock_mount(&old);
50874 if (error)
50875 @@ -2785,7 +2809,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
50876 !nsown_capable(CAP_SYS_ADMIN))
50877 return -EPERM;
50878
50879 - if (fs->users != 1)
50880 + if (atomic_read(&fs->users) != 1)
50881 return -EINVAL;
50882
50883 get_mnt_ns(mnt_ns);
50884 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50885 index ebeb94c..ff35337 100644
50886 --- a/fs/nfs/inode.c
50887 +++ b/fs/nfs/inode.c
50888 @@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50889 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50890 }
50891
50892 -static atomic_long_t nfs_attr_generation_counter;
50893 +static atomic_long_unchecked_t nfs_attr_generation_counter;
50894
50895 static unsigned long nfs_read_attr_generation_counter(void)
50896 {
50897 - return atomic_long_read(&nfs_attr_generation_counter);
50898 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50899 }
50900
50901 unsigned long nfs_inc_attr_generation_counter(void)
50902 {
50903 - return atomic_long_inc_return(&nfs_attr_generation_counter);
50904 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50905 }
50906
50907 void nfs_fattr_init(struct nfs_fattr *fattr)
50908 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50909 index d586117..143d568 100644
50910 --- a/fs/nfsd/vfs.c
50911 +++ b/fs/nfsd/vfs.c
50912 @@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50913 } else {
50914 oldfs = get_fs();
50915 set_fs(KERNEL_DS);
50916 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
50917 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
50918 set_fs(oldfs);
50919 }
50920
50921 @@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50922
50923 /* Write the data. */
50924 oldfs = get_fs(); set_fs(KERNEL_DS);
50925 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50926 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50927 set_fs(oldfs);
50928 if (host_err < 0)
50929 goto out_nfserr;
50930 @@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50931 */
50932
50933 oldfs = get_fs(); set_fs(KERNEL_DS);
50934 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50935 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50936 set_fs(oldfs);
50937
50938 if (host_err < 0)
50939 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50940 index 9ff4a5e..deb1f0f 100644
50941 --- a/fs/notify/fanotify/fanotify_user.c
50942 +++ b/fs/notify/fanotify/fanotify_user.c
50943 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50944
50945 fd = fanotify_event_metadata.fd;
50946 ret = -EFAULT;
50947 - if (copy_to_user(buf, &fanotify_event_metadata,
50948 - fanotify_event_metadata.event_len))
50949 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50950 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50951 goto out_close_fd;
50952
50953 ret = prepare_for_access_response(group, event, fd);
50954 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50955 index 7b51b05..5ea5ef6 100644
50956 --- a/fs/notify/notification.c
50957 +++ b/fs/notify/notification.c
50958 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50959 * get set to 0 so it will never get 'freed'
50960 */
50961 static struct fsnotify_event *q_overflow_event;
50962 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50963 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50964
50965 /**
50966 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50967 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50968 */
50969 u32 fsnotify_get_cookie(void)
50970 {
50971 - return atomic_inc_return(&fsnotify_sync_cookie);
50972 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50973 }
50974 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50975
50976 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50977 index 99e3610..02c1068 100644
50978 --- a/fs/ntfs/dir.c
50979 +++ b/fs/ntfs/dir.c
50980 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
50981 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50982 ~(s64)(ndir->itype.index.block_size - 1)));
50983 /* Bounds checks. */
50984 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50985 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50986 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
50987 "inode 0x%lx or driver bug.", vdir->i_ino);
50988 goto err_out;
50989 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
50990 index 5b2d4f0..c6de396 100644
50991 --- a/fs/ntfs/file.c
50992 +++ b/fs/ntfs/file.c
50993 @@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
50994 #endif /* NTFS_RW */
50995 };
50996
50997 -const struct file_operations ntfs_empty_file_ops = {};
50998 +const struct file_operations ntfs_empty_file_ops __read_only;
50999
51000 -const struct inode_operations ntfs_empty_inode_ops = {};
51001 +const struct inode_operations ntfs_empty_inode_ops __read_only;
51002 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51003 index a9f78c7..ed8a381 100644
51004 --- a/fs/ocfs2/localalloc.c
51005 +++ b/fs/ocfs2/localalloc.c
51006 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51007 goto bail;
51008 }
51009
51010 - atomic_inc(&osb->alloc_stats.moves);
51011 + atomic_inc_unchecked(&osb->alloc_stats.moves);
51012
51013 bail:
51014 if (handle)
51015 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51016 index d355e6e..578d905 100644
51017 --- a/fs/ocfs2/ocfs2.h
51018 +++ b/fs/ocfs2/ocfs2.h
51019 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
51020
51021 struct ocfs2_alloc_stats
51022 {
51023 - atomic_t moves;
51024 - atomic_t local_data;
51025 - atomic_t bitmap_data;
51026 - atomic_t bg_allocs;
51027 - atomic_t bg_extends;
51028 + atomic_unchecked_t moves;
51029 + atomic_unchecked_t local_data;
51030 + atomic_unchecked_t bitmap_data;
51031 + atomic_unchecked_t bg_allocs;
51032 + atomic_unchecked_t bg_extends;
51033 };
51034
51035 enum ocfs2_local_alloc_state
51036 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51037 index f169da4..9112253 100644
51038 --- a/fs/ocfs2/suballoc.c
51039 +++ b/fs/ocfs2/suballoc.c
51040 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51041 mlog_errno(status);
51042 goto bail;
51043 }
51044 - atomic_inc(&osb->alloc_stats.bg_extends);
51045 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51046
51047 /* You should never ask for this much metadata */
51048 BUG_ON(bits_wanted >
51049 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
51050 mlog_errno(status);
51051 goto bail;
51052 }
51053 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51054 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51055
51056 *suballoc_loc = res.sr_bg_blkno;
51057 *suballoc_bit_start = res.sr_bit_offset;
51058 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
51059 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
51060 res->sr_bits);
51061
51062 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51063 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51064
51065 BUG_ON(res->sr_bits != 1);
51066
51067 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
51068 mlog_errno(status);
51069 goto bail;
51070 }
51071 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51072 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51073
51074 BUG_ON(res.sr_bits != 1);
51075
51076 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51077 cluster_start,
51078 num_clusters);
51079 if (!status)
51080 - atomic_inc(&osb->alloc_stats.local_data);
51081 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
51082 } else {
51083 if (min_clusters > (osb->bitmap_cpg - 1)) {
51084 /* The only paths asking for contiguousness
51085 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51086 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51087 res.sr_bg_blkno,
51088 res.sr_bit_offset);
51089 - atomic_inc(&osb->alloc_stats.bitmap_data);
51090 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51091 *num_clusters = res.sr_bits;
51092 }
51093 }
51094 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51095 index 0e91ec2..f4b3fc6 100644
51096 --- a/fs/ocfs2/super.c
51097 +++ b/fs/ocfs2/super.c
51098 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51099 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51100 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51101 "Stats",
51102 - atomic_read(&osb->alloc_stats.bitmap_data),
51103 - atomic_read(&osb->alloc_stats.local_data),
51104 - atomic_read(&osb->alloc_stats.bg_allocs),
51105 - atomic_read(&osb->alloc_stats.moves),
51106 - atomic_read(&osb->alloc_stats.bg_extends));
51107 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51108 + atomic_read_unchecked(&osb->alloc_stats.local_data),
51109 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51110 + atomic_read_unchecked(&osb->alloc_stats.moves),
51111 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51112
51113 out += snprintf(buf + out, len - out,
51114 "%10s => State: %u Descriptor: %llu Size: %u bits "
51115 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51116 spin_lock_init(&osb->osb_xattr_lock);
51117 ocfs2_init_steal_slots(osb);
51118
51119 - atomic_set(&osb->alloc_stats.moves, 0);
51120 - atomic_set(&osb->alloc_stats.local_data, 0);
51121 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
51122 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
51123 - atomic_set(&osb->alloc_stats.bg_extends, 0);
51124 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51125 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51126 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51127 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51128 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51129
51130 /* Copy the blockcheck stats from the superblock probe */
51131 osb->osb_ecc_stats = *stats;
51132 diff --git a/fs/open.c b/fs/open.c
51133 index 9b33c0c..2ffcca2 100644
51134 --- a/fs/open.c
51135 +++ b/fs/open.c
51136 @@ -31,6 +31,8 @@
51137 #include <linux/ima.h>
51138 #include <linux/dnotify.h>
51139
51140 +#define CREATE_TRACE_POINTS
51141 +#include <trace/events/fs.h>
51142 #include "internal.h"
51143
51144 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
51145 @@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
51146 error = locks_verify_truncate(inode, NULL, length);
51147 if (!error)
51148 error = security_path_truncate(path);
51149 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
51150 + error = -EACCES;
51151 if (!error)
51152 error = do_truncate(path->dentry, length, 0, NULL);
51153
51154 @@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
51155 error = locks_verify_truncate(inode, f.file, length);
51156 if (!error)
51157 error = security_path_truncate(&f.file->f_path);
51158 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
51159 + error = -EACCES;
51160 if (!error)
51161 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
51162 sb_end_write(inode->i_sb);
51163 @@ -373,6 +379,9 @@ retry:
51164 if (__mnt_is_readonly(path.mnt))
51165 res = -EROFS;
51166
51167 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51168 + res = -EACCES;
51169 +
51170 out_path_release:
51171 path_put(&path);
51172 if (retry_estale(res, lookup_flags)) {
51173 @@ -404,6 +413,8 @@ retry:
51174 if (error)
51175 goto dput_and_out;
51176
51177 + gr_log_chdir(path.dentry, path.mnt);
51178 +
51179 set_fs_pwd(current->fs, &path);
51180
51181 dput_and_out:
51182 @@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51183 goto out_putf;
51184
51185 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
51186 +
51187 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
51188 + error = -EPERM;
51189 +
51190 + if (!error)
51191 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
51192 +
51193 if (!error)
51194 set_fs_pwd(current->fs, &f.file->f_path);
51195 out_putf:
51196 @@ -462,7 +480,13 @@ retry:
51197 if (error)
51198 goto dput_and_out;
51199
51200 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51201 + goto dput_and_out;
51202 +
51203 set_fs_root(current->fs, &path);
51204 +
51205 + gr_handle_chroot_chdir(&path);
51206 +
51207 error = 0;
51208 dput_and_out:
51209 path_put(&path);
51210 @@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
51211 if (error)
51212 return error;
51213 mutex_lock(&inode->i_mutex);
51214 +
51215 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
51216 + error = -EACCES;
51217 + goto out_unlock;
51218 + }
51219 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
51220 + error = -EACCES;
51221 + goto out_unlock;
51222 + }
51223 +
51224 error = security_path_chmod(path, mode);
51225 if (error)
51226 goto out_unlock;
51227 @@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
51228 uid = make_kuid(current_user_ns(), user);
51229 gid = make_kgid(current_user_ns(), group);
51230
51231 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
51232 + return -EACCES;
51233 +
51234 newattrs.ia_valid = ATTR_CTIME;
51235 if (user != (uid_t) -1) {
51236 if (!uid_valid(uid))
51237 @@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
51238 } else {
51239 fsnotify_open(f);
51240 fd_install(fd, f);
51241 + trace_do_sys_open(tmp->name, flags, mode);
51242 }
51243 }
51244 putname(tmp);
51245 diff --git a/fs/pipe.c b/fs/pipe.c
51246 index bd3479d..fb92c4d 100644
51247 --- a/fs/pipe.c
51248 +++ b/fs/pipe.c
51249 @@ -438,9 +438,9 @@ redo:
51250 }
51251 if (bufs) /* More to do? */
51252 continue;
51253 - if (!pipe->writers)
51254 + if (!atomic_read(&pipe->writers))
51255 break;
51256 - if (!pipe->waiting_writers) {
51257 + if (!atomic_read(&pipe->waiting_writers)) {
51258 /* syscall merging: Usually we must not sleep
51259 * if O_NONBLOCK is set, or if we got some data.
51260 * But if a writer sleeps in kernel space, then
51261 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
51262 mutex_lock(&inode->i_mutex);
51263 pipe = inode->i_pipe;
51264
51265 - if (!pipe->readers) {
51266 + if (!atomic_read(&pipe->readers)) {
51267 send_sig(SIGPIPE, current, 0);
51268 ret = -EPIPE;
51269 goto out;
51270 @@ -553,7 +553,7 @@ redo1:
51271 for (;;) {
51272 int bufs;
51273
51274 - if (!pipe->readers) {
51275 + if (!atomic_read(&pipe->readers)) {
51276 send_sig(SIGPIPE, current, 0);
51277 if (!ret)
51278 ret = -EPIPE;
51279 @@ -644,9 +644,9 @@ redo2:
51280 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
51281 do_wakeup = 0;
51282 }
51283 - pipe->waiting_writers++;
51284 + atomic_inc(&pipe->waiting_writers);
51285 pipe_wait(pipe);
51286 - pipe->waiting_writers--;
51287 + atomic_dec(&pipe->waiting_writers);
51288 }
51289 out:
51290 mutex_unlock(&inode->i_mutex);
51291 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51292 mask = 0;
51293 if (filp->f_mode & FMODE_READ) {
51294 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
51295 - if (!pipe->writers && filp->f_version != pipe->w_counter)
51296 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
51297 mask |= POLLHUP;
51298 }
51299
51300 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51301 * Most Unices do not set POLLERR for FIFOs but on Linux they
51302 * behave exactly like pipes for poll().
51303 */
51304 - if (!pipe->readers)
51305 + if (!atomic_read(&pipe->readers))
51306 mask |= POLLERR;
51307 }
51308
51309 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
51310
51311 mutex_lock(&inode->i_mutex);
51312 pipe = inode->i_pipe;
51313 - pipe->readers -= decr;
51314 - pipe->writers -= decw;
51315 + atomic_sub(decr, &pipe->readers);
51316 + atomic_sub(decw, &pipe->writers);
51317
51318 - if (!pipe->readers && !pipe->writers) {
51319 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
51320 free_pipe_info(inode);
51321 } else {
51322 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
51323 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
51324
51325 if (inode->i_pipe) {
51326 ret = 0;
51327 - inode->i_pipe->readers++;
51328 + atomic_inc(&inode->i_pipe->readers);
51329 }
51330
51331 mutex_unlock(&inode->i_mutex);
51332 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
51333
51334 if (inode->i_pipe) {
51335 ret = 0;
51336 - inode->i_pipe->writers++;
51337 + atomic_inc(&inode->i_pipe->writers);
51338 }
51339
51340 mutex_unlock(&inode->i_mutex);
51341 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
51342 if (inode->i_pipe) {
51343 ret = 0;
51344 if (filp->f_mode & FMODE_READ)
51345 - inode->i_pipe->readers++;
51346 + atomic_inc(&inode->i_pipe->readers);
51347 if (filp->f_mode & FMODE_WRITE)
51348 - inode->i_pipe->writers++;
51349 + atomic_inc(&inode->i_pipe->writers);
51350 }
51351
51352 mutex_unlock(&inode->i_mutex);
51353 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
51354 inode->i_pipe = NULL;
51355 }
51356
51357 -static struct vfsmount *pipe_mnt __read_mostly;
51358 +struct vfsmount *pipe_mnt __read_mostly;
51359
51360 /*
51361 * pipefs_dname() is called from d_path().
51362 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
51363 goto fail_iput;
51364 inode->i_pipe = pipe;
51365
51366 - pipe->readers = pipe->writers = 1;
51367 + atomic_set(&pipe->readers, 1);
51368 + atomic_set(&pipe->writers, 1);
51369 inode->i_fop = &rdwr_pipefifo_fops;
51370
51371 /*
51372 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
51373 index 15af622..0e9f4467 100644
51374 --- a/fs/proc/Kconfig
51375 +++ b/fs/proc/Kconfig
51376 @@ -30,12 +30,12 @@ config PROC_FS
51377
51378 config PROC_KCORE
51379 bool "/proc/kcore support" if !ARM
51380 - depends on PROC_FS && MMU
51381 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
51382
51383 config PROC_VMCORE
51384 bool "/proc/vmcore support"
51385 - depends on PROC_FS && CRASH_DUMP
51386 - default y
51387 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
51388 + default n
51389 help
51390 Exports the dump image of crashed kernel in ELF format.
51391
51392 @@ -59,8 +59,8 @@ config PROC_SYSCTL
51393 limited in memory.
51394
51395 config PROC_PAGE_MONITOR
51396 - default y
51397 - depends on PROC_FS && MMU
51398 + default n
51399 + depends on PROC_FS && MMU && !GRKERNSEC
51400 bool "Enable /proc page monitoring" if EXPERT
51401 help
51402 Various /proc files exist to monitor process memory utilization:
51403 diff --git a/fs/proc/array.c b/fs/proc/array.c
51404 index 6a91e6f..e54dbc14 100644
51405 --- a/fs/proc/array.c
51406 +++ b/fs/proc/array.c
51407 @@ -60,6 +60,7 @@
51408 #include <linux/tty.h>
51409 #include <linux/string.h>
51410 #include <linux/mman.h>
51411 +#include <linux/grsecurity.h>
51412 #include <linux/proc_fs.h>
51413 #include <linux/ioport.h>
51414 #include <linux/uaccess.h>
51415 @@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
51416 seq_putc(m, '\n');
51417 }
51418
51419 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51420 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
51421 +{
51422 + if (p->mm)
51423 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
51424 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
51425 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
51426 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
51427 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
51428 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
51429 + else
51430 + seq_printf(m, "PaX:\t-----\n");
51431 +}
51432 +#endif
51433 +
51434 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51435 struct pid *pid, struct task_struct *task)
51436 {
51437 @@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51438 task_cpus_allowed(m, task);
51439 cpuset_task_status_allowed(m, task);
51440 task_context_switch_counts(m, task);
51441 +
51442 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51443 + task_pax(m, task);
51444 +#endif
51445 +
51446 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
51447 + task_grsec_rbac(m, task);
51448 +#endif
51449 +
51450 return 0;
51451 }
51452
51453 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51454 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51455 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51456 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51457 +#endif
51458 +
51459 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51460 struct pid *pid, struct task_struct *task, int whole)
51461 {
51462 @@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51463 char tcomm[sizeof(task->comm)];
51464 unsigned long flags;
51465
51466 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51467 + if (current->exec_id != m->exec_id) {
51468 + gr_log_badprocpid("stat");
51469 + return 0;
51470 + }
51471 +#endif
51472 +
51473 state = *get_task_state(task);
51474 vsize = eip = esp = 0;
51475 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51476 @@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51477 gtime = task->gtime;
51478 }
51479
51480 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51481 + if (PAX_RAND_FLAGS(mm)) {
51482 + eip = 0;
51483 + esp = 0;
51484 + wchan = 0;
51485 + }
51486 +#endif
51487 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51488 + wchan = 0;
51489 + eip =0;
51490 + esp =0;
51491 +#endif
51492 +
51493 /* scale priority and nice values from timeslices to -20..20 */
51494 /* to make it look like a "normal" Unix priority/nice value */
51495 priority = task_prio(task);
51496 @@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51497 seq_put_decimal_ull(m, ' ', vsize);
51498 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
51499 seq_put_decimal_ull(m, ' ', rsslim);
51500 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51501 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
51502 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
51503 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
51504 +#else
51505 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
51506 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
51507 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
51508 +#endif
51509 seq_put_decimal_ull(m, ' ', esp);
51510 seq_put_decimal_ull(m, ' ', eip);
51511 /* The signal information here is obsolete.
51512 @@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51513 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
51514 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
51515
51516 - if (mm && permitted) {
51517 + if (mm && permitted
51518 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51519 + && !PAX_RAND_FLAGS(mm)
51520 +#endif
51521 + ) {
51522 seq_put_decimal_ull(m, ' ', mm->start_data);
51523 seq_put_decimal_ull(m, ' ', mm->end_data);
51524 seq_put_decimal_ull(m, ' ', mm->start_brk);
51525 @@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51526 struct pid *pid, struct task_struct *task)
51527 {
51528 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
51529 - struct mm_struct *mm = get_task_mm(task);
51530 + struct mm_struct *mm;
51531
51532 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51533 + if (current->exec_id != m->exec_id) {
51534 + gr_log_badprocpid("statm");
51535 + return 0;
51536 + }
51537 +#endif
51538 + mm = get_task_mm(task);
51539 if (mm) {
51540 size = task_statm(mm, &shared, &text, &data, &resident);
51541 mmput(mm);
51542 @@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51543 return 0;
51544 }
51545
51546 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51547 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
51548 +{
51549 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
51550 +}
51551 +#endif
51552 +
51553 #ifdef CONFIG_CHECKPOINT_RESTORE
51554 static struct pid *
51555 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
51556 diff --git a/fs/proc/base.c b/fs/proc/base.c
51557 index 9b43ff77..3d6a99f 100644
51558 --- a/fs/proc/base.c
51559 +++ b/fs/proc/base.c
51560 @@ -111,6 +111,14 @@ struct pid_entry {
51561 union proc_op op;
51562 };
51563
51564 +struct getdents_callback {
51565 + struct linux_dirent __user * current_dir;
51566 + struct linux_dirent __user * previous;
51567 + struct file * file;
51568 + int count;
51569 + int error;
51570 +};
51571 +
51572 #define NOD(NAME, MODE, IOP, FOP, OP) { \
51573 .name = (NAME), \
51574 .len = sizeof(NAME) - 1, \
51575 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
51576 if (!mm->arg_end)
51577 goto out_mm; /* Shh! No looking before we're done */
51578
51579 + if (gr_acl_handle_procpidmem(task))
51580 + goto out_mm;
51581 +
51582 len = mm->arg_end - mm->arg_start;
51583
51584 if (len > PAGE_SIZE)
51585 @@ -235,12 +246,28 @@ out:
51586 return res;
51587 }
51588
51589 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51590 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51591 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51592 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51593 +#endif
51594 +
51595 static int proc_pid_auxv(struct task_struct *task, char *buffer)
51596 {
51597 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
51598 int res = PTR_ERR(mm);
51599 if (mm && !IS_ERR(mm)) {
51600 unsigned int nwords = 0;
51601 +
51602 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51603 + /* allow if we're currently ptracing this task */
51604 + if (PAX_RAND_FLAGS(mm) &&
51605 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
51606 + mmput(mm);
51607 + return 0;
51608 + }
51609 +#endif
51610 +
51611 do {
51612 nwords += 2;
51613 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
51614 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
51615 }
51616
51617
51618 -#ifdef CONFIG_KALLSYMS
51619 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51620 /*
51621 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
51622 * Returns the resolved symbol. If that fails, simply return the address.
51623 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
51624 mutex_unlock(&task->signal->cred_guard_mutex);
51625 }
51626
51627 -#ifdef CONFIG_STACKTRACE
51628 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51629
51630 #define MAX_STACK_TRACE_DEPTH 64
51631
51632 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
51633 return count;
51634 }
51635
51636 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51637 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51638 static int proc_pid_syscall(struct task_struct *task, char *buffer)
51639 {
51640 long nr;
51641 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
51642 /************************************************************************/
51643
51644 /* permission checks */
51645 -static int proc_fd_access_allowed(struct inode *inode)
51646 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
51647 {
51648 struct task_struct *task;
51649 int allowed = 0;
51650 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
51651 */
51652 task = get_proc_task(inode);
51653 if (task) {
51654 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51655 + if (log)
51656 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51657 + else
51658 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51659 put_task_struct(task);
51660 }
51661 return allowed;
51662 @@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
51663 struct task_struct *task,
51664 int hide_pid_min)
51665 {
51666 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51667 + return false;
51668 +
51669 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51670 + rcu_read_lock();
51671 + {
51672 + const struct cred *tmpcred = current_cred();
51673 + const struct cred *cred = __task_cred(task);
51674 +
51675 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
51676 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51677 + || in_group_p(grsec_proc_gid)
51678 +#endif
51679 + ) {
51680 + rcu_read_unlock();
51681 + return true;
51682 + }
51683 + }
51684 + rcu_read_unlock();
51685 +
51686 + if (!pid->hide_pid)
51687 + return false;
51688 +#endif
51689 +
51690 if (pid->hide_pid < hide_pid_min)
51691 return true;
51692 if (in_group_p(pid->pid_gid))
51693 return true;
51694 +
51695 return ptrace_may_access(task, PTRACE_MODE_READ);
51696 }
51697
51698 @@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51699 put_task_struct(task);
51700
51701 if (!has_perms) {
51702 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51703 + {
51704 +#else
51705 if (pid->hide_pid == 2) {
51706 +#endif
51707 /*
51708 * Let's make getdents(), stat(), and open()
51709 * consistent with each other. If a process
51710 @@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51711 if (!task)
51712 return -ESRCH;
51713
51714 + if (gr_acl_handle_procpidmem(task)) {
51715 + put_task_struct(task);
51716 + return -EPERM;
51717 + }
51718 +
51719 mm = mm_access(task, mode);
51720 put_task_struct(task);
51721
51722 @@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51723
51724 file->private_data = mm;
51725
51726 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51727 + file->f_version = current->exec_id;
51728 +#endif
51729 +
51730 return 0;
51731 }
51732
51733 @@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51734 ssize_t copied;
51735 char *page;
51736
51737 +#ifdef CONFIG_GRKERNSEC
51738 + if (write)
51739 + return -EPERM;
51740 +#endif
51741 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51742 + if (file->f_version != current->exec_id) {
51743 + gr_log_badprocpid("mem");
51744 + return 0;
51745 + }
51746 +#endif
51747 +
51748 if (!mm)
51749 return 0;
51750
51751 @@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51752 if (!mm)
51753 return 0;
51754
51755 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51756 + if (file->f_version != current->exec_id) {
51757 + gr_log_badprocpid("environ");
51758 + return 0;
51759 + }
51760 +#endif
51761 +
51762 page = (char *)__get_free_page(GFP_TEMPORARY);
51763 if (!page)
51764 return -ENOMEM;
51765 @@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51766 int error = -EACCES;
51767
51768 /* Are we allowed to snoop on the tasks file descriptors? */
51769 - if (!proc_fd_access_allowed(inode))
51770 + if (!proc_fd_access_allowed(inode, 0))
51771 goto out;
51772
51773 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51774 @@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51775 struct path path;
51776
51777 /* Are we allowed to snoop on the tasks file descriptors? */
51778 - if (!proc_fd_access_allowed(inode))
51779 - goto out;
51780 + /* logging this is needed for learning on chromium to work properly,
51781 + but we don't want to flood the logs from 'ps' which does a readlink
51782 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51783 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
51784 + */
51785 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51786 + if (!proc_fd_access_allowed(inode,0))
51787 + goto out;
51788 + } else {
51789 + if (!proc_fd_access_allowed(inode,1))
51790 + goto out;
51791 + }
51792
51793 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51794 if (error)
51795 @@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51796 rcu_read_lock();
51797 cred = __task_cred(task);
51798 inode->i_uid = cred->euid;
51799 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51800 + inode->i_gid = grsec_proc_gid;
51801 +#else
51802 inode->i_gid = cred->egid;
51803 +#endif
51804 rcu_read_unlock();
51805 }
51806 security_task_to_inode(task, inode);
51807 @@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51808 return -ENOENT;
51809 }
51810 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51811 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51812 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51813 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51814 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51815 +#endif
51816 task_dumpable(task)) {
51817 cred = __task_cred(task);
51818 stat->uid = cred->euid;
51819 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51820 + stat->gid = grsec_proc_gid;
51821 +#else
51822 stat->gid = cred->egid;
51823 +#endif
51824 }
51825 }
51826 rcu_read_unlock();
51827 @@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51828
51829 if (task) {
51830 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51831 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51832 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51833 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51834 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51835 +#endif
51836 task_dumpable(task)) {
51837 rcu_read_lock();
51838 cred = __task_cred(task);
51839 inode->i_uid = cred->euid;
51840 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51841 + inode->i_gid = grsec_proc_gid;
51842 +#else
51843 inode->i_gid = cred->egid;
51844 +#endif
51845 rcu_read_unlock();
51846 } else {
51847 inode->i_uid = GLOBAL_ROOT_UID;
51848 @@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51849 if (!task)
51850 goto out_no_task;
51851
51852 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51853 + goto out;
51854 +
51855 /*
51856 * Yes, it does not scale. And it should not. Don't add
51857 * new entries into /proc/<tgid>/ without very good reasons.
51858 @@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
51859 if (!task)
51860 goto out_no_task;
51861
51862 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51863 + goto out;
51864 +
51865 ret = 0;
51866 i = filp->f_pos;
51867 switch (i) {
51868 @@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51869 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51870 #endif
51871 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51872 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51873 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51874 INF("syscall", S_IRUGO, proc_pid_syscall),
51875 #endif
51876 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51877 @@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51878 #ifdef CONFIG_SECURITY
51879 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51880 #endif
51881 -#ifdef CONFIG_KALLSYMS
51882 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51883 INF("wchan", S_IRUGO, proc_pid_wchan),
51884 #endif
51885 -#ifdef CONFIG_STACKTRACE
51886 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51887 ONE("stack", S_IRUGO, proc_pid_stack),
51888 #endif
51889 #ifdef CONFIG_SCHEDSTATS
51890 @@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51891 #ifdef CONFIG_HARDWALL
51892 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51893 #endif
51894 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51895 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51896 +#endif
51897 #ifdef CONFIG_USER_NS
51898 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51899 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51900 @@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51901 if (!inode)
51902 goto out;
51903
51904 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51905 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51906 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51907 + inode->i_gid = grsec_proc_gid;
51908 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51909 +#else
51910 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51911 +#endif
51912 inode->i_op = &proc_tgid_base_inode_operations;
51913 inode->i_fop = &proc_tgid_base_operations;
51914 inode->i_flags|=S_IMMUTABLE;
51915 @@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
51916 if (!task)
51917 goto out;
51918
51919 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51920 + goto out_put_task;
51921 +
51922 result = proc_pid_instantiate(dir, dentry, task, NULL);
51923 +out_put_task:
51924 put_task_struct(task);
51925 out:
51926 return result;
51927 @@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51928 static int fake_filldir(void *buf, const char *name, int namelen,
51929 loff_t offset, u64 ino, unsigned d_type)
51930 {
51931 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
51932 + __buf->error = -EINVAL;
51933 return 0;
51934 }
51935
51936 @@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
51937 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51938 #endif
51939 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51940 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51941 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51942 INF("syscall", S_IRUGO, proc_pid_syscall),
51943 #endif
51944 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51945 @@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
51946 #ifdef CONFIG_SECURITY
51947 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51948 #endif
51949 -#ifdef CONFIG_KALLSYMS
51950 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51951 INF("wchan", S_IRUGO, proc_pid_wchan),
51952 #endif
51953 -#ifdef CONFIG_STACKTRACE
51954 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51955 ONE("stack", S_IRUGO, proc_pid_stack),
51956 #endif
51957 #ifdef CONFIG_SCHEDSTATS
51958 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51959 index 82676e3..5f8518a 100644
51960 --- a/fs/proc/cmdline.c
51961 +++ b/fs/proc/cmdline.c
51962 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51963
51964 static int __init proc_cmdline_init(void)
51965 {
51966 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51967 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51968 +#else
51969 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51970 +#endif
51971 return 0;
51972 }
51973 module_init(proc_cmdline_init);
51974 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51975 index b143471..bb105e5 100644
51976 --- a/fs/proc/devices.c
51977 +++ b/fs/proc/devices.c
51978 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51979
51980 static int __init proc_devices_init(void)
51981 {
51982 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51983 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51984 +#else
51985 proc_create("devices", 0, NULL, &proc_devinfo_operations);
51986 +#endif
51987 return 0;
51988 }
51989 module_init(proc_devices_init);
51990 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
51991 index d7a4a28..0201742 100644
51992 --- a/fs/proc/fd.c
51993 +++ b/fs/proc/fd.c
51994 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
51995 if (!task)
51996 return -ENOENT;
51997
51998 - files = get_files_struct(task);
51999 + if (!gr_acl_handle_procpidmem(task))
52000 + files = get_files_struct(task);
52001 put_task_struct(task);
52002
52003 if (files) {
52004 @@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
52005 */
52006 int proc_fd_permission(struct inode *inode, int mask)
52007 {
52008 + struct task_struct *task;
52009 int rv = generic_permission(inode, mask);
52010 - if (rv == 0)
52011 - return 0;
52012 +
52013 if (task_pid(current) == proc_pid(inode))
52014 rv = 0;
52015 +
52016 + task = get_proc_task(inode);
52017 + if (task == NULL)
52018 + return rv;
52019 +
52020 + if (gr_acl_handle_procpidmem(task))
52021 + rv = -EACCES;
52022 +
52023 + put_task_struct(task);
52024 +
52025 return rv;
52026 }
52027
52028 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52029 index 439ae688..c21ac36 100644
52030 --- a/fs/proc/inode.c
52031 +++ b/fs/proc/inode.c
52032 @@ -21,11 +21,17 @@
52033 #include <linux/seq_file.h>
52034 #include <linux/slab.h>
52035 #include <linux/mount.h>
52036 +#include <linux/grsecurity.h>
52037
52038 #include <asm/uaccess.h>
52039
52040 #include "internal.h"
52041
52042 +#ifdef CONFIG_PROC_SYSCTL
52043 +extern const struct inode_operations proc_sys_inode_operations;
52044 +extern const struct inode_operations proc_sys_dir_operations;
52045 +#endif
52046 +
52047 static void proc_evict_inode(struct inode *inode)
52048 {
52049 struct proc_dir_entry *de;
52050 @@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
52051 ns = PROC_I(inode)->ns;
52052 if (ns_ops && ns)
52053 ns_ops->put(ns);
52054 +
52055 +#ifdef CONFIG_PROC_SYSCTL
52056 + if (inode->i_op == &proc_sys_inode_operations ||
52057 + inode->i_op == &proc_sys_dir_operations)
52058 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52059 +#endif
52060 +
52061 }
52062
52063 static struct kmem_cache * proc_inode_cachep;
52064 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
52065 if (de->mode) {
52066 inode->i_mode = de->mode;
52067 inode->i_uid = de->uid;
52068 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52069 + inode->i_gid = grsec_proc_gid;
52070 +#else
52071 inode->i_gid = de->gid;
52072 +#endif
52073 }
52074 if (de->size)
52075 inode->i_size = de->size;
52076 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52077 index 252544c..04395b9 100644
52078 --- a/fs/proc/internal.h
52079 +++ b/fs/proc/internal.h
52080 @@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52081 struct pid *pid, struct task_struct *task);
52082 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52083 struct pid *pid, struct task_struct *task);
52084 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52085 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52086 +#endif
52087 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52088
52089 extern const struct file_operations proc_tid_children_operations;
52090 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52091 index e96d4f1..8b116ed 100644
52092 --- a/fs/proc/kcore.c
52093 +++ b/fs/proc/kcore.c
52094 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52095 * the addresses in the elf_phdr on our list.
52096 */
52097 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52098 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52099 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52100 + if (tsz > buflen)
52101 tsz = buflen;
52102 -
52103 +
52104 while (buflen) {
52105 struct kcore_list *m;
52106
52107 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52108 kfree(elf_buf);
52109 } else {
52110 if (kern_addr_valid(start)) {
52111 - unsigned long n;
52112 + char *elf_buf;
52113 + mm_segment_t oldfs;
52114
52115 - n = copy_to_user(buffer, (char *)start, tsz);
52116 - /*
52117 - * We cannot distinguish between fault on source
52118 - * and fault on destination. When this happens
52119 - * we clear too and hope it will trigger the
52120 - * EFAULT again.
52121 - */
52122 - if (n) {
52123 - if (clear_user(buffer + tsz - n,
52124 - n))
52125 + elf_buf = kmalloc(tsz, GFP_KERNEL);
52126 + if (!elf_buf)
52127 + return -ENOMEM;
52128 + oldfs = get_fs();
52129 + set_fs(KERNEL_DS);
52130 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52131 + set_fs(oldfs);
52132 + if (copy_to_user(buffer, elf_buf, tsz)) {
52133 + kfree(elf_buf);
52134 return -EFAULT;
52135 + }
52136 }
52137 + set_fs(oldfs);
52138 + kfree(elf_buf);
52139 } else {
52140 if (clear_user(buffer, tsz))
52141 return -EFAULT;
52142 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52143
52144 static int open_kcore(struct inode *inode, struct file *filp)
52145 {
52146 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52147 + return -EPERM;
52148 +#endif
52149 if (!capable(CAP_SYS_RAWIO))
52150 return -EPERM;
52151 if (kcore_need_update)
52152 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52153 index 80e4645..53e5fcf 100644
52154 --- a/fs/proc/meminfo.c
52155 +++ b/fs/proc/meminfo.c
52156 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52157 vmi.used >> 10,
52158 vmi.largest_chunk >> 10
52159 #ifdef CONFIG_MEMORY_FAILURE
52160 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52161 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52162 #endif
52163 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
52164 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
52165 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52166 index b1822dd..df622cb 100644
52167 --- a/fs/proc/nommu.c
52168 +++ b/fs/proc/nommu.c
52169 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
52170 if (len < 1)
52171 len = 1;
52172 seq_printf(m, "%*c", len, ' ');
52173 - seq_path(m, &file->f_path, "");
52174 + seq_path(m, &file->f_path, "\n\\");
52175 }
52176
52177 seq_putc(m, '\n');
52178 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
52179 index fe72cd0..cb9b67d 100644
52180 --- a/fs/proc/proc_net.c
52181 +++ b/fs/proc/proc_net.c
52182 @@ -23,6 +23,7 @@
52183 #include <linux/nsproxy.h>
52184 #include <net/net_namespace.h>
52185 #include <linux/seq_file.h>
52186 +#include <linux/grsecurity.h>
52187
52188 #include "internal.h"
52189
52190 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
52191 struct task_struct *task;
52192 struct nsproxy *ns;
52193 struct net *net = NULL;
52194 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52195 + const struct cred *cred = current_cred();
52196 +#endif
52197 +
52198 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52199 + if (cred->fsuid)
52200 + return net;
52201 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52202 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
52203 + return net;
52204 +#endif
52205
52206 rcu_read_lock();
52207 task = pid_task(proc_pid(dir), PIDTYPE_PID);
52208 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
52209 index 1827d88..9a60b01 100644
52210 --- a/fs/proc/proc_sysctl.c
52211 +++ b/fs/proc/proc_sysctl.c
52212 @@ -12,11 +12,15 @@
52213 #include <linux/module.h>
52214 #include "internal.h"
52215
52216 +extern int gr_handle_chroot_sysctl(const int op);
52217 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
52218 + const int op);
52219 +
52220 static const struct dentry_operations proc_sys_dentry_operations;
52221 static const struct file_operations proc_sys_file_operations;
52222 -static const struct inode_operations proc_sys_inode_operations;
52223 +const struct inode_operations proc_sys_inode_operations;
52224 static const struct file_operations proc_sys_dir_file_operations;
52225 -static const struct inode_operations proc_sys_dir_operations;
52226 +const struct inode_operations proc_sys_dir_operations;
52227
52228 void proc_sys_poll_notify(struct ctl_table_poll *poll)
52229 {
52230 @@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
52231
52232 err = NULL;
52233 d_set_d_op(dentry, &proc_sys_dentry_operations);
52234 +
52235 + gr_handle_proc_create(dentry, inode);
52236 +
52237 d_add(dentry, inode);
52238
52239 out:
52240 @@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52241 struct inode *inode = filp->f_path.dentry->d_inode;
52242 struct ctl_table_header *head = grab_header(inode);
52243 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
52244 + int op = write ? MAY_WRITE : MAY_READ;
52245 ssize_t error;
52246 size_t res;
52247
52248 @@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52249 * and won't be until we finish.
52250 */
52251 error = -EPERM;
52252 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
52253 + if (sysctl_perm(head, table, op))
52254 goto out;
52255
52256 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
52257 @@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52258 if (!table->proc_handler)
52259 goto out;
52260
52261 +#ifdef CONFIG_GRKERNSEC
52262 + error = -EPERM;
52263 + if (gr_handle_chroot_sysctl(op))
52264 + goto out;
52265 + dget(filp->f_path.dentry);
52266 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
52267 + dput(filp->f_path.dentry);
52268 + goto out;
52269 + }
52270 + dput(filp->f_path.dentry);
52271 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
52272 + goto out;
52273 + if (write && !capable(CAP_SYS_ADMIN))
52274 + goto out;
52275 +#endif
52276 +
52277 /* careful: calling conventions are nasty here */
52278 res = count;
52279 error = table->proc_handler(table, write, buf, &res, ppos);
52280 @@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
52281 return -ENOMEM;
52282 } else {
52283 d_set_d_op(child, &proc_sys_dentry_operations);
52284 +
52285 + gr_handle_proc_create(child, inode);
52286 +
52287 d_add(child, inode);
52288 }
52289 } else {
52290 @@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
52291 if ((*pos)++ < file->f_pos)
52292 return 0;
52293
52294 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
52295 + return 0;
52296 +
52297 if (unlikely(S_ISLNK(table->mode)))
52298 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
52299 else
52300 @@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
52301 if (IS_ERR(head))
52302 return PTR_ERR(head);
52303
52304 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
52305 + return -ENOENT;
52306 +
52307 generic_fillattr(inode, stat);
52308 if (table)
52309 stat->mode = (stat->mode & S_IFMT) | table->mode;
52310 @@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
52311 .llseek = generic_file_llseek,
52312 };
52313
52314 -static const struct inode_operations proc_sys_inode_operations = {
52315 +const struct inode_operations proc_sys_inode_operations = {
52316 .permission = proc_sys_permission,
52317 .setattr = proc_sys_setattr,
52318 .getattr = proc_sys_getattr,
52319 };
52320
52321 -static const struct inode_operations proc_sys_dir_operations = {
52322 +const struct inode_operations proc_sys_dir_operations = {
52323 .lookup = proc_sys_lookup,
52324 .permission = proc_sys_permission,
52325 .setattr = proc_sys_setattr,
52326 diff --git a/fs/proc/root.c b/fs/proc/root.c
52327 index c6e9fac..a740964 100644
52328 --- a/fs/proc/root.c
52329 +++ b/fs/proc/root.c
52330 @@ -176,7 +176,15 @@ void __init proc_root_init(void)
52331 #ifdef CONFIG_PROC_DEVICETREE
52332 proc_device_tree_init();
52333 #endif
52334 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52335 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52336 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
52337 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52338 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
52339 +#endif
52340 +#else
52341 proc_mkdir("bus", NULL);
52342 +#endif
52343 proc_sys_init();
52344 }
52345
52346 diff --git a/fs/proc/self.c b/fs/proc/self.c
52347 index aa5cc3b..c91a5d0 100644
52348 --- a/fs/proc/self.c
52349 +++ b/fs/proc/self.c
52350 @@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52351 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52352 void *cookie)
52353 {
52354 - char *s = nd_get_link(nd);
52355 + const char *s = nd_get_link(nd);
52356 if (!IS_ERR(s))
52357 kfree(s);
52358 }
52359 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
52360 index ca5ce7f..02c1cf0 100644
52361 --- a/fs/proc/task_mmu.c
52362 +++ b/fs/proc/task_mmu.c
52363 @@ -11,12 +11,19 @@
52364 #include <linux/rmap.h>
52365 #include <linux/swap.h>
52366 #include <linux/swapops.h>
52367 +#include <linux/grsecurity.h>
52368
52369 #include <asm/elf.h>
52370 #include <asm/uaccess.h>
52371 #include <asm/tlbflush.h>
52372 #include "internal.h"
52373
52374 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52375 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52376 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
52377 + _mm->pax_flags & MF_PAX_SEGMEXEC))
52378 +#endif
52379 +
52380 void task_mem(struct seq_file *m, struct mm_struct *mm)
52381 {
52382 unsigned long data, text, lib, swap;
52383 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52384 "VmExe:\t%8lu kB\n"
52385 "VmLib:\t%8lu kB\n"
52386 "VmPTE:\t%8lu kB\n"
52387 - "VmSwap:\t%8lu kB\n",
52388 - hiwater_vm << (PAGE_SHIFT-10),
52389 + "VmSwap:\t%8lu kB\n"
52390 +
52391 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52392 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
52393 +#endif
52394 +
52395 + ,hiwater_vm << (PAGE_SHIFT-10),
52396 total_vm << (PAGE_SHIFT-10),
52397 mm->locked_vm << (PAGE_SHIFT-10),
52398 mm->pinned_vm << (PAGE_SHIFT-10),
52399 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52400 data << (PAGE_SHIFT-10),
52401 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
52402 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
52403 - swap << (PAGE_SHIFT-10));
52404 + swap << (PAGE_SHIFT-10)
52405 +
52406 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52407 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52408 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
52409 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
52410 +#else
52411 + , mm->context.user_cs_base
52412 + , mm->context.user_cs_limit
52413 +#endif
52414 +#endif
52415 +
52416 + );
52417 }
52418
52419 unsigned long task_vsize(struct mm_struct *mm)
52420 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52421 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
52422 }
52423
52424 - /* We don't show the stack guard page in /proc/maps */
52425 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52426 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
52427 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
52428 +#else
52429 start = vma->vm_start;
52430 - if (stack_guard_page_start(vma, start))
52431 - start += PAGE_SIZE;
52432 end = vma->vm_end;
52433 - if (stack_guard_page_end(vma, end))
52434 - end -= PAGE_SIZE;
52435 +#endif
52436
52437 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
52438 start,
52439 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52440 flags & VM_WRITE ? 'w' : '-',
52441 flags & VM_EXEC ? 'x' : '-',
52442 flags & VM_MAYSHARE ? 's' : 'p',
52443 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52444 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
52445 +#else
52446 pgoff,
52447 +#endif
52448 MAJOR(dev), MINOR(dev), ino, &len);
52449
52450 /*
52451 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52452 */
52453 if (file) {
52454 pad_len_spaces(m, len);
52455 - seq_path(m, &file->f_path, "\n");
52456 + seq_path(m, &file->f_path, "\n\\");
52457 goto done;
52458 }
52459
52460 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52461 * Thread stack in /proc/PID/task/TID/maps or
52462 * the main process stack.
52463 */
52464 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
52465 - vma->vm_end >= mm->start_stack)) {
52466 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
52467 + (vma->vm_start <= mm->start_stack &&
52468 + vma->vm_end >= mm->start_stack)) {
52469 name = "[stack]";
52470 } else {
52471 /* Thread stack in /proc/PID/maps */
52472 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
52473 struct proc_maps_private *priv = m->private;
52474 struct task_struct *task = priv->task;
52475
52476 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52477 + if (current->exec_id != m->exec_id) {
52478 + gr_log_badprocpid("maps");
52479 + return 0;
52480 + }
52481 +#endif
52482 +
52483 show_map_vma(m, vma, is_pid);
52484
52485 if (m->count < m->size) /* vma is copied successfully */
52486 @@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52487 .private = &mss,
52488 };
52489
52490 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52491 + if (current->exec_id != m->exec_id) {
52492 + gr_log_badprocpid("smaps");
52493 + return 0;
52494 + }
52495 +#endif
52496 memset(&mss, 0, sizeof mss);
52497 - mss.vma = vma;
52498 - /* mmap_sem is held in m_start */
52499 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52500 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52501 -
52502 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52503 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
52504 +#endif
52505 + mss.vma = vma;
52506 + /* mmap_sem is held in m_start */
52507 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52508 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52509 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52510 + }
52511 +#endif
52512 show_map_vma(m, vma, is_pid);
52513
52514 seq_printf(m,
52515 @@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52516 "KernelPageSize: %8lu kB\n"
52517 "MMUPageSize: %8lu kB\n"
52518 "Locked: %8lu kB\n",
52519 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52520 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
52521 +#else
52522 (vma->vm_end - vma->vm_start) >> 10,
52523 +#endif
52524 mss.resident >> 10,
52525 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
52526 mss.shared_clean >> 10,
52527 @@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52528 int n;
52529 char buffer[50];
52530
52531 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52532 + if (current->exec_id != m->exec_id) {
52533 + gr_log_badprocpid("numa_maps");
52534 + return 0;
52535 + }
52536 +#endif
52537 +
52538 if (!mm)
52539 return 0;
52540
52541 @@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52542 mpol_to_str(buffer, sizeof(buffer), pol);
52543 mpol_cond_put(pol);
52544
52545 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52546 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
52547 +#else
52548 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
52549 +#endif
52550
52551 if (file) {
52552 seq_printf(m, " file=");
52553 - seq_path(m, &file->f_path, "\n\t= ");
52554 + seq_path(m, &file->f_path, "\n\t\\= ");
52555 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52556 seq_printf(m, " heap");
52557 } else {
52558 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
52559 index 1ccfa53..0848f95 100644
52560 --- a/fs/proc/task_nommu.c
52561 +++ b/fs/proc/task_nommu.c
52562 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52563 else
52564 bytes += kobjsize(mm);
52565
52566 - if (current->fs && current->fs->users > 1)
52567 + if (current->fs && atomic_read(&current->fs->users) > 1)
52568 sbytes += kobjsize(current->fs);
52569 else
52570 bytes += kobjsize(current->fs);
52571 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
52572
52573 if (file) {
52574 pad_len_spaces(m, len);
52575 - seq_path(m, &file->f_path, "");
52576 + seq_path(m, &file->f_path, "\n\\");
52577 } else if (mm) {
52578 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
52579
52580 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
52581 index 16e8abb..2dcf914 100644
52582 --- a/fs/quota/netlink.c
52583 +++ b/fs/quota/netlink.c
52584 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
52585 void quota_send_warning(struct kqid qid, dev_t dev,
52586 const char warntype)
52587 {
52588 - static atomic_t seq;
52589 + static atomic_unchecked_t seq;
52590 struct sk_buff *skb;
52591 void *msg_head;
52592 int ret;
52593 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
52594 "VFS: Not enough memory to send quota warning.\n");
52595 return;
52596 }
52597 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
52598 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
52599 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
52600 if (!msg_head) {
52601 printk(KERN_ERR
52602 diff --git a/fs/readdir.c b/fs/readdir.c
52603 index 5e69ef5..e5d9099 100644
52604 --- a/fs/readdir.c
52605 +++ b/fs/readdir.c
52606 @@ -17,6 +17,7 @@
52607 #include <linux/security.h>
52608 #include <linux/syscalls.h>
52609 #include <linux/unistd.h>
52610 +#include <linux/namei.h>
52611
52612 #include <asm/uaccess.h>
52613
52614 @@ -67,6 +68,7 @@ struct old_linux_dirent {
52615
52616 struct readdir_callback {
52617 struct old_linux_dirent __user * dirent;
52618 + struct file * file;
52619 int result;
52620 };
52621
52622 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
52623 buf->result = -EOVERFLOW;
52624 return -EOVERFLOW;
52625 }
52626 +
52627 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52628 + return 0;
52629 +
52630 buf->result++;
52631 dirent = buf->dirent;
52632 if (!access_ok(VERIFY_WRITE, dirent,
52633 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
52634
52635 buf.result = 0;
52636 buf.dirent = dirent;
52637 + buf.file = f.file;
52638
52639 error = vfs_readdir(f.file, fillonedir, &buf);
52640 if (buf.result)
52641 @@ -139,6 +146,7 @@ struct linux_dirent {
52642 struct getdents_callback {
52643 struct linux_dirent __user * current_dir;
52644 struct linux_dirent __user * previous;
52645 + struct file * file;
52646 int count;
52647 int error;
52648 };
52649 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
52650 buf->error = -EOVERFLOW;
52651 return -EOVERFLOW;
52652 }
52653 +
52654 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52655 + return 0;
52656 +
52657 dirent = buf->previous;
52658 if (dirent) {
52659 if (__put_user(offset, &dirent->d_off))
52660 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52661 buf.previous = NULL;
52662 buf.count = count;
52663 buf.error = 0;
52664 + buf.file = f.file;
52665
52666 error = vfs_readdir(f.file, filldir, &buf);
52667 if (error >= 0)
52668 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52669 struct getdents_callback64 {
52670 struct linux_dirent64 __user * current_dir;
52671 struct linux_dirent64 __user * previous;
52672 + struct file *file;
52673 int count;
52674 int error;
52675 };
52676 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52677 buf->error = -EINVAL; /* only used if we fail.. */
52678 if (reclen > buf->count)
52679 return -EINVAL;
52680 +
52681 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52682 + return 0;
52683 +
52684 dirent = buf->previous;
52685 if (dirent) {
52686 if (__put_user(offset, &dirent->d_off))
52687 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52688
52689 buf.current_dir = dirent;
52690 buf.previous = NULL;
52691 + buf.file = f.file;
52692 buf.count = count;
52693 buf.error = 0;
52694
52695 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52696 error = buf.error;
52697 lastdirent = buf.previous;
52698 if (lastdirent) {
52699 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
52700 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52701 if (__put_user(d_off, &lastdirent->d_off))
52702 error = -EFAULT;
52703 else
52704 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52705 index 2b7882b..1c5ef48 100644
52706 --- a/fs/reiserfs/do_balan.c
52707 +++ b/fs/reiserfs/do_balan.c
52708 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52709 return;
52710 }
52711
52712 - atomic_inc(&(fs_generation(tb->tb_sb)));
52713 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52714 do_balance_starts(tb);
52715
52716 /* balance leaf returns 0 except if combining L R and S into
52717 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52718 index e60e870..f40ac16 100644
52719 --- a/fs/reiserfs/procfs.c
52720 +++ b/fs/reiserfs/procfs.c
52721 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52722 "SMALL_TAILS " : "NO_TAILS ",
52723 replay_only(sb) ? "REPLAY_ONLY " : "",
52724 convert_reiserfs(sb) ? "CONV " : "",
52725 - atomic_read(&r->s_generation_counter),
52726 + atomic_read_unchecked(&r->s_generation_counter),
52727 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52728 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52729 SF(s_good_search_by_key_reada), SF(s_bmaps),
52730 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52731 index 157e474..65a6114 100644
52732 --- a/fs/reiserfs/reiserfs.h
52733 +++ b/fs/reiserfs/reiserfs.h
52734 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52735 /* Comment? -Hans */
52736 wait_queue_head_t s_wait;
52737 /* To be obsoleted soon by per buffer seals.. -Hans */
52738 - atomic_t s_generation_counter; // increased by one every time the
52739 + atomic_unchecked_t s_generation_counter; // increased by one every time the
52740 // tree gets re-balanced
52741 unsigned long s_properties; /* File system properties. Currently holds
52742 on-disk FS format */
52743 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52744 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52745
52746 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52747 -#define get_generation(s) atomic_read (&fs_generation(s))
52748 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52749 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52750 #define __fs_changed(gen,s) (gen != get_generation (s))
52751 #define fs_changed(gen,s) \
52752 diff --git a/fs/select.c b/fs/select.c
52753 index 2ef72d9..f213b17 100644
52754 --- a/fs/select.c
52755 +++ b/fs/select.c
52756 @@ -20,6 +20,7 @@
52757 #include <linux/export.h>
52758 #include <linux/slab.h>
52759 #include <linux/poll.h>
52760 +#include <linux/security.h>
52761 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52762 #include <linux/file.h>
52763 #include <linux/fdtable.h>
52764 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52765 struct poll_list *walk = head;
52766 unsigned long todo = nfds;
52767
52768 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52769 if (nfds > rlimit(RLIMIT_NOFILE))
52770 return -EINVAL;
52771
52772 diff --git a/fs/seq_file.c b/fs/seq_file.c
52773 index f2bc3df..239d4f6 100644
52774 --- a/fs/seq_file.c
52775 +++ b/fs/seq_file.c
52776 @@ -10,6 +10,7 @@
52777 #include <linux/seq_file.h>
52778 #include <linux/slab.h>
52779 #include <linux/cred.h>
52780 +#include <linux/sched.h>
52781
52782 #include <asm/uaccess.h>
52783 #include <asm/page.h>
52784 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52785 #ifdef CONFIG_USER_NS
52786 p->user_ns = file->f_cred->user_ns;
52787 #endif
52788 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52789 + p->exec_id = current->exec_id;
52790 +#endif
52791
52792 /*
52793 * Wrappers around seq_open(e.g. swaps_open) need to be
52794 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52795 return 0;
52796 }
52797 if (!m->buf) {
52798 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52799 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52800 if (!m->buf)
52801 return -ENOMEM;
52802 }
52803 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52804 Eoverflow:
52805 m->op->stop(m, p);
52806 kfree(m->buf);
52807 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52808 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52809 return !m->buf ? -ENOMEM : -EAGAIN;
52810 }
52811
52812 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52813
52814 /* grab buffer if we didn't have one */
52815 if (!m->buf) {
52816 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52817 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52818 if (!m->buf)
52819 goto Enomem;
52820 }
52821 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52822 goto Fill;
52823 m->op->stop(m, p);
52824 kfree(m->buf);
52825 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52826 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52827 if (!m->buf)
52828 goto Enomem;
52829 m->count = 0;
52830 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52831 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52832 void *data)
52833 {
52834 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52835 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52836 int res = -ENOMEM;
52837
52838 if (op) {
52839 diff --git a/fs/splice.c b/fs/splice.c
52840 index 6909d89..5b2e8f9 100644
52841 --- a/fs/splice.c
52842 +++ b/fs/splice.c
52843 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52844 pipe_lock(pipe);
52845
52846 for (;;) {
52847 - if (!pipe->readers) {
52848 + if (!atomic_read(&pipe->readers)) {
52849 send_sig(SIGPIPE, current, 0);
52850 if (!ret)
52851 ret = -EPIPE;
52852 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52853 do_wakeup = 0;
52854 }
52855
52856 - pipe->waiting_writers++;
52857 + atomic_inc(&pipe->waiting_writers);
52858 pipe_wait(pipe);
52859 - pipe->waiting_writers--;
52860 + atomic_dec(&pipe->waiting_writers);
52861 }
52862
52863 pipe_unlock(pipe);
52864 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52865 old_fs = get_fs();
52866 set_fs(get_ds());
52867 /* The cast to a user pointer is valid due to the set_fs() */
52868 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52869 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52870 set_fs(old_fs);
52871
52872 return res;
52873 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52874 old_fs = get_fs();
52875 set_fs(get_ds());
52876 /* The cast to a user pointer is valid due to the set_fs() */
52877 - res = vfs_write(file, (const char __user *)buf, count, &pos);
52878 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52879 set_fs(old_fs);
52880
52881 return res;
52882 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52883 goto err;
52884
52885 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52886 - vec[i].iov_base = (void __user *) page_address(page);
52887 + vec[i].iov_base = (void __force_user *) page_address(page);
52888 vec[i].iov_len = this_len;
52889 spd.pages[i] = page;
52890 spd.nr_pages++;
52891 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52892 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52893 {
52894 while (!pipe->nrbufs) {
52895 - if (!pipe->writers)
52896 + if (!atomic_read(&pipe->writers))
52897 return 0;
52898
52899 - if (!pipe->waiting_writers && sd->num_spliced)
52900 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52901 return 0;
52902
52903 if (sd->flags & SPLICE_F_NONBLOCK)
52904 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52905 * out of the pipe right after the splice_to_pipe(). So set
52906 * PIPE_READERS appropriately.
52907 */
52908 - pipe->readers = 1;
52909 + atomic_set(&pipe->readers, 1);
52910
52911 current->splice_pipe = pipe;
52912 }
52913 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52914 ret = -ERESTARTSYS;
52915 break;
52916 }
52917 - if (!pipe->writers)
52918 + if (!atomic_read(&pipe->writers))
52919 break;
52920 - if (!pipe->waiting_writers) {
52921 + if (!atomic_read(&pipe->waiting_writers)) {
52922 if (flags & SPLICE_F_NONBLOCK) {
52923 ret = -EAGAIN;
52924 break;
52925 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52926 pipe_lock(pipe);
52927
52928 while (pipe->nrbufs >= pipe->buffers) {
52929 - if (!pipe->readers) {
52930 + if (!atomic_read(&pipe->readers)) {
52931 send_sig(SIGPIPE, current, 0);
52932 ret = -EPIPE;
52933 break;
52934 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52935 ret = -ERESTARTSYS;
52936 break;
52937 }
52938 - pipe->waiting_writers++;
52939 + atomic_inc(&pipe->waiting_writers);
52940 pipe_wait(pipe);
52941 - pipe->waiting_writers--;
52942 + atomic_dec(&pipe->waiting_writers);
52943 }
52944
52945 pipe_unlock(pipe);
52946 @@ -1823,14 +1823,14 @@ retry:
52947 pipe_double_lock(ipipe, opipe);
52948
52949 do {
52950 - if (!opipe->readers) {
52951 + if (!atomic_read(&opipe->readers)) {
52952 send_sig(SIGPIPE, current, 0);
52953 if (!ret)
52954 ret = -EPIPE;
52955 break;
52956 }
52957
52958 - if (!ipipe->nrbufs && !ipipe->writers)
52959 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52960 break;
52961
52962 /*
52963 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52964 pipe_double_lock(ipipe, opipe);
52965
52966 do {
52967 - if (!opipe->readers) {
52968 + if (!atomic_read(&opipe->readers)) {
52969 send_sig(SIGPIPE, current, 0);
52970 if (!ret)
52971 ret = -EPIPE;
52972 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52973 * return EAGAIN if we have the potential of some data in the
52974 * future, otherwise just return 0
52975 */
52976 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52977 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52978 ret = -EAGAIN;
52979
52980 pipe_unlock(ipipe);
52981 diff --git a/fs/stat.c b/fs/stat.c
52982 index 14f4545..9b7f55b 100644
52983 --- a/fs/stat.c
52984 +++ b/fs/stat.c
52985 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
52986 stat->gid = inode->i_gid;
52987 stat->rdev = inode->i_rdev;
52988 stat->size = i_size_read(inode);
52989 - stat->atime = inode->i_atime;
52990 - stat->mtime = inode->i_mtime;
52991 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52992 + stat->atime = inode->i_ctime;
52993 + stat->mtime = inode->i_ctime;
52994 + } else {
52995 + stat->atime = inode->i_atime;
52996 + stat->mtime = inode->i_mtime;
52997 + }
52998 stat->ctime = inode->i_ctime;
52999 stat->blksize = (1 << inode->i_blkbits);
53000 stat->blocks = inode->i_blocks;
53001 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
53002 if (retval)
53003 return retval;
53004
53005 - if (inode->i_op->getattr)
53006 - return inode->i_op->getattr(mnt, dentry, stat);
53007 + if (inode->i_op->getattr) {
53008 + retval = inode->i_op->getattr(mnt, dentry, stat);
53009 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53010 + stat->atime = stat->ctime;
53011 + stat->mtime = stat->ctime;
53012 + }
53013 + return retval;
53014 + }
53015
53016 generic_fillattr(inode, stat);
53017 return 0;
53018 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
53019 index 2fbdff6..5530a61 100644
53020 --- a/fs/sysfs/dir.c
53021 +++ b/fs/sysfs/dir.c
53022 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
53023 struct sysfs_dirent *sd;
53024 int rc;
53025
53026 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
53027 + const char *parent_name = parent_sd->s_name;
53028 +
53029 + mode = S_IFDIR | S_IRWXU;
53030 +
53031 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
53032 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
53033 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
53034 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
53035 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
53036 +#endif
53037 +
53038 /* allocate */
53039 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
53040 if (!sd)
53041 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53042 index 602f56d..6853db8 100644
53043 --- a/fs/sysfs/file.c
53044 +++ b/fs/sysfs/file.c
53045 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53046
53047 struct sysfs_open_dirent {
53048 atomic_t refcnt;
53049 - atomic_t event;
53050 + atomic_unchecked_t event;
53051 wait_queue_head_t poll;
53052 struct list_head buffers; /* goes through sysfs_buffer.list */
53053 };
53054 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53055 if (!sysfs_get_active(attr_sd))
53056 return -ENODEV;
53057
53058 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53059 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53060 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53061
53062 sysfs_put_active(attr_sd);
53063 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53064 return -ENOMEM;
53065
53066 atomic_set(&new_od->refcnt, 0);
53067 - atomic_set(&new_od->event, 1);
53068 + atomic_set_unchecked(&new_od->event, 1);
53069 init_waitqueue_head(&new_od->poll);
53070 INIT_LIST_HEAD(&new_od->buffers);
53071 goto retry;
53072 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53073
53074 sysfs_put_active(attr_sd);
53075
53076 - if (buffer->event != atomic_read(&od->event))
53077 + if (buffer->event != atomic_read_unchecked(&od->event))
53078 goto trigger;
53079
53080 return DEFAULT_POLLMASK;
53081 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53082
53083 od = sd->s_attr.open;
53084 if (od) {
53085 - atomic_inc(&od->event);
53086 + atomic_inc_unchecked(&od->event);
53087 wake_up_interruptible(&od->poll);
53088 }
53089
53090 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
53091 index 3c9eb56..9dea5be 100644
53092 --- a/fs/sysfs/symlink.c
53093 +++ b/fs/sysfs/symlink.c
53094 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53095
53096 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
53097 {
53098 - char *page = nd_get_link(nd);
53099 + const char *page = nd_get_link(nd);
53100 if (!IS_ERR(page))
53101 free_page((unsigned long)page);
53102 }
53103 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
53104 index c175b4d..8f36a16 100644
53105 --- a/fs/udf/misc.c
53106 +++ b/fs/udf/misc.c
53107 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
53108
53109 u8 udf_tag_checksum(const struct tag *t)
53110 {
53111 - u8 *data = (u8 *)t;
53112 + const u8 *data = (const u8 *)t;
53113 u8 checksum = 0;
53114 int i;
53115 for (i = 0; i < sizeof(struct tag); ++i)
53116 diff --git a/fs/utimes.c b/fs/utimes.c
53117 index f4fb7ec..3fe03c0 100644
53118 --- a/fs/utimes.c
53119 +++ b/fs/utimes.c
53120 @@ -1,6 +1,7 @@
53121 #include <linux/compiler.h>
53122 #include <linux/file.h>
53123 #include <linux/fs.h>
53124 +#include <linux/security.h>
53125 #include <linux/linkage.h>
53126 #include <linux/mount.h>
53127 #include <linux/namei.h>
53128 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
53129 goto mnt_drop_write_and_out;
53130 }
53131 }
53132 +
53133 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
53134 + error = -EACCES;
53135 + goto mnt_drop_write_and_out;
53136 + }
53137 +
53138 mutex_lock(&inode->i_mutex);
53139 error = notify_change(path->dentry, &newattrs);
53140 mutex_unlock(&inode->i_mutex);
53141 diff --git a/fs/xattr.c b/fs/xattr.c
53142 index 3377dff..4feded6 100644
53143 --- a/fs/xattr.c
53144 +++ b/fs/xattr.c
53145 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
53146 * Extended attribute SET operations
53147 */
53148 static long
53149 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
53150 +setxattr(struct path *path, const char __user *name, const void __user *value,
53151 size_t size, int flags)
53152 {
53153 int error;
53154 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
53155 posix_acl_fix_xattr_from_user(kvalue, size);
53156 }
53157
53158 - error = vfs_setxattr(d, kname, kvalue, size, flags);
53159 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
53160 + error = -EACCES;
53161 + goto out;
53162 + }
53163 +
53164 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
53165 out:
53166 if (vvalue)
53167 vfree(vvalue);
53168 @@ -377,7 +382,7 @@ retry:
53169 return error;
53170 error = mnt_want_write(path.mnt);
53171 if (!error) {
53172 - error = setxattr(path.dentry, name, value, size, flags);
53173 + error = setxattr(&path, name, value, size, flags);
53174 mnt_drop_write(path.mnt);
53175 }
53176 path_put(&path);
53177 @@ -401,7 +406,7 @@ retry:
53178 return error;
53179 error = mnt_want_write(path.mnt);
53180 if (!error) {
53181 - error = setxattr(path.dentry, name, value, size, flags);
53182 + error = setxattr(&path, name, value, size, flags);
53183 mnt_drop_write(path.mnt);
53184 }
53185 path_put(&path);
53186 @@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
53187 const void __user *,value, size_t, size, int, flags)
53188 {
53189 struct fd f = fdget(fd);
53190 - struct dentry *dentry;
53191 int error = -EBADF;
53192
53193 if (!f.file)
53194 return error;
53195 - dentry = f.file->f_path.dentry;
53196 - audit_inode(NULL, dentry, 0);
53197 + audit_inode(NULL, f.file->f_path.dentry, 0);
53198 error = mnt_want_write_file(f.file);
53199 if (!error) {
53200 - error = setxattr(dentry, name, value, size, flags);
53201 + error = setxattr(&f.file->f_path, name, value, size, flags);
53202 mnt_drop_write_file(f.file);
53203 }
53204 fdput(f);
53205 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
53206 index 9fbea87..6b19972 100644
53207 --- a/fs/xattr_acl.c
53208 +++ b/fs/xattr_acl.c
53209 @@ -76,8 +76,8 @@ struct posix_acl *
53210 posix_acl_from_xattr(struct user_namespace *user_ns,
53211 const void *value, size_t size)
53212 {
53213 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
53214 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
53215 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
53216 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
53217 int count;
53218 struct posix_acl *acl;
53219 struct posix_acl_entry *acl_e;
53220 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
53221 index cdb2d33..704ce7f 100644
53222 --- a/fs/xfs/xfs_bmap.c
53223 +++ b/fs/xfs/xfs_bmap.c
53224 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
53225 int nmap,
53226 int ret_nmap);
53227 #else
53228 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
53229 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
53230 #endif /* DEBUG */
53231
53232 STATIC int
53233 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
53234 index 1b9fc3e..e1bdde0 100644
53235 --- a/fs/xfs/xfs_dir2_sf.c
53236 +++ b/fs/xfs/xfs_dir2_sf.c
53237 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
53238 }
53239
53240 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
53241 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53242 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
53243 + char name[sfep->namelen];
53244 + memcpy(name, sfep->name, sfep->namelen);
53245 + if (filldir(dirent, name, sfep->namelen,
53246 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
53247 + *offset = off & 0x7fffffff;
53248 + return 0;
53249 + }
53250 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53251 off & 0x7fffffff, ino, DT_UNKNOWN)) {
53252 *offset = off & 0x7fffffff;
53253 return 0;
53254 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
53255 index c1c3ef8..0952438 100644
53256 --- a/fs/xfs/xfs_ioctl.c
53257 +++ b/fs/xfs/xfs_ioctl.c
53258 @@ -127,7 +127,7 @@ xfs_find_handle(
53259 }
53260
53261 error = -EFAULT;
53262 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
53263 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
53264 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
53265 goto out_put;
53266
53267 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
53268 index d82efaa..0904a8e 100644
53269 --- a/fs/xfs/xfs_iops.c
53270 +++ b/fs/xfs/xfs_iops.c
53271 @@ -395,7 +395,7 @@ xfs_vn_put_link(
53272 struct nameidata *nd,
53273 void *p)
53274 {
53275 - char *s = nd_get_link(nd);
53276 + const char *s = nd_get_link(nd);
53277
53278 if (!IS_ERR(s))
53279 kfree(s);
53280 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
53281 new file mode 100644
53282 index 0000000..92247e4
53283 --- /dev/null
53284 +++ b/grsecurity/Kconfig
53285 @@ -0,0 +1,1021 @@
53286 +#
53287 +# grecurity configuration
53288 +#
53289 +menu "Memory Protections"
53290 +depends on GRKERNSEC
53291 +
53292 +config GRKERNSEC_KMEM
53293 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
53294 + default y if GRKERNSEC_CONFIG_AUTO
53295 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
53296 + help
53297 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
53298 + be written to or read from to modify or leak the contents of the running
53299 + kernel. /dev/port will also not be allowed to be opened and support
53300 + for /dev/cpu/*/msr will be removed. If you have module
53301 + support disabled, enabling this will close up five ways that are
53302 + currently used to insert malicious code into the running kernel.
53303 +
53304 + Even with all these features enabled, we still highly recommend that
53305 + you use the RBAC system, as it is still possible for an attacker to
53306 + modify the running kernel through privileged I/O granted by ioperm/iopl.
53307 +
53308 + If you are not using XFree86, you may be able to stop this additional
53309 + case by enabling the 'Disable privileged I/O' option. Though nothing
53310 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
53311 + but only to video memory, which is the only writing we allow in this
53312 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
53313 + not be allowed to mprotect it with PROT_WRITE later.
53314 + Enabling this feature will prevent the "cpupower" and "powertop" tools
53315 + from working.
53316 +
53317 + It is highly recommended that you say Y here if you meet all the
53318 + conditions above.
53319 +
53320 +config GRKERNSEC_VM86
53321 + bool "Restrict VM86 mode"
53322 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53323 + depends on X86_32
53324 +
53325 + help
53326 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
53327 + make use of a special execution mode on 32bit x86 processors called
53328 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
53329 + video cards and will still work with this option enabled. The purpose
53330 + of the option is to prevent exploitation of emulation errors in
53331 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
53332 + Nearly all users should be able to enable this option.
53333 +
53334 +config GRKERNSEC_IO
53335 + bool "Disable privileged I/O"
53336 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53337 + depends on X86
53338 + select RTC_CLASS
53339 + select RTC_INTF_DEV
53340 + select RTC_DRV_CMOS
53341 +
53342 + help
53343 + If you say Y here, all ioperm and iopl calls will return an error.
53344 + Ioperm and iopl can be used to modify the running kernel.
53345 + Unfortunately, some programs need this access to operate properly,
53346 + the most notable of which are XFree86 and hwclock. hwclock can be
53347 + remedied by having RTC support in the kernel, so real-time
53348 + clock support is enabled if this option is enabled, to ensure
53349 + that hwclock operates correctly. XFree86 still will not
53350 + operate correctly with this option enabled, so DO NOT CHOOSE Y
53351 + IF YOU USE XFree86. If you use XFree86 and you still want to
53352 + protect your kernel against modification, use the RBAC system.
53353 +
53354 +config GRKERNSEC_JIT_HARDEN
53355 + bool "Harden BPF JIT against spray attacks"
53356 + default y if GRKERNSEC_CONFIG_AUTO
53357 + depends on BPF_JIT
53358 + help
53359 + If you say Y here, the native code generated by the kernel's Berkeley
53360 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
53361 + attacks that attempt to fit attacker-beneficial instructions in
53362 + 32bit immediate fields of JIT-generated native instructions. The
53363 + attacker will generally aim to cause an unintended instruction sequence
53364 + of JIT-generated native code to execute by jumping into the middle of
53365 + a generated instruction. This feature effectively randomizes the 32bit
53366 + immediate constants present in the generated code to thwart such attacks.
53367 +
53368 + If you're using KERNEXEC, it's recommended that you enable this option
53369 + to supplement the hardening of the kernel.
53370 +
53371 +config GRKERNSEC_RAND_THREADSTACK
53372 + bool "Insert random gaps between thread stacks"
53373 + default y if GRKERNSEC_CONFIG_AUTO
53374 + depends on PAX_RANDMMAP && !PPC
53375 + help
53376 + If you say Y here, a random-sized gap will be enforced between allocated
53377 + thread stacks. Glibc's NPTL and other threading libraries that
53378 + pass MAP_STACK to the kernel for thread stack allocation are supported.
53379 + The implementation currently provides 8 bits of entropy for the gap.
53380 +
53381 + Many distributions do not compile threaded remote services with the
53382 + -fstack-check argument to GCC, causing the variable-sized stack-based
53383 + allocator, alloca(), to not probe the stack on allocation. This
53384 + permits an unbounded alloca() to skip over any guard page and potentially
53385 + modify another thread's stack reliably. An enforced random gap
53386 + reduces the reliability of such an attack and increases the chance
53387 + that such a read/write to another thread's stack instead lands in
53388 + an unmapped area, causing a crash and triggering grsecurity's
53389 + anti-bruteforcing logic.
53390 +
53391 +config GRKERNSEC_PROC_MEMMAP
53392 + bool "Harden ASLR against information leaks and entropy reduction"
53393 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
53394 + depends on PAX_NOEXEC || PAX_ASLR
53395 + help
53396 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
53397 + give no information about the addresses of its mappings if
53398 + PaX features that rely on random addresses are enabled on the task.
53399 + In addition to sanitizing this information and disabling other
53400 + dangerous sources of information, this option causes reads of sensitive
53401 + /proc/<pid> entries where the file descriptor was opened in a different
53402 + task than the one performing the read. Such attempts are logged.
53403 + This option also limits argv/env strings for suid/sgid binaries
53404 + to 512KB to prevent a complete exhaustion of the stack entropy provided
53405 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
53406 + binaries to prevent alternative mmap layouts from being abused.
53407 +
53408 + If you use PaX it is essential that you say Y here as it closes up
53409 + several holes that make full ASLR useless locally.
53410 +
53411 +config GRKERNSEC_BRUTE
53412 + bool "Deter exploit bruteforcing"
53413 + default y if GRKERNSEC_CONFIG_AUTO
53414 + help
53415 + If you say Y here, attempts to bruteforce exploits against forking
53416 + daemons such as apache or sshd, as well as against suid/sgid binaries
53417 + will be deterred. When a child of a forking daemon is killed by PaX
53418 + or crashes due to an illegal instruction or other suspicious signal,
53419 + the parent process will be delayed 30 seconds upon every subsequent
53420 + fork until the administrator is able to assess the situation and
53421 + restart the daemon.
53422 + In the suid/sgid case, the attempt is logged, the user has all their
53423 + processes terminated, and they are prevented from executing any further
53424 + processes for 15 minutes.
53425 + It is recommended that you also enable signal logging in the auditing
53426 + section so that logs are generated when a process triggers a suspicious
53427 + signal.
53428 + If the sysctl option is enabled, a sysctl option with name
53429 + "deter_bruteforce" is created.
53430 +
53431 +
53432 +config GRKERNSEC_MODHARDEN
53433 + bool "Harden module auto-loading"
53434 + default y if GRKERNSEC_CONFIG_AUTO
53435 + depends on MODULES
53436 + help
53437 + If you say Y here, module auto-loading in response to use of some
53438 + feature implemented by an unloaded module will be restricted to
53439 + root users. Enabling this option helps defend against attacks
53440 + by unprivileged users who abuse the auto-loading behavior to
53441 + cause a vulnerable module to load that is then exploited.
53442 +
53443 + If this option prevents a legitimate use of auto-loading for a
53444 + non-root user, the administrator can execute modprobe manually
53445 + with the exact name of the module mentioned in the alert log.
53446 + Alternatively, the administrator can add the module to the list
53447 + of modules loaded at boot by modifying init scripts.
53448 +
53449 + Modification of init scripts will most likely be needed on
53450 + Ubuntu servers with encrypted home directory support enabled,
53451 + as the first non-root user logging in will cause the ecb(aes),
53452 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
53453 +
53454 +config GRKERNSEC_HIDESYM
53455 + bool "Hide kernel symbols"
53456 + default y if GRKERNSEC_CONFIG_AUTO
53457 + select PAX_USERCOPY_SLABS
53458 + help
53459 + If you say Y here, getting information on loaded modules, and
53460 + displaying all kernel symbols through a syscall will be restricted
53461 + to users with CAP_SYS_MODULE. For software compatibility reasons,
53462 + /proc/kallsyms will be restricted to the root user. The RBAC
53463 + system can hide that entry even from root.
53464 +
53465 + This option also prevents leaking of kernel addresses through
53466 + several /proc entries.
53467 +
53468 + Note that this option is only effective provided the following
53469 + conditions are met:
53470 + 1) The kernel using grsecurity is not precompiled by some distribution
53471 + 2) You have also enabled GRKERNSEC_DMESG
53472 + 3) You are using the RBAC system and hiding other files such as your
53473 + kernel image and System.map. Alternatively, enabling this option
53474 + causes the permissions on /boot, /lib/modules, and the kernel
53475 + source directory to change at compile time to prevent
53476 + reading by non-root users.
53477 + If the above conditions are met, this option will aid in providing a
53478 + useful protection against local kernel exploitation of overflows
53479 + and arbitrary read/write vulnerabilities.
53480 +
53481 +config GRKERNSEC_KERN_LOCKOUT
53482 + bool "Active kernel exploit response"
53483 + default y if GRKERNSEC_CONFIG_AUTO
53484 + depends on X86 || ARM || PPC || SPARC
53485 + help
53486 + If you say Y here, when a PaX alert is triggered due to suspicious
53487 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
53488 + or an OOPS occurs due to bad memory accesses, instead of just
53489 + terminating the offending process (and potentially allowing
53490 + a subsequent exploit from the same user), we will take one of two
53491 + actions:
53492 + If the user was root, we will panic the system
53493 + If the user was non-root, we will log the attempt, terminate
53494 + all processes owned by the user, then prevent them from creating
53495 + any new processes until the system is restarted
53496 + This deters repeated kernel exploitation/bruteforcing attempts
53497 + and is useful for later forensics.
53498 +
53499 +endmenu
53500 +menu "Role Based Access Control Options"
53501 +depends on GRKERNSEC
53502 +
53503 +config GRKERNSEC_RBAC_DEBUG
53504 + bool
53505 +
53506 +config GRKERNSEC_NO_RBAC
53507 + bool "Disable RBAC system"
53508 + help
53509 + If you say Y here, the /dev/grsec device will be removed from the kernel,
53510 + preventing the RBAC system from being enabled. You should only say Y
53511 + here if you have no intention of using the RBAC system, so as to prevent
53512 + an attacker with root access from misusing the RBAC system to hide files
53513 + and processes when loadable module support and /dev/[k]mem have been
53514 + locked down.
53515 +
53516 +config GRKERNSEC_ACL_HIDEKERN
53517 + bool "Hide kernel processes"
53518 + help
53519 + If you say Y here, all kernel threads will be hidden to all
53520 + processes but those whose subject has the "view hidden processes"
53521 + flag.
53522 +
53523 +config GRKERNSEC_ACL_MAXTRIES
53524 + int "Maximum tries before password lockout"
53525 + default 3
53526 + help
53527 + This option enforces the maximum number of times a user can attempt
53528 + to authorize themselves with the grsecurity RBAC system before being
53529 + denied the ability to attempt authorization again for a specified time.
53530 + The lower the number, the harder it will be to brute-force a password.
53531 +
53532 +config GRKERNSEC_ACL_TIMEOUT
53533 + int "Time to wait after max password tries, in seconds"
53534 + default 30
53535 + help
53536 + This option specifies the time the user must wait after attempting to
53537 + authorize to the RBAC system with the maximum number of invalid
53538 + passwords. The higher the number, the harder it will be to brute-force
53539 + a password.
53540 +
53541 +endmenu
53542 +menu "Filesystem Protections"
53543 +depends on GRKERNSEC
53544 +
53545 +config GRKERNSEC_PROC
53546 + bool "Proc restrictions"
53547 + default y if GRKERNSEC_CONFIG_AUTO
53548 + help
53549 + If you say Y here, the permissions of the /proc filesystem
53550 + will be altered to enhance system security and privacy. You MUST
53551 + choose either a user only restriction or a user and group restriction.
53552 + Depending upon the option you choose, you can either restrict users to
53553 + see only the processes they themselves run, or choose a group that can
53554 + view all processes and files normally restricted to root if you choose
53555 + the "restrict to user only" option. NOTE: If you're running identd or
53556 + ntpd as a non-root user, you will have to run it as the group you
53557 + specify here.
53558 +
53559 +config GRKERNSEC_PROC_USER
53560 + bool "Restrict /proc to user only"
53561 + depends on GRKERNSEC_PROC
53562 + help
53563 + If you say Y here, non-root users will only be able to view their own
53564 + processes, and restricts them from viewing network-related information,
53565 + and viewing kernel symbol and module information.
53566 +
53567 +config GRKERNSEC_PROC_USERGROUP
53568 + bool "Allow special group"
53569 + default y if GRKERNSEC_CONFIG_AUTO
53570 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
53571 + help
53572 + If you say Y here, you will be able to select a group that will be
53573 + able to view all processes and network-related information. If you've
53574 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53575 + remain hidden. This option is useful if you want to run identd as
53576 + a non-root user. The group you select may also be chosen at boot time
53577 + via "grsec_proc_gid=" on the kernel commandline.
53578 +
53579 +config GRKERNSEC_PROC_GID
53580 + int "GID for special group"
53581 + depends on GRKERNSEC_PROC_USERGROUP
53582 + default 1001
53583 +
53584 +config GRKERNSEC_PROC_ADD
53585 + bool "Additional restrictions"
53586 + default y if GRKERNSEC_CONFIG_AUTO
53587 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53588 + help
53589 + If you say Y here, additional restrictions will be placed on
53590 + /proc that keep normal users from viewing device information and
53591 + slabinfo information that could be useful for exploits.
53592 +
53593 +config GRKERNSEC_LINK
53594 + bool "Linking restrictions"
53595 + default y if GRKERNSEC_CONFIG_AUTO
53596 + help
53597 + If you say Y here, /tmp race exploits will be prevented, since users
53598 + will no longer be able to follow symlinks owned by other users in
53599 + world-writable +t directories (e.g. /tmp), unless the owner of the
53600 + symlink is the owner of the directory. users will also not be
53601 + able to hardlink to files they do not own. If the sysctl option is
53602 + enabled, a sysctl option with name "linking_restrictions" is created.
53603 +
53604 +config GRKERNSEC_SYMLINKOWN
53605 + bool "Kernel-enforced SymlinksIfOwnerMatch"
53606 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53607 + help
53608 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
53609 + that prevents it from being used as a security feature. As Apache
53610 + verifies the symlink by performing a stat() against the target of
53611 + the symlink before it is followed, an attacker can setup a symlink
53612 + to point to a same-owned file, then replace the symlink with one
53613 + that targets another user's file just after Apache "validates" the
53614 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
53615 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
53616 + will be in place for the group you specify. If the sysctl option
53617 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
53618 + created.
53619 +
53620 +config GRKERNSEC_SYMLINKOWN_GID
53621 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
53622 + depends on GRKERNSEC_SYMLINKOWN
53623 + default 1006
53624 + help
53625 + Setting this GID determines what group kernel-enforced
53626 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
53627 + is enabled, a sysctl option with name "symlinkown_gid" is created.
53628 +
53629 +config GRKERNSEC_FIFO
53630 + bool "FIFO restrictions"
53631 + default y if GRKERNSEC_CONFIG_AUTO
53632 + help
53633 + If you say Y here, users will not be able to write to FIFOs they don't
53634 + own in world-writable +t directories (e.g. /tmp), unless the owner of
53635 + the FIFO is the same owner of the directory it's held in. If the sysctl
53636 + option is enabled, a sysctl option with name "fifo_restrictions" is
53637 + created.
53638 +
53639 +config GRKERNSEC_SYSFS_RESTRICT
53640 + bool "Sysfs/debugfs restriction"
53641 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53642 + depends on SYSFS
53643 + help
53644 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53645 + any filesystem normally mounted under it (e.g. debugfs) will be
53646 + mostly accessible only by root. These filesystems generally provide access
53647 + to hardware and debug information that isn't appropriate for unprivileged
53648 + users of the system. Sysfs and debugfs have also become a large source
53649 + of new vulnerabilities, ranging from infoleaks to local compromise.
53650 + There has been very little oversight with an eye toward security involved
53651 + in adding new exporters of information to these filesystems, so their
53652 + use is discouraged.
53653 + For reasons of compatibility, a few directories have been whitelisted
53654 + for access by non-root users:
53655 + /sys/fs/selinux
53656 + /sys/fs/fuse
53657 + /sys/devices/system/cpu
53658 +
53659 +config GRKERNSEC_ROFS
53660 + bool "Runtime read-only mount protection"
53661 + help
53662 + If you say Y here, a sysctl option with name "romount_protect" will
53663 + be created. By setting this option to 1 at runtime, filesystems
53664 + will be protected in the following ways:
53665 + * No new writable mounts will be allowed
53666 + * Existing read-only mounts won't be able to be remounted read/write
53667 + * Write operations will be denied on all block devices
53668 + This option acts independently of grsec_lock: once it is set to 1,
53669 + it cannot be turned off. Therefore, please be mindful of the resulting
53670 + behavior if this option is enabled in an init script on a read-only
53671 + filesystem. This feature is mainly intended for secure embedded systems.
53672 +
53673 +config GRKERNSEC_DEVICE_SIDECHANNEL
53674 + bool "Eliminate stat/notify-based device sidechannels"
53675 + default y if GRKERNSEC_CONFIG_AUTO
53676 + help
53677 + If you say Y here, timing analyses on block or character
53678 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53679 + will be thwarted for unprivileged users. If a process without
53680 + CAP_MKNOD stats such a device, the last access and last modify times
53681 + will match the device's create time. No access or modify events
53682 + will be triggered through inotify/dnotify/fanotify for such devices.
53683 + This feature will prevent attacks that may at a minimum
53684 + allow an attacker to determine the administrator's password length.
53685 +
53686 +config GRKERNSEC_CHROOT
53687 + bool "Chroot jail restrictions"
53688 + default y if GRKERNSEC_CONFIG_AUTO
53689 + help
53690 + If you say Y here, you will be able to choose several options that will
53691 + make breaking out of a chrooted jail much more difficult. If you
53692 + encounter no software incompatibilities with the following options, it
53693 + is recommended that you enable each one.
53694 +
53695 +config GRKERNSEC_CHROOT_MOUNT
53696 + bool "Deny mounts"
53697 + default y if GRKERNSEC_CONFIG_AUTO
53698 + depends on GRKERNSEC_CHROOT
53699 + help
53700 + If you say Y here, processes inside a chroot will not be able to
53701 + mount or remount filesystems. If the sysctl option is enabled, a
53702 + sysctl option with name "chroot_deny_mount" is created.
53703 +
53704 +config GRKERNSEC_CHROOT_DOUBLE
53705 + bool "Deny double-chroots"
53706 + default y if GRKERNSEC_CONFIG_AUTO
53707 + depends on GRKERNSEC_CHROOT
53708 + help
53709 + If you say Y here, processes inside a chroot will not be able to chroot
53710 + again outside the chroot. This is a widely used method of breaking
53711 + out of a chroot jail and should not be allowed. If the sysctl
53712 + option is enabled, a sysctl option with name
53713 + "chroot_deny_chroot" is created.
53714 +
53715 +config GRKERNSEC_CHROOT_PIVOT
53716 + bool "Deny pivot_root in chroot"
53717 + default y if GRKERNSEC_CONFIG_AUTO
53718 + depends on GRKERNSEC_CHROOT
53719 + help
53720 + If you say Y here, processes inside a chroot will not be able to use
53721 + a function called pivot_root() that was introduced in Linux 2.3.41. It
53722 + works similar to chroot in that it changes the root filesystem. This
53723 + function could be misused in a chrooted process to attempt to break out
53724 + of the chroot, and therefore should not be allowed. If the sysctl
53725 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
53726 + created.
53727 +
53728 +config GRKERNSEC_CHROOT_CHDIR
53729 + bool "Enforce chdir(\"/\") on all chroots"
53730 + default y if GRKERNSEC_CONFIG_AUTO
53731 + depends on GRKERNSEC_CHROOT
53732 + help
53733 + If you say Y here, the current working directory of all newly-chrooted
53734 + applications will be set to the the root directory of the chroot.
53735 + The man page on chroot(2) states:
53736 + Note that this call does not change the current working
53737 + directory, so that `.' can be outside the tree rooted at
53738 + `/'. In particular, the super-user can escape from a
53739 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53740 +
53741 + It is recommended that you say Y here, since it's not known to break
53742 + any software. If the sysctl option is enabled, a sysctl option with
53743 + name "chroot_enforce_chdir" is created.
53744 +
53745 +config GRKERNSEC_CHROOT_CHMOD
53746 + bool "Deny (f)chmod +s"
53747 + default y if GRKERNSEC_CONFIG_AUTO
53748 + depends on GRKERNSEC_CHROOT
53749 + help
53750 + If you say Y here, processes inside a chroot will not be able to chmod
53751 + or fchmod files to make them have suid or sgid bits. This protects
53752 + against another published method of breaking a chroot. If the sysctl
53753 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
53754 + created.
53755 +
53756 +config GRKERNSEC_CHROOT_FCHDIR
53757 + bool "Deny fchdir out of chroot"
53758 + default y if GRKERNSEC_CONFIG_AUTO
53759 + depends on GRKERNSEC_CHROOT
53760 + help
53761 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
53762 + to a file descriptor of the chrooting process that points to a directory
53763 + outside the filesystem will be stopped. If the sysctl option
53764 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53765 +
53766 +config GRKERNSEC_CHROOT_MKNOD
53767 + bool "Deny mknod"
53768 + default y if GRKERNSEC_CONFIG_AUTO
53769 + depends on GRKERNSEC_CHROOT
53770 + help
53771 + If you say Y here, processes inside a chroot will not be allowed to
53772 + mknod. The problem with using mknod inside a chroot is that it
53773 + would allow an attacker to create a device entry that is the same
53774 + as one on the physical root of your system, which could range from
53775 + anything from the console device to a device for your harddrive (which
53776 + they could then use to wipe the drive or steal data). It is recommended
53777 + that you say Y here, unless you run into software incompatibilities.
53778 + If the sysctl option is enabled, a sysctl option with name
53779 + "chroot_deny_mknod" is created.
53780 +
53781 +config GRKERNSEC_CHROOT_SHMAT
53782 + bool "Deny shmat() out of chroot"
53783 + default y if GRKERNSEC_CONFIG_AUTO
53784 + depends on GRKERNSEC_CHROOT
53785 + help
53786 + If you say Y here, processes inside a chroot will not be able to attach
53787 + to shared memory segments that were created outside of the chroot jail.
53788 + It is recommended that you say Y here. If the sysctl option is enabled,
53789 + a sysctl option with name "chroot_deny_shmat" is created.
53790 +
53791 +config GRKERNSEC_CHROOT_UNIX
53792 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
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
53797 + connect to abstract (meaning not belonging to a filesystem) Unix
53798 + domain sockets that were bound outside of a chroot. It is recommended
53799 + that you say Y here. If the sysctl option is enabled, a sysctl option
53800 + with name "chroot_deny_unix" is created.
53801 +
53802 +config GRKERNSEC_CHROOT_FINDTASK
53803 + bool "Protect outside processes"
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
53808 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53809 + getsid, or view any process outside of the chroot. If the sysctl
53810 + option is enabled, a sysctl option with name "chroot_findtask" is
53811 + created.
53812 +
53813 +config GRKERNSEC_CHROOT_NICE
53814 + bool "Restrict priority changes"
53815 + default y if GRKERNSEC_CONFIG_AUTO
53816 + depends on GRKERNSEC_CHROOT
53817 + help
53818 + If you say Y here, processes inside a chroot will not be able to raise
53819 + the priority of processes in the chroot, or alter the priority of
53820 + processes outside the chroot. This provides more security than simply
53821 + removing CAP_SYS_NICE from the process' capability set. If the
53822 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53823 + is created.
53824 +
53825 +config GRKERNSEC_CHROOT_SYSCTL
53826 + bool "Deny sysctl writes"
53827 + default y if GRKERNSEC_CONFIG_AUTO
53828 + depends on GRKERNSEC_CHROOT
53829 + help
53830 + If you say Y here, an attacker in a chroot will not be able to
53831 + write to sysctl entries, either by sysctl(2) or through a /proc
53832 + interface. It is strongly recommended that you say Y here. If the
53833 + sysctl option is enabled, a sysctl option with name
53834 + "chroot_deny_sysctl" is created.
53835 +
53836 +config GRKERNSEC_CHROOT_CAPS
53837 + bool "Capability restrictions"
53838 + default y if GRKERNSEC_CONFIG_AUTO
53839 + depends on GRKERNSEC_CHROOT
53840 + help
53841 + If you say Y here, the capabilities on all processes within a
53842 + chroot jail will be lowered to stop module insertion, raw i/o,
53843 + system and net admin tasks, rebooting the system, modifying immutable
53844 + files, modifying IPC owned by another, and changing the system time.
53845 + This is left an option because it can break some apps. Disable this
53846 + if your chrooted apps are having problems performing those kinds of
53847 + tasks. If the sysctl option is enabled, a sysctl option with
53848 + name "chroot_caps" is created.
53849 +
53850 +endmenu
53851 +menu "Kernel Auditing"
53852 +depends on GRKERNSEC
53853 +
53854 +config GRKERNSEC_AUDIT_GROUP
53855 + bool "Single group for auditing"
53856 + help
53857 + If you say Y here, the exec and chdir logging features will only operate
53858 + on a group you specify. This option is recommended if you only want to
53859 + watch certain users instead of having a large amount of logs from the
53860 + entire system. If the sysctl option is enabled, a sysctl option with
53861 + name "audit_group" is created.
53862 +
53863 +config GRKERNSEC_AUDIT_GID
53864 + int "GID for auditing"
53865 + depends on GRKERNSEC_AUDIT_GROUP
53866 + default 1007
53867 +
53868 +config GRKERNSEC_EXECLOG
53869 + bool "Exec logging"
53870 + help
53871 + If you say Y here, all execve() calls will be logged (since the
53872 + other exec*() calls are frontends to execve(), all execution
53873 + will be logged). Useful for shell-servers that like to keep track
53874 + of their users. If the sysctl option is enabled, a sysctl option with
53875 + name "exec_logging" is created.
53876 + WARNING: This option when enabled will produce a LOT of logs, especially
53877 + on an active system.
53878 +
53879 +config GRKERNSEC_RESLOG
53880 + bool "Resource logging"
53881 + default y if GRKERNSEC_CONFIG_AUTO
53882 + help
53883 + If you say Y here, all attempts to overstep resource limits will
53884 + be logged with the resource name, the requested size, and the current
53885 + limit. It is highly recommended that you say Y here. If the sysctl
53886 + option is enabled, a sysctl option with name "resource_logging" is
53887 + created. If the RBAC system is enabled, the sysctl value is ignored.
53888 +
53889 +config GRKERNSEC_CHROOT_EXECLOG
53890 + bool "Log execs within chroot"
53891 + help
53892 + If you say Y here, all executions inside a chroot jail will be logged
53893 + to syslog. This can cause a large amount of logs if certain
53894 + applications (eg. djb's daemontools) are installed on the system, and
53895 + is therefore left as an option. If the sysctl option is enabled, a
53896 + sysctl option with name "chroot_execlog" is created.
53897 +
53898 +config GRKERNSEC_AUDIT_PTRACE
53899 + bool "Ptrace logging"
53900 + help
53901 + If you say Y here, all attempts to attach to a process via ptrace
53902 + will be logged. If the sysctl option is enabled, a sysctl option
53903 + with name "audit_ptrace" is created.
53904 +
53905 +config GRKERNSEC_AUDIT_CHDIR
53906 + bool "Chdir logging"
53907 + help
53908 + If you say Y here, all chdir() calls will be logged. If the sysctl
53909 + option is enabled, a sysctl option with name "audit_chdir" is created.
53910 +
53911 +config GRKERNSEC_AUDIT_MOUNT
53912 + bool "(Un)Mount logging"
53913 + help
53914 + If you say Y here, all mounts and unmounts will be logged. If the
53915 + sysctl option is enabled, a sysctl option with name "audit_mount" is
53916 + created.
53917 +
53918 +config GRKERNSEC_SIGNAL
53919 + bool "Signal logging"
53920 + default y if GRKERNSEC_CONFIG_AUTO
53921 + help
53922 + If you say Y here, certain important signals will be logged, such as
53923 + SIGSEGV, which will as a result inform you of when a error in a program
53924 + occurred, which in some cases could mean a possible exploit attempt.
53925 + If the sysctl option is enabled, a sysctl option with name
53926 + "signal_logging" is created.
53927 +
53928 +config GRKERNSEC_FORKFAIL
53929 + bool "Fork failure logging"
53930 + help
53931 + If you say Y here, all failed fork() attempts will be logged.
53932 + This could suggest a fork bomb, or someone attempting to overstep
53933 + their process limit. If the sysctl option is enabled, a sysctl option
53934 + with name "forkfail_logging" is created.
53935 +
53936 +config GRKERNSEC_TIME
53937 + bool "Time change logging"
53938 + default y if GRKERNSEC_CONFIG_AUTO
53939 + help
53940 + If you say Y here, any changes of the system clock will be logged.
53941 + If the sysctl option is enabled, a sysctl option with name
53942 + "timechange_logging" is created.
53943 +
53944 +config GRKERNSEC_PROC_IPADDR
53945 + bool "/proc/<pid>/ipaddr support"
53946 + default y if GRKERNSEC_CONFIG_AUTO
53947 + help
53948 + If you say Y here, a new entry will be added to each /proc/<pid>
53949 + directory that contains the IP address of the person using the task.
53950 + The IP is carried across local TCP and AF_UNIX stream sockets.
53951 + This information can be useful for IDS/IPSes to perform remote response
53952 + to a local attack. The entry is readable by only the owner of the
53953 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53954 + the RBAC system), and thus does not create privacy concerns.
53955 +
53956 +config GRKERNSEC_RWXMAP_LOG
53957 + bool 'Denied RWX mmap/mprotect logging'
53958 + default y if GRKERNSEC_CONFIG_AUTO
53959 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53960 + help
53961 + If you say Y here, calls to mmap() and mprotect() with explicit
53962 + usage of PROT_WRITE and PROT_EXEC together will be logged when
53963 + denied by the PAX_MPROTECT feature. If the sysctl option is
53964 + enabled, a sysctl option with name "rwxmap_logging" is created.
53965 +
53966 +config GRKERNSEC_AUDIT_TEXTREL
53967 + bool 'ELF text relocations logging (READ HELP)'
53968 + depends on PAX_MPROTECT
53969 + help
53970 + If you say Y here, text relocations will be logged with the filename
53971 + of the offending library or binary. The purpose of the feature is
53972 + to help Linux distribution developers get rid of libraries and
53973 + binaries that need text relocations which hinder the future progress
53974 + of PaX. Only Linux distribution developers should say Y here, and
53975 + never on a production machine, as this option creates an information
53976 + leak that could aid an attacker in defeating the randomization of
53977 + a single memory region. If the sysctl option is enabled, a sysctl
53978 + option with name "audit_textrel" is created.
53979 +
53980 +endmenu
53981 +
53982 +menu "Executable Protections"
53983 +depends on GRKERNSEC
53984 +
53985 +config GRKERNSEC_DMESG
53986 + bool "Dmesg(8) restriction"
53987 + default y if GRKERNSEC_CONFIG_AUTO
53988 + help
53989 + If you say Y here, non-root users will not be able to use dmesg(8)
53990 + to view the contents of the kernel's circular log buffer.
53991 + The kernel's log buffer often contains kernel addresses and other
53992 + identifying information useful to an attacker in fingerprinting a
53993 + system for a targeted exploit.
53994 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
53995 + created.
53996 +
53997 +config GRKERNSEC_HARDEN_PTRACE
53998 + bool "Deter ptrace-based process snooping"
53999 + default y if GRKERNSEC_CONFIG_AUTO
54000 + help
54001 + If you say Y here, TTY sniffers and other malicious monitoring
54002 + programs implemented through ptrace will be defeated. If you
54003 + have been using the RBAC system, this option has already been
54004 + enabled for several years for all users, with the ability to make
54005 + fine-grained exceptions.
54006 +
54007 + This option only affects the ability of non-root users to ptrace
54008 + processes that are not a descendent of the ptracing process.
54009 + This means that strace ./binary and gdb ./binary will still work,
54010 + but attaching to arbitrary processes will not. If the sysctl
54011 + option is enabled, a sysctl option with name "harden_ptrace" is
54012 + created.
54013 +
54014 +config GRKERNSEC_PTRACE_READEXEC
54015 + bool "Require read access to ptrace sensitive binaries"
54016 + default y if GRKERNSEC_CONFIG_AUTO
54017 + help
54018 + If you say Y here, unprivileged users will not be able to ptrace unreadable
54019 + binaries. This option is useful in environments that
54020 + remove the read bits (e.g. file mode 4711) from suid binaries to
54021 + prevent infoleaking of their contents. This option adds
54022 + consistency to the use of that file mode, as the binary could normally
54023 + be read out when run without privileges while ptracing.
54024 +
54025 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
54026 + is created.
54027 +
54028 +config GRKERNSEC_SETXID
54029 + bool "Enforce consistent multithreaded privileges"
54030 + default y if GRKERNSEC_CONFIG_AUTO
54031 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
54032 + help
54033 + If you say Y here, a change from a root uid to a non-root uid
54034 + in a multithreaded application will cause the resulting uids,
54035 + gids, supplementary groups, and capabilities in that thread
54036 + to be propagated to the other threads of the process. In most
54037 + cases this is unnecessary, as glibc will emulate this behavior
54038 + on behalf of the application. Other libcs do not act in the
54039 + same way, allowing the other threads of the process to continue
54040 + running with root privileges. If the sysctl option is enabled,
54041 + a sysctl option with name "consistent_setxid" is created.
54042 +
54043 +config GRKERNSEC_TPE
54044 + bool "Trusted Path Execution (TPE)"
54045 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
54046 + help
54047 + If you say Y here, you will be able to choose a gid to add to the
54048 + supplementary groups of users you want to mark as "untrusted."
54049 + These users will not be able to execute any files that are not in
54050 + root-owned directories writable only by root. If the sysctl option
54051 + is enabled, a sysctl option with name "tpe" is created.
54052 +
54053 +config GRKERNSEC_TPE_ALL
54054 + bool "Partially restrict all non-root users"
54055 + depends on GRKERNSEC_TPE
54056 + help
54057 + If you say Y here, all non-root users will be covered under
54058 + a weaker TPE restriction. This is separate from, and in addition to,
54059 + the main TPE options that you have selected elsewhere. Thus, if a
54060 + "trusted" GID is chosen, this restriction applies to even that GID.
54061 + Under this restriction, all non-root users will only be allowed to
54062 + execute files in directories they own that are not group or
54063 + world-writable, or in directories owned by root and writable only by
54064 + root. If the sysctl option is enabled, a sysctl option with name
54065 + "tpe_restrict_all" is created.
54066 +
54067 +config GRKERNSEC_TPE_INVERT
54068 + bool "Invert GID option"
54069 + depends on GRKERNSEC_TPE
54070 + help
54071 + If you say Y here, the group you specify in the TPE configuration will
54072 + decide what group TPE restrictions will be *disabled* for. This
54073 + option is useful if you want TPE restrictions to be applied to most
54074 + users on the system. If the sysctl option is enabled, a sysctl option
54075 + with name "tpe_invert" is created. Unlike other sysctl options, this
54076 + entry will default to on for backward-compatibility.
54077 +
54078 +config GRKERNSEC_TPE_GID
54079 + int
54080 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
54081 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
54082 +
54083 +config GRKERNSEC_TPE_UNTRUSTED_GID
54084 + int "GID for TPE-untrusted users"
54085 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
54086 + default 1005
54087 + help
54088 + Setting this GID determines what group TPE restrictions will be
54089 + *enabled* for. If the sysctl option is enabled, a sysctl option
54090 + with name "tpe_gid" is created.
54091 +
54092 +config GRKERNSEC_TPE_TRUSTED_GID
54093 + int "GID for TPE-trusted users"
54094 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
54095 + default 1005
54096 + help
54097 + Setting this GID determines what group TPE restrictions will be
54098 + *disabled* for. If the sysctl option is enabled, a sysctl option
54099 + with name "tpe_gid" is created.
54100 +
54101 +endmenu
54102 +menu "Network Protections"
54103 +depends on GRKERNSEC
54104 +
54105 +config GRKERNSEC_RANDNET
54106 + bool "Larger entropy pools"
54107 + default y if GRKERNSEC_CONFIG_AUTO
54108 + help
54109 + If you say Y here, the entropy pools used for many features of Linux
54110 + and grsecurity will be doubled in size. Since several grsecurity
54111 + features use additional randomness, it is recommended that you say Y
54112 + here. Saying Y here has a similar effect as modifying
54113 + /proc/sys/kernel/random/poolsize.
54114 +
54115 +config GRKERNSEC_BLACKHOLE
54116 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
54117 + default y if GRKERNSEC_CONFIG_AUTO
54118 + depends on NET
54119 + help
54120 + If you say Y here, neither TCP resets nor ICMP
54121 + destination-unreachable packets will be sent in response to packets
54122 + sent to ports for which no associated listening process exists.
54123 + This feature supports both IPV4 and IPV6 and exempts the
54124 + loopback interface from blackholing. Enabling this feature
54125 + makes a host more resilient to DoS attacks and reduces network
54126 + visibility against scanners.
54127 +
54128 + The blackhole feature as-implemented is equivalent to the FreeBSD
54129 + blackhole feature, as it prevents RST responses to all packets, not
54130 + just SYNs. Under most application behavior this causes no
54131 + problems, but applications (like haproxy) may not close certain
54132 + connections in a way that cleanly terminates them on the remote
54133 + end, leaving the remote host in LAST_ACK state. Because of this
54134 + side-effect and to prevent intentional LAST_ACK DoSes, this
54135 + feature also adds automatic mitigation against such attacks.
54136 + The mitigation drastically reduces the amount of time a socket
54137 + can spend in LAST_ACK state. If you're using haproxy and not
54138 + all servers it connects to have this option enabled, consider
54139 + disabling this feature on the haproxy host.
54140 +
54141 + If the sysctl option is enabled, two sysctl options with names
54142 + "ip_blackhole" and "lastack_retries" will be created.
54143 + While "ip_blackhole" takes the standard zero/non-zero on/off
54144 + toggle, "lastack_retries" uses the same kinds of values as
54145 + "tcp_retries1" and "tcp_retries2". The default value of 4
54146 + prevents a socket from lasting more than 45 seconds in LAST_ACK
54147 + state.
54148 +
54149 +config GRKERNSEC_NO_SIMULT_CONNECT
54150 + bool "Disable TCP Simultaneous Connect"
54151 + default y if GRKERNSEC_CONFIG_AUTO
54152 + depends on NET
54153 + help
54154 + If you say Y here, a feature by Willy Tarreau will be enabled that
54155 + removes a weakness in Linux's strict implementation of TCP that
54156 + allows two clients to connect to each other without either entering
54157 + a listening state. The weakness allows an attacker to easily prevent
54158 + a client from connecting to a known server provided the source port
54159 + for the connection is guessed correctly.
54160 +
54161 + As the weakness could be used to prevent an antivirus or IPS from
54162 + fetching updates, or prevent an SSL gateway from fetching a CRL,
54163 + it should be eliminated by enabling this option. Though Linux is
54164 + one of few operating systems supporting simultaneous connect, it
54165 + has no legitimate use in practice and is rarely supported by firewalls.
54166 +
54167 +config GRKERNSEC_SOCKET
54168 + bool "Socket restrictions"
54169 + depends on NET
54170 + help
54171 + If you say Y here, you will be able to choose from several options.
54172 + If you assign a GID on your system and add it to the supplementary
54173 + groups of users you want to restrict socket access to, this patch
54174 + will perform up to three things, based on the option(s) you choose.
54175 +
54176 +config GRKERNSEC_SOCKET_ALL
54177 + bool "Deny any sockets to group"
54178 + depends on GRKERNSEC_SOCKET
54179 + help
54180 + If you say Y here, you will be able to choose a GID of whose users will
54181 + be unable to connect to other hosts from your machine or run server
54182 + applications from your machine. If the sysctl option is enabled, a
54183 + sysctl option with name "socket_all" is created.
54184 +
54185 +config GRKERNSEC_SOCKET_ALL_GID
54186 + int "GID to deny all sockets for"
54187 + depends on GRKERNSEC_SOCKET_ALL
54188 + default 1004
54189 + help
54190 + Here you can choose the GID to disable socket access for. Remember to
54191 + add the users you want socket access disabled for to the GID
54192 + specified here. If the sysctl option is enabled, a sysctl option
54193 + with name "socket_all_gid" is created.
54194 +
54195 +config GRKERNSEC_SOCKET_CLIENT
54196 + bool "Deny client sockets to group"
54197 + depends on GRKERNSEC_SOCKET
54198 + help
54199 + If you say Y here, you will be able to choose a GID of whose users will
54200 + be unable to connect to other hosts from your machine, but will be
54201 + able to run servers. If this option is enabled, all users in the group
54202 + you specify will have to use passive mode when initiating ftp transfers
54203 + from the shell on your machine. If the sysctl option is enabled, a
54204 + sysctl option with name "socket_client" is created.
54205 +
54206 +config GRKERNSEC_SOCKET_CLIENT_GID
54207 + int "GID to deny client sockets for"
54208 + depends on GRKERNSEC_SOCKET_CLIENT
54209 + default 1003
54210 + help
54211 + Here you can choose the GID to disable client socket access for.
54212 + Remember to add the users you want client socket access disabled for to
54213 + the GID specified here. If the sysctl option is enabled, a sysctl
54214 + option with name "socket_client_gid" is created.
54215 +
54216 +config GRKERNSEC_SOCKET_SERVER
54217 + bool "Deny server sockets to group"
54218 + depends on GRKERNSEC_SOCKET
54219 + help
54220 + If you say Y here, you will be able to choose a GID of whose users will
54221 + be unable to run server applications from your machine. If the sysctl
54222 + option is enabled, a sysctl option with name "socket_server" is created.
54223 +
54224 +config GRKERNSEC_SOCKET_SERVER_GID
54225 + int "GID to deny server sockets for"
54226 + depends on GRKERNSEC_SOCKET_SERVER
54227 + default 1002
54228 + help
54229 + Here you can choose the GID to disable server socket access for.
54230 + Remember to add the users you want server socket access disabled for to
54231 + the GID specified here. If the sysctl option is enabled, a sysctl
54232 + option with name "socket_server_gid" is created.
54233 +
54234 +endmenu
54235 +menu "Sysctl Support"
54236 +depends on GRKERNSEC && SYSCTL
54237 +
54238 +config GRKERNSEC_SYSCTL
54239 + bool "Sysctl support"
54240 + default y if GRKERNSEC_CONFIG_AUTO
54241 + help
54242 + If you say Y here, you will be able to change the options that
54243 + grsecurity runs with at bootup, without having to recompile your
54244 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
54245 + to enable (1) or disable (0) various features. All the sysctl entries
54246 + are mutable until the "grsec_lock" entry is set to a non-zero value.
54247 + All features enabled in the kernel configuration are disabled at boot
54248 + if you do not say Y to the "Turn on features by default" option.
54249 + All options should be set at startup, and the grsec_lock entry should
54250 + be set to a non-zero value after all the options are set.
54251 + *THIS IS EXTREMELY IMPORTANT*
54252 +
54253 +config GRKERNSEC_SYSCTL_DISTRO
54254 + bool "Extra sysctl support for distro makers (READ HELP)"
54255 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
54256 + help
54257 + If you say Y here, additional sysctl options will be created
54258 + for features that affect processes running as root. Therefore,
54259 + it is critical when using this option that the grsec_lock entry be
54260 + enabled after boot. Only distros with prebuilt kernel packages
54261 + with this option enabled that can ensure grsec_lock is enabled
54262 + after boot should use this option.
54263 + *Failure to set grsec_lock after boot makes all grsec features
54264 + this option covers useless*
54265 +
54266 + Currently this option creates the following sysctl entries:
54267 + "Disable Privileged I/O": "disable_priv_io"
54268 +
54269 +config GRKERNSEC_SYSCTL_ON
54270 + bool "Turn on features by default"
54271 + default y if GRKERNSEC_CONFIG_AUTO
54272 + depends on GRKERNSEC_SYSCTL
54273 + help
54274 + If you say Y here, instead of having all features enabled in the
54275 + kernel configuration disabled at boot time, the features will be
54276 + enabled at boot time. It is recommended you say Y here unless
54277 + there is some reason you would want all sysctl-tunable features to
54278 + be disabled by default. As mentioned elsewhere, it is important
54279 + to enable the grsec_lock entry once you have finished modifying
54280 + the sysctl entries.
54281 +
54282 +endmenu
54283 +menu "Logging Options"
54284 +depends on GRKERNSEC
54285 +
54286 +config GRKERNSEC_FLOODTIME
54287 + int "Seconds in between log messages (minimum)"
54288 + default 10
54289 + help
54290 + This option allows you to enforce the number of seconds between
54291 + grsecurity log messages. The default should be suitable for most
54292 + people, however, if you choose to change it, choose a value small enough
54293 + to allow informative logs to be produced, but large enough to
54294 + prevent flooding.
54295 +
54296 +config GRKERNSEC_FLOODBURST
54297 + int "Number of messages in a burst (maximum)"
54298 + default 6
54299 + help
54300 + This option allows you to choose the maximum number of messages allowed
54301 + within the flood time interval you chose in a separate option. The
54302 + default should be suitable for most people, however if you find that
54303 + many of your logs are being interpreted as flooding, you may want to
54304 + raise this value.
54305 +
54306 +endmenu
54307 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
54308 new file mode 100644
54309 index 0000000..1b9afa9
54310 --- /dev/null
54311 +++ b/grsecurity/Makefile
54312 @@ -0,0 +1,38 @@
54313 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
54314 +# during 2001-2009 it has been completely redesigned by Brad Spengler
54315 +# into an RBAC system
54316 +#
54317 +# All code in this directory and various hooks inserted throughout the kernel
54318 +# are copyright Brad Spengler - Open Source Security, Inc., and released
54319 +# under the GPL v2 or higher
54320 +
54321 +KBUILD_CFLAGS += -Werror
54322 +
54323 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
54324 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
54325 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
54326 +
54327 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
54328 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
54329 + gracl_learn.o grsec_log.o
54330 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
54331 +
54332 +ifdef CONFIG_NET
54333 +obj-y += grsec_sock.o
54334 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
54335 +endif
54336 +
54337 +ifndef CONFIG_GRKERNSEC
54338 +obj-y += grsec_disabled.o
54339 +endif
54340 +
54341 +ifdef CONFIG_GRKERNSEC_HIDESYM
54342 +extra-y := grsec_hidesym.o
54343 +$(obj)/grsec_hidesym.o:
54344 + @-chmod -f 500 /boot
54345 + @-chmod -f 500 /lib/modules
54346 + @-chmod -f 500 /lib64/modules
54347 + @-chmod -f 500 /lib32/modules
54348 + @-chmod -f 700 .
54349 + @echo ' grsec: protected kernel image paths'
54350 +endif
54351 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
54352 new file mode 100644
54353 index 0000000..69e1320
54354 --- /dev/null
54355 +++ b/grsecurity/gracl.c
54356 @@ -0,0 +1,4019 @@
54357 +#include <linux/kernel.h>
54358 +#include <linux/module.h>
54359 +#include <linux/sched.h>
54360 +#include <linux/mm.h>
54361 +#include <linux/file.h>
54362 +#include <linux/fs.h>
54363 +#include <linux/namei.h>
54364 +#include <linux/mount.h>
54365 +#include <linux/tty.h>
54366 +#include <linux/proc_fs.h>
54367 +#include <linux/lglock.h>
54368 +#include <linux/slab.h>
54369 +#include <linux/vmalloc.h>
54370 +#include <linux/types.h>
54371 +#include <linux/sysctl.h>
54372 +#include <linux/netdevice.h>
54373 +#include <linux/ptrace.h>
54374 +#include <linux/gracl.h>
54375 +#include <linux/gralloc.h>
54376 +#include <linux/security.h>
54377 +#include <linux/grinternal.h>
54378 +#include <linux/pid_namespace.h>
54379 +#include <linux/stop_machine.h>
54380 +#include <linux/fdtable.h>
54381 +#include <linux/percpu.h>
54382 +#include <linux/lglock.h>
54383 +#include <linux/hugetlb.h>
54384 +#include "../fs/mount.h"
54385 +
54386 +#include <asm/uaccess.h>
54387 +#include <asm/errno.h>
54388 +#include <asm/mman.h>
54389 +
54390 +extern struct lglock vfsmount_lock;
54391 +
54392 +static struct acl_role_db acl_role_set;
54393 +static struct name_db name_set;
54394 +static struct inodev_db inodev_set;
54395 +
54396 +/* for keeping track of userspace pointers used for subjects, so we
54397 + can share references in the kernel as well
54398 +*/
54399 +
54400 +static struct path real_root;
54401 +
54402 +static struct acl_subj_map_db subj_map_set;
54403 +
54404 +static struct acl_role_label *default_role;
54405 +
54406 +static struct acl_role_label *role_list;
54407 +
54408 +static u16 acl_sp_role_value;
54409 +
54410 +extern char *gr_shared_page[4];
54411 +static DEFINE_MUTEX(gr_dev_mutex);
54412 +DEFINE_RWLOCK(gr_inode_lock);
54413 +
54414 +struct gr_arg *gr_usermode;
54415 +
54416 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
54417 +
54418 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
54419 +extern void gr_clear_learn_entries(void);
54420 +
54421 +unsigned char *gr_system_salt;
54422 +unsigned char *gr_system_sum;
54423 +
54424 +static struct sprole_pw **acl_special_roles = NULL;
54425 +static __u16 num_sprole_pws = 0;
54426 +
54427 +static struct acl_role_label *kernel_role = NULL;
54428 +
54429 +static unsigned int gr_auth_attempts = 0;
54430 +static unsigned long gr_auth_expires = 0UL;
54431 +
54432 +#ifdef CONFIG_NET
54433 +extern struct vfsmount *sock_mnt;
54434 +#endif
54435 +
54436 +extern struct vfsmount *pipe_mnt;
54437 +extern struct vfsmount *shm_mnt;
54438 +
54439 +#ifdef CONFIG_HUGETLBFS
54440 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54441 +#endif
54442 +
54443 +static struct acl_object_label *fakefs_obj_rw;
54444 +static struct acl_object_label *fakefs_obj_rwx;
54445 +
54446 +extern int gr_init_uidset(void);
54447 +extern void gr_free_uidset(void);
54448 +extern void gr_remove_uid(uid_t uid);
54449 +extern int gr_find_uid(uid_t uid);
54450 +
54451 +__inline__ int
54452 +gr_acl_is_enabled(void)
54453 +{
54454 + return (gr_status & GR_READY);
54455 +}
54456 +
54457 +#ifdef CONFIG_BTRFS_FS
54458 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
54459 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
54460 +#endif
54461 +
54462 +static inline dev_t __get_dev(const struct dentry *dentry)
54463 +{
54464 +#ifdef CONFIG_BTRFS_FS
54465 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
54466 + return get_btrfs_dev_from_inode(dentry->d_inode);
54467 + else
54468 +#endif
54469 + return dentry->d_inode->i_sb->s_dev;
54470 +}
54471 +
54472 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54473 +{
54474 + return __get_dev(dentry);
54475 +}
54476 +
54477 +static char gr_task_roletype_to_char(struct task_struct *task)
54478 +{
54479 + switch (task->role->roletype &
54480 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
54481 + GR_ROLE_SPECIAL)) {
54482 + case GR_ROLE_DEFAULT:
54483 + return 'D';
54484 + case GR_ROLE_USER:
54485 + return 'U';
54486 + case GR_ROLE_GROUP:
54487 + return 'G';
54488 + case GR_ROLE_SPECIAL:
54489 + return 'S';
54490 + }
54491 +
54492 + return 'X';
54493 +}
54494 +
54495 +char gr_roletype_to_char(void)
54496 +{
54497 + return gr_task_roletype_to_char(current);
54498 +}
54499 +
54500 +__inline__ int
54501 +gr_acl_tpe_check(void)
54502 +{
54503 + if (unlikely(!(gr_status & GR_READY)))
54504 + return 0;
54505 + if (current->role->roletype & GR_ROLE_TPE)
54506 + return 1;
54507 + else
54508 + return 0;
54509 +}
54510 +
54511 +int
54512 +gr_handle_rawio(const struct inode *inode)
54513 +{
54514 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54515 + if (inode && S_ISBLK(inode->i_mode) &&
54516 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54517 + !capable(CAP_SYS_RAWIO))
54518 + return 1;
54519 +#endif
54520 + return 0;
54521 +}
54522 +
54523 +static int
54524 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
54525 +{
54526 + if (likely(lena != lenb))
54527 + return 0;
54528 +
54529 + return !memcmp(a, b, lena);
54530 +}
54531 +
54532 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
54533 +{
54534 + *buflen -= namelen;
54535 + if (*buflen < 0)
54536 + return -ENAMETOOLONG;
54537 + *buffer -= namelen;
54538 + memcpy(*buffer, str, namelen);
54539 + return 0;
54540 +}
54541 +
54542 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
54543 +{
54544 + return prepend(buffer, buflen, name->name, name->len);
54545 +}
54546 +
54547 +static int prepend_path(const struct path *path, struct path *root,
54548 + char **buffer, int *buflen)
54549 +{
54550 + struct dentry *dentry = path->dentry;
54551 + struct vfsmount *vfsmnt = path->mnt;
54552 + struct mount *mnt = real_mount(vfsmnt);
54553 + bool slash = false;
54554 + int error = 0;
54555 +
54556 + while (dentry != root->dentry || vfsmnt != root->mnt) {
54557 + struct dentry * parent;
54558 +
54559 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
54560 + /* Global root? */
54561 + if (!mnt_has_parent(mnt)) {
54562 + goto out;
54563 + }
54564 + dentry = mnt->mnt_mountpoint;
54565 + mnt = mnt->mnt_parent;
54566 + vfsmnt = &mnt->mnt;
54567 + continue;
54568 + }
54569 + parent = dentry->d_parent;
54570 + prefetch(parent);
54571 + spin_lock(&dentry->d_lock);
54572 + error = prepend_name(buffer, buflen, &dentry->d_name);
54573 + spin_unlock(&dentry->d_lock);
54574 + if (!error)
54575 + error = prepend(buffer, buflen, "/", 1);
54576 + if (error)
54577 + break;
54578 +
54579 + slash = true;
54580 + dentry = parent;
54581 + }
54582 +
54583 +out:
54584 + if (!error && !slash)
54585 + error = prepend(buffer, buflen, "/", 1);
54586 +
54587 + return error;
54588 +}
54589 +
54590 +/* this must be called with vfsmount_lock and rename_lock held */
54591 +
54592 +static char *__our_d_path(const struct path *path, struct path *root,
54593 + char *buf, int buflen)
54594 +{
54595 + char *res = buf + buflen;
54596 + int error;
54597 +
54598 + prepend(&res, &buflen, "\0", 1);
54599 + error = prepend_path(path, root, &res, &buflen);
54600 + if (error)
54601 + return ERR_PTR(error);
54602 +
54603 + return res;
54604 +}
54605 +
54606 +static char *
54607 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
54608 +{
54609 + char *retval;
54610 +
54611 + retval = __our_d_path(path, root, buf, buflen);
54612 + if (unlikely(IS_ERR(retval)))
54613 + retval = strcpy(buf, "<path too long>");
54614 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
54615 + retval[1] = '\0';
54616 +
54617 + return retval;
54618 +}
54619 +
54620 +static char *
54621 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54622 + char *buf, int buflen)
54623 +{
54624 + struct path path;
54625 + char *res;
54626 +
54627 + path.dentry = (struct dentry *)dentry;
54628 + path.mnt = (struct vfsmount *)vfsmnt;
54629 +
54630 + /* we can use real_root.dentry, real_root.mnt, because this is only called
54631 + by the RBAC system */
54632 + res = gen_full_path(&path, &real_root, buf, buflen);
54633 +
54634 + return res;
54635 +}
54636 +
54637 +static char *
54638 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54639 + char *buf, int buflen)
54640 +{
54641 + char *res;
54642 + struct path path;
54643 + struct path root;
54644 + struct task_struct *reaper = init_pid_ns.child_reaper;
54645 +
54646 + path.dentry = (struct dentry *)dentry;
54647 + path.mnt = (struct vfsmount *)vfsmnt;
54648 +
54649 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
54650 + get_fs_root(reaper->fs, &root);
54651 +
54652 + write_seqlock(&rename_lock);
54653 + br_read_lock(&vfsmount_lock);
54654 + res = gen_full_path(&path, &root, buf, buflen);
54655 + br_read_unlock(&vfsmount_lock);
54656 + write_sequnlock(&rename_lock);
54657 +
54658 + path_put(&root);
54659 + return res;
54660 +}
54661 +
54662 +static char *
54663 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54664 +{
54665 + char *ret;
54666 + write_seqlock(&rename_lock);
54667 + br_read_lock(&vfsmount_lock);
54668 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54669 + PAGE_SIZE);
54670 + br_read_unlock(&vfsmount_lock);
54671 + write_sequnlock(&rename_lock);
54672 + return ret;
54673 +}
54674 +
54675 +static char *
54676 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54677 +{
54678 + char *ret;
54679 + char *buf;
54680 + int buflen;
54681 +
54682 + write_seqlock(&rename_lock);
54683 + br_read_lock(&vfsmount_lock);
54684 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54685 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54686 + buflen = (int)(ret - buf);
54687 + if (buflen >= 5)
54688 + prepend(&ret, &buflen, "/proc", 5);
54689 + else
54690 + ret = strcpy(buf, "<path too long>");
54691 + br_read_unlock(&vfsmount_lock);
54692 + write_sequnlock(&rename_lock);
54693 + return ret;
54694 +}
54695 +
54696 +char *
54697 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54698 +{
54699 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54700 + PAGE_SIZE);
54701 +}
54702 +
54703 +char *
54704 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54705 +{
54706 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54707 + PAGE_SIZE);
54708 +}
54709 +
54710 +char *
54711 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54712 +{
54713 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54714 + PAGE_SIZE);
54715 +}
54716 +
54717 +char *
54718 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54719 +{
54720 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54721 + PAGE_SIZE);
54722 +}
54723 +
54724 +char *
54725 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54726 +{
54727 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54728 + PAGE_SIZE);
54729 +}
54730 +
54731 +__inline__ __u32
54732 +to_gr_audit(const __u32 reqmode)
54733 +{
54734 + /* masks off auditable permission flags, then shifts them to create
54735 + auditing flags, and adds the special case of append auditing if
54736 + we're requesting write */
54737 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54738 +}
54739 +
54740 +struct acl_subject_label *
54741 +lookup_subject_map(const struct acl_subject_label *userp)
54742 +{
54743 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
54744 + struct subject_map *match;
54745 +
54746 + match = subj_map_set.s_hash[index];
54747 +
54748 + while (match && match->user != userp)
54749 + match = match->next;
54750 +
54751 + if (match != NULL)
54752 + return match->kernel;
54753 + else
54754 + return NULL;
54755 +}
54756 +
54757 +static void
54758 +insert_subj_map_entry(struct subject_map *subjmap)
54759 +{
54760 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54761 + struct subject_map **curr;
54762 +
54763 + subjmap->prev = NULL;
54764 +
54765 + curr = &subj_map_set.s_hash[index];
54766 + if (*curr != NULL)
54767 + (*curr)->prev = subjmap;
54768 +
54769 + subjmap->next = *curr;
54770 + *curr = subjmap;
54771 +
54772 + return;
54773 +}
54774 +
54775 +static struct acl_role_label *
54776 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54777 + const gid_t gid)
54778 +{
54779 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54780 + struct acl_role_label *match;
54781 + struct role_allowed_ip *ipp;
54782 + unsigned int x;
54783 + u32 curr_ip = task->signal->curr_ip;
54784 +
54785 + task->signal->saved_ip = curr_ip;
54786 +
54787 + match = acl_role_set.r_hash[index];
54788 +
54789 + while (match) {
54790 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54791 + for (x = 0; x < match->domain_child_num; x++) {
54792 + if (match->domain_children[x] == uid)
54793 + goto found;
54794 + }
54795 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54796 + break;
54797 + match = match->next;
54798 + }
54799 +found:
54800 + if (match == NULL) {
54801 + try_group:
54802 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54803 + match = acl_role_set.r_hash[index];
54804 +
54805 + while (match) {
54806 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54807 + for (x = 0; x < match->domain_child_num; x++) {
54808 + if (match->domain_children[x] == gid)
54809 + goto found2;
54810 + }
54811 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54812 + break;
54813 + match = match->next;
54814 + }
54815 +found2:
54816 + if (match == NULL)
54817 + match = default_role;
54818 + if (match->allowed_ips == NULL)
54819 + return match;
54820 + else {
54821 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54822 + if (likely
54823 + ((ntohl(curr_ip) & ipp->netmask) ==
54824 + (ntohl(ipp->addr) & ipp->netmask)))
54825 + return match;
54826 + }
54827 + match = default_role;
54828 + }
54829 + } else if (match->allowed_ips == NULL) {
54830 + return match;
54831 + } else {
54832 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54833 + if (likely
54834 + ((ntohl(curr_ip) & ipp->netmask) ==
54835 + (ntohl(ipp->addr) & ipp->netmask)))
54836 + return match;
54837 + }
54838 + goto try_group;
54839 + }
54840 +
54841 + return match;
54842 +}
54843 +
54844 +struct acl_subject_label *
54845 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54846 + const struct acl_role_label *role)
54847 +{
54848 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54849 + struct acl_subject_label *match;
54850 +
54851 + match = role->subj_hash[index];
54852 +
54853 + while (match && (match->inode != ino || match->device != dev ||
54854 + (match->mode & GR_DELETED))) {
54855 + match = match->next;
54856 + }
54857 +
54858 + if (match && !(match->mode & GR_DELETED))
54859 + return match;
54860 + else
54861 + return NULL;
54862 +}
54863 +
54864 +struct acl_subject_label *
54865 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54866 + const struct acl_role_label *role)
54867 +{
54868 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54869 + struct acl_subject_label *match;
54870 +
54871 + match = role->subj_hash[index];
54872 +
54873 + while (match && (match->inode != ino || match->device != dev ||
54874 + !(match->mode & GR_DELETED))) {
54875 + match = match->next;
54876 + }
54877 +
54878 + if (match && (match->mode & GR_DELETED))
54879 + return match;
54880 + else
54881 + return NULL;
54882 +}
54883 +
54884 +static struct acl_object_label *
54885 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54886 + const struct acl_subject_label *subj)
54887 +{
54888 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54889 + struct acl_object_label *match;
54890 +
54891 + match = subj->obj_hash[index];
54892 +
54893 + while (match && (match->inode != ino || match->device != dev ||
54894 + (match->mode & GR_DELETED))) {
54895 + match = match->next;
54896 + }
54897 +
54898 + if (match && !(match->mode & GR_DELETED))
54899 + return match;
54900 + else
54901 + return NULL;
54902 +}
54903 +
54904 +static struct acl_object_label *
54905 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54906 + const struct acl_subject_label *subj)
54907 +{
54908 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54909 + struct acl_object_label *match;
54910 +
54911 + match = subj->obj_hash[index];
54912 +
54913 + while (match && (match->inode != ino || match->device != dev ||
54914 + !(match->mode & GR_DELETED))) {
54915 + match = match->next;
54916 + }
54917 +
54918 + if (match && (match->mode & GR_DELETED))
54919 + return match;
54920 +
54921 + match = subj->obj_hash[index];
54922 +
54923 + while (match && (match->inode != ino || match->device != dev ||
54924 + (match->mode & GR_DELETED))) {
54925 + match = match->next;
54926 + }
54927 +
54928 + if (match && !(match->mode & GR_DELETED))
54929 + return match;
54930 + else
54931 + return NULL;
54932 +}
54933 +
54934 +static struct name_entry *
54935 +lookup_name_entry(const char *name)
54936 +{
54937 + unsigned int len = strlen(name);
54938 + unsigned int key = full_name_hash(name, len);
54939 + unsigned int index = key % name_set.n_size;
54940 + struct name_entry *match;
54941 +
54942 + match = name_set.n_hash[index];
54943 +
54944 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54945 + match = match->next;
54946 +
54947 + return match;
54948 +}
54949 +
54950 +static struct name_entry *
54951 +lookup_name_entry_create(const char *name)
54952 +{
54953 + unsigned int len = strlen(name);
54954 + unsigned int key = full_name_hash(name, len);
54955 + unsigned int index = key % name_set.n_size;
54956 + struct name_entry *match;
54957 +
54958 + match = name_set.n_hash[index];
54959 +
54960 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54961 + !match->deleted))
54962 + match = match->next;
54963 +
54964 + if (match && match->deleted)
54965 + return match;
54966 +
54967 + match = name_set.n_hash[index];
54968 +
54969 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54970 + match->deleted))
54971 + match = match->next;
54972 +
54973 + if (match && !match->deleted)
54974 + return match;
54975 + else
54976 + return NULL;
54977 +}
54978 +
54979 +static struct inodev_entry *
54980 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
54981 +{
54982 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54983 + struct inodev_entry *match;
54984 +
54985 + match = inodev_set.i_hash[index];
54986 +
54987 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
54988 + match = match->next;
54989 +
54990 + return match;
54991 +}
54992 +
54993 +static void
54994 +insert_inodev_entry(struct inodev_entry *entry)
54995 +{
54996 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
54997 + inodev_set.i_size);
54998 + struct inodev_entry **curr;
54999 +
55000 + entry->prev = NULL;
55001 +
55002 + curr = &inodev_set.i_hash[index];
55003 + if (*curr != NULL)
55004 + (*curr)->prev = entry;
55005 +
55006 + entry->next = *curr;
55007 + *curr = entry;
55008 +
55009 + return;
55010 +}
55011 +
55012 +static void
55013 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
55014 +{
55015 + unsigned int index =
55016 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
55017 + struct acl_role_label **curr;
55018 + struct acl_role_label *tmp, *tmp2;
55019 +
55020 + curr = &acl_role_set.r_hash[index];
55021 +
55022 + /* simple case, slot is empty, just set it to our role */
55023 + if (*curr == NULL) {
55024 + *curr = role;
55025 + } else {
55026 + /* example:
55027 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
55028 + 2 -> 3
55029 + */
55030 + /* first check to see if we can already be reached via this slot */
55031 + tmp = *curr;
55032 + while (tmp && tmp != role)
55033 + tmp = tmp->next;
55034 + if (tmp == role) {
55035 + /* we don't need to add ourselves to this slot's chain */
55036 + return;
55037 + }
55038 + /* we need to add ourselves to this chain, two cases */
55039 + if (role->next == NULL) {
55040 + /* simple case, append the current chain to our role */
55041 + role->next = *curr;
55042 + *curr = role;
55043 + } else {
55044 + /* 1 -> 2 -> 3 -> 4
55045 + 2 -> 3 -> 4
55046 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
55047 + */
55048 + /* trickier case: walk our role's chain until we find
55049 + the role for the start of the current slot's chain */
55050 + tmp = role;
55051 + tmp2 = *curr;
55052 + while (tmp->next && tmp->next != tmp2)
55053 + tmp = tmp->next;
55054 + if (tmp->next == tmp2) {
55055 + /* from example above, we found 3, so just
55056 + replace this slot's chain with ours */
55057 + *curr = role;
55058 + } else {
55059 + /* we didn't find a subset of our role's chain
55060 + in the current slot's chain, so append their
55061 + chain to ours, and set us as the first role in
55062 + the slot's chain
55063 +
55064 + we could fold this case with the case above,
55065 + but making it explicit for clarity
55066 + */
55067 + tmp->next = tmp2;
55068 + *curr = role;
55069 + }
55070 + }
55071 + }
55072 +
55073 + return;
55074 +}
55075 +
55076 +static void
55077 +insert_acl_role_label(struct acl_role_label *role)
55078 +{
55079 + int i;
55080 +
55081 + if (role_list == NULL) {
55082 + role_list = role;
55083 + role->prev = NULL;
55084 + } else {
55085 + role->prev = role_list;
55086 + role_list = role;
55087 + }
55088 +
55089 + /* used for hash chains */
55090 + role->next = NULL;
55091 +
55092 + if (role->roletype & GR_ROLE_DOMAIN) {
55093 + for (i = 0; i < role->domain_child_num; i++)
55094 + __insert_acl_role_label(role, role->domain_children[i]);
55095 + } else
55096 + __insert_acl_role_label(role, role->uidgid);
55097 +}
55098 +
55099 +static int
55100 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
55101 +{
55102 + struct name_entry **curr, *nentry;
55103 + struct inodev_entry *ientry;
55104 + unsigned int len = strlen(name);
55105 + unsigned int key = full_name_hash(name, len);
55106 + unsigned int index = key % name_set.n_size;
55107 +
55108 + curr = &name_set.n_hash[index];
55109 +
55110 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
55111 + curr = &((*curr)->next);
55112 +
55113 + if (*curr != NULL)
55114 + return 1;
55115 +
55116 + nentry = acl_alloc(sizeof (struct name_entry));
55117 + if (nentry == NULL)
55118 + return 0;
55119 + ientry = acl_alloc(sizeof (struct inodev_entry));
55120 + if (ientry == NULL)
55121 + return 0;
55122 + ientry->nentry = nentry;
55123 +
55124 + nentry->key = key;
55125 + nentry->name = name;
55126 + nentry->inode = inode;
55127 + nentry->device = device;
55128 + nentry->len = len;
55129 + nentry->deleted = deleted;
55130 +
55131 + nentry->prev = NULL;
55132 + curr = &name_set.n_hash[index];
55133 + if (*curr != NULL)
55134 + (*curr)->prev = nentry;
55135 + nentry->next = *curr;
55136 + *curr = nentry;
55137 +
55138 + /* insert us into the table searchable by inode/dev */
55139 + insert_inodev_entry(ientry);
55140 +
55141 + return 1;
55142 +}
55143 +
55144 +static void
55145 +insert_acl_obj_label(struct acl_object_label *obj,
55146 + struct acl_subject_label *subj)
55147 +{
55148 + unsigned int index =
55149 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
55150 + struct acl_object_label **curr;
55151 +
55152 +
55153 + obj->prev = NULL;
55154 +
55155 + curr = &subj->obj_hash[index];
55156 + if (*curr != NULL)
55157 + (*curr)->prev = obj;
55158 +
55159 + obj->next = *curr;
55160 + *curr = obj;
55161 +
55162 + return;
55163 +}
55164 +
55165 +static void
55166 +insert_acl_subj_label(struct acl_subject_label *obj,
55167 + struct acl_role_label *role)
55168 +{
55169 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
55170 + struct acl_subject_label **curr;
55171 +
55172 + obj->prev = NULL;
55173 +
55174 + curr = &role->subj_hash[index];
55175 + if (*curr != NULL)
55176 + (*curr)->prev = obj;
55177 +
55178 + obj->next = *curr;
55179 + *curr = obj;
55180 +
55181 + return;
55182 +}
55183 +
55184 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
55185 +
55186 +static void *
55187 +create_table(__u32 * len, int elementsize)
55188 +{
55189 + unsigned int table_sizes[] = {
55190 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
55191 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
55192 + 4194301, 8388593, 16777213, 33554393, 67108859
55193 + };
55194 + void *newtable = NULL;
55195 + unsigned int pwr = 0;
55196 +
55197 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
55198 + table_sizes[pwr] <= *len)
55199 + pwr++;
55200 +
55201 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
55202 + return newtable;
55203 +
55204 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
55205 + newtable =
55206 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
55207 + else
55208 + newtable = vmalloc(table_sizes[pwr] * elementsize);
55209 +
55210 + *len = table_sizes[pwr];
55211 +
55212 + return newtable;
55213 +}
55214 +
55215 +static int
55216 +init_variables(const struct gr_arg *arg)
55217 +{
55218 + struct task_struct *reaper = init_pid_ns.child_reaper;
55219 + unsigned int stacksize;
55220 +
55221 + subj_map_set.s_size = arg->role_db.num_subjects;
55222 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
55223 + name_set.n_size = arg->role_db.num_objects;
55224 + inodev_set.i_size = arg->role_db.num_objects;
55225 +
55226 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
55227 + !name_set.n_size || !inodev_set.i_size)
55228 + return 1;
55229 +
55230 + if (!gr_init_uidset())
55231 + return 1;
55232 +
55233 + /* set up the stack that holds allocation info */
55234 +
55235 + stacksize = arg->role_db.num_pointers + 5;
55236 +
55237 + if (!acl_alloc_stack_init(stacksize))
55238 + return 1;
55239 +
55240 + /* grab reference for the real root dentry and vfsmount */
55241 + get_fs_root(reaper->fs, &real_root);
55242 +
55243 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55244 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
55245 +#endif
55246 +
55247 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
55248 + if (fakefs_obj_rw == NULL)
55249 + return 1;
55250 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
55251 +
55252 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
55253 + if (fakefs_obj_rwx == NULL)
55254 + return 1;
55255 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
55256 +
55257 + subj_map_set.s_hash =
55258 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
55259 + acl_role_set.r_hash =
55260 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
55261 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
55262 + inodev_set.i_hash =
55263 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
55264 +
55265 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
55266 + !name_set.n_hash || !inodev_set.i_hash)
55267 + return 1;
55268 +
55269 + memset(subj_map_set.s_hash, 0,
55270 + sizeof(struct subject_map *) * subj_map_set.s_size);
55271 + memset(acl_role_set.r_hash, 0,
55272 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
55273 + memset(name_set.n_hash, 0,
55274 + sizeof (struct name_entry *) * name_set.n_size);
55275 + memset(inodev_set.i_hash, 0,
55276 + sizeof (struct inodev_entry *) * inodev_set.i_size);
55277 +
55278 + return 0;
55279 +}
55280 +
55281 +/* free information not needed after startup
55282 + currently contains user->kernel pointer mappings for subjects
55283 +*/
55284 +
55285 +static void
55286 +free_init_variables(void)
55287 +{
55288 + __u32 i;
55289 +
55290 + if (subj_map_set.s_hash) {
55291 + for (i = 0; i < subj_map_set.s_size; i++) {
55292 + if (subj_map_set.s_hash[i]) {
55293 + kfree(subj_map_set.s_hash[i]);
55294 + subj_map_set.s_hash[i] = NULL;
55295 + }
55296 + }
55297 +
55298 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
55299 + PAGE_SIZE)
55300 + kfree(subj_map_set.s_hash);
55301 + else
55302 + vfree(subj_map_set.s_hash);
55303 + }
55304 +
55305 + return;
55306 +}
55307 +
55308 +static void
55309 +free_variables(void)
55310 +{
55311 + struct acl_subject_label *s;
55312 + struct acl_role_label *r;
55313 + struct task_struct *task, *task2;
55314 + unsigned int x;
55315 +
55316 + gr_clear_learn_entries();
55317 +
55318 + read_lock(&tasklist_lock);
55319 + do_each_thread(task2, task) {
55320 + task->acl_sp_role = 0;
55321 + task->acl_role_id = 0;
55322 + task->acl = NULL;
55323 + task->role = NULL;
55324 + } while_each_thread(task2, task);
55325 + read_unlock(&tasklist_lock);
55326 +
55327 + /* release the reference to the real root dentry and vfsmount */
55328 + path_put(&real_root);
55329 + memset(&real_root, 0, sizeof(real_root));
55330 +
55331 + /* free all object hash tables */
55332 +
55333 + FOR_EACH_ROLE_START(r)
55334 + if (r->subj_hash == NULL)
55335 + goto next_role;
55336 + FOR_EACH_SUBJECT_START(r, s, x)
55337 + if (s->obj_hash == NULL)
55338 + break;
55339 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55340 + kfree(s->obj_hash);
55341 + else
55342 + vfree(s->obj_hash);
55343 + FOR_EACH_SUBJECT_END(s, x)
55344 + FOR_EACH_NESTED_SUBJECT_START(r, s)
55345 + if (s->obj_hash == NULL)
55346 + break;
55347 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55348 + kfree(s->obj_hash);
55349 + else
55350 + vfree(s->obj_hash);
55351 + FOR_EACH_NESTED_SUBJECT_END(s)
55352 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
55353 + kfree(r->subj_hash);
55354 + else
55355 + vfree(r->subj_hash);
55356 + r->subj_hash = NULL;
55357 +next_role:
55358 + FOR_EACH_ROLE_END(r)
55359 +
55360 + acl_free_all();
55361 +
55362 + if (acl_role_set.r_hash) {
55363 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
55364 + PAGE_SIZE)
55365 + kfree(acl_role_set.r_hash);
55366 + else
55367 + vfree(acl_role_set.r_hash);
55368 + }
55369 + if (name_set.n_hash) {
55370 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
55371 + PAGE_SIZE)
55372 + kfree(name_set.n_hash);
55373 + else
55374 + vfree(name_set.n_hash);
55375 + }
55376 +
55377 + if (inodev_set.i_hash) {
55378 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
55379 + PAGE_SIZE)
55380 + kfree(inodev_set.i_hash);
55381 + else
55382 + vfree(inodev_set.i_hash);
55383 + }
55384 +
55385 + gr_free_uidset();
55386 +
55387 + memset(&name_set, 0, sizeof (struct name_db));
55388 + memset(&inodev_set, 0, sizeof (struct inodev_db));
55389 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
55390 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
55391 +
55392 + default_role = NULL;
55393 + kernel_role = NULL;
55394 + role_list = NULL;
55395 +
55396 + return;
55397 +}
55398 +
55399 +static __u32
55400 +count_user_objs(struct acl_object_label *userp)
55401 +{
55402 + struct acl_object_label o_tmp;
55403 + __u32 num = 0;
55404 +
55405 + while (userp) {
55406 + if (copy_from_user(&o_tmp, userp,
55407 + sizeof (struct acl_object_label)))
55408 + break;
55409 +
55410 + userp = o_tmp.prev;
55411 + num++;
55412 + }
55413 +
55414 + return num;
55415 +}
55416 +
55417 +static struct acl_subject_label *
55418 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
55419 +
55420 +static int
55421 +copy_user_glob(struct acl_object_label *obj)
55422 +{
55423 + struct acl_object_label *g_tmp, **guser;
55424 + unsigned int len;
55425 + char *tmp;
55426 +
55427 + if (obj->globbed == NULL)
55428 + return 0;
55429 +
55430 + guser = &obj->globbed;
55431 + while (*guser) {
55432 + g_tmp = (struct acl_object_label *)
55433 + acl_alloc(sizeof (struct acl_object_label));
55434 + if (g_tmp == NULL)
55435 + return -ENOMEM;
55436 +
55437 + if (copy_from_user(g_tmp, *guser,
55438 + sizeof (struct acl_object_label)))
55439 + return -EFAULT;
55440 +
55441 + len = strnlen_user(g_tmp->filename, PATH_MAX);
55442 +
55443 + if (!len || len >= PATH_MAX)
55444 + return -EINVAL;
55445 +
55446 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55447 + return -ENOMEM;
55448 +
55449 + if (copy_from_user(tmp, g_tmp->filename, len))
55450 + return -EFAULT;
55451 + tmp[len-1] = '\0';
55452 + g_tmp->filename = tmp;
55453 +
55454 + *guser = g_tmp;
55455 + guser = &(g_tmp->next);
55456 + }
55457 +
55458 + return 0;
55459 +}
55460 +
55461 +static int
55462 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
55463 + struct acl_role_label *role)
55464 +{
55465 + struct acl_object_label *o_tmp;
55466 + unsigned int len;
55467 + int ret;
55468 + char *tmp;
55469 +
55470 + while (userp) {
55471 + if ((o_tmp = (struct acl_object_label *)
55472 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
55473 + return -ENOMEM;
55474 +
55475 + if (copy_from_user(o_tmp, userp,
55476 + sizeof (struct acl_object_label)))
55477 + return -EFAULT;
55478 +
55479 + userp = o_tmp->prev;
55480 +
55481 + len = strnlen_user(o_tmp->filename, PATH_MAX);
55482 +
55483 + if (!len || len >= PATH_MAX)
55484 + return -EINVAL;
55485 +
55486 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55487 + return -ENOMEM;
55488 +
55489 + if (copy_from_user(tmp, o_tmp->filename, len))
55490 + return -EFAULT;
55491 + tmp[len-1] = '\0';
55492 + o_tmp->filename = tmp;
55493 +
55494 + insert_acl_obj_label(o_tmp, subj);
55495 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
55496 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
55497 + return -ENOMEM;
55498 +
55499 + ret = copy_user_glob(o_tmp);
55500 + if (ret)
55501 + return ret;
55502 +
55503 + if (o_tmp->nested) {
55504 + int already_copied;
55505 +
55506 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
55507 + if (IS_ERR(o_tmp->nested))
55508 + return PTR_ERR(o_tmp->nested);
55509 +
55510 + /* insert into nested subject list if we haven't copied this one yet
55511 + to prevent duplicate entries */
55512 + if (!already_copied) {
55513 + o_tmp->nested->next = role->hash->first;
55514 + role->hash->first = o_tmp->nested;
55515 + }
55516 + }
55517 + }
55518 +
55519 + return 0;
55520 +}
55521 +
55522 +static __u32
55523 +count_user_subjs(struct acl_subject_label *userp)
55524 +{
55525 + struct acl_subject_label s_tmp;
55526 + __u32 num = 0;
55527 +
55528 + while (userp) {
55529 + if (copy_from_user(&s_tmp, userp,
55530 + sizeof (struct acl_subject_label)))
55531 + break;
55532 +
55533 + userp = s_tmp.prev;
55534 + }
55535 +
55536 + return num;
55537 +}
55538 +
55539 +static int
55540 +copy_user_allowedips(struct acl_role_label *rolep)
55541 +{
55542 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
55543 +
55544 + ruserip = rolep->allowed_ips;
55545 +
55546 + while (ruserip) {
55547 + rlast = rtmp;
55548 +
55549 + if ((rtmp = (struct role_allowed_ip *)
55550 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
55551 + return -ENOMEM;
55552 +
55553 + if (copy_from_user(rtmp, ruserip,
55554 + sizeof (struct role_allowed_ip)))
55555 + return -EFAULT;
55556 +
55557 + ruserip = rtmp->prev;
55558 +
55559 + if (!rlast) {
55560 + rtmp->prev = NULL;
55561 + rolep->allowed_ips = rtmp;
55562 + } else {
55563 + rlast->next = rtmp;
55564 + rtmp->prev = rlast;
55565 + }
55566 +
55567 + if (!ruserip)
55568 + rtmp->next = NULL;
55569 + }
55570 +
55571 + return 0;
55572 +}
55573 +
55574 +static int
55575 +copy_user_transitions(struct acl_role_label *rolep)
55576 +{
55577 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
55578 +
55579 + unsigned int len;
55580 + char *tmp;
55581 +
55582 + rusertp = rolep->transitions;
55583 +
55584 + while (rusertp) {
55585 + rlast = rtmp;
55586 +
55587 + if ((rtmp = (struct role_transition *)
55588 + acl_alloc(sizeof (struct role_transition))) == NULL)
55589 + return -ENOMEM;
55590 +
55591 + if (copy_from_user(rtmp, rusertp,
55592 + sizeof (struct role_transition)))
55593 + return -EFAULT;
55594 +
55595 + rusertp = rtmp->prev;
55596 +
55597 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
55598 +
55599 + if (!len || len >= GR_SPROLE_LEN)
55600 + return -EINVAL;
55601 +
55602 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55603 + return -ENOMEM;
55604 +
55605 + if (copy_from_user(tmp, rtmp->rolename, len))
55606 + return -EFAULT;
55607 + tmp[len-1] = '\0';
55608 + rtmp->rolename = tmp;
55609 +
55610 + if (!rlast) {
55611 + rtmp->prev = NULL;
55612 + rolep->transitions = rtmp;
55613 + } else {
55614 + rlast->next = rtmp;
55615 + rtmp->prev = rlast;
55616 + }
55617 +
55618 + if (!rusertp)
55619 + rtmp->next = NULL;
55620 + }
55621 +
55622 + return 0;
55623 +}
55624 +
55625 +static struct acl_subject_label *
55626 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
55627 +{
55628 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
55629 + unsigned int len;
55630 + char *tmp;
55631 + __u32 num_objs;
55632 + struct acl_ip_label **i_tmp, *i_utmp2;
55633 + struct gr_hash_struct ghash;
55634 + struct subject_map *subjmap;
55635 + unsigned int i_num;
55636 + int err;
55637 +
55638 + if (already_copied != NULL)
55639 + *already_copied = 0;
55640 +
55641 + s_tmp = lookup_subject_map(userp);
55642 +
55643 + /* we've already copied this subject into the kernel, just return
55644 + the reference to it, and don't copy it over again
55645 + */
55646 + if (s_tmp) {
55647 + if (already_copied != NULL)
55648 + *already_copied = 1;
55649 + return(s_tmp);
55650 + }
55651 +
55652 + if ((s_tmp = (struct acl_subject_label *)
55653 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
55654 + return ERR_PTR(-ENOMEM);
55655 +
55656 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
55657 + if (subjmap == NULL)
55658 + return ERR_PTR(-ENOMEM);
55659 +
55660 + subjmap->user = userp;
55661 + subjmap->kernel = s_tmp;
55662 + insert_subj_map_entry(subjmap);
55663 +
55664 + if (copy_from_user(s_tmp, userp,
55665 + sizeof (struct acl_subject_label)))
55666 + return ERR_PTR(-EFAULT);
55667 +
55668 + len = strnlen_user(s_tmp->filename, PATH_MAX);
55669 +
55670 + if (!len || len >= PATH_MAX)
55671 + return ERR_PTR(-EINVAL);
55672 +
55673 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55674 + return ERR_PTR(-ENOMEM);
55675 +
55676 + if (copy_from_user(tmp, s_tmp->filename, len))
55677 + return ERR_PTR(-EFAULT);
55678 + tmp[len-1] = '\0';
55679 + s_tmp->filename = tmp;
55680 +
55681 + if (!strcmp(s_tmp->filename, "/"))
55682 + role->root_label = s_tmp;
55683 +
55684 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55685 + return ERR_PTR(-EFAULT);
55686 +
55687 + /* copy user and group transition tables */
55688 +
55689 + if (s_tmp->user_trans_num) {
55690 + uid_t *uidlist;
55691 +
55692 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55693 + if (uidlist == NULL)
55694 + return ERR_PTR(-ENOMEM);
55695 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55696 + return ERR_PTR(-EFAULT);
55697 +
55698 + s_tmp->user_transitions = uidlist;
55699 + }
55700 +
55701 + if (s_tmp->group_trans_num) {
55702 + gid_t *gidlist;
55703 +
55704 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55705 + if (gidlist == NULL)
55706 + return ERR_PTR(-ENOMEM);
55707 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55708 + return ERR_PTR(-EFAULT);
55709 +
55710 + s_tmp->group_transitions = gidlist;
55711 + }
55712 +
55713 + /* set up object hash table */
55714 + num_objs = count_user_objs(ghash.first);
55715 +
55716 + s_tmp->obj_hash_size = num_objs;
55717 + s_tmp->obj_hash =
55718 + (struct acl_object_label **)
55719 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55720 +
55721 + if (!s_tmp->obj_hash)
55722 + return ERR_PTR(-ENOMEM);
55723 +
55724 + memset(s_tmp->obj_hash, 0,
55725 + s_tmp->obj_hash_size *
55726 + sizeof (struct acl_object_label *));
55727 +
55728 + /* add in objects */
55729 + err = copy_user_objs(ghash.first, s_tmp, role);
55730 +
55731 + if (err)
55732 + return ERR_PTR(err);
55733 +
55734 + /* set pointer for parent subject */
55735 + if (s_tmp->parent_subject) {
55736 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55737 +
55738 + if (IS_ERR(s_tmp2))
55739 + return s_tmp2;
55740 +
55741 + s_tmp->parent_subject = s_tmp2;
55742 + }
55743 +
55744 + /* add in ip acls */
55745 +
55746 + if (!s_tmp->ip_num) {
55747 + s_tmp->ips = NULL;
55748 + goto insert;
55749 + }
55750 +
55751 + i_tmp =
55752 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55753 + sizeof (struct acl_ip_label *));
55754 +
55755 + if (!i_tmp)
55756 + return ERR_PTR(-ENOMEM);
55757 +
55758 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55759 + *(i_tmp + i_num) =
55760 + (struct acl_ip_label *)
55761 + acl_alloc(sizeof (struct acl_ip_label));
55762 + if (!*(i_tmp + i_num))
55763 + return ERR_PTR(-ENOMEM);
55764 +
55765 + if (copy_from_user
55766 + (&i_utmp2, s_tmp->ips + i_num,
55767 + sizeof (struct acl_ip_label *)))
55768 + return ERR_PTR(-EFAULT);
55769 +
55770 + if (copy_from_user
55771 + (*(i_tmp + i_num), i_utmp2,
55772 + sizeof (struct acl_ip_label)))
55773 + return ERR_PTR(-EFAULT);
55774 +
55775 + if ((*(i_tmp + i_num))->iface == NULL)
55776 + continue;
55777 +
55778 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55779 + if (!len || len >= IFNAMSIZ)
55780 + return ERR_PTR(-EINVAL);
55781 + tmp = acl_alloc(len);
55782 + if (tmp == NULL)
55783 + return ERR_PTR(-ENOMEM);
55784 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55785 + return ERR_PTR(-EFAULT);
55786 + (*(i_tmp + i_num))->iface = tmp;
55787 + }
55788 +
55789 + s_tmp->ips = i_tmp;
55790 +
55791 +insert:
55792 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55793 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55794 + return ERR_PTR(-ENOMEM);
55795 +
55796 + return s_tmp;
55797 +}
55798 +
55799 +static int
55800 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55801 +{
55802 + struct acl_subject_label s_pre;
55803 + struct acl_subject_label * ret;
55804 + int err;
55805 +
55806 + while (userp) {
55807 + if (copy_from_user(&s_pre, userp,
55808 + sizeof (struct acl_subject_label)))
55809 + return -EFAULT;
55810 +
55811 + ret = do_copy_user_subj(userp, role, NULL);
55812 +
55813 + err = PTR_ERR(ret);
55814 + if (IS_ERR(ret))
55815 + return err;
55816 +
55817 + insert_acl_subj_label(ret, role);
55818 +
55819 + userp = s_pre.prev;
55820 + }
55821 +
55822 + return 0;
55823 +}
55824 +
55825 +static int
55826 +copy_user_acl(struct gr_arg *arg)
55827 +{
55828 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55829 + struct acl_subject_label *subj_list;
55830 + struct sprole_pw *sptmp;
55831 + struct gr_hash_struct *ghash;
55832 + uid_t *domainlist;
55833 + unsigned int r_num;
55834 + unsigned int len;
55835 + char *tmp;
55836 + int err = 0;
55837 + __u16 i;
55838 + __u32 num_subjs;
55839 +
55840 + /* we need a default and kernel role */
55841 + if (arg->role_db.num_roles < 2)
55842 + return -EINVAL;
55843 +
55844 + /* copy special role authentication info from userspace */
55845 +
55846 + num_sprole_pws = arg->num_sprole_pws;
55847 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55848 +
55849 + if (!acl_special_roles && num_sprole_pws)
55850 + return -ENOMEM;
55851 +
55852 + for (i = 0; i < num_sprole_pws; i++) {
55853 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55854 + if (!sptmp)
55855 + return -ENOMEM;
55856 + if (copy_from_user(sptmp, arg->sprole_pws + i,
55857 + sizeof (struct sprole_pw)))
55858 + return -EFAULT;
55859 +
55860 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55861 +
55862 + if (!len || len >= GR_SPROLE_LEN)
55863 + return -EINVAL;
55864 +
55865 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55866 + return -ENOMEM;
55867 +
55868 + if (copy_from_user(tmp, sptmp->rolename, len))
55869 + return -EFAULT;
55870 +
55871 + tmp[len-1] = '\0';
55872 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55873 + printk(KERN_ALERT "Copying special role %s\n", tmp);
55874 +#endif
55875 + sptmp->rolename = tmp;
55876 + acl_special_roles[i] = sptmp;
55877 + }
55878 +
55879 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55880 +
55881 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55882 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
55883 +
55884 + if (!r_tmp)
55885 + return -ENOMEM;
55886 +
55887 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
55888 + sizeof (struct acl_role_label *)))
55889 + return -EFAULT;
55890 +
55891 + if (copy_from_user(r_tmp, r_utmp2,
55892 + sizeof (struct acl_role_label)))
55893 + return -EFAULT;
55894 +
55895 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55896 +
55897 + if (!len || len >= PATH_MAX)
55898 + return -EINVAL;
55899 +
55900 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55901 + return -ENOMEM;
55902 +
55903 + if (copy_from_user(tmp, r_tmp->rolename, len))
55904 + return -EFAULT;
55905 +
55906 + tmp[len-1] = '\0';
55907 + r_tmp->rolename = tmp;
55908 +
55909 + if (!strcmp(r_tmp->rolename, "default")
55910 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55911 + default_role = r_tmp;
55912 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55913 + kernel_role = r_tmp;
55914 + }
55915 +
55916 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55917 + return -ENOMEM;
55918 +
55919 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55920 + return -EFAULT;
55921 +
55922 + r_tmp->hash = ghash;
55923 +
55924 + num_subjs = count_user_subjs(r_tmp->hash->first);
55925 +
55926 + r_tmp->subj_hash_size = num_subjs;
55927 + r_tmp->subj_hash =
55928 + (struct acl_subject_label **)
55929 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55930 +
55931 + if (!r_tmp->subj_hash)
55932 + return -ENOMEM;
55933 +
55934 + err = copy_user_allowedips(r_tmp);
55935 + if (err)
55936 + return err;
55937 +
55938 + /* copy domain info */
55939 + if (r_tmp->domain_children != NULL) {
55940 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55941 + if (domainlist == NULL)
55942 + return -ENOMEM;
55943 +
55944 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55945 + return -EFAULT;
55946 +
55947 + r_tmp->domain_children = domainlist;
55948 + }
55949 +
55950 + err = copy_user_transitions(r_tmp);
55951 + if (err)
55952 + return err;
55953 +
55954 + memset(r_tmp->subj_hash, 0,
55955 + r_tmp->subj_hash_size *
55956 + sizeof (struct acl_subject_label *));
55957 +
55958 + /* acquire the list of subjects, then NULL out
55959 + the list prior to parsing the subjects for this role,
55960 + as during this parsing the list is replaced with a list
55961 + of *nested* subjects for the role
55962 + */
55963 + subj_list = r_tmp->hash->first;
55964 +
55965 + /* set nested subject list to null */
55966 + r_tmp->hash->first = NULL;
55967 +
55968 + err = copy_user_subjs(subj_list, r_tmp);
55969 +
55970 + if (err)
55971 + return err;
55972 +
55973 + insert_acl_role_label(r_tmp);
55974 + }
55975 +
55976 + if (default_role == NULL || kernel_role == NULL)
55977 + return -EINVAL;
55978 +
55979 + return err;
55980 +}
55981 +
55982 +static int
55983 +gracl_init(struct gr_arg *args)
55984 +{
55985 + int error = 0;
55986 +
55987 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
55988 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
55989 +
55990 + if (init_variables(args)) {
55991 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
55992 + error = -ENOMEM;
55993 + free_variables();
55994 + goto out;
55995 + }
55996 +
55997 + error = copy_user_acl(args);
55998 + free_init_variables();
55999 + if (error) {
56000 + free_variables();
56001 + goto out;
56002 + }
56003 +
56004 + if ((error = gr_set_acls(0))) {
56005 + free_variables();
56006 + goto out;
56007 + }
56008 +
56009 + pax_open_kernel();
56010 + gr_status |= GR_READY;
56011 + pax_close_kernel();
56012 +
56013 + out:
56014 + return error;
56015 +}
56016 +
56017 +/* derived from glibc fnmatch() 0: match, 1: no match*/
56018 +
56019 +static int
56020 +glob_match(const char *p, const char *n)
56021 +{
56022 + char c;
56023 +
56024 + while ((c = *p++) != '\0') {
56025 + switch (c) {
56026 + case '?':
56027 + if (*n == '\0')
56028 + return 1;
56029 + else if (*n == '/')
56030 + return 1;
56031 + break;
56032 + case '\\':
56033 + if (*n != c)
56034 + return 1;
56035 + break;
56036 + case '*':
56037 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
56038 + if (*n == '/')
56039 + return 1;
56040 + else if (c == '?') {
56041 + if (*n == '\0')
56042 + return 1;
56043 + else
56044 + ++n;
56045 + }
56046 + }
56047 + if (c == '\0') {
56048 + return 0;
56049 + } else {
56050 + const char *endp;
56051 +
56052 + if ((endp = strchr(n, '/')) == NULL)
56053 + endp = n + strlen(n);
56054 +
56055 + if (c == '[') {
56056 + for (--p; n < endp; ++n)
56057 + if (!glob_match(p, n))
56058 + return 0;
56059 + } else if (c == '/') {
56060 + while (*n != '\0' && *n != '/')
56061 + ++n;
56062 + if (*n == '/' && !glob_match(p, n + 1))
56063 + return 0;
56064 + } else {
56065 + for (--p; n < endp; ++n)
56066 + if (*n == c && !glob_match(p, n))
56067 + return 0;
56068 + }
56069 +
56070 + return 1;
56071 + }
56072 + case '[':
56073 + {
56074 + int not;
56075 + char cold;
56076 +
56077 + if (*n == '\0' || *n == '/')
56078 + return 1;
56079 +
56080 + not = (*p == '!' || *p == '^');
56081 + if (not)
56082 + ++p;
56083 +
56084 + c = *p++;
56085 + for (;;) {
56086 + unsigned char fn = (unsigned char)*n;
56087 +
56088 + if (c == '\0')
56089 + return 1;
56090 + else {
56091 + if (c == fn)
56092 + goto matched;
56093 + cold = c;
56094 + c = *p++;
56095 +
56096 + if (c == '-' && *p != ']') {
56097 + unsigned char cend = *p++;
56098 +
56099 + if (cend == '\0')
56100 + return 1;
56101 +
56102 + if (cold <= fn && fn <= cend)
56103 + goto matched;
56104 +
56105 + c = *p++;
56106 + }
56107 + }
56108 +
56109 + if (c == ']')
56110 + break;
56111 + }
56112 + if (!not)
56113 + return 1;
56114 + break;
56115 + matched:
56116 + while (c != ']') {
56117 + if (c == '\0')
56118 + return 1;
56119 +
56120 + c = *p++;
56121 + }
56122 + if (not)
56123 + return 1;
56124 + }
56125 + break;
56126 + default:
56127 + if (c != *n)
56128 + return 1;
56129 + }
56130 +
56131 + ++n;
56132 + }
56133 +
56134 + if (*n == '\0')
56135 + return 0;
56136 +
56137 + if (*n == '/')
56138 + return 0;
56139 +
56140 + return 1;
56141 +}
56142 +
56143 +static struct acl_object_label *
56144 +chk_glob_label(struct acl_object_label *globbed,
56145 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
56146 +{
56147 + struct acl_object_label *tmp;
56148 +
56149 + if (*path == NULL)
56150 + *path = gr_to_filename_nolock(dentry, mnt);
56151 +
56152 + tmp = globbed;
56153 +
56154 + while (tmp) {
56155 + if (!glob_match(tmp->filename, *path))
56156 + return tmp;
56157 + tmp = tmp->next;
56158 + }
56159 +
56160 + return NULL;
56161 +}
56162 +
56163 +static struct acl_object_label *
56164 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56165 + const ino_t curr_ino, const dev_t curr_dev,
56166 + const struct acl_subject_label *subj, char **path, const int checkglob)
56167 +{
56168 + struct acl_subject_label *tmpsubj;
56169 + struct acl_object_label *retval;
56170 + struct acl_object_label *retval2;
56171 +
56172 + tmpsubj = (struct acl_subject_label *) subj;
56173 + read_lock(&gr_inode_lock);
56174 + do {
56175 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
56176 + if (retval) {
56177 + if (checkglob && retval->globbed) {
56178 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
56179 + if (retval2)
56180 + retval = retval2;
56181 + }
56182 + break;
56183 + }
56184 + } while ((tmpsubj = tmpsubj->parent_subject));
56185 + read_unlock(&gr_inode_lock);
56186 +
56187 + return retval;
56188 +}
56189 +
56190 +static __inline__ struct acl_object_label *
56191 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56192 + struct dentry *curr_dentry,
56193 + const struct acl_subject_label *subj, char **path, const int checkglob)
56194 +{
56195 + int newglob = checkglob;
56196 + ino_t inode;
56197 + dev_t device;
56198 +
56199 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
56200 + as we don't want a / * rule to match instead of the / object
56201 + don't do this for create lookups that call this function though, since they're looking up
56202 + on the parent and thus need globbing checks on all paths
56203 + */
56204 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
56205 + newglob = GR_NO_GLOB;
56206 +
56207 + spin_lock(&curr_dentry->d_lock);
56208 + inode = curr_dentry->d_inode->i_ino;
56209 + device = __get_dev(curr_dentry);
56210 + spin_unlock(&curr_dentry->d_lock);
56211 +
56212 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
56213 +}
56214 +
56215 +#ifdef CONFIG_HUGETLBFS
56216 +static inline bool
56217 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
56218 +{
56219 + int i;
56220 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
56221 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
56222 + return true;
56223 + }
56224 +
56225 + return false;
56226 +}
56227 +#endif
56228 +
56229 +static struct acl_object_label *
56230 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56231 + const struct acl_subject_label *subj, char *path, const int checkglob)
56232 +{
56233 + struct dentry *dentry = (struct dentry *) l_dentry;
56234 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56235 + struct mount *real_mnt = real_mount(mnt);
56236 + struct acl_object_label *retval;
56237 + struct dentry *parent;
56238 +
56239 + write_seqlock(&rename_lock);
56240 + br_read_lock(&vfsmount_lock);
56241 +
56242 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
56243 +#ifdef CONFIG_NET
56244 + mnt == sock_mnt ||
56245 +#endif
56246 +#ifdef CONFIG_HUGETLBFS
56247 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
56248 +#endif
56249 + /* ignore Eric Biederman */
56250 + IS_PRIVATE(l_dentry->d_inode))) {
56251 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
56252 + goto out;
56253 + }
56254 +
56255 + for (;;) {
56256 + if (dentry == real_root.dentry && mnt == real_root.mnt)
56257 + break;
56258 +
56259 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56260 + if (!mnt_has_parent(real_mnt))
56261 + break;
56262 +
56263 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56264 + if (retval != NULL)
56265 + goto out;
56266 +
56267 + dentry = real_mnt->mnt_mountpoint;
56268 + real_mnt = real_mnt->mnt_parent;
56269 + mnt = &real_mnt->mnt;
56270 + continue;
56271 + }
56272 +
56273 + parent = dentry->d_parent;
56274 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56275 + if (retval != NULL)
56276 + goto out;
56277 +
56278 + dentry = parent;
56279 + }
56280 +
56281 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56282 +
56283 + /* real_root is pinned so we don't have to hold a reference */
56284 + if (retval == NULL)
56285 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
56286 +out:
56287 + br_read_unlock(&vfsmount_lock);
56288 + write_sequnlock(&rename_lock);
56289 +
56290 + BUG_ON(retval == NULL);
56291 +
56292 + return retval;
56293 +}
56294 +
56295 +static __inline__ struct acl_object_label *
56296 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56297 + const struct acl_subject_label *subj)
56298 +{
56299 + char *path = NULL;
56300 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
56301 +}
56302 +
56303 +static __inline__ struct acl_object_label *
56304 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56305 + const struct acl_subject_label *subj)
56306 +{
56307 + char *path = NULL;
56308 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
56309 +}
56310 +
56311 +static __inline__ struct acl_object_label *
56312 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56313 + const struct acl_subject_label *subj, char *path)
56314 +{
56315 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
56316 +}
56317 +
56318 +static struct acl_subject_label *
56319 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56320 + const struct acl_role_label *role)
56321 +{
56322 + struct dentry *dentry = (struct dentry *) l_dentry;
56323 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56324 + struct mount *real_mnt = real_mount(mnt);
56325 + struct acl_subject_label *retval;
56326 + struct dentry *parent;
56327 +
56328 + write_seqlock(&rename_lock);
56329 + br_read_lock(&vfsmount_lock);
56330 +
56331 + for (;;) {
56332 + if (dentry == real_root.dentry && mnt == real_root.mnt)
56333 + break;
56334 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56335 + if (!mnt_has_parent(real_mnt))
56336 + break;
56337 +
56338 + spin_lock(&dentry->d_lock);
56339 + read_lock(&gr_inode_lock);
56340 + retval =
56341 + lookup_acl_subj_label(dentry->d_inode->i_ino,
56342 + __get_dev(dentry), role);
56343 + read_unlock(&gr_inode_lock);
56344 + spin_unlock(&dentry->d_lock);
56345 + if (retval != NULL)
56346 + goto out;
56347 +
56348 + dentry = real_mnt->mnt_mountpoint;
56349 + real_mnt = real_mnt->mnt_parent;
56350 + mnt = &real_mnt->mnt;
56351 + continue;
56352 + }
56353 +
56354 + spin_lock(&dentry->d_lock);
56355 + read_lock(&gr_inode_lock);
56356 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56357 + __get_dev(dentry), role);
56358 + read_unlock(&gr_inode_lock);
56359 + parent = dentry->d_parent;
56360 + spin_unlock(&dentry->d_lock);
56361 +
56362 + if (retval != NULL)
56363 + goto out;
56364 +
56365 + dentry = parent;
56366 + }
56367 +
56368 + spin_lock(&dentry->d_lock);
56369 + read_lock(&gr_inode_lock);
56370 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56371 + __get_dev(dentry), role);
56372 + read_unlock(&gr_inode_lock);
56373 + spin_unlock(&dentry->d_lock);
56374 +
56375 + if (unlikely(retval == NULL)) {
56376 + /* real_root is pinned, we don't need to hold a reference */
56377 + read_lock(&gr_inode_lock);
56378 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
56379 + __get_dev(real_root.dentry), role);
56380 + read_unlock(&gr_inode_lock);
56381 + }
56382 +out:
56383 + br_read_unlock(&vfsmount_lock);
56384 + write_sequnlock(&rename_lock);
56385 +
56386 + BUG_ON(retval == NULL);
56387 +
56388 + return retval;
56389 +}
56390 +
56391 +static void
56392 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
56393 +{
56394 + struct task_struct *task = current;
56395 + const struct cred *cred = current_cred();
56396 +
56397 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
56398 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56399 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56400 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
56401 +
56402 + return;
56403 +}
56404 +
56405 +static void
56406 +gr_log_learn_id_change(const char type, const unsigned int real,
56407 + const unsigned int effective, const unsigned int fs)
56408 +{
56409 + struct task_struct *task = current;
56410 + const struct cred *cred = current_cred();
56411 +
56412 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
56413 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56414 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56415 + type, real, effective, fs, &task->signal->saved_ip);
56416 +
56417 + return;
56418 +}
56419 +
56420 +__u32
56421 +gr_search_file(const struct dentry * dentry, const __u32 mode,
56422 + const struct vfsmount * mnt)
56423 +{
56424 + __u32 retval = mode;
56425 + struct acl_subject_label *curracl;
56426 + struct acl_object_label *currobj;
56427 +
56428 + if (unlikely(!(gr_status & GR_READY)))
56429 + return (mode & ~GR_AUDITS);
56430 +
56431 + curracl = current->acl;
56432 +
56433 + currobj = chk_obj_label(dentry, mnt, curracl);
56434 + retval = currobj->mode & mode;
56435 +
56436 + /* if we're opening a specified transfer file for writing
56437 + (e.g. /dev/initctl), then transfer our role to init
56438 + */
56439 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
56440 + current->role->roletype & GR_ROLE_PERSIST)) {
56441 + struct task_struct *task = init_pid_ns.child_reaper;
56442 +
56443 + if (task->role != current->role) {
56444 + task->acl_sp_role = 0;
56445 + task->acl_role_id = current->acl_role_id;
56446 + task->role = current->role;
56447 + rcu_read_lock();
56448 + read_lock(&grsec_exec_file_lock);
56449 + gr_apply_subject_to_task(task);
56450 + read_unlock(&grsec_exec_file_lock);
56451 + rcu_read_unlock();
56452 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
56453 + }
56454 + }
56455 +
56456 + if (unlikely
56457 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
56458 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
56459 + __u32 new_mode = mode;
56460 +
56461 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56462 +
56463 + retval = new_mode;
56464 +
56465 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
56466 + new_mode |= GR_INHERIT;
56467 +
56468 + if (!(mode & GR_NOLEARN))
56469 + gr_log_learn(dentry, mnt, new_mode);
56470 + }
56471 +
56472 + return retval;
56473 +}
56474 +
56475 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
56476 + const struct dentry *parent,
56477 + const struct vfsmount *mnt)
56478 +{
56479 + struct name_entry *match;
56480 + struct acl_object_label *matchpo;
56481 + struct acl_subject_label *curracl;
56482 + char *path;
56483 +
56484 + if (unlikely(!(gr_status & GR_READY)))
56485 + return NULL;
56486 +
56487 + preempt_disable();
56488 + path = gr_to_filename_rbac(new_dentry, mnt);
56489 + match = lookup_name_entry_create(path);
56490 +
56491 + curracl = current->acl;
56492 +
56493 + if (match) {
56494 + read_lock(&gr_inode_lock);
56495 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
56496 + read_unlock(&gr_inode_lock);
56497 +
56498 + if (matchpo) {
56499 + preempt_enable();
56500 + return matchpo;
56501 + }
56502 + }
56503 +
56504 + // lookup parent
56505 +
56506 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
56507 +
56508 + preempt_enable();
56509 + return matchpo;
56510 +}
56511 +
56512 +__u32
56513 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
56514 + const struct vfsmount * mnt, const __u32 mode)
56515 +{
56516 + struct acl_object_label *matchpo;
56517 + __u32 retval;
56518 +
56519 + if (unlikely(!(gr_status & GR_READY)))
56520 + return (mode & ~GR_AUDITS);
56521 +
56522 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
56523 +
56524 + retval = matchpo->mode & mode;
56525 +
56526 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
56527 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56528 + __u32 new_mode = mode;
56529 +
56530 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56531 +
56532 + gr_log_learn(new_dentry, mnt, new_mode);
56533 + return new_mode;
56534 + }
56535 +
56536 + return retval;
56537 +}
56538 +
56539 +__u32
56540 +gr_check_link(const struct dentry * new_dentry,
56541 + const struct dentry * parent_dentry,
56542 + const struct vfsmount * parent_mnt,
56543 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
56544 +{
56545 + struct acl_object_label *obj;
56546 + __u32 oldmode, newmode;
56547 + __u32 needmode;
56548 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
56549 + GR_DELETE | GR_INHERIT;
56550 +
56551 + if (unlikely(!(gr_status & GR_READY)))
56552 + return (GR_CREATE | GR_LINK);
56553 +
56554 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
56555 + oldmode = obj->mode;
56556 +
56557 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
56558 + newmode = obj->mode;
56559 +
56560 + needmode = newmode & checkmodes;
56561 +
56562 + // old name for hardlink must have at least the permissions of the new name
56563 + if ((oldmode & needmode) != needmode)
56564 + goto bad;
56565 +
56566 + // if old name had restrictions/auditing, make sure the new name does as well
56567 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
56568 +
56569 + // don't allow hardlinking of suid/sgid/fcapped files without permission
56570 + if (is_privileged_binary(old_dentry))
56571 + needmode |= GR_SETID;
56572 +
56573 + if ((newmode & needmode) != needmode)
56574 + goto bad;
56575 +
56576 + // enforce minimum permissions
56577 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
56578 + return newmode;
56579 +bad:
56580 + needmode = oldmode;
56581 + if (is_privileged_binary(old_dentry))
56582 + needmode |= GR_SETID;
56583 +
56584 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
56585 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
56586 + return (GR_CREATE | GR_LINK);
56587 + } else if (newmode & GR_SUPPRESS)
56588 + return GR_SUPPRESS;
56589 + else
56590 + return 0;
56591 +}
56592 +
56593 +int
56594 +gr_check_hidden_task(const struct task_struct *task)
56595 +{
56596 + if (unlikely(!(gr_status & GR_READY)))
56597 + return 0;
56598 +
56599 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
56600 + return 1;
56601 +
56602 + return 0;
56603 +}
56604 +
56605 +int
56606 +gr_check_protected_task(const struct task_struct *task)
56607 +{
56608 + if (unlikely(!(gr_status & GR_READY) || !task))
56609 + return 0;
56610 +
56611 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56612 + task->acl != current->acl)
56613 + return 1;
56614 +
56615 + return 0;
56616 +}
56617 +
56618 +int
56619 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56620 +{
56621 + struct task_struct *p;
56622 + int ret = 0;
56623 +
56624 + if (unlikely(!(gr_status & GR_READY) || !pid))
56625 + return ret;
56626 +
56627 + read_lock(&tasklist_lock);
56628 + do_each_pid_task(pid, type, p) {
56629 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56630 + p->acl != current->acl) {
56631 + ret = 1;
56632 + goto out;
56633 + }
56634 + } while_each_pid_task(pid, type, p);
56635 +out:
56636 + read_unlock(&tasklist_lock);
56637 +
56638 + return ret;
56639 +}
56640 +
56641 +void
56642 +gr_copy_label(struct task_struct *tsk)
56643 +{
56644 + tsk->signal->used_accept = 0;
56645 + tsk->acl_sp_role = 0;
56646 + tsk->acl_role_id = current->acl_role_id;
56647 + tsk->acl = current->acl;
56648 + tsk->role = current->role;
56649 + tsk->signal->curr_ip = current->signal->curr_ip;
56650 + tsk->signal->saved_ip = current->signal->saved_ip;
56651 + if (current->exec_file)
56652 + get_file(current->exec_file);
56653 + tsk->exec_file = current->exec_file;
56654 + tsk->is_writable = current->is_writable;
56655 + if (unlikely(current->signal->used_accept)) {
56656 + current->signal->curr_ip = 0;
56657 + current->signal->saved_ip = 0;
56658 + }
56659 +
56660 + return;
56661 +}
56662 +
56663 +static void
56664 +gr_set_proc_res(struct task_struct *task)
56665 +{
56666 + struct acl_subject_label *proc;
56667 + unsigned short i;
56668 +
56669 + proc = task->acl;
56670 +
56671 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
56672 + return;
56673 +
56674 + for (i = 0; i < RLIM_NLIMITS; i++) {
56675 + if (!(proc->resmask & (1 << i)))
56676 + continue;
56677 +
56678 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
56679 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
56680 + }
56681 +
56682 + return;
56683 +}
56684 +
56685 +extern int __gr_process_user_ban(struct user_struct *user);
56686 +
56687 +int
56688 +gr_check_user_change(int real, int effective, int fs)
56689 +{
56690 + unsigned int i;
56691 + __u16 num;
56692 + uid_t *uidlist;
56693 + int curuid;
56694 + int realok = 0;
56695 + int effectiveok = 0;
56696 + int fsok = 0;
56697 +
56698 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56699 + struct user_struct *user;
56700 +
56701 + if (real == -1)
56702 + goto skipit;
56703 +
56704 + user = find_user(real);
56705 + if (user == NULL)
56706 + goto skipit;
56707 +
56708 + if (__gr_process_user_ban(user)) {
56709 + /* for find_user */
56710 + free_uid(user);
56711 + return 1;
56712 + }
56713 +
56714 + /* for find_user */
56715 + free_uid(user);
56716 +
56717 +skipit:
56718 +#endif
56719 +
56720 + if (unlikely(!(gr_status & GR_READY)))
56721 + return 0;
56722 +
56723 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56724 + gr_log_learn_id_change('u', real, effective, fs);
56725 +
56726 + num = current->acl->user_trans_num;
56727 + uidlist = current->acl->user_transitions;
56728 +
56729 + if (uidlist == NULL)
56730 + return 0;
56731 +
56732 + if (real == -1)
56733 + realok = 1;
56734 + if (effective == -1)
56735 + effectiveok = 1;
56736 + if (fs == -1)
56737 + fsok = 1;
56738 +
56739 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
56740 + for (i = 0; i < num; i++) {
56741 + curuid = (int)uidlist[i];
56742 + if (real == curuid)
56743 + realok = 1;
56744 + if (effective == curuid)
56745 + effectiveok = 1;
56746 + if (fs == curuid)
56747 + fsok = 1;
56748 + }
56749 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
56750 + for (i = 0; i < num; i++) {
56751 + curuid = (int)uidlist[i];
56752 + if (real == curuid)
56753 + break;
56754 + if (effective == curuid)
56755 + break;
56756 + if (fs == curuid)
56757 + break;
56758 + }
56759 + /* not in deny list */
56760 + if (i == num) {
56761 + realok = 1;
56762 + effectiveok = 1;
56763 + fsok = 1;
56764 + }
56765 + }
56766 +
56767 + if (realok && effectiveok && fsok)
56768 + return 0;
56769 + else {
56770 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56771 + return 1;
56772 + }
56773 +}
56774 +
56775 +int
56776 +gr_check_group_change(int real, int effective, int fs)
56777 +{
56778 + unsigned int i;
56779 + __u16 num;
56780 + gid_t *gidlist;
56781 + int curgid;
56782 + int realok = 0;
56783 + int effectiveok = 0;
56784 + int fsok = 0;
56785 +
56786 + if (unlikely(!(gr_status & GR_READY)))
56787 + return 0;
56788 +
56789 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56790 + gr_log_learn_id_change('g', real, effective, fs);
56791 +
56792 + num = current->acl->group_trans_num;
56793 + gidlist = current->acl->group_transitions;
56794 +
56795 + if (gidlist == NULL)
56796 + return 0;
56797 +
56798 + if (real == -1)
56799 + realok = 1;
56800 + if (effective == -1)
56801 + effectiveok = 1;
56802 + if (fs == -1)
56803 + fsok = 1;
56804 +
56805 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
56806 + for (i = 0; i < num; i++) {
56807 + curgid = (int)gidlist[i];
56808 + if (real == curgid)
56809 + realok = 1;
56810 + if (effective == curgid)
56811 + effectiveok = 1;
56812 + if (fs == curgid)
56813 + fsok = 1;
56814 + }
56815 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
56816 + for (i = 0; i < num; i++) {
56817 + curgid = (int)gidlist[i];
56818 + if (real == curgid)
56819 + break;
56820 + if (effective == curgid)
56821 + break;
56822 + if (fs == curgid)
56823 + break;
56824 + }
56825 + /* not in deny list */
56826 + if (i == num) {
56827 + realok = 1;
56828 + effectiveok = 1;
56829 + fsok = 1;
56830 + }
56831 + }
56832 +
56833 + if (realok && effectiveok && fsok)
56834 + return 0;
56835 + else {
56836 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56837 + return 1;
56838 + }
56839 +}
56840 +
56841 +extern int gr_acl_is_capable(const int cap);
56842 +
56843 +void
56844 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56845 +{
56846 + struct acl_role_label *role = task->role;
56847 + struct acl_subject_label *subj = NULL;
56848 + struct acl_object_label *obj;
56849 + struct file *filp;
56850 +
56851 + if (unlikely(!(gr_status & GR_READY)))
56852 + return;
56853 +
56854 + filp = task->exec_file;
56855 +
56856 + /* kernel process, we'll give them the kernel role */
56857 + if (unlikely(!filp)) {
56858 + task->role = kernel_role;
56859 + task->acl = kernel_role->root_label;
56860 + return;
56861 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56862 + role = lookup_acl_role_label(task, uid, gid);
56863 +
56864 + /* don't change the role if we're not a privileged process */
56865 + if (role && task->role != role &&
56866 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56867 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56868 + return;
56869 +
56870 + /* perform subject lookup in possibly new role
56871 + we can use this result below in the case where role == task->role
56872 + */
56873 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56874 +
56875 + /* if we changed uid/gid, but result in the same role
56876 + and are using inheritance, don't lose the inherited subject
56877 + if current subject is other than what normal lookup
56878 + would result in, we arrived via inheritance, don't
56879 + lose subject
56880 + */
56881 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56882 + (subj == task->acl)))
56883 + task->acl = subj;
56884 +
56885 + task->role = role;
56886 +
56887 + task->is_writable = 0;
56888 +
56889 + /* ignore additional mmap checks for processes that are writable
56890 + by the default ACL */
56891 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56892 + if (unlikely(obj->mode & GR_WRITE))
56893 + task->is_writable = 1;
56894 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56895 + if (unlikely(obj->mode & GR_WRITE))
56896 + task->is_writable = 1;
56897 +
56898 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56899 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56900 +#endif
56901 +
56902 + gr_set_proc_res(task);
56903 +
56904 + return;
56905 +}
56906 +
56907 +int
56908 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56909 + const int unsafe_flags)
56910 +{
56911 + struct task_struct *task = current;
56912 + struct acl_subject_label *newacl;
56913 + struct acl_object_label *obj;
56914 + __u32 retmode;
56915 +
56916 + if (unlikely(!(gr_status & GR_READY)))
56917 + return 0;
56918 +
56919 + newacl = chk_subj_label(dentry, mnt, task->role);
56920 +
56921 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56922 + did an exec
56923 + */
56924 + rcu_read_lock();
56925 + read_lock(&tasklist_lock);
56926 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56927 + (task->parent->acl->mode & GR_POVERRIDE))) {
56928 + read_unlock(&tasklist_lock);
56929 + rcu_read_unlock();
56930 + goto skip_check;
56931 + }
56932 + read_unlock(&tasklist_lock);
56933 + rcu_read_unlock();
56934 +
56935 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56936 + !(task->role->roletype & GR_ROLE_GOD) &&
56937 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56938 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56939 + if (unsafe_flags & LSM_UNSAFE_SHARE)
56940 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56941 + else
56942 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56943 + return -EACCES;
56944 + }
56945 +
56946 +skip_check:
56947 +
56948 + obj = chk_obj_label(dentry, mnt, task->acl);
56949 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56950 +
56951 + if (!(task->acl->mode & GR_INHERITLEARN) &&
56952 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56953 + if (obj->nested)
56954 + task->acl = obj->nested;
56955 + else
56956 + task->acl = newacl;
56957 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56958 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56959 +
56960 + task->is_writable = 0;
56961 +
56962 + /* ignore additional mmap checks for processes that are writable
56963 + by the default ACL */
56964 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
56965 + if (unlikely(obj->mode & GR_WRITE))
56966 + task->is_writable = 1;
56967 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
56968 + if (unlikely(obj->mode & GR_WRITE))
56969 + task->is_writable = 1;
56970 +
56971 + gr_set_proc_res(task);
56972 +
56973 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56974 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56975 +#endif
56976 + return 0;
56977 +}
56978 +
56979 +/* always called with valid inodev ptr */
56980 +static void
56981 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56982 +{
56983 + struct acl_object_label *matchpo;
56984 + struct acl_subject_label *matchps;
56985 + struct acl_subject_label *subj;
56986 + struct acl_role_label *role;
56987 + unsigned int x;
56988 +
56989 + FOR_EACH_ROLE_START(role)
56990 + FOR_EACH_SUBJECT_START(role, subj, x)
56991 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56992 + matchpo->mode |= GR_DELETED;
56993 + FOR_EACH_SUBJECT_END(subj,x)
56994 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56995 + /* nested subjects aren't in the role's subj_hash table */
56996 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56997 + matchpo->mode |= GR_DELETED;
56998 + FOR_EACH_NESTED_SUBJECT_END(subj)
56999 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57000 + matchps->mode |= GR_DELETED;
57001 + FOR_EACH_ROLE_END(role)
57002 +
57003 + inodev->nentry->deleted = 1;
57004 +
57005 + return;
57006 +}
57007 +
57008 +void
57009 +gr_handle_delete(const ino_t ino, const dev_t dev)
57010 +{
57011 + struct inodev_entry *inodev;
57012 +
57013 + if (unlikely(!(gr_status & GR_READY)))
57014 + return;
57015 +
57016 + write_lock(&gr_inode_lock);
57017 + inodev = lookup_inodev_entry(ino, dev);
57018 + if (inodev != NULL)
57019 + do_handle_delete(inodev, ino, dev);
57020 + write_unlock(&gr_inode_lock);
57021 +
57022 + return;
57023 +}
57024 +
57025 +static void
57026 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
57027 + const ino_t newinode, const dev_t newdevice,
57028 + struct acl_subject_label *subj)
57029 +{
57030 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
57031 + struct acl_object_label *match;
57032 +
57033 + match = subj->obj_hash[index];
57034 +
57035 + while (match && (match->inode != oldinode ||
57036 + match->device != olddevice ||
57037 + !(match->mode & GR_DELETED)))
57038 + match = match->next;
57039 +
57040 + if (match && (match->inode == oldinode)
57041 + && (match->device == olddevice)
57042 + && (match->mode & GR_DELETED)) {
57043 + if (match->prev == NULL) {
57044 + subj->obj_hash[index] = match->next;
57045 + if (match->next != NULL)
57046 + match->next->prev = NULL;
57047 + } else {
57048 + match->prev->next = match->next;
57049 + if (match->next != NULL)
57050 + match->next->prev = match->prev;
57051 + }
57052 + match->prev = NULL;
57053 + match->next = NULL;
57054 + match->inode = newinode;
57055 + match->device = newdevice;
57056 + match->mode &= ~GR_DELETED;
57057 +
57058 + insert_acl_obj_label(match, subj);
57059 + }
57060 +
57061 + return;
57062 +}
57063 +
57064 +static void
57065 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
57066 + const ino_t newinode, const dev_t newdevice,
57067 + struct acl_role_label *role)
57068 +{
57069 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
57070 + struct acl_subject_label *match;
57071 +
57072 + match = role->subj_hash[index];
57073 +
57074 + while (match && (match->inode != oldinode ||
57075 + match->device != olddevice ||
57076 + !(match->mode & GR_DELETED)))
57077 + match = match->next;
57078 +
57079 + if (match && (match->inode == oldinode)
57080 + && (match->device == olddevice)
57081 + && (match->mode & GR_DELETED)) {
57082 + if (match->prev == NULL) {
57083 + role->subj_hash[index] = match->next;
57084 + if (match->next != NULL)
57085 + match->next->prev = NULL;
57086 + } else {
57087 + match->prev->next = match->next;
57088 + if (match->next != NULL)
57089 + match->next->prev = match->prev;
57090 + }
57091 + match->prev = NULL;
57092 + match->next = NULL;
57093 + match->inode = newinode;
57094 + match->device = newdevice;
57095 + match->mode &= ~GR_DELETED;
57096 +
57097 + insert_acl_subj_label(match, role);
57098 + }
57099 +
57100 + return;
57101 +}
57102 +
57103 +static void
57104 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
57105 + const ino_t newinode, const dev_t newdevice)
57106 +{
57107 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
57108 + struct inodev_entry *match;
57109 +
57110 + match = inodev_set.i_hash[index];
57111 +
57112 + while (match && (match->nentry->inode != oldinode ||
57113 + match->nentry->device != olddevice || !match->nentry->deleted))
57114 + match = match->next;
57115 +
57116 + if (match && (match->nentry->inode == oldinode)
57117 + && (match->nentry->device == olddevice) &&
57118 + match->nentry->deleted) {
57119 + if (match->prev == NULL) {
57120 + inodev_set.i_hash[index] = match->next;
57121 + if (match->next != NULL)
57122 + match->next->prev = NULL;
57123 + } else {
57124 + match->prev->next = match->next;
57125 + if (match->next != NULL)
57126 + match->next->prev = match->prev;
57127 + }
57128 + match->prev = NULL;
57129 + match->next = NULL;
57130 + match->nentry->inode = newinode;
57131 + match->nentry->device = newdevice;
57132 + match->nentry->deleted = 0;
57133 +
57134 + insert_inodev_entry(match);
57135 + }
57136 +
57137 + return;
57138 +}
57139 +
57140 +static void
57141 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
57142 +{
57143 + struct acl_subject_label *subj;
57144 + struct acl_role_label *role;
57145 + unsigned int x;
57146 +
57147 + FOR_EACH_ROLE_START(role)
57148 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
57149 +
57150 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
57151 + if ((subj->inode == ino) && (subj->device == dev)) {
57152 + subj->inode = ino;
57153 + subj->device = dev;
57154 + }
57155 + /* nested subjects aren't in the role's subj_hash table */
57156 + update_acl_obj_label(matchn->inode, matchn->device,
57157 + ino, dev, subj);
57158 + FOR_EACH_NESTED_SUBJECT_END(subj)
57159 + FOR_EACH_SUBJECT_START(role, subj, x)
57160 + update_acl_obj_label(matchn->inode, matchn->device,
57161 + ino, dev, subj);
57162 + FOR_EACH_SUBJECT_END(subj,x)
57163 + FOR_EACH_ROLE_END(role)
57164 +
57165 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
57166 +
57167 + return;
57168 +}
57169 +
57170 +static void
57171 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
57172 + const struct vfsmount *mnt)
57173 +{
57174 + ino_t ino = dentry->d_inode->i_ino;
57175 + dev_t dev = __get_dev(dentry);
57176 +
57177 + __do_handle_create(matchn, ino, dev);
57178 +
57179 + return;
57180 +}
57181 +
57182 +void
57183 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57184 +{
57185 + struct name_entry *matchn;
57186 +
57187 + if (unlikely(!(gr_status & GR_READY)))
57188 + return;
57189 +
57190 + preempt_disable();
57191 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
57192 +
57193 + if (unlikely((unsigned long)matchn)) {
57194 + write_lock(&gr_inode_lock);
57195 + do_handle_create(matchn, dentry, mnt);
57196 + write_unlock(&gr_inode_lock);
57197 + }
57198 + preempt_enable();
57199 +
57200 + return;
57201 +}
57202 +
57203 +void
57204 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57205 +{
57206 + struct name_entry *matchn;
57207 +
57208 + if (unlikely(!(gr_status & GR_READY)))
57209 + return;
57210 +
57211 + preempt_disable();
57212 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
57213 +
57214 + if (unlikely((unsigned long)matchn)) {
57215 + write_lock(&gr_inode_lock);
57216 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
57217 + write_unlock(&gr_inode_lock);
57218 + }
57219 + preempt_enable();
57220 +
57221 + return;
57222 +}
57223 +
57224 +void
57225 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57226 + struct dentry *old_dentry,
57227 + struct dentry *new_dentry,
57228 + struct vfsmount *mnt, const __u8 replace)
57229 +{
57230 + struct name_entry *matchn;
57231 + struct inodev_entry *inodev;
57232 + struct inode *inode = new_dentry->d_inode;
57233 + ino_t old_ino = old_dentry->d_inode->i_ino;
57234 + dev_t old_dev = __get_dev(old_dentry);
57235 +
57236 + /* vfs_rename swaps the name and parent link for old_dentry and
57237 + new_dentry
57238 + at this point, old_dentry has the new name, parent link, and inode
57239 + for the renamed file
57240 + if a file is being replaced by a rename, new_dentry has the inode
57241 + and name for the replaced file
57242 + */
57243 +
57244 + if (unlikely(!(gr_status & GR_READY)))
57245 + return;
57246 +
57247 + preempt_disable();
57248 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
57249 +
57250 + /* we wouldn't have to check d_inode if it weren't for
57251 + NFS silly-renaming
57252 + */
57253 +
57254 + write_lock(&gr_inode_lock);
57255 + if (unlikely(replace && inode)) {
57256 + ino_t new_ino = inode->i_ino;
57257 + dev_t new_dev = __get_dev(new_dentry);
57258 +
57259 + inodev = lookup_inodev_entry(new_ino, new_dev);
57260 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
57261 + do_handle_delete(inodev, new_ino, new_dev);
57262 + }
57263 +
57264 + inodev = lookup_inodev_entry(old_ino, old_dev);
57265 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
57266 + do_handle_delete(inodev, old_ino, old_dev);
57267 +
57268 + if (unlikely((unsigned long)matchn))
57269 + do_handle_create(matchn, old_dentry, mnt);
57270 +
57271 + write_unlock(&gr_inode_lock);
57272 + preempt_enable();
57273 +
57274 + return;
57275 +}
57276 +
57277 +static int
57278 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
57279 + unsigned char **sum)
57280 +{
57281 + struct acl_role_label *r;
57282 + struct role_allowed_ip *ipp;
57283 + struct role_transition *trans;
57284 + unsigned int i;
57285 + int found = 0;
57286 + u32 curr_ip = current->signal->curr_ip;
57287 +
57288 + current->signal->saved_ip = curr_ip;
57289 +
57290 + /* check transition table */
57291 +
57292 + for (trans = current->role->transitions; trans; trans = trans->next) {
57293 + if (!strcmp(rolename, trans->rolename)) {
57294 + found = 1;
57295 + break;
57296 + }
57297 + }
57298 +
57299 + if (!found)
57300 + return 0;
57301 +
57302 + /* handle special roles that do not require authentication
57303 + and check ip */
57304 +
57305 + FOR_EACH_ROLE_START(r)
57306 + if (!strcmp(rolename, r->rolename) &&
57307 + (r->roletype & GR_ROLE_SPECIAL)) {
57308 + found = 0;
57309 + if (r->allowed_ips != NULL) {
57310 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
57311 + if ((ntohl(curr_ip) & ipp->netmask) ==
57312 + (ntohl(ipp->addr) & ipp->netmask))
57313 + found = 1;
57314 + }
57315 + } else
57316 + found = 2;
57317 + if (!found)
57318 + return 0;
57319 +
57320 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
57321 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
57322 + *salt = NULL;
57323 + *sum = NULL;
57324 + return 1;
57325 + }
57326 + }
57327 + FOR_EACH_ROLE_END(r)
57328 +
57329 + for (i = 0; i < num_sprole_pws; i++) {
57330 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
57331 + *salt = acl_special_roles[i]->salt;
57332 + *sum = acl_special_roles[i]->sum;
57333 + return 1;
57334 + }
57335 + }
57336 +
57337 + return 0;
57338 +}
57339 +
57340 +static void
57341 +assign_special_role(char *rolename)
57342 +{
57343 + struct acl_object_label *obj;
57344 + struct acl_role_label *r;
57345 + struct acl_role_label *assigned = NULL;
57346 + struct task_struct *tsk;
57347 + struct file *filp;
57348 +
57349 + FOR_EACH_ROLE_START(r)
57350 + if (!strcmp(rolename, r->rolename) &&
57351 + (r->roletype & GR_ROLE_SPECIAL)) {
57352 + assigned = r;
57353 + break;
57354 + }
57355 + FOR_EACH_ROLE_END(r)
57356 +
57357 + if (!assigned)
57358 + return;
57359 +
57360 + read_lock(&tasklist_lock);
57361 + read_lock(&grsec_exec_file_lock);
57362 +
57363 + tsk = current->real_parent;
57364 + if (tsk == NULL)
57365 + goto out_unlock;
57366 +
57367 + filp = tsk->exec_file;
57368 + if (filp == NULL)
57369 + goto out_unlock;
57370 +
57371 + tsk->is_writable = 0;
57372 +
57373 + tsk->acl_sp_role = 1;
57374 + tsk->acl_role_id = ++acl_sp_role_value;
57375 + tsk->role = assigned;
57376 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
57377 +
57378 + /* ignore additional mmap checks for processes that are writable
57379 + by the default ACL */
57380 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57381 + if (unlikely(obj->mode & GR_WRITE))
57382 + tsk->is_writable = 1;
57383 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
57384 + if (unlikely(obj->mode & GR_WRITE))
57385 + tsk->is_writable = 1;
57386 +
57387 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57388 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
57389 +#endif
57390 +
57391 +out_unlock:
57392 + read_unlock(&grsec_exec_file_lock);
57393 + read_unlock(&tasklist_lock);
57394 + return;
57395 +}
57396 +
57397 +int gr_check_secure_terminal(struct task_struct *task)
57398 +{
57399 + struct task_struct *p, *p2, *p3;
57400 + struct files_struct *files;
57401 + struct fdtable *fdt;
57402 + struct file *our_file = NULL, *file;
57403 + int i;
57404 +
57405 + if (task->signal->tty == NULL)
57406 + return 1;
57407 +
57408 + files = get_files_struct(task);
57409 + if (files != NULL) {
57410 + rcu_read_lock();
57411 + fdt = files_fdtable(files);
57412 + for (i=0; i < fdt->max_fds; i++) {
57413 + file = fcheck_files(files, i);
57414 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
57415 + get_file(file);
57416 + our_file = file;
57417 + }
57418 + }
57419 + rcu_read_unlock();
57420 + put_files_struct(files);
57421 + }
57422 +
57423 + if (our_file == NULL)
57424 + return 1;
57425 +
57426 + read_lock(&tasklist_lock);
57427 + do_each_thread(p2, p) {
57428 + files = get_files_struct(p);
57429 + if (files == NULL ||
57430 + (p->signal && p->signal->tty == task->signal->tty)) {
57431 + if (files != NULL)
57432 + put_files_struct(files);
57433 + continue;
57434 + }
57435 + rcu_read_lock();
57436 + fdt = files_fdtable(files);
57437 + for (i=0; i < fdt->max_fds; i++) {
57438 + file = fcheck_files(files, i);
57439 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
57440 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
57441 + p3 = task;
57442 + while (p3->pid > 0) {
57443 + if (p3 == p)
57444 + break;
57445 + p3 = p3->real_parent;
57446 + }
57447 + if (p3 == p)
57448 + break;
57449 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
57450 + gr_handle_alertkill(p);
57451 + rcu_read_unlock();
57452 + put_files_struct(files);
57453 + read_unlock(&tasklist_lock);
57454 + fput(our_file);
57455 + return 0;
57456 + }
57457 + }
57458 + rcu_read_unlock();
57459 + put_files_struct(files);
57460 + } while_each_thread(p2, p);
57461 + read_unlock(&tasklist_lock);
57462 +
57463 + fput(our_file);
57464 + return 1;
57465 +}
57466 +
57467 +static int gr_rbac_disable(void *unused)
57468 +{
57469 + pax_open_kernel();
57470 + gr_status &= ~GR_READY;
57471 + pax_close_kernel();
57472 +
57473 + return 0;
57474 +}
57475 +
57476 +ssize_t
57477 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
57478 +{
57479 + struct gr_arg_wrapper uwrap;
57480 + unsigned char *sprole_salt = NULL;
57481 + unsigned char *sprole_sum = NULL;
57482 + int error = sizeof (struct gr_arg_wrapper);
57483 + int error2 = 0;
57484 +
57485 + mutex_lock(&gr_dev_mutex);
57486 +
57487 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
57488 + error = -EPERM;
57489 + goto out;
57490 + }
57491 +
57492 + if (count != sizeof (struct gr_arg_wrapper)) {
57493 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
57494 + error = -EINVAL;
57495 + goto out;
57496 + }
57497 +
57498 +
57499 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
57500 + gr_auth_expires = 0;
57501 + gr_auth_attempts = 0;
57502 + }
57503 +
57504 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
57505 + error = -EFAULT;
57506 + goto out;
57507 + }
57508 +
57509 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
57510 + error = -EINVAL;
57511 + goto out;
57512 + }
57513 +
57514 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
57515 + error = -EFAULT;
57516 + goto out;
57517 + }
57518 +
57519 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57520 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57521 + time_after(gr_auth_expires, get_seconds())) {
57522 + error = -EBUSY;
57523 + goto out;
57524 + }
57525 +
57526 + /* if non-root trying to do anything other than use a special role,
57527 + do not attempt authentication, do not count towards authentication
57528 + locking
57529 + */
57530 +
57531 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
57532 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57533 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
57534 + error = -EPERM;
57535 + goto out;
57536 + }
57537 +
57538 + /* ensure pw and special role name are null terminated */
57539 +
57540 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
57541 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
57542 +
57543 + /* Okay.
57544 + * We have our enough of the argument structure..(we have yet
57545 + * to copy_from_user the tables themselves) . Copy the tables
57546 + * only if we need them, i.e. for loading operations. */
57547 +
57548 + switch (gr_usermode->mode) {
57549 + case GR_STATUS:
57550 + if (gr_status & GR_READY) {
57551 + error = 1;
57552 + if (!gr_check_secure_terminal(current))
57553 + error = 3;
57554 + } else
57555 + error = 2;
57556 + goto out;
57557 + case GR_SHUTDOWN:
57558 + if ((gr_status & GR_READY)
57559 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57560 + stop_machine(gr_rbac_disable, NULL, NULL);
57561 + free_variables();
57562 + memset(gr_usermode, 0, sizeof (struct gr_arg));
57563 + memset(gr_system_salt, 0, GR_SALT_LEN);
57564 + memset(gr_system_sum, 0, GR_SHA_LEN);
57565 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
57566 + } else if (gr_status & GR_READY) {
57567 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
57568 + error = -EPERM;
57569 + } else {
57570 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
57571 + error = -EAGAIN;
57572 + }
57573 + break;
57574 + case GR_ENABLE:
57575 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
57576 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
57577 + else {
57578 + if (gr_status & GR_READY)
57579 + error = -EAGAIN;
57580 + else
57581 + error = error2;
57582 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
57583 + }
57584 + break;
57585 + case GR_RELOAD:
57586 + if (!(gr_status & GR_READY)) {
57587 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
57588 + error = -EAGAIN;
57589 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57590 + stop_machine(gr_rbac_disable, NULL, NULL);
57591 + free_variables();
57592 + error2 = gracl_init(gr_usermode);
57593 + if (!error2)
57594 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
57595 + else {
57596 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57597 + error = error2;
57598 + }
57599 + } else {
57600 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57601 + error = -EPERM;
57602 + }
57603 + break;
57604 + case GR_SEGVMOD:
57605 + if (unlikely(!(gr_status & GR_READY))) {
57606 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
57607 + error = -EAGAIN;
57608 + break;
57609 + }
57610 +
57611 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57612 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
57613 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
57614 + struct acl_subject_label *segvacl;
57615 + segvacl =
57616 + lookup_acl_subj_label(gr_usermode->segv_inode,
57617 + gr_usermode->segv_device,
57618 + current->role);
57619 + if (segvacl) {
57620 + segvacl->crashes = 0;
57621 + segvacl->expires = 0;
57622 + }
57623 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
57624 + gr_remove_uid(gr_usermode->segv_uid);
57625 + }
57626 + } else {
57627 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
57628 + error = -EPERM;
57629 + }
57630 + break;
57631 + case GR_SPROLE:
57632 + case GR_SPROLEPAM:
57633 + if (unlikely(!(gr_status & GR_READY))) {
57634 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
57635 + error = -EAGAIN;
57636 + break;
57637 + }
57638 +
57639 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
57640 + current->role->expires = 0;
57641 + current->role->auth_attempts = 0;
57642 + }
57643 +
57644 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57645 + time_after(current->role->expires, get_seconds())) {
57646 + error = -EBUSY;
57647 + goto out;
57648 + }
57649 +
57650 + if (lookup_special_role_auth
57651 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
57652 + && ((!sprole_salt && !sprole_sum)
57653 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
57654 + char *p = "";
57655 + assign_special_role(gr_usermode->sp_role);
57656 + read_lock(&tasklist_lock);
57657 + if (current->real_parent)
57658 + p = current->real_parent->role->rolename;
57659 + read_unlock(&tasklist_lock);
57660 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
57661 + p, acl_sp_role_value);
57662 + } else {
57663 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
57664 + error = -EPERM;
57665 + if(!(current->role->auth_attempts++))
57666 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57667 +
57668 + goto out;
57669 + }
57670 + break;
57671 + case GR_UNSPROLE:
57672 + if (unlikely(!(gr_status & GR_READY))) {
57673 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
57674 + error = -EAGAIN;
57675 + break;
57676 + }
57677 +
57678 + if (current->role->roletype & GR_ROLE_SPECIAL) {
57679 + char *p = "";
57680 + int i = 0;
57681 +
57682 + read_lock(&tasklist_lock);
57683 + if (current->real_parent) {
57684 + p = current->real_parent->role->rolename;
57685 + i = current->real_parent->acl_role_id;
57686 + }
57687 + read_unlock(&tasklist_lock);
57688 +
57689 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57690 + gr_set_acls(1);
57691 + } else {
57692 + error = -EPERM;
57693 + goto out;
57694 + }
57695 + break;
57696 + default:
57697 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57698 + error = -EINVAL;
57699 + break;
57700 + }
57701 +
57702 + if (error != -EPERM)
57703 + goto out;
57704 +
57705 + if(!(gr_auth_attempts++))
57706 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57707 +
57708 + out:
57709 + mutex_unlock(&gr_dev_mutex);
57710 + return error;
57711 +}
57712 +
57713 +/* must be called with
57714 + rcu_read_lock();
57715 + read_lock(&tasklist_lock);
57716 + read_lock(&grsec_exec_file_lock);
57717 +*/
57718 +int gr_apply_subject_to_task(struct task_struct *task)
57719 +{
57720 + struct acl_object_label *obj;
57721 + char *tmpname;
57722 + struct acl_subject_label *tmpsubj;
57723 + struct file *filp;
57724 + struct name_entry *nmatch;
57725 +
57726 + filp = task->exec_file;
57727 + if (filp == NULL)
57728 + return 0;
57729 +
57730 + /* the following is to apply the correct subject
57731 + on binaries running when the RBAC system
57732 + is enabled, when the binaries have been
57733 + replaced or deleted since their execution
57734 + -----
57735 + when the RBAC system starts, the inode/dev
57736 + from exec_file will be one the RBAC system
57737 + is unaware of. It only knows the inode/dev
57738 + of the present file on disk, or the absence
57739 + of it.
57740 + */
57741 + preempt_disable();
57742 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57743 +
57744 + nmatch = lookup_name_entry(tmpname);
57745 + preempt_enable();
57746 + tmpsubj = NULL;
57747 + if (nmatch) {
57748 + if (nmatch->deleted)
57749 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57750 + else
57751 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57752 + if (tmpsubj != NULL)
57753 + task->acl = tmpsubj;
57754 + }
57755 + if (tmpsubj == NULL)
57756 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57757 + task->role);
57758 + if (task->acl) {
57759 + task->is_writable = 0;
57760 + /* ignore additional mmap checks for processes that are writable
57761 + by the default ACL */
57762 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57763 + if (unlikely(obj->mode & GR_WRITE))
57764 + task->is_writable = 1;
57765 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57766 + if (unlikely(obj->mode & GR_WRITE))
57767 + task->is_writable = 1;
57768 +
57769 + gr_set_proc_res(task);
57770 +
57771 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57772 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57773 +#endif
57774 + } else {
57775 + return 1;
57776 + }
57777 +
57778 + return 0;
57779 +}
57780 +
57781 +int
57782 +gr_set_acls(const int type)
57783 +{
57784 + struct task_struct *task, *task2;
57785 + struct acl_role_label *role = current->role;
57786 + __u16 acl_role_id = current->acl_role_id;
57787 + const struct cred *cred;
57788 + int ret;
57789 +
57790 + rcu_read_lock();
57791 + read_lock(&tasklist_lock);
57792 + read_lock(&grsec_exec_file_lock);
57793 + do_each_thread(task2, task) {
57794 + /* check to see if we're called from the exit handler,
57795 + if so, only replace ACLs that have inherited the admin
57796 + ACL */
57797 +
57798 + if (type && (task->role != role ||
57799 + task->acl_role_id != acl_role_id))
57800 + continue;
57801 +
57802 + task->acl_role_id = 0;
57803 + task->acl_sp_role = 0;
57804 +
57805 + if (task->exec_file) {
57806 + cred = __task_cred(task);
57807 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57808 + ret = gr_apply_subject_to_task(task);
57809 + if (ret) {
57810 + read_unlock(&grsec_exec_file_lock);
57811 + read_unlock(&tasklist_lock);
57812 + rcu_read_unlock();
57813 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57814 + return ret;
57815 + }
57816 + } else {
57817 + // it's a kernel process
57818 + task->role = kernel_role;
57819 + task->acl = kernel_role->root_label;
57820 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57821 + task->acl->mode &= ~GR_PROCFIND;
57822 +#endif
57823 + }
57824 + } while_each_thread(task2, task);
57825 + read_unlock(&grsec_exec_file_lock);
57826 + read_unlock(&tasklist_lock);
57827 + rcu_read_unlock();
57828 +
57829 + return 0;
57830 +}
57831 +
57832 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57833 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57834 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57835 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57836 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57837 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57838 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57839 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57840 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57841 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57842 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57843 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57844 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57845 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57846 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57847 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57848 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57849 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57850 +};
57851 +
57852 +void
57853 +gr_learn_resource(const struct task_struct *task,
57854 + const int res, const unsigned long wanted, const int gt)
57855 +{
57856 + struct acl_subject_label *acl;
57857 + const struct cred *cred;
57858 +
57859 + if (unlikely((gr_status & GR_READY) &&
57860 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57861 + goto skip_reslog;
57862 +
57863 + gr_log_resource(task, res, wanted, gt);
57864 +skip_reslog:
57865 +
57866 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57867 + return;
57868 +
57869 + acl = task->acl;
57870 +
57871 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57872 + !(acl->resmask & (1 << (unsigned short) res))))
57873 + return;
57874 +
57875 + if (wanted >= acl->res[res].rlim_cur) {
57876 + unsigned long res_add;
57877 +
57878 + res_add = wanted + res_learn_bumps[res];
57879 +
57880 + acl->res[res].rlim_cur = res_add;
57881 +
57882 + if (wanted > acl->res[res].rlim_max)
57883 + acl->res[res].rlim_max = res_add;
57884 +
57885 + /* only log the subject filename, since resource logging is supported for
57886 + single-subject learning only */
57887 + rcu_read_lock();
57888 + cred = __task_cred(task);
57889 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57890 + task->role->roletype, cred->uid, cred->gid, acl->filename,
57891 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57892 + "", (unsigned long) res, &task->signal->saved_ip);
57893 + rcu_read_unlock();
57894 + }
57895 +
57896 + return;
57897 +}
57898 +EXPORT_SYMBOL(gr_learn_resource);
57899 +#endif
57900 +
57901 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57902 +void
57903 +pax_set_initial_flags(struct linux_binprm *bprm)
57904 +{
57905 + struct task_struct *task = current;
57906 + struct acl_subject_label *proc;
57907 + unsigned long flags;
57908 +
57909 + if (unlikely(!(gr_status & GR_READY)))
57910 + return;
57911 +
57912 + flags = pax_get_flags(task);
57913 +
57914 + proc = task->acl;
57915 +
57916 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57917 + flags &= ~MF_PAX_PAGEEXEC;
57918 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57919 + flags &= ~MF_PAX_SEGMEXEC;
57920 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57921 + flags &= ~MF_PAX_RANDMMAP;
57922 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57923 + flags &= ~MF_PAX_EMUTRAMP;
57924 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57925 + flags &= ~MF_PAX_MPROTECT;
57926 +
57927 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57928 + flags |= MF_PAX_PAGEEXEC;
57929 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57930 + flags |= MF_PAX_SEGMEXEC;
57931 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57932 + flags |= MF_PAX_RANDMMAP;
57933 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57934 + flags |= MF_PAX_EMUTRAMP;
57935 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57936 + flags |= MF_PAX_MPROTECT;
57937 +
57938 + pax_set_flags(task, flags);
57939 +
57940 + return;
57941 +}
57942 +#endif
57943 +
57944 +int
57945 +gr_handle_proc_ptrace(struct task_struct *task)
57946 +{
57947 + struct file *filp;
57948 + struct task_struct *tmp = task;
57949 + struct task_struct *curtemp = current;
57950 + __u32 retmode;
57951 +
57952 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57953 + if (unlikely(!(gr_status & GR_READY)))
57954 + return 0;
57955 +#endif
57956 +
57957 + read_lock(&tasklist_lock);
57958 + read_lock(&grsec_exec_file_lock);
57959 + filp = task->exec_file;
57960 +
57961 + while (tmp->pid > 0) {
57962 + if (tmp == curtemp)
57963 + break;
57964 + tmp = tmp->real_parent;
57965 + }
57966 +
57967 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57968 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57969 + read_unlock(&grsec_exec_file_lock);
57970 + read_unlock(&tasklist_lock);
57971 + return 1;
57972 + }
57973 +
57974 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57975 + if (!(gr_status & GR_READY)) {
57976 + read_unlock(&grsec_exec_file_lock);
57977 + read_unlock(&tasklist_lock);
57978 + return 0;
57979 + }
57980 +#endif
57981 +
57982 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57983 + read_unlock(&grsec_exec_file_lock);
57984 + read_unlock(&tasklist_lock);
57985 +
57986 + if (retmode & GR_NOPTRACE)
57987 + return 1;
57988 +
57989 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
57990 + && (current->acl != task->acl || (current->acl != current->role->root_label
57991 + && current->pid != task->pid)))
57992 + return 1;
57993 +
57994 + return 0;
57995 +}
57996 +
57997 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
57998 +{
57999 + if (unlikely(!(gr_status & GR_READY)))
58000 + return;
58001 +
58002 + if (!(current->role->roletype & GR_ROLE_GOD))
58003 + return;
58004 +
58005 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
58006 + p->role->rolename, gr_task_roletype_to_char(p),
58007 + p->acl->filename);
58008 +}
58009 +
58010 +int
58011 +gr_handle_ptrace(struct task_struct *task, const long request)
58012 +{
58013 + struct task_struct *tmp = task;
58014 + struct task_struct *curtemp = current;
58015 + __u32 retmode;
58016 +
58017 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58018 + if (unlikely(!(gr_status & GR_READY)))
58019 + return 0;
58020 +#endif
58021 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
58022 + read_lock(&tasklist_lock);
58023 + while (tmp->pid > 0) {
58024 + if (tmp == curtemp)
58025 + break;
58026 + tmp = tmp->real_parent;
58027 + }
58028 +
58029 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58030 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
58031 + read_unlock(&tasklist_lock);
58032 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58033 + return 1;
58034 + }
58035 + read_unlock(&tasklist_lock);
58036 + }
58037 +
58038 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58039 + if (!(gr_status & GR_READY))
58040 + return 0;
58041 +#endif
58042 +
58043 + read_lock(&grsec_exec_file_lock);
58044 + if (unlikely(!task->exec_file)) {
58045 + read_unlock(&grsec_exec_file_lock);
58046 + return 0;
58047 + }
58048 +
58049 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
58050 + read_unlock(&grsec_exec_file_lock);
58051 +
58052 + if (retmode & GR_NOPTRACE) {
58053 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58054 + return 1;
58055 + }
58056 +
58057 + if (retmode & GR_PTRACERD) {
58058 + switch (request) {
58059 + case PTRACE_SEIZE:
58060 + case PTRACE_POKETEXT:
58061 + case PTRACE_POKEDATA:
58062 + case PTRACE_POKEUSR:
58063 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
58064 + case PTRACE_SETREGS:
58065 + case PTRACE_SETFPREGS:
58066 +#endif
58067 +#ifdef CONFIG_X86
58068 + case PTRACE_SETFPXREGS:
58069 +#endif
58070 +#ifdef CONFIG_ALTIVEC
58071 + case PTRACE_SETVRREGS:
58072 +#endif
58073 + return 1;
58074 + default:
58075 + return 0;
58076 + }
58077 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
58078 + !(current->role->roletype & GR_ROLE_GOD) &&
58079 + (current->acl != task->acl)) {
58080 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58081 + return 1;
58082 + }
58083 +
58084 + return 0;
58085 +}
58086 +
58087 +static int is_writable_mmap(const struct file *filp)
58088 +{
58089 + struct task_struct *task = current;
58090 + struct acl_object_label *obj, *obj2;
58091 +
58092 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
58093 + !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))) {
58094 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58095 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
58096 + task->role->root_label);
58097 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
58098 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
58099 + return 1;
58100 + }
58101 + }
58102 + return 0;
58103 +}
58104 +
58105 +int
58106 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
58107 +{
58108 + __u32 mode;
58109 +
58110 + if (unlikely(!file || !(prot & PROT_EXEC)))
58111 + return 1;
58112 +
58113 + if (is_writable_mmap(file))
58114 + return 0;
58115 +
58116 + mode =
58117 + gr_search_file(file->f_path.dentry,
58118 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58119 + file->f_path.mnt);
58120 +
58121 + if (!gr_tpe_allow(file))
58122 + return 0;
58123 +
58124 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58125 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58126 + return 0;
58127 + } else if (unlikely(!(mode & GR_EXEC))) {
58128 + return 0;
58129 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58130 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58131 + return 1;
58132 + }
58133 +
58134 + return 1;
58135 +}
58136 +
58137 +int
58138 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58139 +{
58140 + __u32 mode;
58141 +
58142 + if (unlikely(!file || !(prot & PROT_EXEC)))
58143 + return 1;
58144 +
58145 + if (is_writable_mmap(file))
58146 + return 0;
58147 +
58148 + mode =
58149 + gr_search_file(file->f_path.dentry,
58150 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58151 + file->f_path.mnt);
58152 +
58153 + if (!gr_tpe_allow(file))
58154 + return 0;
58155 +
58156 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58157 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58158 + return 0;
58159 + } else if (unlikely(!(mode & GR_EXEC))) {
58160 + return 0;
58161 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58162 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58163 + return 1;
58164 + }
58165 +
58166 + return 1;
58167 +}
58168 +
58169 +void
58170 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58171 +{
58172 + unsigned long runtime;
58173 + unsigned long cputime;
58174 + unsigned int wday, cday;
58175 + __u8 whr, chr;
58176 + __u8 wmin, cmin;
58177 + __u8 wsec, csec;
58178 + struct timespec timeval;
58179 +
58180 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
58181 + !(task->acl->mode & GR_PROCACCT)))
58182 + return;
58183 +
58184 + do_posix_clock_monotonic_gettime(&timeval);
58185 + runtime = timeval.tv_sec - task->start_time.tv_sec;
58186 + wday = runtime / (3600 * 24);
58187 + runtime -= wday * (3600 * 24);
58188 + whr = runtime / 3600;
58189 + runtime -= whr * 3600;
58190 + wmin = runtime / 60;
58191 + runtime -= wmin * 60;
58192 + wsec = runtime;
58193 +
58194 + cputime = (task->utime + task->stime) / HZ;
58195 + cday = cputime / (3600 * 24);
58196 + cputime -= cday * (3600 * 24);
58197 + chr = cputime / 3600;
58198 + cputime -= chr * 3600;
58199 + cmin = cputime / 60;
58200 + cputime -= cmin * 60;
58201 + csec = cputime;
58202 +
58203 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
58204 +
58205 + return;
58206 +}
58207 +
58208 +void gr_set_kernel_label(struct task_struct *task)
58209 +{
58210 + if (gr_status & GR_READY) {
58211 + task->role = kernel_role;
58212 + task->acl = kernel_role->root_label;
58213 + }
58214 + return;
58215 +}
58216 +
58217 +#ifdef CONFIG_TASKSTATS
58218 +int gr_is_taskstats_denied(int pid)
58219 +{
58220 + struct task_struct *task;
58221 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58222 + const struct cred *cred;
58223 +#endif
58224 + int ret = 0;
58225 +
58226 + /* restrict taskstats viewing to un-chrooted root users
58227 + who have the 'view' subject flag if the RBAC system is enabled
58228 + */
58229 +
58230 + rcu_read_lock();
58231 + read_lock(&tasklist_lock);
58232 + task = find_task_by_vpid(pid);
58233 + if (task) {
58234 +#ifdef CONFIG_GRKERNSEC_CHROOT
58235 + if (proc_is_chrooted(task))
58236 + ret = -EACCES;
58237 +#endif
58238 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58239 + cred = __task_cred(task);
58240 +#ifdef CONFIG_GRKERNSEC_PROC_USER
58241 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
58242 + ret = -EACCES;
58243 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58244 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
58245 + ret = -EACCES;
58246 +#endif
58247 +#endif
58248 + if (gr_status & GR_READY) {
58249 + if (!(task->acl->mode & GR_VIEW))
58250 + ret = -EACCES;
58251 + }
58252 + } else
58253 + ret = -ENOENT;
58254 +
58255 + read_unlock(&tasklist_lock);
58256 + rcu_read_unlock();
58257 +
58258 + return ret;
58259 +}
58260 +#endif
58261 +
58262 +/* AUXV entries are filled via a descendant of search_binary_handler
58263 + after we've already applied the subject for the target
58264 +*/
58265 +int gr_acl_enable_at_secure(void)
58266 +{
58267 + if (unlikely(!(gr_status & GR_READY)))
58268 + return 0;
58269 +
58270 + if (current->acl->mode & GR_ATSECURE)
58271 + return 1;
58272 +
58273 + return 0;
58274 +}
58275 +
58276 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
58277 +{
58278 + struct task_struct *task = current;
58279 + struct dentry *dentry = file->f_path.dentry;
58280 + struct vfsmount *mnt = file->f_path.mnt;
58281 + struct acl_object_label *obj, *tmp;
58282 + struct acl_subject_label *subj;
58283 + unsigned int bufsize;
58284 + int is_not_root;
58285 + char *path;
58286 + dev_t dev = __get_dev(dentry);
58287 +
58288 + if (unlikely(!(gr_status & GR_READY)))
58289 + return 1;
58290 +
58291 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58292 + return 1;
58293 +
58294 + /* ignore Eric Biederman */
58295 + if (IS_PRIVATE(dentry->d_inode))
58296 + return 1;
58297 +
58298 + subj = task->acl;
58299 + read_lock(&gr_inode_lock);
58300 + do {
58301 + obj = lookup_acl_obj_label(ino, dev, subj);
58302 + if (obj != NULL) {
58303 + read_unlock(&gr_inode_lock);
58304 + return (obj->mode & GR_FIND) ? 1 : 0;
58305 + }
58306 + } while ((subj = subj->parent_subject));
58307 + read_unlock(&gr_inode_lock);
58308 +
58309 + /* this is purely an optimization since we're looking for an object
58310 + for the directory we're doing a readdir on
58311 + if it's possible for any globbed object to match the entry we're
58312 + filling into the directory, then the object we find here will be
58313 + an anchor point with attached globbed objects
58314 + */
58315 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
58316 + if (obj->globbed == NULL)
58317 + return (obj->mode & GR_FIND) ? 1 : 0;
58318 +
58319 + is_not_root = ((obj->filename[0] == '/') &&
58320 + (obj->filename[1] == '\0')) ? 0 : 1;
58321 + bufsize = PAGE_SIZE - namelen - is_not_root;
58322 +
58323 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
58324 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
58325 + return 1;
58326 +
58327 + preempt_disable();
58328 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58329 + bufsize);
58330 +
58331 + bufsize = strlen(path);
58332 +
58333 + /* if base is "/", don't append an additional slash */
58334 + if (is_not_root)
58335 + *(path + bufsize) = '/';
58336 + memcpy(path + bufsize + is_not_root, name, namelen);
58337 + *(path + bufsize + namelen + is_not_root) = '\0';
58338 +
58339 + tmp = obj->globbed;
58340 + while (tmp) {
58341 + if (!glob_match(tmp->filename, path)) {
58342 + preempt_enable();
58343 + return (tmp->mode & GR_FIND) ? 1 : 0;
58344 + }
58345 + tmp = tmp->next;
58346 + }
58347 + preempt_enable();
58348 + return (obj->mode & GR_FIND) ? 1 : 0;
58349 +}
58350 +
58351 +void gr_put_exec_file(struct task_struct *task)
58352 +{
58353 + struct file *filp;
58354 +
58355 + write_lock(&grsec_exec_file_lock);
58356 + filp = task->exec_file;
58357 + task->exec_file = NULL;
58358 + write_unlock(&grsec_exec_file_lock);
58359 +
58360 + if (filp)
58361 + fput(filp);
58362 +
58363 + return;
58364 +}
58365 +
58366 +
58367 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
58368 +EXPORT_SYMBOL(gr_acl_is_enabled);
58369 +#endif
58370 +EXPORT_SYMBOL(gr_set_kernel_label);
58371 +#ifdef CONFIG_SECURITY
58372 +EXPORT_SYMBOL(gr_check_user_change);
58373 +EXPORT_SYMBOL(gr_check_group_change);
58374 +#endif
58375 +
58376 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
58377 new file mode 100644
58378 index 0000000..34fefda
58379 --- /dev/null
58380 +++ b/grsecurity/gracl_alloc.c
58381 @@ -0,0 +1,105 @@
58382 +#include <linux/kernel.h>
58383 +#include <linux/mm.h>
58384 +#include <linux/slab.h>
58385 +#include <linux/vmalloc.h>
58386 +#include <linux/gracl.h>
58387 +#include <linux/grsecurity.h>
58388 +
58389 +static unsigned long alloc_stack_next = 1;
58390 +static unsigned long alloc_stack_size = 1;
58391 +static void **alloc_stack;
58392 +
58393 +static __inline__ int
58394 +alloc_pop(void)
58395 +{
58396 + if (alloc_stack_next == 1)
58397 + return 0;
58398 +
58399 + kfree(alloc_stack[alloc_stack_next - 2]);
58400 +
58401 + alloc_stack_next--;
58402 +
58403 + return 1;
58404 +}
58405 +
58406 +static __inline__ int
58407 +alloc_push(void *buf)
58408 +{
58409 + if (alloc_stack_next >= alloc_stack_size)
58410 + return 1;
58411 +
58412 + alloc_stack[alloc_stack_next - 1] = buf;
58413 +
58414 + alloc_stack_next++;
58415 +
58416 + return 0;
58417 +}
58418 +
58419 +void *
58420 +acl_alloc(unsigned long len)
58421 +{
58422 + void *ret = NULL;
58423 +
58424 + if (!len || len > PAGE_SIZE)
58425 + goto out;
58426 +
58427 + ret = kmalloc(len, GFP_KERNEL);
58428 +
58429 + if (ret) {
58430 + if (alloc_push(ret)) {
58431 + kfree(ret);
58432 + ret = NULL;
58433 + }
58434 + }
58435 +
58436 +out:
58437 + return ret;
58438 +}
58439 +
58440 +void *
58441 +acl_alloc_num(unsigned long num, unsigned long len)
58442 +{
58443 + if (!len || (num > (PAGE_SIZE / len)))
58444 + return NULL;
58445 +
58446 + return acl_alloc(num * len);
58447 +}
58448 +
58449 +void
58450 +acl_free_all(void)
58451 +{
58452 + if (gr_acl_is_enabled() || !alloc_stack)
58453 + return;
58454 +
58455 + while (alloc_pop()) ;
58456 +
58457 + if (alloc_stack) {
58458 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
58459 + kfree(alloc_stack);
58460 + else
58461 + vfree(alloc_stack);
58462 + }
58463 +
58464 + alloc_stack = NULL;
58465 + alloc_stack_size = 1;
58466 + alloc_stack_next = 1;
58467 +
58468 + return;
58469 +}
58470 +
58471 +int
58472 +acl_alloc_stack_init(unsigned long size)
58473 +{
58474 + if ((size * sizeof (void *)) <= PAGE_SIZE)
58475 + alloc_stack =
58476 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
58477 + else
58478 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
58479 +
58480 + alloc_stack_size = size;
58481 +
58482 + if (!alloc_stack)
58483 + return 0;
58484 + else
58485 + return 1;
58486 +}
58487 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
58488 new file mode 100644
58489 index 0000000..6d21049
58490 --- /dev/null
58491 +++ b/grsecurity/gracl_cap.c
58492 @@ -0,0 +1,110 @@
58493 +#include <linux/kernel.h>
58494 +#include <linux/module.h>
58495 +#include <linux/sched.h>
58496 +#include <linux/gracl.h>
58497 +#include <linux/grsecurity.h>
58498 +#include <linux/grinternal.h>
58499 +
58500 +extern const char *captab_log[];
58501 +extern int captab_log_entries;
58502 +
58503 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58504 +{
58505 + struct acl_subject_label *curracl;
58506 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58507 + kernel_cap_t cap_audit = __cap_empty_set;
58508 +
58509 + if (!gr_acl_is_enabled())
58510 + return 1;
58511 +
58512 + curracl = task->acl;
58513 +
58514 + cap_drop = curracl->cap_lower;
58515 + cap_mask = curracl->cap_mask;
58516 + cap_audit = curracl->cap_invert_audit;
58517 +
58518 + while ((curracl = curracl->parent_subject)) {
58519 + /* if the cap isn't specified in the current computed mask but is specified in the
58520 + current level subject, and is lowered in the current level subject, then add
58521 + it to the set of dropped capabilities
58522 + otherwise, add the current level subject's mask to the current computed mask
58523 + */
58524 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58525 + cap_raise(cap_mask, cap);
58526 + if (cap_raised(curracl->cap_lower, cap))
58527 + cap_raise(cap_drop, cap);
58528 + if (cap_raised(curracl->cap_invert_audit, cap))
58529 + cap_raise(cap_audit, cap);
58530 + }
58531 + }
58532 +
58533 + if (!cap_raised(cap_drop, cap)) {
58534 + if (cap_raised(cap_audit, cap))
58535 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
58536 + return 1;
58537 + }
58538 +
58539 + curracl = task->acl;
58540 +
58541 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
58542 + && cap_raised(cred->cap_effective, cap)) {
58543 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58544 + task->role->roletype, cred->uid,
58545 + cred->gid, task->exec_file ?
58546 + gr_to_filename(task->exec_file->f_path.dentry,
58547 + task->exec_file->f_path.mnt) : curracl->filename,
58548 + curracl->filename, 0UL,
58549 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
58550 + return 1;
58551 + }
58552 +
58553 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
58554 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
58555 +
58556 + return 0;
58557 +}
58558 +
58559 +int
58560 +gr_acl_is_capable(const int cap)
58561 +{
58562 + return gr_task_acl_is_capable(current, current_cred(), cap);
58563 +}
58564 +
58565 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
58566 +{
58567 + struct acl_subject_label *curracl;
58568 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58569 +
58570 + if (!gr_acl_is_enabled())
58571 + return 1;
58572 +
58573 + curracl = task->acl;
58574 +
58575 + cap_drop = curracl->cap_lower;
58576 + cap_mask = curracl->cap_mask;
58577 +
58578 + while ((curracl = curracl->parent_subject)) {
58579 + /* if the cap isn't specified in the current computed mask but is specified in the
58580 + current level subject, and is lowered in the current level subject, then add
58581 + it to the set of dropped capabilities
58582 + otherwise, add the current level subject's mask to the current computed mask
58583 + */
58584 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58585 + cap_raise(cap_mask, cap);
58586 + if (cap_raised(curracl->cap_lower, cap))
58587 + cap_raise(cap_drop, cap);
58588 + }
58589 + }
58590 +
58591 + if (!cap_raised(cap_drop, cap))
58592 + return 1;
58593 +
58594 + return 0;
58595 +}
58596 +
58597 +int
58598 +gr_acl_is_capable_nolog(const int cap)
58599 +{
58600 + return gr_task_acl_is_capable_nolog(current, cap);
58601 +}
58602 +
58603 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
58604 new file mode 100644
58605 index 0000000..a340c17
58606 --- /dev/null
58607 +++ b/grsecurity/gracl_fs.c
58608 @@ -0,0 +1,431 @@
58609 +#include <linux/kernel.h>
58610 +#include <linux/sched.h>
58611 +#include <linux/types.h>
58612 +#include <linux/fs.h>
58613 +#include <linux/file.h>
58614 +#include <linux/stat.h>
58615 +#include <linux/grsecurity.h>
58616 +#include <linux/grinternal.h>
58617 +#include <linux/gracl.h>
58618 +
58619 +umode_t
58620 +gr_acl_umask(void)
58621 +{
58622 + if (unlikely(!gr_acl_is_enabled()))
58623 + return 0;
58624 +
58625 + return current->role->umask;
58626 +}
58627 +
58628 +__u32
58629 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58630 + const struct vfsmount * mnt)
58631 +{
58632 + __u32 mode;
58633 +
58634 + if (unlikely(!dentry->d_inode))
58635 + return GR_FIND;
58636 +
58637 + mode =
58638 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
58639 +
58640 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
58641 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58642 + return mode;
58643 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
58644 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58645 + return 0;
58646 + } else if (unlikely(!(mode & GR_FIND)))
58647 + return 0;
58648 +
58649 + return GR_FIND;
58650 +}
58651 +
58652 +__u32
58653 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58654 + int acc_mode)
58655 +{
58656 + __u32 reqmode = GR_FIND;
58657 + __u32 mode;
58658 +
58659 + if (unlikely(!dentry->d_inode))
58660 + return reqmode;
58661 +
58662 + if (acc_mode & MAY_APPEND)
58663 + reqmode |= GR_APPEND;
58664 + else if (acc_mode & MAY_WRITE)
58665 + reqmode |= GR_WRITE;
58666 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
58667 + reqmode |= GR_READ;
58668 +
58669 + mode =
58670 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58671 + mnt);
58672 +
58673 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58674 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58675 + reqmode & GR_READ ? " reading" : "",
58676 + reqmode & GR_WRITE ? " writing" : reqmode &
58677 + GR_APPEND ? " appending" : "");
58678 + return reqmode;
58679 + } else
58680 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58681 + {
58682 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58683 + reqmode & GR_READ ? " reading" : "",
58684 + reqmode & GR_WRITE ? " writing" : reqmode &
58685 + GR_APPEND ? " appending" : "");
58686 + return 0;
58687 + } else if (unlikely((mode & reqmode) != reqmode))
58688 + return 0;
58689 +
58690 + return reqmode;
58691 +}
58692 +
58693 +__u32
58694 +gr_acl_handle_creat(const struct dentry * dentry,
58695 + const struct dentry * p_dentry,
58696 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58697 + const int imode)
58698 +{
58699 + __u32 reqmode = GR_WRITE | GR_CREATE;
58700 + __u32 mode;
58701 +
58702 + if (acc_mode & MAY_APPEND)
58703 + reqmode |= GR_APPEND;
58704 + // if a directory was required or the directory already exists, then
58705 + // don't count this open as a read
58706 + if ((acc_mode & MAY_READ) &&
58707 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58708 + reqmode |= GR_READ;
58709 + if ((open_flags & O_CREAT) &&
58710 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58711 + reqmode |= GR_SETID;
58712 +
58713 + mode =
58714 + gr_check_create(dentry, p_dentry, p_mnt,
58715 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58716 +
58717 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58718 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58719 + reqmode & GR_READ ? " reading" : "",
58720 + reqmode & GR_WRITE ? " writing" : reqmode &
58721 + GR_APPEND ? " appending" : "");
58722 + return reqmode;
58723 + } else
58724 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58725 + {
58726 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58727 + reqmode & GR_READ ? " reading" : "",
58728 + reqmode & GR_WRITE ? " writing" : reqmode &
58729 + GR_APPEND ? " appending" : "");
58730 + return 0;
58731 + } else if (unlikely((mode & reqmode) != reqmode))
58732 + return 0;
58733 +
58734 + return reqmode;
58735 +}
58736 +
58737 +__u32
58738 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58739 + const int fmode)
58740 +{
58741 + __u32 mode, reqmode = GR_FIND;
58742 +
58743 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58744 + reqmode |= GR_EXEC;
58745 + if (fmode & S_IWOTH)
58746 + reqmode |= GR_WRITE;
58747 + if (fmode & S_IROTH)
58748 + reqmode |= GR_READ;
58749 +
58750 + mode =
58751 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58752 + mnt);
58753 +
58754 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58755 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58756 + reqmode & GR_READ ? " reading" : "",
58757 + reqmode & GR_WRITE ? " writing" : "",
58758 + reqmode & GR_EXEC ? " executing" : "");
58759 + return reqmode;
58760 + } else
58761 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58762 + {
58763 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58764 + reqmode & GR_READ ? " reading" : "",
58765 + reqmode & GR_WRITE ? " writing" : "",
58766 + reqmode & GR_EXEC ? " executing" : "");
58767 + return 0;
58768 + } else if (unlikely((mode & reqmode) != reqmode))
58769 + return 0;
58770 +
58771 + return reqmode;
58772 +}
58773 +
58774 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58775 +{
58776 + __u32 mode;
58777 +
58778 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58779 +
58780 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58781 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58782 + return mode;
58783 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58784 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58785 + return 0;
58786 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58787 + return 0;
58788 +
58789 + return (reqmode);
58790 +}
58791 +
58792 +__u32
58793 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58794 +{
58795 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58796 +}
58797 +
58798 +__u32
58799 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58800 +{
58801 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58802 +}
58803 +
58804 +__u32
58805 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58806 +{
58807 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58808 +}
58809 +
58810 +__u32
58811 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58812 +{
58813 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58814 +}
58815 +
58816 +__u32
58817 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58818 + umode_t *modeptr)
58819 +{
58820 + umode_t mode;
58821 +
58822 + *modeptr &= ~gr_acl_umask();
58823 + mode = *modeptr;
58824 +
58825 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58826 + return 1;
58827 +
58828 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58829 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58830 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58831 + GR_CHMOD_ACL_MSG);
58832 + } else {
58833 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58834 + }
58835 +}
58836 +
58837 +__u32
58838 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58839 +{
58840 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58841 +}
58842 +
58843 +__u32
58844 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58845 +{
58846 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58847 +}
58848 +
58849 +__u32
58850 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58851 +{
58852 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58853 +}
58854 +
58855 +__u32
58856 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58857 +{
58858 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58859 + GR_UNIXCONNECT_ACL_MSG);
58860 +}
58861 +
58862 +/* hardlinks require at minimum create and link permission,
58863 + any additional privilege required is based on the
58864 + privilege of the file being linked to
58865 +*/
58866 +__u32
58867 +gr_acl_handle_link(const struct dentry * new_dentry,
58868 + const struct dentry * parent_dentry,
58869 + const struct vfsmount * parent_mnt,
58870 + const struct dentry * old_dentry,
58871 + const struct vfsmount * old_mnt, const struct filename *to)
58872 +{
58873 + __u32 mode;
58874 + __u32 needmode = GR_CREATE | GR_LINK;
58875 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58876 +
58877 + mode =
58878 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58879 + old_mnt);
58880 +
58881 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58882 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58883 + return mode;
58884 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58885 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58886 + return 0;
58887 + } else if (unlikely((mode & needmode) != needmode))
58888 + return 0;
58889 +
58890 + return 1;
58891 +}
58892 +
58893 +__u32
58894 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58895 + const struct dentry * parent_dentry,
58896 + const struct vfsmount * parent_mnt, const struct filename *from)
58897 +{
58898 + __u32 needmode = GR_WRITE | GR_CREATE;
58899 + __u32 mode;
58900 +
58901 + mode =
58902 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
58903 + GR_CREATE | GR_AUDIT_CREATE |
58904 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58905 +
58906 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58907 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58908 + return mode;
58909 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58910 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58911 + return 0;
58912 + } else if (unlikely((mode & needmode) != needmode))
58913 + return 0;
58914 +
58915 + return (GR_WRITE | GR_CREATE);
58916 +}
58917 +
58918 +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)
58919 +{
58920 + __u32 mode;
58921 +
58922 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58923 +
58924 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58925 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58926 + return mode;
58927 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58928 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58929 + return 0;
58930 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58931 + return 0;
58932 +
58933 + return (reqmode);
58934 +}
58935 +
58936 +__u32
58937 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58938 + const struct dentry * parent_dentry,
58939 + const struct vfsmount * parent_mnt,
58940 + const int mode)
58941 +{
58942 + __u32 reqmode = GR_WRITE | GR_CREATE;
58943 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58944 + reqmode |= GR_SETID;
58945 +
58946 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58947 + reqmode, GR_MKNOD_ACL_MSG);
58948 +}
58949 +
58950 +__u32
58951 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
58952 + const struct dentry *parent_dentry,
58953 + const struct vfsmount *parent_mnt)
58954 +{
58955 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58956 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58957 +}
58958 +
58959 +#define RENAME_CHECK_SUCCESS(old, new) \
58960 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58961 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58962 +
58963 +int
58964 +gr_acl_handle_rename(struct dentry *new_dentry,
58965 + struct dentry *parent_dentry,
58966 + const struct vfsmount *parent_mnt,
58967 + struct dentry *old_dentry,
58968 + struct inode *old_parent_inode,
58969 + struct vfsmount *old_mnt, const struct filename *newname)
58970 +{
58971 + __u32 comp1, comp2;
58972 + int error = 0;
58973 +
58974 + if (unlikely(!gr_acl_is_enabled()))
58975 + return 0;
58976 +
58977 + if (!new_dentry->d_inode) {
58978 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58979 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58980 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58981 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58982 + GR_DELETE | GR_AUDIT_DELETE |
58983 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58984 + GR_SUPPRESS, old_mnt);
58985 + } else {
58986 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
58987 + GR_CREATE | GR_DELETE |
58988 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
58989 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58990 + GR_SUPPRESS, parent_mnt);
58991 + comp2 =
58992 + gr_search_file(old_dentry,
58993 + GR_READ | GR_WRITE | GR_AUDIT_READ |
58994 + GR_DELETE | GR_AUDIT_DELETE |
58995 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
58996 + }
58997 +
58998 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
58999 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
59000 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59001 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
59002 + && !(comp2 & GR_SUPPRESS)) {
59003 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59004 + error = -EACCES;
59005 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
59006 + error = -EACCES;
59007 +
59008 + return error;
59009 +}
59010 +
59011 +void
59012 +gr_acl_handle_exit(void)
59013 +{
59014 + u16 id;
59015 + char *rolename;
59016 +
59017 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
59018 + !(current->role->roletype & GR_ROLE_PERSIST))) {
59019 + id = current->acl_role_id;
59020 + rolename = current->role->rolename;
59021 + gr_set_acls(1);
59022 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
59023 + }
59024 +
59025 + gr_put_exec_file(current);
59026 + return;
59027 +}
59028 +
59029 +int
59030 +gr_acl_handle_procpidmem(const struct task_struct *task)
59031 +{
59032 + if (unlikely(!gr_acl_is_enabled()))
59033 + return 0;
59034 +
59035 + if (task != current && task->acl->mode & GR_PROTPROCFD)
59036 + return -EACCES;
59037 +
59038 + return 0;
59039 +}
59040 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
59041 new file mode 100644
59042 index 0000000..58800a7
59043 --- /dev/null
59044 +++ b/grsecurity/gracl_ip.c
59045 @@ -0,0 +1,384 @@
59046 +#include <linux/kernel.h>
59047 +#include <asm/uaccess.h>
59048 +#include <asm/errno.h>
59049 +#include <net/sock.h>
59050 +#include <linux/file.h>
59051 +#include <linux/fs.h>
59052 +#include <linux/net.h>
59053 +#include <linux/in.h>
59054 +#include <linux/skbuff.h>
59055 +#include <linux/ip.h>
59056 +#include <linux/udp.h>
59057 +#include <linux/types.h>
59058 +#include <linux/sched.h>
59059 +#include <linux/netdevice.h>
59060 +#include <linux/inetdevice.h>
59061 +#include <linux/gracl.h>
59062 +#include <linux/grsecurity.h>
59063 +#include <linux/grinternal.h>
59064 +
59065 +#define GR_BIND 0x01
59066 +#define GR_CONNECT 0x02
59067 +#define GR_INVERT 0x04
59068 +#define GR_BINDOVERRIDE 0x08
59069 +#define GR_CONNECTOVERRIDE 0x10
59070 +#define GR_SOCK_FAMILY 0x20
59071 +
59072 +static const char * gr_protocols[IPPROTO_MAX] = {
59073 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
59074 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
59075 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
59076 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
59077 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
59078 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
59079 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
59080 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
59081 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
59082 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
59083 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
59084 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
59085 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
59086 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
59087 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
59088 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
59089 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
59090 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
59091 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
59092 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
59093 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
59094 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
59095 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
59096 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
59097 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
59098 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
59099 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
59100 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
59101 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
59102 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
59103 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
59104 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
59105 + };
59106 +
59107 +static const char * gr_socktypes[SOCK_MAX] = {
59108 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
59109 + "unknown:7", "unknown:8", "unknown:9", "packet"
59110 + };
59111 +
59112 +static const char * gr_sockfamilies[AF_MAX+1] = {
59113 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
59114 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
59115 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
59116 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
59117 + };
59118 +
59119 +const char *
59120 +gr_proto_to_name(unsigned char proto)
59121 +{
59122 + return gr_protocols[proto];
59123 +}
59124 +
59125 +const char *
59126 +gr_socktype_to_name(unsigned char type)
59127 +{
59128 + return gr_socktypes[type];
59129 +}
59130 +
59131 +const char *
59132 +gr_sockfamily_to_name(unsigned char family)
59133 +{
59134 + return gr_sockfamilies[family];
59135 +}
59136 +
59137 +int
59138 +gr_search_socket(const int domain, const int type, const int protocol)
59139 +{
59140 + struct acl_subject_label *curr;
59141 + const struct cred *cred = current_cred();
59142 +
59143 + if (unlikely(!gr_acl_is_enabled()))
59144 + goto exit;
59145 +
59146 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
59147 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
59148 + goto exit; // let the kernel handle it
59149 +
59150 + curr = current->acl;
59151 +
59152 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
59153 + /* the family is allowed, if this is PF_INET allow it only if
59154 + the extra sock type/protocol checks pass */
59155 + if (domain == PF_INET)
59156 + goto inet_check;
59157 + goto exit;
59158 + } else {
59159 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59160 + __u32 fakeip = 0;
59161 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59162 + current->role->roletype, cred->uid,
59163 + cred->gid, current->exec_file ?
59164 + gr_to_filename(current->exec_file->f_path.dentry,
59165 + current->exec_file->f_path.mnt) :
59166 + curr->filename, curr->filename,
59167 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
59168 + &current->signal->saved_ip);
59169 + goto exit;
59170 + }
59171 + goto exit_fail;
59172 + }
59173 +
59174 +inet_check:
59175 + /* the rest of this checking is for IPv4 only */
59176 + if (!curr->ips)
59177 + goto exit;
59178 +
59179 + if ((curr->ip_type & (1 << type)) &&
59180 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
59181 + goto exit;
59182 +
59183 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59184 + /* we don't place acls on raw sockets , and sometimes
59185 + dgram/ip sockets are opened for ioctl and not
59186 + bind/connect, so we'll fake a bind learn log */
59187 + if (type == SOCK_RAW || type == SOCK_PACKET) {
59188 + __u32 fakeip = 0;
59189 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59190 + current->role->roletype, cred->uid,
59191 + cred->gid, current->exec_file ?
59192 + gr_to_filename(current->exec_file->f_path.dentry,
59193 + current->exec_file->f_path.mnt) :
59194 + curr->filename, curr->filename,
59195 + &fakeip, 0, type,
59196 + protocol, GR_CONNECT, &current->signal->saved_ip);
59197 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
59198 + __u32 fakeip = 0;
59199 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59200 + current->role->roletype, cred->uid,
59201 + cred->gid, current->exec_file ?
59202 + gr_to_filename(current->exec_file->f_path.dentry,
59203 + current->exec_file->f_path.mnt) :
59204 + curr->filename, curr->filename,
59205 + &fakeip, 0, type,
59206 + protocol, GR_BIND, &current->signal->saved_ip);
59207 + }
59208 + /* we'll log when they use connect or bind */
59209 + goto exit;
59210 + }
59211 +
59212 +exit_fail:
59213 + if (domain == PF_INET)
59214 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
59215 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
59216 + else
59217 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
59218 + gr_socktype_to_name(type), protocol);
59219 +
59220 + return 0;
59221 +exit:
59222 + return 1;
59223 +}
59224 +
59225 +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)
59226 +{
59227 + if ((ip->mode & mode) &&
59228 + (ip_port >= ip->low) &&
59229 + (ip_port <= ip->high) &&
59230 + ((ntohl(ip_addr) & our_netmask) ==
59231 + (ntohl(our_addr) & our_netmask))
59232 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
59233 + && (ip->type & (1 << type))) {
59234 + if (ip->mode & GR_INVERT)
59235 + return 2; // specifically denied
59236 + else
59237 + return 1; // allowed
59238 + }
59239 +
59240 + return 0; // not specifically allowed, may continue parsing
59241 +}
59242 +
59243 +static int
59244 +gr_search_connectbind(const int full_mode, struct sock *sk,
59245 + struct sockaddr_in *addr, const int type)
59246 +{
59247 + char iface[IFNAMSIZ] = {0};
59248 + struct acl_subject_label *curr;
59249 + struct acl_ip_label *ip;
59250 + struct inet_sock *isk;
59251 + struct net_device *dev;
59252 + struct in_device *idev;
59253 + unsigned long i;
59254 + int ret;
59255 + int mode = full_mode & (GR_BIND | GR_CONNECT);
59256 + __u32 ip_addr = 0;
59257 + __u32 our_addr;
59258 + __u32 our_netmask;
59259 + char *p;
59260 + __u16 ip_port = 0;
59261 + const struct cred *cred = current_cred();
59262 +
59263 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
59264 + return 0;
59265 +
59266 + curr = current->acl;
59267 + isk = inet_sk(sk);
59268 +
59269 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
59270 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
59271 + addr->sin_addr.s_addr = curr->inaddr_any_override;
59272 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
59273 + struct sockaddr_in saddr;
59274 + int err;
59275 +
59276 + saddr.sin_family = AF_INET;
59277 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
59278 + saddr.sin_port = isk->inet_sport;
59279 +
59280 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59281 + if (err)
59282 + return err;
59283 +
59284 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59285 + if (err)
59286 + return err;
59287 + }
59288 +
59289 + if (!curr->ips)
59290 + return 0;
59291 +
59292 + ip_addr = addr->sin_addr.s_addr;
59293 + ip_port = ntohs(addr->sin_port);
59294 +
59295 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59296 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59297 + current->role->roletype, cred->uid,
59298 + cred->gid, current->exec_file ?
59299 + gr_to_filename(current->exec_file->f_path.dentry,
59300 + current->exec_file->f_path.mnt) :
59301 + curr->filename, curr->filename,
59302 + &ip_addr, ip_port, type,
59303 + sk->sk_protocol, mode, &current->signal->saved_ip);
59304 + return 0;
59305 + }
59306 +
59307 + for (i = 0; i < curr->ip_num; i++) {
59308 + ip = *(curr->ips + i);
59309 + if (ip->iface != NULL) {
59310 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
59311 + p = strchr(iface, ':');
59312 + if (p != NULL)
59313 + *p = '\0';
59314 + dev = dev_get_by_name(sock_net(sk), iface);
59315 + if (dev == NULL)
59316 + continue;
59317 + idev = in_dev_get(dev);
59318 + if (idev == NULL) {
59319 + dev_put(dev);
59320 + continue;
59321 + }
59322 + rcu_read_lock();
59323 + for_ifa(idev) {
59324 + if (!strcmp(ip->iface, ifa->ifa_label)) {
59325 + our_addr = ifa->ifa_address;
59326 + our_netmask = 0xffffffff;
59327 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59328 + if (ret == 1) {
59329 + rcu_read_unlock();
59330 + in_dev_put(idev);
59331 + dev_put(dev);
59332 + return 0;
59333 + } else if (ret == 2) {
59334 + rcu_read_unlock();
59335 + in_dev_put(idev);
59336 + dev_put(dev);
59337 + goto denied;
59338 + }
59339 + }
59340 + } endfor_ifa(idev);
59341 + rcu_read_unlock();
59342 + in_dev_put(idev);
59343 + dev_put(dev);
59344 + } else {
59345 + our_addr = ip->addr;
59346 + our_netmask = ip->netmask;
59347 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59348 + if (ret == 1)
59349 + return 0;
59350 + else if (ret == 2)
59351 + goto denied;
59352 + }
59353 + }
59354 +
59355 +denied:
59356 + if (mode == GR_BIND)
59357 + 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));
59358 + else if (mode == GR_CONNECT)
59359 + 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));
59360 +
59361 + return -EACCES;
59362 +}
59363 +
59364 +int
59365 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
59366 +{
59367 + /* always allow disconnection of dgram sockets with connect */
59368 + if (addr->sin_family == AF_UNSPEC)
59369 + return 0;
59370 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
59371 +}
59372 +
59373 +int
59374 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
59375 +{
59376 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
59377 +}
59378 +
59379 +int gr_search_listen(struct socket *sock)
59380 +{
59381 + struct sock *sk = sock->sk;
59382 + struct sockaddr_in addr;
59383 +
59384 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59385 + addr.sin_port = inet_sk(sk)->inet_sport;
59386 +
59387 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59388 +}
59389 +
59390 +int gr_search_accept(struct socket *sock)
59391 +{
59392 + struct sock *sk = sock->sk;
59393 + struct sockaddr_in addr;
59394 +
59395 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59396 + addr.sin_port = inet_sk(sk)->inet_sport;
59397 +
59398 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59399 +}
59400 +
59401 +int
59402 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
59403 +{
59404 + if (addr)
59405 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
59406 + else {
59407 + struct sockaddr_in sin;
59408 + const struct inet_sock *inet = inet_sk(sk);
59409 +
59410 + sin.sin_addr.s_addr = inet->inet_daddr;
59411 + sin.sin_port = inet->inet_dport;
59412 +
59413 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59414 + }
59415 +}
59416 +
59417 +int
59418 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
59419 +{
59420 + struct sockaddr_in sin;
59421 +
59422 + if (unlikely(skb->len < sizeof (struct udphdr)))
59423 + return 0; // skip this packet
59424 +
59425 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
59426 + sin.sin_port = udp_hdr(skb)->source;
59427 +
59428 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59429 +}
59430 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
59431 new file mode 100644
59432 index 0000000..25f54ef
59433 --- /dev/null
59434 +++ b/grsecurity/gracl_learn.c
59435 @@ -0,0 +1,207 @@
59436 +#include <linux/kernel.h>
59437 +#include <linux/mm.h>
59438 +#include <linux/sched.h>
59439 +#include <linux/poll.h>
59440 +#include <linux/string.h>
59441 +#include <linux/file.h>
59442 +#include <linux/types.h>
59443 +#include <linux/vmalloc.h>
59444 +#include <linux/grinternal.h>
59445 +
59446 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
59447 + size_t count, loff_t *ppos);
59448 +extern int gr_acl_is_enabled(void);
59449 +
59450 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
59451 +static int gr_learn_attached;
59452 +
59453 +/* use a 512k buffer */
59454 +#define LEARN_BUFFER_SIZE (512 * 1024)
59455 +
59456 +static DEFINE_SPINLOCK(gr_learn_lock);
59457 +static DEFINE_MUTEX(gr_learn_user_mutex);
59458 +
59459 +/* we need to maintain two buffers, so that the kernel context of grlearn
59460 + uses a semaphore around the userspace copying, and the other kernel contexts
59461 + use a spinlock when copying into the buffer, since they cannot sleep
59462 +*/
59463 +static char *learn_buffer;
59464 +static char *learn_buffer_user;
59465 +static int learn_buffer_len;
59466 +static int learn_buffer_user_len;
59467 +
59468 +static ssize_t
59469 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
59470 +{
59471 + DECLARE_WAITQUEUE(wait, current);
59472 + ssize_t retval = 0;
59473 +
59474 + add_wait_queue(&learn_wait, &wait);
59475 + set_current_state(TASK_INTERRUPTIBLE);
59476 + do {
59477 + mutex_lock(&gr_learn_user_mutex);
59478 + spin_lock(&gr_learn_lock);
59479 + if (learn_buffer_len)
59480 + break;
59481 + spin_unlock(&gr_learn_lock);
59482 + mutex_unlock(&gr_learn_user_mutex);
59483 + if (file->f_flags & O_NONBLOCK) {
59484 + retval = -EAGAIN;
59485 + goto out;
59486 + }
59487 + if (signal_pending(current)) {
59488 + retval = -ERESTARTSYS;
59489 + goto out;
59490 + }
59491 +
59492 + schedule();
59493 + } while (1);
59494 +
59495 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
59496 + learn_buffer_user_len = learn_buffer_len;
59497 + retval = learn_buffer_len;
59498 + learn_buffer_len = 0;
59499 +
59500 + spin_unlock(&gr_learn_lock);
59501 +
59502 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
59503 + retval = -EFAULT;
59504 +
59505 + mutex_unlock(&gr_learn_user_mutex);
59506 +out:
59507 + set_current_state(TASK_RUNNING);
59508 + remove_wait_queue(&learn_wait, &wait);
59509 + return retval;
59510 +}
59511 +
59512 +static unsigned int
59513 +poll_learn(struct file * file, poll_table * wait)
59514 +{
59515 + poll_wait(file, &learn_wait, wait);
59516 +
59517 + if (learn_buffer_len)
59518 + return (POLLIN | POLLRDNORM);
59519 +
59520 + return 0;
59521 +}
59522 +
59523 +void
59524 +gr_clear_learn_entries(void)
59525 +{
59526 + char *tmp;
59527 +
59528 + mutex_lock(&gr_learn_user_mutex);
59529 + spin_lock(&gr_learn_lock);
59530 + tmp = learn_buffer;
59531 + learn_buffer = NULL;
59532 + spin_unlock(&gr_learn_lock);
59533 + if (tmp)
59534 + vfree(tmp);
59535 + if (learn_buffer_user != NULL) {
59536 + vfree(learn_buffer_user);
59537 + learn_buffer_user = NULL;
59538 + }
59539 + learn_buffer_len = 0;
59540 + mutex_unlock(&gr_learn_user_mutex);
59541 +
59542 + return;
59543 +}
59544 +
59545 +void
59546 +gr_add_learn_entry(const char *fmt, ...)
59547 +{
59548 + va_list args;
59549 + unsigned int len;
59550 +
59551 + if (!gr_learn_attached)
59552 + return;
59553 +
59554 + spin_lock(&gr_learn_lock);
59555 +
59556 + /* leave a gap at the end so we know when it's "full" but don't have to
59557 + compute the exact length of the string we're trying to append
59558 + */
59559 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
59560 + spin_unlock(&gr_learn_lock);
59561 + wake_up_interruptible(&learn_wait);
59562 + return;
59563 + }
59564 + if (learn_buffer == NULL) {
59565 + spin_unlock(&gr_learn_lock);
59566 + return;
59567 + }
59568 +
59569 + va_start(args, fmt);
59570 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
59571 + va_end(args);
59572 +
59573 + learn_buffer_len += len + 1;
59574 +
59575 + spin_unlock(&gr_learn_lock);
59576 + wake_up_interruptible(&learn_wait);
59577 +
59578 + return;
59579 +}
59580 +
59581 +static int
59582 +open_learn(struct inode *inode, struct file *file)
59583 +{
59584 + if (file->f_mode & FMODE_READ && gr_learn_attached)
59585 + return -EBUSY;
59586 + if (file->f_mode & FMODE_READ) {
59587 + int retval = 0;
59588 + mutex_lock(&gr_learn_user_mutex);
59589 + if (learn_buffer == NULL)
59590 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
59591 + if (learn_buffer_user == NULL)
59592 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
59593 + if (learn_buffer == NULL) {
59594 + retval = -ENOMEM;
59595 + goto out_error;
59596 + }
59597 + if (learn_buffer_user == NULL) {
59598 + retval = -ENOMEM;
59599 + goto out_error;
59600 + }
59601 + learn_buffer_len = 0;
59602 + learn_buffer_user_len = 0;
59603 + gr_learn_attached = 1;
59604 +out_error:
59605 + mutex_unlock(&gr_learn_user_mutex);
59606 + return retval;
59607 + }
59608 + return 0;
59609 +}
59610 +
59611 +static int
59612 +close_learn(struct inode *inode, struct file *file)
59613 +{
59614 + if (file->f_mode & FMODE_READ) {
59615 + char *tmp = NULL;
59616 + mutex_lock(&gr_learn_user_mutex);
59617 + spin_lock(&gr_learn_lock);
59618 + tmp = learn_buffer;
59619 + learn_buffer = NULL;
59620 + spin_unlock(&gr_learn_lock);
59621 + if (tmp)
59622 + vfree(tmp);
59623 + if (learn_buffer_user != NULL) {
59624 + vfree(learn_buffer_user);
59625 + learn_buffer_user = NULL;
59626 + }
59627 + learn_buffer_len = 0;
59628 + learn_buffer_user_len = 0;
59629 + gr_learn_attached = 0;
59630 + mutex_unlock(&gr_learn_user_mutex);
59631 + }
59632 +
59633 + return 0;
59634 +}
59635 +
59636 +const struct file_operations grsec_fops = {
59637 + .read = read_learn,
59638 + .write = write_grsec_handler,
59639 + .open = open_learn,
59640 + .release = close_learn,
59641 + .poll = poll_learn,
59642 +};
59643 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
59644 new file mode 100644
59645 index 0000000..39645c9
59646 --- /dev/null
59647 +++ b/grsecurity/gracl_res.c
59648 @@ -0,0 +1,68 @@
59649 +#include <linux/kernel.h>
59650 +#include <linux/sched.h>
59651 +#include <linux/gracl.h>
59652 +#include <linux/grinternal.h>
59653 +
59654 +static const char *restab_log[] = {
59655 + [RLIMIT_CPU] = "RLIMIT_CPU",
59656 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
59657 + [RLIMIT_DATA] = "RLIMIT_DATA",
59658 + [RLIMIT_STACK] = "RLIMIT_STACK",
59659 + [RLIMIT_CORE] = "RLIMIT_CORE",
59660 + [RLIMIT_RSS] = "RLIMIT_RSS",
59661 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
59662 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
59663 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
59664 + [RLIMIT_AS] = "RLIMIT_AS",
59665 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
59666 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
59667 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
59668 + [RLIMIT_NICE] = "RLIMIT_NICE",
59669 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
59670 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
59671 + [GR_CRASH_RES] = "RLIMIT_CRASH"
59672 +};
59673 +
59674 +void
59675 +gr_log_resource(const struct task_struct *task,
59676 + const int res, const unsigned long wanted, const int gt)
59677 +{
59678 + const struct cred *cred;
59679 + unsigned long rlim;
59680 +
59681 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
59682 + return;
59683 +
59684 + // not yet supported resource
59685 + if (unlikely(!restab_log[res]))
59686 + return;
59687 +
59688 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59689 + rlim = task_rlimit_max(task, res);
59690 + else
59691 + rlim = task_rlimit(task, res);
59692 +
59693 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59694 + return;
59695 +
59696 + rcu_read_lock();
59697 + cred = __task_cred(task);
59698 +
59699 + if (res == RLIMIT_NPROC &&
59700 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59701 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59702 + goto out_rcu_unlock;
59703 + else if (res == RLIMIT_MEMLOCK &&
59704 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59705 + goto out_rcu_unlock;
59706 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59707 + goto out_rcu_unlock;
59708 + rcu_read_unlock();
59709 +
59710 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59711 +
59712 + return;
59713 +out_rcu_unlock:
59714 + rcu_read_unlock();
59715 + return;
59716 +}
59717 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59718 new file mode 100644
59719 index 0000000..25197e9
59720 --- /dev/null
59721 +++ b/grsecurity/gracl_segv.c
59722 @@ -0,0 +1,299 @@
59723 +#include <linux/kernel.h>
59724 +#include <linux/mm.h>
59725 +#include <asm/uaccess.h>
59726 +#include <asm/errno.h>
59727 +#include <asm/mman.h>
59728 +#include <net/sock.h>
59729 +#include <linux/file.h>
59730 +#include <linux/fs.h>
59731 +#include <linux/net.h>
59732 +#include <linux/in.h>
59733 +#include <linux/slab.h>
59734 +#include <linux/types.h>
59735 +#include <linux/sched.h>
59736 +#include <linux/timer.h>
59737 +#include <linux/gracl.h>
59738 +#include <linux/grsecurity.h>
59739 +#include <linux/grinternal.h>
59740 +
59741 +static struct crash_uid *uid_set;
59742 +static unsigned short uid_used;
59743 +static DEFINE_SPINLOCK(gr_uid_lock);
59744 +extern rwlock_t gr_inode_lock;
59745 +extern struct acl_subject_label *
59746 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59747 + struct acl_role_label *role);
59748 +
59749 +#ifdef CONFIG_BTRFS_FS
59750 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59751 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59752 +#endif
59753 +
59754 +static inline dev_t __get_dev(const struct dentry *dentry)
59755 +{
59756 +#ifdef CONFIG_BTRFS_FS
59757 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59758 + return get_btrfs_dev_from_inode(dentry->d_inode);
59759 + else
59760 +#endif
59761 + return dentry->d_inode->i_sb->s_dev;
59762 +}
59763 +
59764 +int
59765 +gr_init_uidset(void)
59766 +{
59767 + uid_set =
59768 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59769 + uid_used = 0;
59770 +
59771 + return uid_set ? 1 : 0;
59772 +}
59773 +
59774 +void
59775 +gr_free_uidset(void)
59776 +{
59777 + if (uid_set)
59778 + kfree(uid_set);
59779 +
59780 + return;
59781 +}
59782 +
59783 +int
59784 +gr_find_uid(const uid_t uid)
59785 +{
59786 + struct crash_uid *tmp = uid_set;
59787 + uid_t buid;
59788 + int low = 0, high = uid_used - 1, mid;
59789 +
59790 + while (high >= low) {
59791 + mid = (low + high) >> 1;
59792 + buid = tmp[mid].uid;
59793 + if (buid == uid)
59794 + return mid;
59795 + if (buid > uid)
59796 + high = mid - 1;
59797 + if (buid < uid)
59798 + low = mid + 1;
59799 + }
59800 +
59801 + return -1;
59802 +}
59803 +
59804 +static __inline__ void
59805 +gr_insertsort(void)
59806 +{
59807 + unsigned short i, j;
59808 + struct crash_uid index;
59809 +
59810 + for (i = 1; i < uid_used; i++) {
59811 + index = uid_set[i];
59812 + j = i;
59813 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59814 + uid_set[j] = uid_set[j - 1];
59815 + j--;
59816 + }
59817 + uid_set[j] = index;
59818 + }
59819 +
59820 + return;
59821 +}
59822 +
59823 +static __inline__ void
59824 +gr_insert_uid(const uid_t uid, const unsigned long expires)
59825 +{
59826 + int loc;
59827 +
59828 + if (uid_used == GR_UIDTABLE_MAX)
59829 + return;
59830 +
59831 + loc = gr_find_uid(uid);
59832 +
59833 + if (loc >= 0) {
59834 + uid_set[loc].expires = expires;
59835 + return;
59836 + }
59837 +
59838 + uid_set[uid_used].uid = uid;
59839 + uid_set[uid_used].expires = expires;
59840 + uid_used++;
59841 +
59842 + gr_insertsort();
59843 +
59844 + return;
59845 +}
59846 +
59847 +void
59848 +gr_remove_uid(const unsigned short loc)
59849 +{
59850 + unsigned short i;
59851 +
59852 + for (i = loc + 1; i < uid_used; i++)
59853 + uid_set[i - 1] = uid_set[i];
59854 +
59855 + uid_used--;
59856 +
59857 + return;
59858 +}
59859 +
59860 +int
59861 +gr_check_crash_uid(const uid_t uid)
59862 +{
59863 + int loc;
59864 + int ret = 0;
59865 +
59866 + if (unlikely(!gr_acl_is_enabled()))
59867 + return 0;
59868 +
59869 + spin_lock(&gr_uid_lock);
59870 + loc = gr_find_uid(uid);
59871 +
59872 + if (loc < 0)
59873 + goto out_unlock;
59874 +
59875 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
59876 + gr_remove_uid(loc);
59877 + else
59878 + ret = 1;
59879 +
59880 +out_unlock:
59881 + spin_unlock(&gr_uid_lock);
59882 + return ret;
59883 +}
59884 +
59885 +static __inline__ int
59886 +proc_is_setxid(const struct cred *cred)
59887 +{
59888 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59889 + !uid_eq(cred->uid, cred->fsuid))
59890 + return 1;
59891 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59892 + !uid_eq(cred->gid, cred->fsgid))
59893 + return 1;
59894 +
59895 + return 0;
59896 +}
59897 +
59898 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
59899 +
59900 +void
59901 +gr_handle_crash(struct task_struct *task, const int sig)
59902 +{
59903 + struct acl_subject_label *curr;
59904 + struct task_struct *tsk, *tsk2;
59905 + const struct cred *cred;
59906 + const struct cred *cred2;
59907 +
59908 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59909 + return;
59910 +
59911 + if (unlikely(!gr_acl_is_enabled()))
59912 + return;
59913 +
59914 + curr = task->acl;
59915 +
59916 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
59917 + return;
59918 +
59919 + if (time_before_eq(curr->expires, get_seconds())) {
59920 + curr->expires = 0;
59921 + curr->crashes = 0;
59922 + }
59923 +
59924 + curr->crashes++;
59925 +
59926 + if (!curr->expires)
59927 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59928 +
59929 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59930 + time_after(curr->expires, get_seconds())) {
59931 + rcu_read_lock();
59932 + cred = __task_cred(task);
59933 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59934 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59935 + spin_lock(&gr_uid_lock);
59936 + gr_insert_uid(cred->uid, curr->expires);
59937 + spin_unlock(&gr_uid_lock);
59938 + curr->expires = 0;
59939 + curr->crashes = 0;
59940 + read_lock(&tasklist_lock);
59941 + do_each_thread(tsk2, tsk) {
59942 + cred2 = __task_cred(tsk);
59943 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
59944 + gr_fake_force_sig(SIGKILL, tsk);
59945 + } while_each_thread(tsk2, tsk);
59946 + read_unlock(&tasklist_lock);
59947 + } else {
59948 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59949 + read_lock(&tasklist_lock);
59950 + read_lock(&grsec_exec_file_lock);
59951 + do_each_thread(tsk2, tsk) {
59952 + if (likely(tsk != task)) {
59953 + // if this thread has the same subject as the one that triggered
59954 + // RES_CRASH and it's the same binary, kill it
59955 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59956 + gr_fake_force_sig(SIGKILL, tsk);
59957 + }
59958 + } while_each_thread(tsk2, tsk);
59959 + read_unlock(&grsec_exec_file_lock);
59960 + read_unlock(&tasklist_lock);
59961 + }
59962 + rcu_read_unlock();
59963 + }
59964 +
59965 + return;
59966 +}
59967 +
59968 +int
59969 +gr_check_crash_exec(const struct file *filp)
59970 +{
59971 + struct acl_subject_label *curr;
59972 +
59973 + if (unlikely(!gr_acl_is_enabled()))
59974 + return 0;
59975 +
59976 + read_lock(&gr_inode_lock);
59977 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59978 + __get_dev(filp->f_path.dentry),
59979 + current->role);
59980 + read_unlock(&gr_inode_lock);
59981 +
59982 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59983 + (!curr->crashes && !curr->expires))
59984 + return 0;
59985 +
59986 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59987 + time_after(curr->expires, get_seconds()))
59988 + return 1;
59989 + else if (time_before_eq(curr->expires, get_seconds())) {
59990 + curr->crashes = 0;
59991 + curr->expires = 0;
59992 + }
59993 +
59994 + return 0;
59995 +}
59996 +
59997 +void
59998 +gr_handle_alertkill(struct task_struct *task)
59999 +{
60000 + struct acl_subject_label *curracl;
60001 + __u32 curr_ip;
60002 + struct task_struct *p, *p2;
60003 +
60004 + if (unlikely(!gr_acl_is_enabled()))
60005 + return;
60006 +
60007 + curracl = task->acl;
60008 + curr_ip = task->signal->curr_ip;
60009 +
60010 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
60011 + read_lock(&tasklist_lock);
60012 + do_each_thread(p2, p) {
60013 + if (p->signal->curr_ip == curr_ip)
60014 + gr_fake_force_sig(SIGKILL, p);
60015 + } while_each_thread(p2, p);
60016 + read_unlock(&tasklist_lock);
60017 + } else if (curracl->mode & GR_KILLPROC)
60018 + gr_fake_force_sig(SIGKILL, task);
60019 +
60020 + return;
60021 +}
60022 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
60023 new file mode 100644
60024 index 0000000..9d83a69
60025 --- /dev/null
60026 +++ b/grsecurity/gracl_shm.c
60027 @@ -0,0 +1,40 @@
60028 +#include <linux/kernel.h>
60029 +#include <linux/mm.h>
60030 +#include <linux/sched.h>
60031 +#include <linux/file.h>
60032 +#include <linux/ipc.h>
60033 +#include <linux/gracl.h>
60034 +#include <linux/grsecurity.h>
60035 +#include <linux/grinternal.h>
60036 +
60037 +int
60038 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60039 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60040 +{
60041 + struct task_struct *task;
60042 +
60043 + if (!gr_acl_is_enabled())
60044 + return 1;
60045 +
60046 + rcu_read_lock();
60047 + read_lock(&tasklist_lock);
60048 +
60049 + task = find_task_by_vpid(shm_cprid);
60050 +
60051 + if (unlikely(!task))
60052 + task = find_task_by_vpid(shm_lapid);
60053 +
60054 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
60055 + (task->pid == shm_lapid)) &&
60056 + (task->acl->mode & GR_PROTSHM) &&
60057 + (task->acl != current->acl))) {
60058 + read_unlock(&tasklist_lock);
60059 + rcu_read_unlock();
60060 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
60061 + return 0;
60062 + }
60063 + read_unlock(&tasklist_lock);
60064 + rcu_read_unlock();
60065 +
60066 + return 1;
60067 +}
60068 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
60069 new file mode 100644
60070 index 0000000..bc0be01
60071 --- /dev/null
60072 +++ b/grsecurity/grsec_chdir.c
60073 @@ -0,0 +1,19 @@
60074 +#include <linux/kernel.h>
60075 +#include <linux/sched.h>
60076 +#include <linux/fs.h>
60077 +#include <linux/file.h>
60078 +#include <linux/grsecurity.h>
60079 +#include <linux/grinternal.h>
60080 +
60081 +void
60082 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
60083 +{
60084 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60085 + if ((grsec_enable_chdir && grsec_enable_group &&
60086 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
60087 + !grsec_enable_group)) {
60088 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
60089 + }
60090 +#endif
60091 + return;
60092 +}
60093 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
60094 new file mode 100644
60095 index 0000000..70fe0ae
60096 --- /dev/null
60097 +++ b/grsecurity/grsec_chroot.c
60098 @@ -0,0 +1,357 @@
60099 +#include <linux/kernel.h>
60100 +#include <linux/module.h>
60101 +#include <linux/sched.h>
60102 +#include <linux/file.h>
60103 +#include <linux/fs.h>
60104 +#include <linux/mount.h>
60105 +#include <linux/types.h>
60106 +#include "../fs/mount.h"
60107 +#include <linux/grsecurity.h>
60108 +#include <linux/grinternal.h>
60109 +
60110 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
60111 +{
60112 +#ifdef CONFIG_GRKERNSEC
60113 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
60114 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
60115 + task->gr_is_chrooted = 1;
60116 + else
60117 + task->gr_is_chrooted = 0;
60118 +
60119 + task->gr_chroot_dentry = path->dentry;
60120 +#endif
60121 + return;
60122 +}
60123 +
60124 +void gr_clear_chroot_entries(struct task_struct *task)
60125 +{
60126 +#ifdef CONFIG_GRKERNSEC
60127 + task->gr_is_chrooted = 0;
60128 + task->gr_chroot_dentry = NULL;
60129 +#endif
60130 + return;
60131 +}
60132 +
60133 +int
60134 +gr_handle_chroot_unix(const pid_t pid)
60135 +{
60136 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60137 + struct task_struct *p;
60138 +
60139 + if (unlikely(!grsec_enable_chroot_unix))
60140 + return 1;
60141 +
60142 + if (likely(!proc_is_chrooted(current)))
60143 + return 1;
60144 +
60145 + rcu_read_lock();
60146 + read_lock(&tasklist_lock);
60147 + p = find_task_by_vpid_unrestricted(pid);
60148 + if (unlikely(p && !have_same_root(current, p))) {
60149 + read_unlock(&tasklist_lock);
60150 + rcu_read_unlock();
60151 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
60152 + return 0;
60153 + }
60154 + read_unlock(&tasklist_lock);
60155 + rcu_read_unlock();
60156 +#endif
60157 + return 1;
60158 +}
60159 +
60160 +int
60161 +gr_handle_chroot_nice(void)
60162 +{
60163 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60164 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
60165 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
60166 + return -EPERM;
60167 + }
60168 +#endif
60169 + return 0;
60170 +}
60171 +
60172 +int
60173 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
60174 +{
60175 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60176 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
60177 + && proc_is_chrooted(current)) {
60178 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
60179 + return -EACCES;
60180 + }
60181 +#endif
60182 + return 0;
60183 +}
60184 +
60185 +int
60186 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
60187 +{
60188 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60189 + struct task_struct *p;
60190 + int ret = 0;
60191 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
60192 + return ret;
60193 +
60194 + read_lock(&tasklist_lock);
60195 + do_each_pid_task(pid, type, p) {
60196 + if (!have_same_root(current, p)) {
60197 + ret = 1;
60198 + goto out;
60199 + }
60200 + } while_each_pid_task(pid, type, p);
60201 +out:
60202 + read_unlock(&tasklist_lock);
60203 + return ret;
60204 +#endif
60205 + return 0;
60206 +}
60207 +
60208 +int
60209 +gr_pid_is_chrooted(struct task_struct *p)
60210 +{
60211 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60212 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
60213 + return 0;
60214 +
60215 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
60216 + !have_same_root(current, p)) {
60217 + return 1;
60218 + }
60219 +#endif
60220 + return 0;
60221 +}
60222 +
60223 +EXPORT_SYMBOL(gr_pid_is_chrooted);
60224 +
60225 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
60226 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
60227 +{
60228 + struct path path, currentroot;
60229 + int ret = 0;
60230 +
60231 + path.dentry = (struct dentry *)u_dentry;
60232 + path.mnt = (struct vfsmount *)u_mnt;
60233 + get_fs_root(current->fs, &currentroot);
60234 + if (path_is_under(&path, &currentroot))
60235 + ret = 1;
60236 + path_put(&currentroot);
60237 +
60238 + return ret;
60239 +}
60240 +#endif
60241 +
60242 +int
60243 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
60244 +{
60245 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60246 + if (!grsec_enable_chroot_fchdir)
60247 + return 1;
60248 +
60249 + if (!proc_is_chrooted(current))
60250 + return 1;
60251 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
60252 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
60253 + return 0;
60254 + }
60255 +#endif
60256 + return 1;
60257 +}
60258 +
60259 +int
60260 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60261 + const time_t shm_createtime)
60262 +{
60263 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60264 + struct task_struct *p;
60265 + time_t starttime;
60266 +
60267 + if (unlikely(!grsec_enable_chroot_shmat))
60268 + return 1;
60269 +
60270 + if (likely(!proc_is_chrooted(current)))
60271 + return 1;
60272 +
60273 + rcu_read_lock();
60274 + read_lock(&tasklist_lock);
60275 +
60276 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
60277 + starttime = p->start_time.tv_sec;
60278 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
60279 + if (have_same_root(current, p)) {
60280 + goto allow;
60281 + } else {
60282 + read_unlock(&tasklist_lock);
60283 + rcu_read_unlock();
60284 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60285 + return 0;
60286 + }
60287 + }
60288 + /* creator exited, pid reuse, fall through to next check */
60289 + }
60290 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
60291 + if (unlikely(!have_same_root(current, p))) {
60292 + read_unlock(&tasklist_lock);
60293 + rcu_read_unlock();
60294 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60295 + return 0;
60296 + }
60297 + }
60298 +
60299 +allow:
60300 + read_unlock(&tasklist_lock);
60301 + rcu_read_unlock();
60302 +#endif
60303 + return 1;
60304 +}
60305 +
60306 +void
60307 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
60308 +{
60309 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60310 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
60311 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
60312 +#endif
60313 + return;
60314 +}
60315 +
60316 +int
60317 +gr_handle_chroot_mknod(const struct dentry *dentry,
60318 + const struct vfsmount *mnt, const int mode)
60319 +{
60320 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60321 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
60322 + proc_is_chrooted(current)) {
60323 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
60324 + return -EPERM;
60325 + }
60326 +#endif
60327 + return 0;
60328 +}
60329 +
60330 +int
60331 +gr_handle_chroot_mount(const struct dentry *dentry,
60332 + const struct vfsmount *mnt, const char *dev_name)
60333 +{
60334 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60335 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
60336 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
60337 + return -EPERM;
60338 + }
60339 +#endif
60340 + return 0;
60341 +}
60342 +
60343 +int
60344 +gr_handle_chroot_pivot(void)
60345 +{
60346 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60347 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
60348 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
60349 + return -EPERM;
60350 + }
60351 +#endif
60352 + return 0;
60353 +}
60354 +
60355 +int
60356 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
60357 +{
60358 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60359 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
60360 + !gr_is_outside_chroot(dentry, mnt)) {
60361 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
60362 + return -EPERM;
60363 + }
60364 +#endif
60365 + return 0;
60366 +}
60367 +
60368 +extern const char *captab_log[];
60369 +extern int captab_log_entries;
60370 +
60371 +int
60372 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60373 +{
60374 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60375 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60376 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60377 + if (cap_raised(chroot_caps, cap)) {
60378 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
60379 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
60380 + }
60381 + return 0;
60382 + }
60383 + }
60384 +#endif
60385 + return 1;
60386 +}
60387 +
60388 +int
60389 +gr_chroot_is_capable(const int cap)
60390 +{
60391 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60392 + return gr_task_chroot_is_capable(current, current_cred(), cap);
60393 +#endif
60394 + return 1;
60395 +}
60396 +
60397 +int
60398 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
60399 +{
60400 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60401 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60402 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60403 + if (cap_raised(chroot_caps, cap)) {
60404 + return 0;
60405 + }
60406 + }
60407 +#endif
60408 + return 1;
60409 +}
60410 +
60411 +int
60412 +gr_chroot_is_capable_nolog(const int cap)
60413 +{
60414 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60415 + return gr_task_chroot_is_capable_nolog(current, cap);
60416 +#endif
60417 + return 1;
60418 +}
60419 +
60420 +int
60421 +gr_handle_chroot_sysctl(const int op)
60422 +{
60423 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60424 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
60425 + proc_is_chrooted(current))
60426 + return -EACCES;
60427 +#endif
60428 + return 0;
60429 +}
60430 +
60431 +void
60432 +gr_handle_chroot_chdir(struct path *path)
60433 +{
60434 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60435 + if (grsec_enable_chroot_chdir)
60436 + set_fs_pwd(current->fs, path);
60437 +#endif
60438 + return;
60439 +}
60440 +
60441 +int
60442 +gr_handle_chroot_chmod(const struct dentry *dentry,
60443 + const struct vfsmount *mnt, const int mode)
60444 +{
60445 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60446 + /* allow chmod +s on directories, but not files */
60447 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
60448 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
60449 + proc_is_chrooted(current)) {
60450 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
60451 + return -EPERM;
60452 + }
60453 +#endif
60454 + return 0;
60455 +}
60456 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
60457 new file mode 100644
60458 index 0000000..e6796b3
60459 --- /dev/null
60460 +++ b/grsecurity/grsec_disabled.c
60461 @@ -0,0 +1,434 @@
60462 +#include <linux/kernel.h>
60463 +#include <linux/module.h>
60464 +#include <linux/sched.h>
60465 +#include <linux/file.h>
60466 +#include <linux/fs.h>
60467 +#include <linux/kdev_t.h>
60468 +#include <linux/net.h>
60469 +#include <linux/in.h>
60470 +#include <linux/ip.h>
60471 +#include <linux/skbuff.h>
60472 +#include <linux/sysctl.h>
60473 +
60474 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60475 +void
60476 +pax_set_initial_flags(struct linux_binprm *bprm)
60477 +{
60478 + return;
60479 +}
60480 +#endif
60481 +
60482 +#ifdef CONFIG_SYSCTL
60483 +__u32
60484 +gr_handle_sysctl(const struct ctl_table * table, const int op)
60485 +{
60486 + return 0;
60487 +}
60488 +#endif
60489 +
60490 +#ifdef CONFIG_TASKSTATS
60491 +int gr_is_taskstats_denied(int pid)
60492 +{
60493 + return 0;
60494 +}
60495 +#endif
60496 +
60497 +int
60498 +gr_acl_is_enabled(void)
60499 +{
60500 + return 0;
60501 +}
60502 +
60503 +void
60504 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60505 +{
60506 + return;
60507 +}
60508 +
60509 +int
60510 +gr_handle_rawio(const struct inode *inode)
60511 +{
60512 + return 0;
60513 +}
60514 +
60515 +void
60516 +gr_acl_handle_psacct(struct task_struct *task, const long code)
60517 +{
60518 + return;
60519 +}
60520 +
60521 +int
60522 +gr_handle_ptrace(struct task_struct *task, const long request)
60523 +{
60524 + return 0;
60525 +}
60526 +
60527 +int
60528 +gr_handle_proc_ptrace(struct task_struct *task)
60529 +{
60530 + return 0;
60531 +}
60532 +
60533 +int
60534 +gr_set_acls(const int type)
60535 +{
60536 + return 0;
60537 +}
60538 +
60539 +int
60540 +gr_check_hidden_task(const struct task_struct *tsk)
60541 +{
60542 + return 0;
60543 +}
60544 +
60545 +int
60546 +gr_check_protected_task(const struct task_struct *task)
60547 +{
60548 + return 0;
60549 +}
60550 +
60551 +int
60552 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60553 +{
60554 + return 0;
60555 +}
60556 +
60557 +void
60558 +gr_copy_label(struct task_struct *tsk)
60559 +{
60560 + return;
60561 +}
60562 +
60563 +void
60564 +gr_set_pax_flags(struct task_struct *task)
60565 +{
60566 + return;
60567 +}
60568 +
60569 +int
60570 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60571 + const int unsafe_share)
60572 +{
60573 + return 0;
60574 +}
60575 +
60576 +void
60577 +gr_handle_delete(const ino_t ino, const dev_t dev)
60578 +{
60579 + return;
60580 +}
60581 +
60582 +void
60583 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60584 +{
60585 + return;
60586 +}
60587 +
60588 +void
60589 +gr_handle_crash(struct task_struct *task, const int sig)
60590 +{
60591 + return;
60592 +}
60593 +
60594 +int
60595 +gr_check_crash_exec(const struct file *filp)
60596 +{
60597 + return 0;
60598 +}
60599 +
60600 +int
60601 +gr_check_crash_uid(const uid_t uid)
60602 +{
60603 + return 0;
60604 +}
60605 +
60606 +void
60607 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60608 + struct dentry *old_dentry,
60609 + struct dentry *new_dentry,
60610 + struct vfsmount *mnt, const __u8 replace)
60611 +{
60612 + return;
60613 +}
60614 +
60615 +int
60616 +gr_search_socket(const int family, const int type, const int protocol)
60617 +{
60618 + return 1;
60619 +}
60620 +
60621 +int
60622 +gr_search_connectbind(const int mode, const struct socket *sock,
60623 + const struct sockaddr_in *addr)
60624 +{
60625 + return 0;
60626 +}
60627 +
60628 +void
60629 +gr_handle_alertkill(struct task_struct *task)
60630 +{
60631 + return;
60632 +}
60633 +
60634 +__u32
60635 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
60636 +{
60637 + return 1;
60638 +}
60639 +
60640 +__u32
60641 +gr_acl_handle_hidden_file(const struct dentry * dentry,
60642 + const struct vfsmount * mnt)
60643 +{
60644 + return 1;
60645 +}
60646 +
60647 +__u32
60648 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60649 + int acc_mode)
60650 +{
60651 + return 1;
60652 +}
60653 +
60654 +__u32
60655 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60656 +{
60657 + return 1;
60658 +}
60659 +
60660 +__u32
60661 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
60662 +{
60663 + return 1;
60664 +}
60665 +
60666 +int
60667 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
60668 + unsigned int *vm_flags)
60669 +{
60670 + return 1;
60671 +}
60672 +
60673 +__u32
60674 +gr_acl_handle_truncate(const struct dentry * dentry,
60675 + const struct vfsmount * mnt)
60676 +{
60677 + return 1;
60678 +}
60679 +
60680 +__u32
60681 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
60682 +{
60683 + return 1;
60684 +}
60685 +
60686 +__u32
60687 +gr_acl_handle_access(const struct dentry * dentry,
60688 + const struct vfsmount * mnt, const int fmode)
60689 +{
60690 + return 1;
60691 +}
60692 +
60693 +__u32
60694 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60695 + umode_t *mode)
60696 +{
60697 + return 1;
60698 +}
60699 +
60700 +__u32
60701 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60702 +{
60703 + return 1;
60704 +}
60705 +
60706 +__u32
60707 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60708 +{
60709 + return 1;
60710 +}
60711 +
60712 +void
60713 +grsecurity_init(void)
60714 +{
60715 + return;
60716 +}
60717 +
60718 +umode_t gr_acl_umask(void)
60719 +{
60720 + return 0;
60721 +}
60722 +
60723 +__u32
60724 +gr_acl_handle_mknod(const struct dentry * new_dentry,
60725 + const struct dentry * parent_dentry,
60726 + const struct vfsmount * parent_mnt,
60727 + const int mode)
60728 +{
60729 + return 1;
60730 +}
60731 +
60732 +__u32
60733 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
60734 + const struct dentry * parent_dentry,
60735 + const struct vfsmount * parent_mnt)
60736 +{
60737 + return 1;
60738 +}
60739 +
60740 +__u32
60741 +gr_acl_handle_symlink(const struct dentry * new_dentry,
60742 + const struct dentry * parent_dentry,
60743 + const struct vfsmount * parent_mnt, const struct filename *from)
60744 +{
60745 + return 1;
60746 +}
60747 +
60748 +__u32
60749 +gr_acl_handle_link(const struct dentry * new_dentry,
60750 + const struct dentry * parent_dentry,
60751 + const struct vfsmount * parent_mnt,
60752 + const struct dentry * old_dentry,
60753 + const struct vfsmount * old_mnt, const struct filename *to)
60754 +{
60755 + return 1;
60756 +}
60757 +
60758 +int
60759 +gr_acl_handle_rename(const struct dentry *new_dentry,
60760 + const struct dentry *parent_dentry,
60761 + const struct vfsmount *parent_mnt,
60762 + const struct dentry *old_dentry,
60763 + const struct inode *old_parent_inode,
60764 + const struct vfsmount *old_mnt, const struct filename *newname)
60765 +{
60766 + return 0;
60767 +}
60768 +
60769 +int
60770 +gr_acl_handle_filldir(const struct file *file, const char *name,
60771 + const int namelen, const ino_t ino)
60772 +{
60773 + return 1;
60774 +}
60775 +
60776 +int
60777 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60778 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60779 +{
60780 + return 1;
60781 +}
60782 +
60783 +int
60784 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60785 +{
60786 + return 0;
60787 +}
60788 +
60789 +int
60790 +gr_search_accept(const struct socket *sock)
60791 +{
60792 + return 0;
60793 +}
60794 +
60795 +int
60796 +gr_search_listen(const struct socket *sock)
60797 +{
60798 + return 0;
60799 +}
60800 +
60801 +int
60802 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60803 +{
60804 + return 0;
60805 +}
60806 +
60807 +__u32
60808 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60809 +{
60810 + return 1;
60811 +}
60812 +
60813 +__u32
60814 +gr_acl_handle_creat(const struct dentry * dentry,
60815 + const struct dentry * p_dentry,
60816 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60817 + const int imode)
60818 +{
60819 + return 1;
60820 +}
60821 +
60822 +void
60823 +gr_acl_handle_exit(void)
60824 +{
60825 + return;
60826 +}
60827 +
60828 +int
60829 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60830 +{
60831 + return 1;
60832 +}
60833 +
60834 +void
60835 +gr_set_role_label(const uid_t uid, const gid_t gid)
60836 +{
60837 + return;
60838 +}
60839 +
60840 +int
60841 +gr_acl_handle_procpidmem(const struct task_struct *task)
60842 +{
60843 + return 0;
60844 +}
60845 +
60846 +int
60847 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60848 +{
60849 + return 0;
60850 +}
60851 +
60852 +int
60853 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60854 +{
60855 + return 0;
60856 +}
60857 +
60858 +void
60859 +gr_set_kernel_label(struct task_struct *task)
60860 +{
60861 + return;
60862 +}
60863 +
60864 +int
60865 +gr_check_user_change(int real, int effective, int fs)
60866 +{
60867 + return 0;
60868 +}
60869 +
60870 +int
60871 +gr_check_group_change(int real, int effective, int fs)
60872 +{
60873 + return 0;
60874 +}
60875 +
60876 +int gr_acl_enable_at_secure(void)
60877 +{
60878 + return 0;
60879 +}
60880 +
60881 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60882 +{
60883 + return dentry->d_inode->i_sb->s_dev;
60884 +}
60885 +
60886 +void gr_put_exec_file(struct task_struct *task)
60887 +{
60888 + return;
60889 +}
60890 +
60891 +EXPORT_SYMBOL(gr_set_kernel_label);
60892 +#ifdef CONFIG_SECURITY
60893 +EXPORT_SYMBOL(gr_check_user_change);
60894 +EXPORT_SYMBOL(gr_check_group_change);
60895 +#endif
60896 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60897 new file mode 100644
60898 index 0000000..abfa971
60899 --- /dev/null
60900 +++ b/grsecurity/grsec_exec.c
60901 @@ -0,0 +1,174 @@
60902 +#include <linux/kernel.h>
60903 +#include <linux/sched.h>
60904 +#include <linux/file.h>
60905 +#include <linux/binfmts.h>
60906 +#include <linux/fs.h>
60907 +#include <linux/types.h>
60908 +#include <linux/grdefs.h>
60909 +#include <linux/grsecurity.h>
60910 +#include <linux/grinternal.h>
60911 +#include <linux/capability.h>
60912 +#include <linux/module.h>
60913 +
60914 +#include <asm/uaccess.h>
60915 +
60916 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60917 +static char gr_exec_arg_buf[132];
60918 +static DEFINE_MUTEX(gr_exec_arg_mutex);
60919 +#endif
60920 +
60921 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60922 +
60923 +void
60924 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60925 +{
60926 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60927 + char *grarg = gr_exec_arg_buf;
60928 + unsigned int i, x, execlen = 0;
60929 + char c;
60930 +
60931 + if (!((grsec_enable_execlog && grsec_enable_group &&
60932 + in_group_p(grsec_audit_gid))
60933 + || (grsec_enable_execlog && !grsec_enable_group)))
60934 + return;
60935 +
60936 + mutex_lock(&gr_exec_arg_mutex);
60937 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
60938 +
60939 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
60940 + const char __user *p;
60941 + unsigned int len;
60942 +
60943 + p = get_user_arg_ptr(argv, i);
60944 + if (IS_ERR(p))
60945 + goto log;
60946 +
60947 + len = strnlen_user(p, 128 - execlen);
60948 + if (len > 128 - execlen)
60949 + len = 128 - execlen;
60950 + else if (len > 0)
60951 + len--;
60952 + if (copy_from_user(grarg + execlen, p, len))
60953 + goto log;
60954 +
60955 + /* rewrite unprintable characters */
60956 + for (x = 0; x < len; x++) {
60957 + c = *(grarg + execlen + x);
60958 + if (c < 32 || c > 126)
60959 + *(grarg + execlen + x) = ' ';
60960 + }
60961 +
60962 + execlen += len;
60963 + *(grarg + execlen) = ' ';
60964 + *(grarg + execlen + 1) = '\0';
60965 + execlen++;
60966 + }
60967 +
60968 + log:
60969 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60970 + bprm->file->f_path.mnt, grarg);
60971 + mutex_unlock(&gr_exec_arg_mutex);
60972 +#endif
60973 + return;
60974 +}
60975 +
60976 +#ifdef CONFIG_GRKERNSEC
60977 +extern int gr_acl_is_capable(const int cap);
60978 +extern int gr_acl_is_capable_nolog(const int cap);
60979 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60980 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60981 +extern int gr_chroot_is_capable(const int cap);
60982 +extern int gr_chroot_is_capable_nolog(const int cap);
60983 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60984 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60985 +#endif
60986 +
60987 +const char *captab_log[] = {
60988 + "CAP_CHOWN",
60989 + "CAP_DAC_OVERRIDE",
60990 + "CAP_DAC_READ_SEARCH",
60991 + "CAP_FOWNER",
60992 + "CAP_FSETID",
60993 + "CAP_KILL",
60994 + "CAP_SETGID",
60995 + "CAP_SETUID",
60996 + "CAP_SETPCAP",
60997 + "CAP_LINUX_IMMUTABLE",
60998 + "CAP_NET_BIND_SERVICE",
60999 + "CAP_NET_BROADCAST",
61000 + "CAP_NET_ADMIN",
61001 + "CAP_NET_RAW",
61002 + "CAP_IPC_LOCK",
61003 + "CAP_IPC_OWNER",
61004 + "CAP_SYS_MODULE",
61005 + "CAP_SYS_RAWIO",
61006 + "CAP_SYS_CHROOT",
61007 + "CAP_SYS_PTRACE",
61008 + "CAP_SYS_PACCT",
61009 + "CAP_SYS_ADMIN",
61010 + "CAP_SYS_BOOT",
61011 + "CAP_SYS_NICE",
61012 + "CAP_SYS_RESOURCE",
61013 + "CAP_SYS_TIME",
61014 + "CAP_SYS_TTY_CONFIG",
61015 + "CAP_MKNOD",
61016 + "CAP_LEASE",
61017 + "CAP_AUDIT_WRITE",
61018 + "CAP_AUDIT_CONTROL",
61019 + "CAP_SETFCAP",
61020 + "CAP_MAC_OVERRIDE",
61021 + "CAP_MAC_ADMIN",
61022 + "CAP_SYSLOG",
61023 + "CAP_WAKE_ALARM"
61024 +};
61025 +
61026 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
61027 +
61028 +int gr_is_capable(const int cap)
61029 +{
61030 +#ifdef CONFIG_GRKERNSEC
61031 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
61032 + return 1;
61033 + return 0;
61034 +#else
61035 + return 1;
61036 +#endif
61037 +}
61038 +
61039 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61040 +{
61041 +#ifdef CONFIG_GRKERNSEC
61042 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
61043 + return 1;
61044 + return 0;
61045 +#else
61046 + return 1;
61047 +#endif
61048 +}
61049 +
61050 +int gr_is_capable_nolog(const int cap)
61051 +{
61052 +#ifdef CONFIG_GRKERNSEC
61053 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
61054 + return 1;
61055 + return 0;
61056 +#else
61057 + return 1;
61058 +#endif
61059 +}
61060 +
61061 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
61062 +{
61063 +#ifdef CONFIG_GRKERNSEC
61064 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
61065 + return 1;
61066 + return 0;
61067 +#else
61068 + return 1;
61069 +#endif
61070 +}
61071 +
61072 +EXPORT_SYMBOL(gr_is_capable);
61073 +EXPORT_SYMBOL(gr_is_capable_nolog);
61074 +EXPORT_SYMBOL(gr_task_is_capable);
61075 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
61076 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
61077 new file mode 100644
61078 index 0000000..d3ee748
61079 --- /dev/null
61080 +++ b/grsecurity/grsec_fifo.c
61081 @@ -0,0 +1,24 @@
61082 +#include <linux/kernel.h>
61083 +#include <linux/sched.h>
61084 +#include <linux/fs.h>
61085 +#include <linux/file.h>
61086 +#include <linux/grinternal.h>
61087 +
61088 +int
61089 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
61090 + const struct dentry *dir, const int flag, const int acc_mode)
61091 +{
61092 +#ifdef CONFIG_GRKERNSEC_FIFO
61093 + const struct cred *cred = current_cred();
61094 +
61095 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
61096 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
61097 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
61098 + (cred->fsuid != dentry->d_inode->i_uid)) {
61099 + if (!inode_permission(dentry->d_inode, acc_mode))
61100 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
61101 + return -EACCES;
61102 + }
61103 +#endif
61104 + return 0;
61105 +}
61106 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
61107 new file mode 100644
61108 index 0000000..8ca18bf
61109 --- /dev/null
61110 +++ b/grsecurity/grsec_fork.c
61111 @@ -0,0 +1,23 @@
61112 +#include <linux/kernel.h>
61113 +#include <linux/sched.h>
61114 +#include <linux/grsecurity.h>
61115 +#include <linux/grinternal.h>
61116 +#include <linux/errno.h>
61117 +
61118 +void
61119 +gr_log_forkfail(const int retval)
61120 +{
61121 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61122 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
61123 + switch (retval) {
61124 + case -EAGAIN:
61125 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
61126 + break;
61127 + case -ENOMEM:
61128 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
61129 + break;
61130 + }
61131 + }
61132 +#endif
61133 + return;
61134 +}
61135 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
61136 new file mode 100644
61137 index 0000000..05a6015
61138 --- /dev/null
61139 +++ b/grsecurity/grsec_init.c
61140 @@ -0,0 +1,283 @@
61141 +#include <linux/kernel.h>
61142 +#include <linux/sched.h>
61143 +#include <linux/mm.h>
61144 +#include <linux/gracl.h>
61145 +#include <linux/slab.h>
61146 +#include <linux/vmalloc.h>
61147 +#include <linux/percpu.h>
61148 +#include <linux/module.h>
61149 +
61150 +int grsec_enable_ptrace_readexec;
61151 +int grsec_enable_setxid;
61152 +int grsec_enable_symlinkown;
61153 +int grsec_symlinkown_gid;
61154 +int grsec_enable_brute;
61155 +int grsec_enable_link;
61156 +int grsec_enable_dmesg;
61157 +int grsec_enable_harden_ptrace;
61158 +int grsec_enable_fifo;
61159 +int grsec_enable_execlog;
61160 +int grsec_enable_signal;
61161 +int grsec_enable_forkfail;
61162 +int grsec_enable_audit_ptrace;
61163 +int grsec_enable_time;
61164 +int grsec_enable_audit_textrel;
61165 +int grsec_enable_group;
61166 +int grsec_audit_gid;
61167 +int grsec_enable_chdir;
61168 +int grsec_enable_mount;
61169 +int grsec_enable_rofs;
61170 +int grsec_enable_chroot_findtask;
61171 +int grsec_enable_chroot_mount;
61172 +int grsec_enable_chroot_shmat;
61173 +int grsec_enable_chroot_fchdir;
61174 +int grsec_enable_chroot_double;
61175 +int grsec_enable_chroot_pivot;
61176 +int grsec_enable_chroot_chdir;
61177 +int grsec_enable_chroot_chmod;
61178 +int grsec_enable_chroot_mknod;
61179 +int grsec_enable_chroot_nice;
61180 +int grsec_enable_chroot_execlog;
61181 +int grsec_enable_chroot_caps;
61182 +int grsec_enable_chroot_sysctl;
61183 +int grsec_enable_chroot_unix;
61184 +int grsec_enable_tpe;
61185 +int grsec_tpe_gid;
61186 +int grsec_enable_blackhole;
61187 +#ifdef CONFIG_IPV6_MODULE
61188 +EXPORT_SYMBOL(grsec_enable_blackhole);
61189 +#endif
61190 +int grsec_lastack_retries;
61191 +int grsec_enable_tpe_all;
61192 +int grsec_enable_tpe_invert;
61193 +int grsec_enable_socket_all;
61194 +int grsec_socket_all_gid;
61195 +int grsec_enable_socket_client;
61196 +int grsec_socket_client_gid;
61197 +int grsec_enable_socket_server;
61198 +int grsec_socket_server_gid;
61199 +int grsec_resource_logging;
61200 +int grsec_disable_privio;
61201 +int grsec_enable_log_rwxmaps;
61202 +int grsec_lock;
61203 +
61204 +DEFINE_SPINLOCK(grsec_alert_lock);
61205 +unsigned long grsec_alert_wtime = 0;
61206 +unsigned long grsec_alert_fyet = 0;
61207 +
61208 +DEFINE_SPINLOCK(grsec_audit_lock);
61209 +
61210 +DEFINE_RWLOCK(grsec_exec_file_lock);
61211 +
61212 +char *gr_shared_page[4];
61213 +
61214 +char *gr_alert_log_fmt;
61215 +char *gr_audit_log_fmt;
61216 +char *gr_alert_log_buf;
61217 +char *gr_audit_log_buf;
61218 +
61219 +extern struct gr_arg *gr_usermode;
61220 +extern unsigned char *gr_system_salt;
61221 +extern unsigned char *gr_system_sum;
61222 +
61223 +void __init
61224 +grsecurity_init(void)
61225 +{
61226 + int j;
61227 + /* create the per-cpu shared pages */
61228 +
61229 +#ifdef CONFIG_X86
61230 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
61231 +#endif
61232 +
61233 + for (j = 0; j < 4; j++) {
61234 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
61235 + if (gr_shared_page[j] == NULL) {
61236 + panic("Unable to allocate grsecurity shared page");
61237 + return;
61238 + }
61239 + }
61240 +
61241 + /* allocate log buffers */
61242 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
61243 + if (!gr_alert_log_fmt) {
61244 + panic("Unable to allocate grsecurity alert log format buffer");
61245 + return;
61246 + }
61247 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
61248 + if (!gr_audit_log_fmt) {
61249 + panic("Unable to allocate grsecurity audit log format buffer");
61250 + return;
61251 + }
61252 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61253 + if (!gr_alert_log_buf) {
61254 + panic("Unable to allocate grsecurity alert log buffer");
61255 + return;
61256 + }
61257 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61258 + if (!gr_audit_log_buf) {
61259 + panic("Unable to allocate grsecurity audit log buffer");
61260 + return;
61261 + }
61262 +
61263 + /* allocate memory for authentication structure */
61264 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
61265 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
61266 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
61267 +
61268 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
61269 + panic("Unable to allocate grsecurity authentication structure");
61270 + return;
61271 + }
61272 +
61273 +
61274 +#ifdef CONFIG_GRKERNSEC_IO
61275 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
61276 + grsec_disable_privio = 1;
61277 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61278 + grsec_disable_privio = 1;
61279 +#else
61280 + grsec_disable_privio = 0;
61281 +#endif
61282 +#endif
61283 +
61284 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61285 + /* for backward compatibility, tpe_invert always defaults to on if
61286 + enabled in the kernel
61287 + */
61288 + grsec_enable_tpe_invert = 1;
61289 +#endif
61290 +
61291 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61292 +#ifndef CONFIG_GRKERNSEC_SYSCTL
61293 + grsec_lock = 1;
61294 +#endif
61295 +
61296 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61297 + grsec_enable_audit_textrel = 1;
61298 +#endif
61299 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61300 + grsec_enable_log_rwxmaps = 1;
61301 +#endif
61302 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61303 + grsec_enable_group = 1;
61304 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
61305 +#endif
61306 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61307 + grsec_enable_ptrace_readexec = 1;
61308 +#endif
61309 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61310 + grsec_enable_chdir = 1;
61311 +#endif
61312 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61313 + grsec_enable_harden_ptrace = 1;
61314 +#endif
61315 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61316 + grsec_enable_mount = 1;
61317 +#endif
61318 +#ifdef CONFIG_GRKERNSEC_LINK
61319 + grsec_enable_link = 1;
61320 +#endif
61321 +#ifdef CONFIG_GRKERNSEC_BRUTE
61322 + grsec_enable_brute = 1;
61323 +#endif
61324 +#ifdef CONFIG_GRKERNSEC_DMESG
61325 + grsec_enable_dmesg = 1;
61326 +#endif
61327 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61328 + grsec_enable_blackhole = 1;
61329 + grsec_lastack_retries = 4;
61330 +#endif
61331 +#ifdef CONFIG_GRKERNSEC_FIFO
61332 + grsec_enable_fifo = 1;
61333 +#endif
61334 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61335 + grsec_enable_execlog = 1;
61336 +#endif
61337 +#ifdef CONFIG_GRKERNSEC_SETXID
61338 + grsec_enable_setxid = 1;
61339 +#endif
61340 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61341 + grsec_enable_signal = 1;
61342 +#endif
61343 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61344 + grsec_enable_forkfail = 1;
61345 +#endif
61346 +#ifdef CONFIG_GRKERNSEC_TIME
61347 + grsec_enable_time = 1;
61348 +#endif
61349 +#ifdef CONFIG_GRKERNSEC_RESLOG
61350 + grsec_resource_logging = 1;
61351 +#endif
61352 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61353 + grsec_enable_chroot_findtask = 1;
61354 +#endif
61355 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61356 + grsec_enable_chroot_unix = 1;
61357 +#endif
61358 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61359 + grsec_enable_chroot_mount = 1;
61360 +#endif
61361 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61362 + grsec_enable_chroot_fchdir = 1;
61363 +#endif
61364 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61365 + grsec_enable_chroot_shmat = 1;
61366 +#endif
61367 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61368 + grsec_enable_audit_ptrace = 1;
61369 +#endif
61370 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61371 + grsec_enable_chroot_double = 1;
61372 +#endif
61373 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61374 + grsec_enable_chroot_pivot = 1;
61375 +#endif
61376 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61377 + grsec_enable_chroot_chdir = 1;
61378 +#endif
61379 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61380 + grsec_enable_chroot_chmod = 1;
61381 +#endif
61382 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61383 + grsec_enable_chroot_mknod = 1;
61384 +#endif
61385 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61386 + grsec_enable_chroot_nice = 1;
61387 +#endif
61388 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61389 + grsec_enable_chroot_execlog = 1;
61390 +#endif
61391 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61392 + grsec_enable_chroot_caps = 1;
61393 +#endif
61394 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61395 + grsec_enable_chroot_sysctl = 1;
61396 +#endif
61397 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61398 + grsec_enable_symlinkown = 1;
61399 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
61400 +#endif
61401 +#ifdef CONFIG_GRKERNSEC_TPE
61402 + grsec_enable_tpe = 1;
61403 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
61404 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
61405 + grsec_enable_tpe_all = 1;
61406 +#endif
61407 +#endif
61408 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61409 + grsec_enable_socket_all = 1;
61410 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
61411 +#endif
61412 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61413 + grsec_enable_socket_client = 1;
61414 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
61415 +#endif
61416 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61417 + grsec_enable_socket_server = 1;
61418 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
61419 +#endif
61420 +#endif
61421 +
61422 + return;
61423 +}
61424 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
61425 new file mode 100644
61426 index 0000000..6095407
61427 --- /dev/null
61428 +++ b/grsecurity/grsec_link.c
61429 @@ -0,0 +1,58 @@
61430 +#include <linux/kernel.h>
61431 +#include <linux/sched.h>
61432 +#include <linux/fs.h>
61433 +#include <linux/file.h>
61434 +#include <linux/grinternal.h>
61435 +
61436 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
61437 +{
61438 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61439 + const struct inode *link_inode = link->dentry->d_inode;
61440 +
61441 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
61442 + /* ignore root-owned links, e.g. /proc/self */
61443 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
61444 + !uid_eq(link_inode->i_uid, target->i_uid)) {
61445 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
61446 + return 1;
61447 + }
61448 +#endif
61449 + return 0;
61450 +}
61451 +
61452 +int
61453 +gr_handle_follow_link(const struct inode *parent,
61454 + const struct inode *inode,
61455 + const struct dentry *dentry, const struct vfsmount *mnt)
61456 +{
61457 +#ifdef CONFIG_GRKERNSEC_LINK
61458 + const struct cred *cred = current_cred();
61459 +
61460 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
61461 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
61462 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
61463 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
61464 + return -EACCES;
61465 + }
61466 +#endif
61467 + return 0;
61468 +}
61469 +
61470 +int
61471 +gr_handle_hardlink(const struct dentry *dentry,
61472 + const struct vfsmount *mnt,
61473 + struct inode *inode, const int mode, const struct filename *to)
61474 +{
61475 +#ifdef CONFIG_GRKERNSEC_LINK
61476 + const struct cred *cred = current_cred();
61477 +
61478 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
61479 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
61480 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
61481 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61482 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
61483 + return -EPERM;
61484 + }
61485 +#endif
61486 + return 0;
61487 +}
61488 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
61489 new file mode 100644
61490 index 0000000..7bd6c2b
61491 --- /dev/null
61492 +++ b/grsecurity/grsec_log.c
61493 @@ -0,0 +1,329 @@
61494 +#include <linux/kernel.h>
61495 +#include <linux/sched.h>
61496 +#include <linux/file.h>
61497 +#include <linux/tty.h>
61498 +#include <linux/fs.h>
61499 +#include <linux/grinternal.h>
61500 +
61501 +#ifdef CONFIG_TREE_PREEMPT_RCU
61502 +#define DISABLE_PREEMPT() preempt_disable()
61503 +#define ENABLE_PREEMPT() preempt_enable()
61504 +#else
61505 +#define DISABLE_PREEMPT()
61506 +#define ENABLE_PREEMPT()
61507 +#endif
61508 +
61509 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
61510 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
61511 +
61512 +#define BEGIN_LOCKS(x) \
61513 + DISABLE_PREEMPT(); \
61514 + rcu_read_lock(); \
61515 + read_lock(&tasklist_lock); \
61516 + read_lock(&grsec_exec_file_lock); \
61517 + if (x != GR_DO_AUDIT) \
61518 + spin_lock(&grsec_alert_lock); \
61519 + else \
61520 + spin_lock(&grsec_audit_lock)
61521 +
61522 +#define END_LOCKS(x) \
61523 + if (x != GR_DO_AUDIT) \
61524 + spin_unlock(&grsec_alert_lock); \
61525 + else \
61526 + spin_unlock(&grsec_audit_lock); \
61527 + read_unlock(&grsec_exec_file_lock); \
61528 + read_unlock(&tasklist_lock); \
61529 + rcu_read_unlock(); \
61530 + ENABLE_PREEMPT(); \
61531 + if (x == GR_DONT_AUDIT) \
61532 + gr_handle_alertkill(current)
61533 +
61534 +enum {
61535 + FLOODING,
61536 + NO_FLOODING
61537 +};
61538 +
61539 +extern char *gr_alert_log_fmt;
61540 +extern char *gr_audit_log_fmt;
61541 +extern char *gr_alert_log_buf;
61542 +extern char *gr_audit_log_buf;
61543 +
61544 +static int gr_log_start(int audit)
61545 +{
61546 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
61547 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
61548 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61549 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
61550 + unsigned long curr_secs = get_seconds();
61551 +
61552 + if (audit == GR_DO_AUDIT)
61553 + goto set_fmt;
61554 +
61555 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
61556 + grsec_alert_wtime = curr_secs;
61557 + grsec_alert_fyet = 0;
61558 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
61559 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
61560 + grsec_alert_fyet++;
61561 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
61562 + grsec_alert_wtime = curr_secs;
61563 + grsec_alert_fyet++;
61564 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
61565 + return FLOODING;
61566 + }
61567 + else return FLOODING;
61568 +
61569 +set_fmt:
61570 +#endif
61571 + memset(buf, 0, PAGE_SIZE);
61572 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
61573 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
61574 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61575 + } else if (current->signal->curr_ip) {
61576 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
61577 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
61578 + } else if (gr_acl_is_enabled()) {
61579 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
61580 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61581 + } else {
61582 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
61583 + strcpy(buf, fmt);
61584 + }
61585 +
61586 + return NO_FLOODING;
61587 +}
61588 +
61589 +static void gr_log_middle(int audit, const char *msg, va_list ap)
61590 + __attribute__ ((format (printf, 2, 0)));
61591 +
61592 +static void gr_log_middle(int audit, const char *msg, va_list ap)
61593 +{
61594 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61595 + unsigned int len = strlen(buf);
61596 +
61597 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61598 +
61599 + return;
61600 +}
61601 +
61602 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
61603 + __attribute__ ((format (printf, 2, 3)));
61604 +
61605 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
61606 +{
61607 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61608 + unsigned int len = strlen(buf);
61609 + va_list ap;
61610 +
61611 + va_start(ap, msg);
61612 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61613 + va_end(ap);
61614 +
61615 + return;
61616 +}
61617 +
61618 +static void gr_log_end(int audit, int append_default)
61619 +{
61620 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61621 + if (append_default) {
61622 + struct task_struct *task = current;
61623 + struct task_struct *parent = task->real_parent;
61624 + const struct cred *cred = __task_cred(task);
61625 + const struct cred *pcred = __task_cred(parent);
61626 + unsigned int len = strlen(buf);
61627 +
61628 + 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));
61629 + }
61630 +
61631 + printk("%s\n", buf);
61632 +
61633 + return;
61634 +}
61635 +
61636 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
61637 +{
61638 + int logtype;
61639 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
61640 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
61641 + void *voidptr = NULL;
61642 + int num1 = 0, num2 = 0;
61643 + unsigned long ulong1 = 0, ulong2 = 0;
61644 + struct dentry *dentry = NULL;
61645 + struct vfsmount *mnt = NULL;
61646 + struct file *file = NULL;
61647 + struct task_struct *task = NULL;
61648 + const struct cred *cred, *pcred;
61649 + va_list ap;
61650 +
61651 + BEGIN_LOCKS(audit);
61652 + logtype = gr_log_start(audit);
61653 + if (logtype == FLOODING) {
61654 + END_LOCKS(audit);
61655 + return;
61656 + }
61657 + va_start(ap, argtypes);
61658 + switch (argtypes) {
61659 + case GR_TTYSNIFF:
61660 + task = va_arg(ap, struct task_struct *);
61661 + 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));
61662 + break;
61663 + case GR_SYSCTL_HIDDEN:
61664 + str1 = va_arg(ap, char *);
61665 + gr_log_middle_varargs(audit, msg, result, str1);
61666 + break;
61667 + case GR_RBAC:
61668 + dentry = va_arg(ap, struct dentry *);
61669 + mnt = va_arg(ap, struct vfsmount *);
61670 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
61671 + break;
61672 + case GR_RBAC_STR:
61673 + dentry = va_arg(ap, struct dentry *);
61674 + mnt = va_arg(ap, struct vfsmount *);
61675 + str1 = va_arg(ap, char *);
61676 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
61677 + break;
61678 + case GR_STR_RBAC:
61679 + str1 = va_arg(ap, char *);
61680 + dentry = va_arg(ap, struct dentry *);
61681 + mnt = va_arg(ap, struct vfsmount *);
61682 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
61683 + break;
61684 + case GR_RBAC_MODE2:
61685 + dentry = va_arg(ap, struct dentry *);
61686 + mnt = va_arg(ap, struct vfsmount *);
61687 + str1 = va_arg(ap, char *);
61688 + str2 = va_arg(ap, char *);
61689 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61690 + break;
61691 + case GR_RBAC_MODE3:
61692 + dentry = va_arg(ap, struct dentry *);
61693 + mnt = va_arg(ap, struct vfsmount *);
61694 + str1 = va_arg(ap, char *);
61695 + str2 = va_arg(ap, char *);
61696 + str3 = va_arg(ap, char *);
61697 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61698 + break;
61699 + case GR_FILENAME:
61700 + dentry = va_arg(ap, struct dentry *);
61701 + mnt = va_arg(ap, struct vfsmount *);
61702 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61703 + break;
61704 + case GR_STR_FILENAME:
61705 + str1 = va_arg(ap, char *);
61706 + dentry = va_arg(ap, struct dentry *);
61707 + mnt = va_arg(ap, struct vfsmount *);
61708 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61709 + break;
61710 + case GR_FILENAME_STR:
61711 + dentry = va_arg(ap, struct dentry *);
61712 + mnt = va_arg(ap, struct vfsmount *);
61713 + str1 = va_arg(ap, char *);
61714 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61715 + break;
61716 + case GR_FILENAME_TWO_INT:
61717 + dentry = va_arg(ap, struct dentry *);
61718 + mnt = va_arg(ap, struct vfsmount *);
61719 + num1 = va_arg(ap, int);
61720 + num2 = va_arg(ap, int);
61721 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61722 + break;
61723 + case GR_FILENAME_TWO_INT_STR:
61724 + dentry = va_arg(ap, struct dentry *);
61725 + mnt = va_arg(ap, struct vfsmount *);
61726 + num1 = va_arg(ap, int);
61727 + num2 = va_arg(ap, int);
61728 + str1 = va_arg(ap, char *);
61729 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61730 + break;
61731 + case GR_TEXTREL:
61732 + file = va_arg(ap, struct file *);
61733 + ulong1 = va_arg(ap, unsigned long);
61734 + ulong2 = va_arg(ap, unsigned long);
61735 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61736 + break;
61737 + case GR_PTRACE:
61738 + task = va_arg(ap, struct task_struct *);
61739 + 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));
61740 + break;
61741 + case GR_RESOURCE:
61742 + task = va_arg(ap, struct task_struct *);
61743 + cred = __task_cred(task);
61744 + pcred = __task_cred(task->real_parent);
61745 + ulong1 = va_arg(ap, unsigned long);
61746 + str1 = va_arg(ap, char *);
61747 + ulong2 = va_arg(ap, unsigned long);
61748 + 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));
61749 + break;
61750 + case GR_CAP:
61751 + task = va_arg(ap, struct task_struct *);
61752 + cred = __task_cred(task);
61753 + pcred = __task_cred(task->real_parent);
61754 + str1 = va_arg(ap, char *);
61755 + 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));
61756 + break;
61757 + case GR_SIG:
61758 + str1 = va_arg(ap, char *);
61759 + voidptr = va_arg(ap, void *);
61760 + gr_log_middle_varargs(audit, msg, str1, voidptr);
61761 + break;
61762 + case GR_SIG2:
61763 + task = va_arg(ap, struct task_struct *);
61764 + cred = __task_cred(task);
61765 + pcred = __task_cred(task->real_parent);
61766 + num1 = va_arg(ap, int);
61767 + 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));
61768 + break;
61769 + case GR_CRASH1:
61770 + task = va_arg(ap, struct task_struct *);
61771 + cred = __task_cred(task);
61772 + pcred = __task_cred(task->real_parent);
61773 + ulong1 = va_arg(ap, unsigned long);
61774 + 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);
61775 + break;
61776 + case GR_CRASH2:
61777 + task = va_arg(ap, struct task_struct *);
61778 + cred = __task_cred(task);
61779 + pcred = __task_cred(task->real_parent);
61780 + ulong1 = va_arg(ap, unsigned long);
61781 + 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);
61782 + break;
61783 + case GR_RWXMAP:
61784 + file = va_arg(ap, struct file *);
61785 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61786 + break;
61787 + case GR_PSACCT:
61788 + {
61789 + unsigned int wday, cday;
61790 + __u8 whr, chr;
61791 + __u8 wmin, cmin;
61792 + __u8 wsec, csec;
61793 + char cur_tty[64] = { 0 };
61794 + char parent_tty[64] = { 0 };
61795 +
61796 + task = va_arg(ap, struct task_struct *);
61797 + wday = va_arg(ap, unsigned int);
61798 + cday = va_arg(ap, unsigned int);
61799 + whr = va_arg(ap, int);
61800 + chr = va_arg(ap, int);
61801 + wmin = va_arg(ap, int);
61802 + cmin = va_arg(ap, int);
61803 + wsec = va_arg(ap, int);
61804 + csec = va_arg(ap, int);
61805 + ulong1 = va_arg(ap, unsigned long);
61806 + cred = __task_cred(task);
61807 + pcred = __task_cred(task->real_parent);
61808 +
61809 + 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));
61810 + }
61811 + break;
61812 + default:
61813 + gr_log_middle(audit, msg, ap);
61814 + }
61815 + va_end(ap);
61816 + // these don't need DEFAULTSECARGS printed on the end
61817 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61818 + gr_log_end(audit, 0);
61819 + else
61820 + gr_log_end(audit, 1);
61821 + END_LOCKS(audit);
61822 +}
61823 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61824 new file mode 100644
61825 index 0000000..f536303
61826 --- /dev/null
61827 +++ b/grsecurity/grsec_mem.c
61828 @@ -0,0 +1,40 @@
61829 +#include <linux/kernel.h>
61830 +#include <linux/sched.h>
61831 +#include <linux/mm.h>
61832 +#include <linux/mman.h>
61833 +#include <linux/grinternal.h>
61834 +
61835 +void
61836 +gr_handle_ioperm(void)
61837 +{
61838 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61839 + return;
61840 +}
61841 +
61842 +void
61843 +gr_handle_iopl(void)
61844 +{
61845 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61846 + return;
61847 +}
61848 +
61849 +void
61850 +gr_handle_mem_readwrite(u64 from, u64 to)
61851 +{
61852 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61853 + return;
61854 +}
61855 +
61856 +void
61857 +gr_handle_vm86(void)
61858 +{
61859 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61860 + return;
61861 +}
61862 +
61863 +void
61864 +gr_log_badprocpid(const char *entry)
61865 +{
61866 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61867 + return;
61868 +}
61869 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61870 new file mode 100644
61871 index 0000000..2131422
61872 --- /dev/null
61873 +++ b/grsecurity/grsec_mount.c
61874 @@ -0,0 +1,62 @@
61875 +#include <linux/kernel.h>
61876 +#include <linux/sched.h>
61877 +#include <linux/mount.h>
61878 +#include <linux/grsecurity.h>
61879 +#include <linux/grinternal.h>
61880 +
61881 +void
61882 +gr_log_remount(const char *devname, const int retval)
61883 +{
61884 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61885 + if (grsec_enable_mount && (retval >= 0))
61886 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61887 +#endif
61888 + return;
61889 +}
61890 +
61891 +void
61892 +gr_log_unmount(const char *devname, const int retval)
61893 +{
61894 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61895 + if (grsec_enable_mount && (retval >= 0))
61896 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61897 +#endif
61898 + return;
61899 +}
61900 +
61901 +void
61902 +gr_log_mount(const char *from, const char *to, const int retval)
61903 +{
61904 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61905 + if (grsec_enable_mount && (retval >= 0))
61906 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61907 +#endif
61908 + return;
61909 +}
61910 +
61911 +int
61912 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
61913 +{
61914 +#ifdef CONFIG_GRKERNSEC_ROFS
61915 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
61916 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61917 + return -EPERM;
61918 + } else
61919 + return 0;
61920 +#endif
61921 + return 0;
61922 +}
61923 +
61924 +int
61925 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61926 +{
61927 +#ifdef CONFIG_GRKERNSEC_ROFS
61928 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61929 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61930 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61931 + return -EPERM;
61932 + } else
61933 + return 0;
61934 +#endif
61935 + return 0;
61936 +}
61937 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61938 new file mode 100644
61939 index 0000000..a3b12a0
61940 --- /dev/null
61941 +++ b/grsecurity/grsec_pax.c
61942 @@ -0,0 +1,36 @@
61943 +#include <linux/kernel.h>
61944 +#include <linux/sched.h>
61945 +#include <linux/mm.h>
61946 +#include <linux/file.h>
61947 +#include <linux/grinternal.h>
61948 +#include <linux/grsecurity.h>
61949 +
61950 +void
61951 +gr_log_textrel(struct vm_area_struct * vma)
61952 +{
61953 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61954 + if (grsec_enable_audit_textrel)
61955 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61956 +#endif
61957 + return;
61958 +}
61959 +
61960 +void
61961 +gr_log_rwxmmap(struct file *file)
61962 +{
61963 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61964 + if (grsec_enable_log_rwxmaps)
61965 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61966 +#endif
61967 + return;
61968 +}
61969 +
61970 +void
61971 +gr_log_rwxmprotect(struct file *file)
61972 +{
61973 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61974 + if (grsec_enable_log_rwxmaps)
61975 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61976 +#endif
61977 + return;
61978 +}
61979 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61980 new file mode 100644
61981 index 0000000..f7f29aa
61982 --- /dev/null
61983 +++ b/grsecurity/grsec_ptrace.c
61984 @@ -0,0 +1,30 @@
61985 +#include <linux/kernel.h>
61986 +#include <linux/sched.h>
61987 +#include <linux/grinternal.h>
61988 +#include <linux/security.h>
61989 +
61990 +void
61991 +gr_audit_ptrace(struct task_struct *task)
61992 +{
61993 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61994 + if (grsec_enable_audit_ptrace)
61995 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
61996 +#endif
61997 + return;
61998 +}
61999 +
62000 +int
62001 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
62002 +{
62003 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62004 + const struct dentry *dentry = file->f_path.dentry;
62005 + const struct vfsmount *mnt = file->f_path.mnt;
62006 +
62007 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
62008 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
62009 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
62010 + return -EACCES;
62011 + }
62012 +#endif
62013 + return 0;
62014 +}
62015 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
62016 new file mode 100644
62017 index 0000000..5c00416
62018 --- /dev/null
62019 +++ b/grsecurity/grsec_sig.c
62020 @@ -0,0 +1,222 @@
62021 +#include <linux/kernel.h>
62022 +#include <linux/sched.h>
62023 +#include <linux/delay.h>
62024 +#include <linux/grsecurity.h>
62025 +#include <linux/grinternal.h>
62026 +#include <linux/hardirq.h>
62027 +
62028 +char *signames[] = {
62029 + [SIGSEGV] = "Segmentation fault",
62030 + [SIGILL] = "Illegal instruction",
62031 + [SIGABRT] = "Abort",
62032 + [SIGBUS] = "Invalid alignment/Bus error"
62033 +};
62034 +
62035 +void
62036 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
62037 +{
62038 +#ifdef CONFIG_GRKERNSEC_SIGNAL
62039 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
62040 + (sig == SIGABRT) || (sig == SIGBUS))) {
62041 + if (t->pid == current->pid) {
62042 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
62043 + } else {
62044 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
62045 + }
62046 + }
62047 +#endif
62048 + return;
62049 +}
62050 +
62051 +int
62052 +gr_handle_signal(const struct task_struct *p, const int sig)
62053 +{
62054 +#ifdef CONFIG_GRKERNSEC
62055 + /* ignore the 0 signal for protected task checks */
62056 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
62057 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
62058 + return -EPERM;
62059 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
62060 + return -EPERM;
62061 + }
62062 +#endif
62063 + return 0;
62064 +}
62065 +
62066 +#ifdef CONFIG_GRKERNSEC
62067 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
62068 +
62069 +int gr_fake_force_sig(int sig, struct task_struct *t)
62070 +{
62071 + unsigned long int flags;
62072 + int ret, blocked, ignored;
62073 + struct k_sigaction *action;
62074 +
62075 + spin_lock_irqsave(&t->sighand->siglock, flags);
62076 + action = &t->sighand->action[sig-1];
62077 + ignored = action->sa.sa_handler == SIG_IGN;
62078 + blocked = sigismember(&t->blocked, sig);
62079 + if (blocked || ignored) {
62080 + action->sa.sa_handler = SIG_DFL;
62081 + if (blocked) {
62082 + sigdelset(&t->blocked, sig);
62083 + recalc_sigpending_and_wake(t);
62084 + }
62085 + }
62086 + if (action->sa.sa_handler == SIG_DFL)
62087 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
62088 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
62089 +
62090 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
62091 +
62092 + return ret;
62093 +}
62094 +#endif
62095 +
62096 +#ifdef CONFIG_GRKERNSEC_BRUTE
62097 +#define GR_USER_BAN_TIME (15 * 60)
62098 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
62099 +
62100 +static int __get_dumpable(unsigned long mm_flags)
62101 +{
62102 + int ret;
62103 +
62104 + ret = mm_flags & MMF_DUMPABLE_MASK;
62105 + return (ret >= 2) ? 2 : ret;
62106 +}
62107 +#endif
62108 +
62109 +void gr_handle_brute_attach(unsigned long mm_flags)
62110 +{
62111 +#ifdef CONFIG_GRKERNSEC_BRUTE
62112 + struct task_struct *p = current;
62113 + kuid_t uid = GLOBAL_ROOT_UID;
62114 + int daemon = 0;
62115 +
62116 + if (!grsec_enable_brute)
62117 + return;
62118 +
62119 + rcu_read_lock();
62120 + read_lock(&tasklist_lock);
62121 + read_lock(&grsec_exec_file_lock);
62122 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
62123 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
62124 + p->real_parent->brute = 1;
62125 + daemon = 1;
62126 + } else {
62127 + const struct cred *cred = __task_cred(p), *cred2;
62128 + struct task_struct *tsk, *tsk2;
62129 +
62130 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
62131 + struct user_struct *user;
62132 +
62133 + uid = cred->uid;
62134 +
62135 + /* this is put upon execution past expiration */
62136 + user = find_user(uid);
62137 + if (user == NULL)
62138 + goto unlock;
62139 + user->banned = 1;
62140 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
62141 + if (user->ban_expires == ~0UL)
62142 + user->ban_expires--;
62143 +
62144 + do_each_thread(tsk2, tsk) {
62145 + cred2 = __task_cred(tsk);
62146 + if (tsk != p && uid_eq(cred2->uid, uid))
62147 + gr_fake_force_sig(SIGKILL, tsk);
62148 + } while_each_thread(tsk2, tsk);
62149 + }
62150 + }
62151 +unlock:
62152 + read_unlock(&grsec_exec_file_lock);
62153 + read_unlock(&tasklist_lock);
62154 + rcu_read_unlock();
62155 +
62156 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
62157 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
62158 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
62159 + else if (daemon)
62160 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
62161 +
62162 +#endif
62163 + return;
62164 +}
62165 +
62166 +void gr_handle_brute_check(void)
62167 +{
62168 +#ifdef CONFIG_GRKERNSEC_BRUTE
62169 + struct task_struct *p = current;
62170 +
62171 + if (unlikely(p->brute)) {
62172 + if (!grsec_enable_brute)
62173 + p->brute = 0;
62174 + else if (time_before(get_seconds(), p->brute_expires))
62175 + msleep(30 * 1000);
62176 + }
62177 +#endif
62178 + return;
62179 +}
62180 +
62181 +void gr_handle_kernel_exploit(void)
62182 +{
62183 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
62184 + const struct cred *cred;
62185 + struct task_struct *tsk, *tsk2;
62186 + struct user_struct *user;
62187 + kuid_t uid;
62188 +
62189 + if (in_irq() || in_serving_softirq() || in_nmi())
62190 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
62191 +
62192 + uid = current_uid();
62193 +
62194 + if (uid_eq(uid, GLOBAL_ROOT_UID))
62195 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
62196 + else {
62197 + /* kill all the processes of this user, hold a reference
62198 + to their creds struct, and prevent them from creating
62199 + another process until system reset
62200 + */
62201 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
62202 + from_kuid_munged(&init_user_ns, uid));
62203 + /* we intentionally leak this ref */
62204 + user = get_uid(current->cred->user);
62205 + if (user) {
62206 + user->banned = 1;
62207 + user->ban_expires = ~0UL;
62208 + }
62209 +
62210 + read_lock(&tasklist_lock);
62211 + do_each_thread(tsk2, tsk) {
62212 + cred = __task_cred(tsk);
62213 + if (uid_eq(cred->uid, uid))
62214 + gr_fake_force_sig(SIGKILL, tsk);
62215 + } while_each_thread(tsk2, tsk);
62216 + read_unlock(&tasklist_lock);
62217 + }
62218 +#endif
62219 +}
62220 +
62221 +int __gr_process_user_ban(struct user_struct *user)
62222 +{
62223 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62224 + if (unlikely(user->banned)) {
62225 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
62226 + user->banned = 0;
62227 + user->ban_expires = 0;
62228 + free_uid(user);
62229 + } else
62230 + return -EPERM;
62231 + }
62232 +#endif
62233 + return 0;
62234 +}
62235 +
62236 +int gr_process_user_ban(void)
62237 +{
62238 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62239 + return __gr_process_user_ban(current->cred->user);
62240 +#endif
62241 + return 0;
62242 +}
62243 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
62244 new file mode 100644
62245 index 0000000..4030d57
62246 --- /dev/null
62247 +++ b/grsecurity/grsec_sock.c
62248 @@ -0,0 +1,244 @@
62249 +#include <linux/kernel.h>
62250 +#include <linux/module.h>
62251 +#include <linux/sched.h>
62252 +#include <linux/file.h>
62253 +#include <linux/net.h>
62254 +#include <linux/in.h>
62255 +#include <linux/ip.h>
62256 +#include <net/sock.h>
62257 +#include <net/inet_sock.h>
62258 +#include <linux/grsecurity.h>
62259 +#include <linux/grinternal.h>
62260 +#include <linux/gracl.h>
62261 +
62262 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
62263 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
62264 +
62265 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
62266 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
62267 +
62268 +#ifdef CONFIG_UNIX_MODULE
62269 +EXPORT_SYMBOL(gr_acl_handle_unix);
62270 +EXPORT_SYMBOL(gr_acl_handle_mknod);
62271 +EXPORT_SYMBOL(gr_handle_chroot_unix);
62272 +EXPORT_SYMBOL(gr_handle_create);
62273 +#endif
62274 +
62275 +#ifdef CONFIG_GRKERNSEC
62276 +#define gr_conn_table_size 32749
62277 +struct conn_table_entry {
62278 + struct conn_table_entry *next;
62279 + struct signal_struct *sig;
62280 +};
62281 +
62282 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
62283 +DEFINE_SPINLOCK(gr_conn_table_lock);
62284 +
62285 +extern const char * gr_socktype_to_name(unsigned char type);
62286 +extern const char * gr_proto_to_name(unsigned char proto);
62287 +extern const char * gr_sockfamily_to_name(unsigned char family);
62288 +
62289 +static __inline__ int
62290 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
62291 +{
62292 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
62293 +}
62294 +
62295 +static __inline__ int
62296 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
62297 + __u16 sport, __u16 dport)
62298 +{
62299 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
62300 + sig->gr_sport == sport && sig->gr_dport == dport))
62301 + return 1;
62302 + else
62303 + return 0;
62304 +}
62305 +
62306 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
62307 +{
62308 + struct conn_table_entry **match;
62309 + unsigned int index;
62310 +
62311 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62312 + sig->gr_sport, sig->gr_dport,
62313 + gr_conn_table_size);
62314 +
62315 + newent->sig = sig;
62316 +
62317 + match = &gr_conn_table[index];
62318 + newent->next = *match;
62319 + *match = newent;
62320 +
62321 + return;
62322 +}
62323 +
62324 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
62325 +{
62326 + struct conn_table_entry *match, *last = NULL;
62327 + unsigned int index;
62328 +
62329 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62330 + sig->gr_sport, sig->gr_dport,
62331 + gr_conn_table_size);
62332 +
62333 + match = gr_conn_table[index];
62334 + while (match && !conn_match(match->sig,
62335 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
62336 + sig->gr_dport)) {
62337 + last = match;
62338 + match = match->next;
62339 + }
62340 +
62341 + if (match) {
62342 + if (last)
62343 + last->next = match->next;
62344 + else
62345 + gr_conn_table[index] = NULL;
62346 + kfree(match);
62347 + }
62348 +
62349 + return;
62350 +}
62351 +
62352 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
62353 + __u16 sport, __u16 dport)
62354 +{
62355 + struct conn_table_entry *match;
62356 + unsigned int index;
62357 +
62358 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
62359 +
62360 + match = gr_conn_table[index];
62361 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
62362 + match = match->next;
62363 +
62364 + if (match)
62365 + return match->sig;
62366 + else
62367 + return NULL;
62368 +}
62369 +
62370 +#endif
62371 +
62372 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
62373 +{
62374 +#ifdef CONFIG_GRKERNSEC
62375 + struct signal_struct *sig = task->signal;
62376 + struct conn_table_entry *newent;
62377 +
62378 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
62379 + if (newent == NULL)
62380 + return;
62381 + /* no bh lock needed since we are called with bh disabled */
62382 + spin_lock(&gr_conn_table_lock);
62383 + gr_del_task_from_ip_table_nolock(sig);
62384 + sig->gr_saddr = inet->inet_rcv_saddr;
62385 + sig->gr_daddr = inet->inet_daddr;
62386 + sig->gr_sport = inet->inet_sport;
62387 + sig->gr_dport = inet->inet_dport;
62388 + gr_add_to_task_ip_table_nolock(sig, newent);
62389 + spin_unlock(&gr_conn_table_lock);
62390 +#endif
62391 + return;
62392 +}
62393 +
62394 +void gr_del_task_from_ip_table(struct task_struct *task)
62395 +{
62396 +#ifdef CONFIG_GRKERNSEC
62397 + spin_lock_bh(&gr_conn_table_lock);
62398 + gr_del_task_from_ip_table_nolock(task->signal);
62399 + spin_unlock_bh(&gr_conn_table_lock);
62400 +#endif
62401 + return;
62402 +}
62403 +
62404 +void
62405 +gr_attach_curr_ip(const struct sock *sk)
62406 +{
62407 +#ifdef CONFIG_GRKERNSEC
62408 + struct signal_struct *p, *set;
62409 + const struct inet_sock *inet = inet_sk(sk);
62410 +
62411 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
62412 + return;
62413 +
62414 + set = current->signal;
62415 +
62416 + spin_lock_bh(&gr_conn_table_lock);
62417 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
62418 + inet->inet_dport, inet->inet_sport);
62419 + if (unlikely(p != NULL)) {
62420 + set->curr_ip = p->curr_ip;
62421 + set->used_accept = 1;
62422 + gr_del_task_from_ip_table_nolock(p);
62423 + spin_unlock_bh(&gr_conn_table_lock);
62424 + return;
62425 + }
62426 + spin_unlock_bh(&gr_conn_table_lock);
62427 +
62428 + set->curr_ip = inet->inet_daddr;
62429 + set->used_accept = 1;
62430 +#endif
62431 + return;
62432 +}
62433 +
62434 +int
62435 +gr_handle_sock_all(const int family, const int type, const int protocol)
62436 +{
62437 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62438 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
62439 + (family != AF_UNIX)) {
62440 + if (family == AF_INET)
62441 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
62442 + else
62443 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
62444 + return -EACCES;
62445 + }
62446 +#endif
62447 + return 0;
62448 +}
62449 +
62450 +int
62451 +gr_handle_sock_server(const struct sockaddr *sck)
62452 +{
62453 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62454 + if (grsec_enable_socket_server &&
62455 + in_group_p(grsec_socket_server_gid) &&
62456 + sck && (sck->sa_family != AF_UNIX) &&
62457 + (sck->sa_family != AF_LOCAL)) {
62458 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62459 + return -EACCES;
62460 + }
62461 +#endif
62462 + return 0;
62463 +}
62464 +
62465 +int
62466 +gr_handle_sock_server_other(const struct sock *sck)
62467 +{
62468 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62469 + if (grsec_enable_socket_server &&
62470 + in_group_p(grsec_socket_server_gid) &&
62471 + sck && (sck->sk_family != AF_UNIX) &&
62472 + (sck->sk_family != AF_LOCAL)) {
62473 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62474 + return -EACCES;
62475 + }
62476 +#endif
62477 + return 0;
62478 +}
62479 +
62480 +int
62481 +gr_handle_sock_client(const struct sockaddr *sck)
62482 +{
62483 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62484 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
62485 + sck && (sck->sa_family != AF_UNIX) &&
62486 + (sck->sa_family != AF_LOCAL)) {
62487 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
62488 + return -EACCES;
62489 + }
62490 +#endif
62491 + return 0;
62492 +}
62493 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
62494 new file mode 100644
62495 index 0000000..f55ef0f
62496 --- /dev/null
62497 +++ b/grsecurity/grsec_sysctl.c
62498 @@ -0,0 +1,469 @@
62499 +#include <linux/kernel.h>
62500 +#include <linux/sched.h>
62501 +#include <linux/sysctl.h>
62502 +#include <linux/grsecurity.h>
62503 +#include <linux/grinternal.h>
62504 +
62505 +int
62506 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
62507 +{
62508 +#ifdef CONFIG_GRKERNSEC_SYSCTL
62509 + if (dirname == NULL || name == NULL)
62510 + return 0;
62511 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
62512 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
62513 + return -EACCES;
62514 + }
62515 +#endif
62516 + return 0;
62517 +}
62518 +
62519 +#ifdef CONFIG_GRKERNSEC_ROFS
62520 +static int __maybe_unused one = 1;
62521 +#endif
62522 +
62523 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62524 +struct ctl_table grsecurity_table[] = {
62525 +#ifdef CONFIG_GRKERNSEC_SYSCTL
62526 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
62527 +#ifdef CONFIG_GRKERNSEC_IO
62528 + {
62529 + .procname = "disable_priv_io",
62530 + .data = &grsec_disable_privio,
62531 + .maxlen = sizeof(int),
62532 + .mode = 0600,
62533 + .proc_handler = &proc_dointvec,
62534 + },
62535 +#endif
62536 +#endif
62537 +#ifdef CONFIG_GRKERNSEC_LINK
62538 + {
62539 + .procname = "linking_restrictions",
62540 + .data = &grsec_enable_link,
62541 + .maxlen = sizeof(int),
62542 + .mode = 0600,
62543 + .proc_handler = &proc_dointvec,
62544 + },
62545 +#endif
62546 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
62547 + {
62548 + .procname = "enforce_symlinksifowner",
62549 + .data = &grsec_enable_symlinkown,
62550 + .maxlen = sizeof(int),
62551 + .mode = 0600,
62552 + .proc_handler = &proc_dointvec,
62553 + },
62554 + {
62555 + .procname = "symlinkown_gid",
62556 + .data = &grsec_symlinkown_gid,
62557 + .maxlen = sizeof(int),
62558 + .mode = 0600,
62559 + .proc_handler = &proc_dointvec,
62560 + },
62561 +#endif
62562 +#ifdef CONFIG_GRKERNSEC_BRUTE
62563 + {
62564 + .procname = "deter_bruteforce",
62565 + .data = &grsec_enable_brute,
62566 + .maxlen = sizeof(int),
62567 + .mode = 0600,
62568 + .proc_handler = &proc_dointvec,
62569 + },
62570 +#endif
62571 +#ifdef CONFIG_GRKERNSEC_FIFO
62572 + {
62573 + .procname = "fifo_restrictions",
62574 + .data = &grsec_enable_fifo,
62575 + .maxlen = sizeof(int),
62576 + .mode = 0600,
62577 + .proc_handler = &proc_dointvec,
62578 + },
62579 +#endif
62580 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62581 + {
62582 + .procname = "ptrace_readexec",
62583 + .data = &grsec_enable_ptrace_readexec,
62584 + .maxlen = sizeof(int),
62585 + .mode = 0600,
62586 + .proc_handler = &proc_dointvec,
62587 + },
62588 +#endif
62589 +#ifdef CONFIG_GRKERNSEC_SETXID
62590 + {
62591 + .procname = "consistent_setxid",
62592 + .data = &grsec_enable_setxid,
62593 + .maxlen = sizeof(int),
62594 + .mode = 0600,
62595 + .proc_handler = &proc_dointvec,
62596 + },
62597 +#endif
62598 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62599 + {
62600 + .procname = "ip_blackhole",
62601 + .data = &grsec_enable_blackhole,
62602 + .maxlen = sizeof(int),
62603 + .mode = 0600,
62604 + .proc_handler = &proc_dointvec,
62605 + },
62606 + {
62607 + .procname = "lastack_retries",
62608 + .data = &grsec_lastack_retries,
62609 + .maxlen = sizeof(int),
62610 + .mode = 0600,
62611 + .proc_handler = &proc_dointvec,
62612 + },
62613 +#endif
62614 +#ifdef CONFIG_GRKERNSEC_EXECLOG
62615 + {
62616 + .procname = "exec_logging",
62617 + .data = &grsec_enable_execlog,
62618 + .maxlen = sizeof(int),
62619 + .mode = 0600,
62620 + .proc_handler = &proc_dointvec,
62621 + },
62622 +#endif
62623 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62624 + {
62625 + .procname = "rwxmap_logging",
62626 + .data = &grsec_enable_log_rwxmaps,
62627 + .maxlen = sizeof(int),
62628 + .mode = 0600,
62629 + .proc_handler = &proc_dointvec,
62630 + },
62631 +#endif
62632 +#ifdef CONFIG_GRKERNSEC_SIGNAL
62633 + {
62634 + .procname = "signal_logging",
62635 + .data = &grsec_enable_signal,
62636 + .maxlen = sizeof(int),
62637 + .mode = 0600,
62638 + .proc_handler = &proc_dointvec,
62639 + },
62640 +#endif
62641 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
62642 + {
62643 + .procname = "forkfail_logging",
62644 + .data = &grsec_enable_forkfail,
62645 + .maxlen = sizeof(int),
62646 + .mode = 0600,
62647 + .proc_handler = &proc_dointvec,
62648 + },
62649 +#endif
62650 +#ifdef CONFIG_GRKERNSEC_TIME
62651 + {
62652 + .procname = "timechange_logging",
62653 + .data = &grsec_enable_time,
62654 + .maxlen = sizeof(int),
62655 + .mode = 0600,
62656 + .proc_handler = &proc_dointvec,
62657 + },
62658 +#endif
62659 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62660 + {
62661 + .procname = "chroot_deny_shmat",
62662 + .data = &grsec_enable_chroot_shmat,
62663 + .maxlen = sizeof(int),
62664 + .mode = 0600,
62665 + .proc_handler = &proc_dointvec,
62666 + },
62667 +#endif
62668 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62669 + {
62670 + .procname = "chroot_deny_unix",
62671 + .data = &grsec_enable_chroot_unix,
62672 + .maxlen = sizeof(int),
62673 + .mode = 0600,
62674 + .proc_handler = &proc_dointvec,
62675 + },
62676 +#endif
62677 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62678 + {
62679 + .procname = "chroot_deny_mount",
62680 + .data = &grsec_enable_chroot_mount,
62681 + .maxlen = sizeof(int),
62682 + .mode = 0600,
62683 + .proc_handler = &proc_dointvec,
62684 + },
62685 +#endif
62686 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62687 + {
62688 + .procname = "chroot_deny_fchdir",
62689 + .data = &grsec_enable_chroot_fchdir,
62690 + .maxlen = sizeof(int),
62691 + .mode = 0600,
62692 + .proc_handler = &proc_dointvec,
62693 + },
62694 +#endif
62695 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62696 + {
62697 + .procname = "chroot_deny_chroot",
62698 + .data = &grsec_enable_chroot_double,
62699 + .maxlen = sizeof(int),
62700 + .mode = 0600,
62701 + .proc_handler = &proc_dointvec,
62702 + },
62703 +#endif
62704 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62705 + {
62706 + .procname = "chroot_deny_pivot",
62707 + .data = &grsec_enable_chroot_pivot,
62708 + .maxlen = sizeof(int),
62709 + .mode = 0600,
62710 + .proc_handler = &proc_dointvec,
62711 + },
62712 +#endif
62713 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62714 + {
62715 + .procname = "chroot_enforce_chdir",
62716 + .data = &grsec_enable_chroot_chdir,
62717 + .maxlen = sizeof(int),
62718 + .mode = 0600,
62719 + .proc_handler = &proc_dointvec,
62720 + },
62721 +#endif
62722 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62723 + {
62724 + .procname = "chroot_deny_chmod",
62725 + .data = &grsec_enable_chroot_chmod,
62726 + .maxlen = sizeof(int),
62727 + .mode = 0600,
62728 + .proc_handler = &proc_dointvec,
62729 + },
62730 +#endif
62731 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62732 + {
62733 + .procname = "chroot_deny_mknod",
62734 + .data = &grsec_enable_chroot_mknod,
62735 + .maxlen = sizeof(int),
62736 + .mode = 0600,
62737 + .proc_handler = &proc_dointvec,
62738 + },
62739 +#endif
62740 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62741 + {
62742 + .procname = "chroot_restrict_nice",
62743 + .data = &grsec_enable_chroot_nice,
62744 + .maxlen = sizeof(int),
62745 + .mode = 0600,
62746 + .proc_handler = &proc_dointvec,
62747 + },
62748 +#endif
62749 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62750 + {
62751 + .procname = "chroot_execlog",
62752 + .data = &grsec_enable_chroot_execlog,
62753 + .maxlen = sizeof(int),
62754 + .mode = 0600,
62755 + .proc_handler = &proc_dointvec,
62756 + },
62757 +#endif
62758 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62759 + {
62760 + .procname = "chroot_caps",
62761 + .data = &grsec_enable_chroot_caps,
62762 + .maxlen = sizeof(int),
62763 + .mode = 0600,
62764 + .proc_handler = &proc_dointvec,
62765 + },
62766 +#endif
62767 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62768 + {
62769 + .procname = "chroot_deny_sysctl",
62770 + .data = &grsec_enable_chroot_sysctl,
62771 + .maxlen = sizeof(int),
62772 + .mode = 0600,
62773 + .proc_handler = &proc_dointvec,
62774 + },
62775 +#endif
62776 +#ifdef CONFIG_GRKERNSEC_TPE
62777 + {
62778 + .procname = "tpe",
62779 + .data = &grsec_enable_tpe,
62780 + .maxlen = sizeof(int),
62781 + .mode = 0600,
62782 + .proc_handler = &proc_dointvec,
62783 + },
62784 + {
62785 + .procname = "tpe_gid",
62786 + .data = &grsec_tpe_gid,
62787 + .maxlen = sizeof(int),
62788 + .mode = 0600,
62789 + .proc_handler = &proc_dointvec,
62790 + },
62791 +#endif
62792 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62793 + {
62794 + .procname = "tpe_invert",
62795 + .data = &grsec_enable_tpe_invert,
62796 + .maxlen = sizeof(int),
62797 + .mode = 0600,
62798 + .proc_handler = &proc_dointvec,
62799 + },
62800 +#endif
62801 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62802 + {
62803 + .procname = "tpe_restrict_all",
62804 + .data = &grsec_enable_tpe_all,
62805 + .maxlen = sizeof(int),
62806 + .mode = 0600,
62807 + .proc_handler = &proc_dointvec,
62808 + },
62809 +#endif
62810 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62811 + {
62812 + .procname = "socket_all",
62813 + .data = &grsec_enable_socket_all,
62814 + .maxlen = sizeof(int),
62815 + .mode = 0600,
62816 + .proc_handler = &proc_dointvec,
62817 + },
62818 + {
62819 + .procname = "socket_all_gid",
62820 + .data = &grsec_socket_all_gid,
62821 + .maxlen = sizeof(int),
62822 + .mode = 0600,
62823 + .proc_handler = &proc_dointvec,
62824 + },
62825 +#endif
62826 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62827 + {
62828 + .procname = "socket_client",
62829 + .data = &grsec_enable_socket_client,
62830 + .maxlen = sizeof(int),
62831 + .mode = 0600,
62832 + .proc_handler = &proc_dointvec,
62833 + },
62834 + {
62835 + .procname = "socket_client_gid",
62836 + .data = &grsec_socket_client_gid,
62837 + .maxlen = sizeof(int),
62838 + .mode = 0600,
62839 + .proc_handler = &proc_dointvec,
62840 + },
62841 +#endif
62842 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62843 + {
62844 + .procname = "socket_server",
62845 + .data = &grsec_enable_socket_server,
62846 + .maxlen = sizeof(int),
62847 + .mode = 0600,
62848 + .proc_handler = &proc_dointvec,
62849 + },
62850 + {
62851 + .procname = "socket_server_gid",
62852 + .data = &grsec_socket_server_gid,
62853 + .maxlen = sizeof(int),
62854 + .mode = 0600,
62855 + .proc_handler = &proc_dointvec,
62856 + },
62857 +#endif
62858 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62859 + {
62860 + .procname = "audit_group",
62861 + .data = &grsec_enable_group,
62862 + .maxlen = sizeof(int),
62863 + .mode = 0600,
62864 + .proc_handler = &proc_dointvec,
62865 + },
62866 + {
62867 + .procname = "audit_gid",
62868 + .data = &grsec_audit_gid,
62869 + .maxlen = sizeof(int),
62870 + .mode = 0600,
62871 + .proc_handler = &proc_dointvec,
62872 + },
62873 +#endif
62874 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62875 + {
62876 + .procname = "audit_chdir",
62877 + .data = &grsec_enable_chdir,
62878 + .maxlen = sizeof(int),
62879 + .mode = 0600,
62880 + .proc_handler = &proc_dointvec,
62881 + },
62882 +#endif
62883 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62884 + {
62885 + .procname = "audit_mount",
62886 + .data = &grsec_enable_mount,
62887 + .maxlen = sizeof(int),
62888 + .mode = 0600,
62889 + .proc_handler = &proc_dointvec,
62890 + },
62891 +#endif
62892 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62893 + {
62894 + .procname = "audit_textrel",
62895 + .data = &grsec_enable_audit_textrel,
62896 + .maxlen = sizeof(int),
62897 + .mode = 0600,
62898 + .proc_handler = &proc_dointvec,
62899 + },
62900 +#endif
62901 +#ifdef CONFIG_GRKERNSEC_DMESG
62902 + {
62903 + .procname = "dmesg",
62904 + .data = &grsec_enable_dmesg,
62905 + .maxlen = sizeof(int),
62906 + .mode = 0600,
62907 + .proc_handler = &proc_dointvec,
62908 + },
62909 +#endif
62910 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62911 + {
62912 + .procname = "chroot_findtask",
62913 + .data = &grsec_enable_chroot_findtask,
62914 + .maxlen = sizeof(int),
62915 + .mode = 0600,
62916 + .proc_handler = &proc_dointvec,
62917 + },
62918 +#endif
62919 +#ifdef CONFIG_GRKERNSEC_RESLOG
62920 + {
62921 + .procname = "resource_logging",
62922 + .data = &grsec_resource_logging,
62923 + .maxlen = sizeof(int),
62924 + .mode = 0600,
62925 + .proc_handler = &proc_dointvec,
62926 + },
62927 +#endif
62928 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62929 + {
62930 + .procname = "audit_ptrace",
62931 + .data = &grsec_enable_audit_ptrace,
62932 + .maxlen = sizeof(int),
62933 + .mode = 0600,
62934 + .proc_handler = &proc_dointvec,
62935 + },
62936 +#endif
62937 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62938 + {
62939 + .procname = "harden_ptrace",
62940 + .data = &grsec_enable_harden_ptrace,
62941 + .maxlen = sizeof(int),
62942 + .mode = 0600,
62943 + .proc_handler = &proc_dointvec,
62944 + },
62945 +#endif
62946 + {
62947 + .procname = "grsec_lock",
62948 + .data = &grsec_lock,
62949 + .maxlen = sizeof(int),
62950 + .mode = 0600,
62951 + .proc_handler = &proc_dointvec,
62952 + },
62953 +#endif
62954 +#ifdef CONFIG_GRKERNSEC_ROFS
62955 + {
62956 + .procname = "romount_protect",
62957 + .data = &grsec_enable_rofs,
62958 + .maxlen = sizeof(int),
62959 + .mode = 0600,
62960 + .proc_handler = &proc_dointvec_minmax,
62961 + .extra1 = &one,
62962 + .extra2 = &one,
62963 + },
62964 +#endif
62965 + { }
62966 +};
62967 +#endif
62968 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62969 new file mode 100644
62970 index 0000000..0dc13c3
62971 --- /dev/null
62972 +++ b/grsecurity/grsec_time.c
62973 @@ -0,0 +1,16 @@
62974 +#include <linux/kernel.h>
62975 +#include <linux/sched.h>
62976 +#include <linux/grinternal.h>
62977 +#include <linux/module.h>
62978 +
62979 +void
62980 +gr_log_timechange(void)
62981 +{
62982 +#ifdef CONFIG_GRKERNSEC_TIME
62983 + if (grsec_enable_time)
62984 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62985 +#endif
62986 + return;
62987 +}
62988 +
62989 +EXPORT_SYMBOL(gr_log_timechange);
62990 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
62991 new file mode 100644
62992 index 0000000..07e0dc0
62993 --- /dev/null
62994 +++ b/grsecurity/grsec_tpe.c
62995 @@ -0,0 +1,73 @@
62996 +#include <linux/kernel.h>
62997 +#include <linux/sched.h>
62998 +#include <linux/file.h>
62999 +#include <linux/fs.h>
63000 +#include <linux/grinternal.h>
63001 +
63002 +extern int gr_acl_tpe_check(void);
63003 +
63004 +int
63005 +gr_tpe_allow(const struct file *file)
63006 +{
63007 +#ifdef CONFIG_GRKERNSEC
63008 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
63009 + const struct cred *cred = current_cred();
63010 + char *msg = NULL;
63011 + char *msg2 = NULL;
63012 +
63013 + // never restrict root
63014 + if (!cred->uid)
63015 + return 1;
63016 +
63017 + if (grsec_enable_tpe) {
63018 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63019 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
63020 + msg = "not being in trusted group";
63021 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
63022 + msg = "being in untrusted group";
63023 +#else
63024 + if (in_group_p(grsec_tpe_gid))
63025 + msg = "being in untrusted group";
63026 +#endif
63027 + }
63028 + if (!msg && gr_acl_tpe_check())
63029 + msg = "being in untrusted role";
63030 +
63031 + // not in any affected group/role
63032 + if (!msg)
63033 + goto next_check;
63034 +
63035 + if (inode->i_uid)
63036 + msg2 = "file in non-root-owned directory";
63037 + else if (inode->i_mode & S_IWOTH)
63038 + msg2 = "file in world-writable directory";
63039 + else if (inode->i_mode & S_IWGRP)
63040 + msg2 = "file in group-writable directory";
63041 +
63042 + if (msg && msg2) {
63043 + char fullmsg[70] = {0};
63044 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
63045 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
63046 + return 0;
63047 + }
63048 + msg = NULL;
63049 +next_check:
63050 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
63051 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
63052 + return 1;
63053 +
63054 + if (inode->i_uid && (inode->i_uid != cred->uid))
63055 + msg = "directory not owned by user";
63056 + else if (inode->i_mode & S_IWOTH)
63057 + msg = "file in world-writable directory";
63058 + else if (inode->i_mode & S_IWGRP)
63059 + msg = "file in group-writable directory";
63060 +
63061 + if (msg) {
63062 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
63063 + return 0;
63064 + }
63065 +#endif
63066 +#endif
63067 + return 1;
63068 +}
63069 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
63070 new file mode 100644
63071 index 0000000..9f7b1ac
63072 --- /dev/null
63073 +++ b/grsecurity/grsum.c
63074 @@ -0,0 +1,61 @@
63075 +#include <linux/err.h>
63076 +#include <linux/kernel.h>
63077 +#include <linux/sched.h>
63078 +#include <linux/mm.h>
63079 +#include <linux/scatterlist.h>
63080 +#include <linux/crypto.h>
63081 +#include <linux/gracl.h>
63082 +
63083 +
63084 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
63085 +#error "crypto and sha256 must be built into the kernel"
63086 +#endif
63087 +
63088 +int
63089 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
63090 +{
63091 + char *p;
63092 + struct crypto_hash *tfm;
63093 + struct hash_desc desc;
63094 + struct scatterlist sg;
63095 + unsigned char temp_sum[GR_SHA_LEN];
63096 + volatile int retval = 0;
63097 + volatile int dummy = 0;
63098 + unsigned int i;
63099 +
63100 + sg_init_table(&sg, 1);
63101 +
63102 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
63103 + if (IS_ERR(tfm)) {
63104 + /* should never happen, since sha256 should be built in */
63105 + return 1;
63106 + }
63107 +
63108 + desc.tfm = tfm;
63109 + desc.flags = 0;
63110 +
63111 + crypto_hash_init(&desc);
63112 +
63113 + p = salt;
63114 + sg_set_buf(&sg, p, GR_SALT_LEN);
63115 + crypto_hash_update(&desc, &sg, sg.length);
63116 +
63117 + p = entry->pw;
63118 + sg_set_buf(&sg, p, strlen(p));
63119 +
63120 + crypto_hash_update(&desc, &sg, sg.length);
63121 +
63122 + crypto_hash_final(&desc, temp_sum);
63123 +
63124 + memset(entry->pw, 0, GR_PW_LEN);
63125 +
63126 + for (i = 0; i < GR_SHA_LEN; i++)
63127 + if (sum[i] != temp_sum[i])
63128 + retval = 1;
63129 + else
63130 + dummy = 1; // waste a cycle
63131 +
63132 + crypto_free_hash(tfm);
63133 +
63134 + return retval;
63135 +}
63136 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
63137 index 77ff547..181834f 100644
63138 --- a/include/asm-generic/4level-fixup.h
63139 +++ b/include/asm-generic/4level-fixup.h
63140 @@ -13,8 +13,10 @@
63141 #define pmd_alloc(mm, pud, address) \
63142 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
63143 NULL: pmd_offset(pud, address))
63144 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
63145
63146 #define pud_alloc(mm, pgd, address) (pgd)
63147 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
63148 #define pud_offset(pgd, start) (pgd)
63149 #define pud_none(pud) 0
63150 #define pud_bad(pud) 0
63151 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
63152 index b7babf0..04ad282 100644
63153 --- a/include/asm-generic/atomic-long.h
63154 +++ b/include/asm-generic/atomic-long.h
63155 @@ -22,6 +22,12 @@
63156
63157 typedef atomic64_t atomic_long_t;
63158
63159 +#ifdef CONFIG_PAX_REFCOUNT
63160 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
63161 +#else
63162 +typedef atomic64_t atomic_long_unchecked_t;
63163 +#endif
63164 +
63165 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
63166
63167 static inline long atomic_long_read(atomic_long_t *l)
63168 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63169 return (long)atomic64_read(v);
63170 }
63171
63172 +#ifdef CONFIG_PAX_REFCOUNT
63173 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63174 +{
63175 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63176 +
63177 + return (long)atomic64_read_unchecked(v);
63178 +}
63179 +#endif
63180 +
63181 static inline void atomic_long_set(atomic_long_t *l, long i)
63182 {
63183 atomic64_t *v = (atomic64_t *)l;
63184 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63185 atomic64_set(v, i);
63186 }
63187
63188 +#ifdef CONFIG_PAX_REFCOUNT
63189 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63190 +{
63191 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63192 +
63193 + atomic64_set_unchecked(v, i);
63194 +}
63195 +#endif
63196 +
63197 static inline void atomic_long_inc(atomic_long_t *l)
63198 {
63199 atomic64_t *v = (atomic64_t *)l;
63200 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63201 atomic64_inc(v);
63202 }
63203
63204 +#ifdef CONFIG_PAX_REFCOUNT
63205 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63206 +{
63207 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63208 +
63209 + atomic64_inc_unchecked(v);
63210 +}
63211 +#endif
63212 +
63213 static inline void atomic_long_dec(atomic_long_t *l)
63214 {
63215 atomic64_t *v = (atomic64_t *)l;
63216 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63217 atomic64_dec(v);
63218 }
63219
63220 +#ifdef CONFIG_PAX_REFCOUNT
63221 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63222 +{
63223 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63224 +
63225 + atomic64_dec_unchecked(v);
63226 +}
63227 +#endif
63228 +
63229 static inline void atomic_long_add(long i, atomic_long_t *l)
63230 {
63231 atomic64_t *v = (atomic64_t *)l;
63232 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63233 atomic64_add(i, v);
63234 }
63235
63236 +#ifdef CONFIG_PAX_REFCOUNT
63237 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63238 +{
63239 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63240 +
63241 + atomic64_add_unchecked(i, v);
63242 +}
63243 +#endif
63244 +
63245 static inline void atomic_long_sub(long i, atomic_long_t *l)
63246 {
63247 atomic64_t *v = (atomic64_t *)l;
63248 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63249 atomic64_sub(i, v);
63250 }
63251
63252 +#ifdef CONFIG_PAX_REFCOUNT
63253 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63254 +{
63255 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63256 +
63257 + atomic64_sub_unchecked(i, v);
63258 +}
63259 +#endif
63260 +
63261 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63262 {
63263 atomic64_t *v = (atomic64_t *)l;
63264 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63265 return (long)atomic64_add_return(i, v);
63266 }
63267
63268 +#ifdef CONFIG_PAX_REFCOUNT
63269 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63270 +{
63271 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63272 +
63273 + return (long)atomic64_add_return_unchecked(i, v);
63274 +}
63275 +#endif
63276 +
63277 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63278 {
63279 atomic64_t *v = (atomic64_t *)l;
63280 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63281 return (long)atomic64_inc_return(v);
63282 }
63283
63284 +#ifdef CONFIG_PAX_REFCOUNT
63285 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63286 +{
63287 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63288 +
63289 + return (long)atomic64_inc_return_unchecked(v);
63290 +}
63291 +#endif
63292 +
63293 static inline long atomic_long_dec_return(atomic_long_t *l)
63294 {
63295 atomic64_t *v = (atomic64_t *)l;
63296 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63297
63298 typedef atomic_t atomic_long_t;
63299
63300 +#ifdef CONFIG_PAX_REFCOUNT
63301 +typedef atomic_unchecked_t atomic_long_unchecked_t;
63302 +#else
63303 +typedef atomic_t atomic_long_unchecked_t;
63304 +#endif
63305 +
63306 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
63307 static inline long atomic_long_read(atomic_long_t *l)
63308 {
63309 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63310 return (long)atomic_read(v);
63311 }
63312
63313 +#ifdef CONFIG_PAX_REFCOUNT
63314 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63315 +{
63316 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63317 +
63318 + return (long)atomic_read_unchecked(v);
63319 +}
63320 +#endif
63321 +
63322 static inline void atomic_long_set(atomic_long_t *l, long i)
63323 {
63324 atomic_t *v = (atomic_t *)l;
63325 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63326 atomic_set(v, i);
63327 }
63328
63329 +#ifdef CONFIG_PAX_REFCOUNT
63330 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63331 +{
63332 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63333 +
63334 + atomic_set_unchecked(v, i);
63335 +}
63336 +#endif
63337 +
63338 static inline void atomic_long_inc(atomic_long_t *l)
63339 {
63340 atomic_t *v = (atomic_t *)l;
63341 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63342 atomic_inc(v);
63343 }
63344
63345 +#ifdef CONFIG_PAX_REFCOUNT
63346 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63347 +{
63348 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63349 +
63350 + atomic_inc_unchecked(v);
63351 +}
63352 +#endif
63353 +
63354 static inline void atomic_long_dec(atomic_long_t *l)
63355 {
63356 atomic_t *v = (atomic_t *)l;
63357 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63358 atomic_dec(v);
63359 }
63360
63361 +#ifdef CONFIG_PAX_REFCOUNT
63362 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63363 +{
63364 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63365 +
63366 + atomic_dec_unchecked(v);
63367 +}
63368 +#endif
63369 +
63370 static inline void atomic_long_add(long i, atomic_long_t *l)
63371 {
63372 atomic_t *v = (atomic_t *)l;
63373 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63374 atomic_add(i, v);
63375 }
63376
63377 +#ifdef CONFIG_PAX_REFCOUNT
63378 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63379 +{
63380 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63381 +
63382 + atomic_add_unchecked(i, v);
63383 +}
63384 +#endif
63385 +
63386 static inline void atomic_long_sub(long i, atomic_long_t *l)
63387 {
63388 atomic_t *v = (atomic_t *)l;
63389 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63390 atomic_sub(i, v);
63391 }
63392
63393 +#ifdef CONFIG_PAX_REFCOUNT
63394 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63395 +{
63396 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63397 +
63398 + atomic_sub_unchecked(i, v);
63399 +}
63400 +#endif
63401 +
63402 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63403 {
63404 atomic_t *v = (atomic_t *)l;
63405 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63406 return (long)atomic_add_return(i, v);
63407 }
63408
63409 +#ifdef CONFIG_PAX_REFCOUNT
63410 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63411 +{
63412 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63413 +
63414 + return (long)atomic_add_return_unchecked(i, v);
63415 +}
63416 +
63417 +#endif
63418 +
63419 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63420 {
63421 atomic_t *v = (atomic_t *)l;
63422 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63423 return (long)atomic_inc_return(v);
63424 }
63425
63426 +#ifdef CONFIG_PAX_REFCOUNT
63427 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63428 +{
63429 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63430 +
63431 + return (long)atomic_inc_return_unchecked(v);
63432 +}
63433 +#endif
63434 +
63435 static inline long atomic_long_dec_return(atomic_long_t *l)
63436 {
63437 atomic_t *v = (atomic_t *)l;
63438 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63439
63440 #endif /* BITS_PER_LONG == 64 */
63441
63442 +#ifdef CONFIG_PAX_REFCOUNT
63443 +static inline void pax_refcount_needs_these_functions(void)
63444 +{
63445 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
63446 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
63447 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
63448 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
63449 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
63450 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
63451 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
63452 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
63453 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
63454 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
63455 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
63456 +#ifdef CONFIG_X86
63457 + atomic_clear_mask_unchecked(0, NULL);
63458 + atomic_set_mask_unchecked(0, NULL);
63459 +#endif
63460 +
63461 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
63462 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
63463 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
63464 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
63465 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
63466 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
63467 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
63468 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
63469 +}
63470 +#else
63471 +#define atomic_read_unchecked(v) atomic_read(v)
63472 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
63473 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
63474 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
63475 +#define atomic_inc_unchecked(v) atomic_inc(v)
63476 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
63477 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
63478 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
63479 +#define atomic_dec_unchecked(v) atomic_dec(v)
63480 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
63481 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
63482 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
63483 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
63484 +
63485 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
63486 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
63487 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
63488 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
63489 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
63490 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
63491 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
63492 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
63493 +#endif
63494 +
63495 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
63496 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
63497 index 1ced641..c896ee8 100644
63498 --- a/include/asm-generic/atomic.h
63499 +++ b/include/asm-generic/atomic.h
63500 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
63501 * Atomically clears the bits set in @mask from @v
63502 */
63503 #ifndef atomic_clear_mask
63504 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
63505 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
63506 {
63507 unsigned long flags;
63508
63509 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
63510 index b18ce4f..2ee2843 100644
63511 --- a/include/asm-generic/atomic64.h
63512 +++ b/include/asm-generic/atomic64.h
63513 @@ -16,6 +16,8 @@ typedef struct {
63514 long long counter;
63515 } atomic64_t;
63516
63517 +typedef atomic64_t atomic64_unchecked_t;
63518 +
63519 #define ATOMIC64_INIT(i) { (i) }
63520
63521 extern long long atomic64_read(const atomic64_t *v);
63522 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
63523 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
63524 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
63525
63526 +#define atomic64_read_unchecked(v) atomic64_read(v)
63527 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
63528 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
63529 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
63530 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
63531 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
63532 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
63533 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
63534 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
63535 +
63536 #endif /* _ASM_GENERIC_ATOMIC64_H */
63537 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
63538 index 1bfcfe5..e04c5c9 100644
63539 --- a/include/asm-generic/cache.h
63540 +++ b/include/asm-generic/cache.h
63541 @@ -6,7 +6,7 @@
63542 * cache lines need to provide their own cache.h.
63543 */
63544
63545 -#define L1_CACHE_SHIFT 5
63546 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
63547 +#define L1_CACHE_SHIFT 5UL
63548 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
63549
63550 #endif /* __ASM_GENERIC_CACHE_H */
63551 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
63552 index 0d68a1e..b74a761 100644
63553 --- a/include/asm-generic/emergency-restart.h
63554 +++ b/include/asm-generic/emergency-restart.h
63555 @@ -1,7 +1,7 @@
63556 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
63557 #define _ASM_GENERIC_EMERGENCY_RESTART_H
63558
63559 -static inline void machine_emergency_restart(void)
63560 +static inline __noreturn void machine_emergency_restart(void)
63561 {
63562 machine_restart(NULL);
63563 }
63564 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
63565 index 90f99c7..00ce236 100644
63566 --- a/include/asm-generic/kmap_types.h
63567 +++ b/include/asm-generic/kmap_types.h
63568 @@ -2,9 +2,9 @@
63569 #define _ASM_GENERIC_KMAP_TYPES_H
63570
63571 #ifdef __WITH_KM_FENCE
63572 -# define KM_TYPE_NR 41
63573 +# define KM_TYPE_NR 42
63574 #else
63575 -# define KM_TYPE_NR 20
63576 +# define KM_TYPE_NR 21
63577 #endif
63578
63579 #endif
63580 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
63581 index 9ceb03b..62b0b8f 100644
63582 --- a/include/asm-generic/local.h
63583 +++ b/include/asm-generic/local.h
63584 @@ -23,24 +23,37 @@ typedef struct
63585 atomic_long_t a;
63586 } local_t;
63587
63588 +typedef struct {
63589 + atomic_long_unchecked_t a;
63590 +} local_unchecked_t;
63591 +
63592 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
63593
63594 #define local_read(l) atomic_long_read(&(l)->a)
63595 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
63596 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
63597 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
63598 #define local_inc(l) atomic_long_inc(&(l)->a)
63599 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
63600 #define local_dec(l) atomic_long_dec(&(l)->a)
63601 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
63602 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
63603 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
63604 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
63605 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
63606
63607 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
63608 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
63609 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
63610 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
63611 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
63612 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
63613 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
63614 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
63615 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
63616
63617 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63618 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63619 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
63620 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
63621 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
63622 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
63623 index 725612b..9cc513a 100644
63624 --- a/include/asm-generic/pgtable-nopmd.h
63625 +++ b/include/asm-generic/pgtable-nopmd.h
63626 @@ -1,14 +1,19 @@
63627 #ifndef _PGTABLE_NOPMD_H
63628 #define _PGTABLE_NOPMD_H
63629
63630 -#ifndef __ASSEMBLY__
63631 -
63632 #include <asm-generic/pgtable-nopud.h>
63633
63634 -struct mm_struct;
63635 -
63636 #define __PAGETABLE_PMD_FOLDED
63637
63638 +#define PMD_SHIFT PUD_SHIFT
63639 +#define PTRS_PER_PMD 1
63640 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
63641 +#define PMD_MASK (~(PMD_SIZE-1))
63642 +
63643 +#ifndef __ASSEMBLY__
63644 +
63645 +struct mm_struct;
63646 +
63647 /*
63648 * Having the pmd type consist of a pud gets the size right, and allows
63649 * us to conceptually access the pud entry that this pmd is folded into
63650 @@ -16,11 +21,6 @@ struct mm_struct;
63651 */
63652 typedef struct { pud_t pud; } pmd_t;
63653
63654 -#define PMD_SHIFT PUD_SHIFT
63655 -#define PTRS_PER_PMD 1
63656 -#define PMD_SIZE (1UL << PMD_SHIFT)
63657 -#define PMD_MASK (~(PMD_SIZE-1))
63658 -
63659 /*
63660 * The "pud_xxx()" functions here are trivial for a folded two-level
63661 * setup: the pmd is never bad, and a pmd always exists (as it's folded
63662 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
63663 index 810431d..0ec4804f 100644
63664 --- a/include/asm-generic/pgtable-nopud.h
63665 +++ b/include/asm-generic/pgtable-nopud.h
63666 @@ -1,10 +1,15 @@
63667 #ifndef _PGTABLE_NOPUD_H
63668 #define _PGTABLE_NOPUD_H
63669
63670 -#ifndef __ASSEMBLY__
63671 -
63672 #define __PAGETABLE_PUD_FOLDED
63673
63674 +#define PUD_SHIFT PGDIR_SHIFT
63675 +#define PTRS_PER_PUD 1
63676 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
63677 +#define PUD_MASK (~(PUD_SIZE-1))
63678 +
63679 +#ifndef __ASSEMBLY__
63680 +
63681 /*
63682 * Having the pud type consist of a pgd gets the size right, and allows
63683 * us to conceptually access the pgd entry that this pud is folded into
63684 @@ -12,11 +17,6 @@
63685 */
63686 typedef struct { pgd_t pgd; } pud_t;
63687
63688 -#define PUD_SHIFT PGDIR_SHIFT
63689 -#define PTRS_PER_PUD 1
63690 -#define PUD_SIZE (1UL << PUD_SHIFT)
63691 -#define PUD_MASK (~(PUD_SIZE-1))
63692 -
63693 /*
63694 * The "pgd_xxx()" functions here are trivial for a folded two-level
63695 * setup: the pud is never bad, and a pud always exists (as it's folded
63696 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63697 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63698
63699 #define pgd_populate(mm, pgd, pud) do { } while (0)
63700 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63701 /*
63702 * (puds are folded into pgds so this doesn't get actually called,
63703 * but the define is needed for a generic inline function.)
63704 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63705 index 5cf680a..4b74d62 100644
63706 --- a/include/asm-generic/pgtable.h
63707 +++ b/include/asm-generic/pgtable.h
63708 @@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
63709 }
63710 #endif /* CONFIG_NUMA_BALANCING */
63711
63712 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63713 +static inline unsigned long pax_open_kernel(void) { return 0; }
63714 +#endif
63715 +
63716 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63717 +static inline unsigned long pax_close_kernel(void) { return 0; }
63718 +#endif
63719 +
63720 #endif /* CONFIG_MMU */
63721
63722 #endif /* !__ASSEMBLY__ */
63723 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63724 index d1ea7ce..b1ebf2a 100644
63725 --- a/include/asm-generic/vmlinux.lds.h
63726 +++ b/include/asm-generic/vmlinux.lds.h
63727 @@ -218,6 +218,7 @@
63728 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63729 VMLINUX_SYMBOL(__start_rodata) = .; \
63730 *(.rodata) *(.rodata.*) \
63731 + *(.data..read_only) \
63732 *(__vermagic) /* Kernel version magic */ \
63733 . = ALIGN(8); \
63734 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63735 @@ -725,17 +726,18 @@
63736 * section in the linker script will go there too. @phdr should have
63737 * a leading colon.
63738 *
63739 - * Note that this macros defines __per_cpu_load as an absolute symbol.
63740 + * Note that this macros defines per_cpu_load as an absolute symbol.
63741 * If there is no need to put the percpu section at a predetermined
63742 * address, use PERCPU_SECTION.
63743 */
63744 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63745 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
63746 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63747 + per_cpu_load = .; \
63748 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63749 - LOAD_OFFSET) { \
63750 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63751 PERCPU_INPUT(cacheline) \
63752 } phdr \
63753 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63754 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63755
63756 /**
63757 * PERCPU_SECTION - define output section for percpu area, simple version
63758 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63759 index 418d270..bfd2794 100644
63760 --- a/include/crypto/algapi.h
63761 +++ b/include/crypto/algapi.h
63762 @@ -34,7 +34,7 @@ struct crypto_type {
63763 unsigned int maskclear;
63764 unsigned int maskset;
63765 unsigned int tfmsize;
63766 -};
63767 +} __do_const;
63768
63769 struct crypto_instance {
63770 struct crypto_alg alg;
63771 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63772 index fad21c9..3fff955 100644
63773 --- a/include/drm/drmP.h
63774 +++ b/include/drm/drmP.h
63775 @@ -72,6 +72,7 @@
63776 #include <linux/workqueue.h>
63777 #include <linux/poll.h>
63778 #include <asm/pgalloc.h>
63779 +#include <asm/local.h>
63780 #include <drm/drm.h>
63781 #include <drm/drm_sarea.h>
63782
63783 @@ -1068,7 +1069,7 @@ struct drm_device {
63784
63785 /** \name Usage Counters */
63786 /*@{ */
63787 - int open_count; /**< Outstanding files open */
63788 + local_t open_count; /**< Outstanding files open */
63789 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63790 atomic_t vma_count; /**< Outstanding vma areas open */
63791 int buf_use; /**< Buffers in use -- cannot alloc */
63792 @@ -1079,7 +1080,7 @@ struct drm_device {
63793 /*@{ */
63794 unsigned long counters;
63795 enum drm_stat_type types[15];
63796 - atomic_t counts[15];
63797 + atomic_unchecked_t counts[15];
63798 /*@} */
63799
63800 struct list_head filelist;
63801 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63802 index f43d556..94d9343 100644
63803 --- a/include/drm/drm_crtc_helper.h
63804 +++ b/include/drm/drm_crtc_helper.h
63805 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63806 struct drm_connector *connector);
63807 /* disable encoder when not in use - more explicit than dpms off */
63808 void (*disable)(struct drm_encoder *encoder);
63809 -};
63810 +} __no_const;
63811
63812 /**
63813 * drm_connector_helper_funcs - helper operations for connectors
63814 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63815 index 72dcbe8..8db58d7 100644
63816 --- a/include/drm/ttm/ttm_memory.h
63817 +++ b/include/drm/ttm/ttm_memory.h
63818 @@ -48,7 +48,7 @@
63819
63820 struct ttm_mem_shrink {
63821 int (*do_shrink) (struct ttm_mem_shrink *);
63822 -};
63823 +} __no_const;
63824
63825 /**
63826 * struct ttm_mem_global - Global memory accounting structure.
63827 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63828 index c1da539..4db35ec 100644
63829 --- a/include/linux/atmdev.h
63830 +++ b/include/linux/atmdev.h
63831 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63832 #endif
63833
63834 struct k_atm_aal_stats {
63835 -#define __HANDLE_ITEM(i) atomic_t i
63836 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63837 __AAL_STAT_ITEMS
63838 #undef __HANDLE_ITEM
63839 };
63840 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63841 index 0530b98..b127a9e 100644
63842 --- a/include/linux/binfmts.h
63843 +++ b/include/linux/binfmts.h
63844 @@ -73,6 +73,7 @@ struct linux_binfmt {
63845 int (*load_binary)(struct linux_binprm *);
63846 int (*load_shlib)(struct file *);
63847 int (*core_dump)(struct coredump_params *cprm);
63848 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63849 unsigned long min_coredump; /* minimal dump size */
63850 };
63851
63852 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63853 index f94bc83..62b9cfe 100644
63854 --- a/include/linux/blkdev.h
63855 +++ b/include/linux/blkdev.h
63856 @@ -1498,7 +1498,7 @@ struct block_device_operations {
63857 /* this callback is with swap_lock and sometimes page table lock held */
63858 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63859 struct module *owner;
63860 -};
63861 +} __do_const;
63862
63863 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63864 unsigned long);
63865 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63866 index 7c2e030..b72475d 100644
63867 --- a/include/linux/blktrace_api.h
63868 +++ b/include/linux/blktrace_api.h
63869 @@ -23,7 +23,7 @@ struct blk_trace {
63870 struct dentry *dir;
63871 struct dentry *dropped_file;
63872 struct dentry *msg_file;
63873 - atomic_t dropped;
63874 + atomic_unchecked_t dropped;
63875 };
63876
63877 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63878 diff --git a/include/linux/cache.h b/include/linux/cache.h
63879 index 4c57065..4307975 100644
63880 --- a/include/linux/cache.h
63881 +++ b/include/linux/cache.h
63882 @@ -16,6 +16,10 @@
63883 #define __read_mostly
63884 #endif
63885
63886 +#ifndef __read_only
63887 +#define __read_only __read_mostly
63888 +#endif
63889 +
63890 #ifndef ____cacheline_aligned
63891 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63892 #endif
63893 diff --git a/include/linux/capability.h b/include/linux/capability.h
63894 index 98503b7..cc36d18 100644
63895 --- a/include/linux/capability.h
63896 +++ b/include/linux/capability.h
63897 @@ -211,8 +211,13 @@ extern bool capable(int cap);
63898 extern bool ns_capable(struct user_namespace *ns, int cap);
63899 extern bool nsown_capable(int cap);
63900 extern bool inode_capable(const struct inode *inode, int cap);
63901 +extern bool capable_nolog(int cap);
63902 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63903 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
63904
63905 /* audit system wants to get cap info from files as well */
63906 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63907
63908 +extern int is_privileged_binary(const struct dentry *dentry);
63909 +
63910 #endif /* !_LINUX_CAPABILITY_H */
63911 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63912 index 8609d57..86e4d79 100644
63913 --- a/include/linux/cdrom.h
63914 +++ b/include/linux/cdrom.h
63915 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
63916
63917 /* driver specifications */
63918 const int capability; /* capability flags */
63919 - int n_minors; /* number of active minor devices */
63920 /* handle uniform packets for scsi type devices (scsi,atapi) */
63921 int (*generic_packet) (struct cdrom_device_info *,
63922 struct packet_command *);
63923 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63924 index 42e55de..1cd0e66 100644
63925 --- a/include/linux/cleancache.h
63926 +++ b/include/linux/cleancache.h
63927 @@ -31,7 +31,7 @@ struct cleancache_ops {
63928 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63929 void (*invalidate_inode)(int, struct cleancache_filekey);
63930 void (*invalidate_fs)(int);
63931 -};
63932 +} __no_const;
63933
63934 extern struct cleancache_ops
63935 cleancache_register_ops(struct cleancache_ops *ops);
63936 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63937 index 662fd1b..e801992 100644
63938 --- a/include/linux/compiler-gcc4.h
63939 +++ b/include/linux/compiler-gcc4.h
63940 @@ -34,6 +34,21 @@
63941 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
63942
63943 #if __GNUC_MINOR__ >= 5
63944 +
63945 +#ifdef CONSTIFY_PLUGIN
63946 +#define __no_const __attribute__((no_const))
63947 +#define __do_const __attribute__((do_const))
63948 +#endif
63949 +
63950 +#ifdef SIZE_OVERFLOW_PLUGIN
63951 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63952 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63953 +#endif
63954 +
63955 +#ifdef LATENT_ENTROPY_PLUGIN
63956 +#define __latent_entropy __attribute__((latent_entropy))
63957 +#endif
63958 +
63959 /*
63960 * Mark a position in code as unreachable. This can be used to
63961 * suppress control flow warnings after asm blocks that transfer
63962 @@ -49,6 +64,11 @@
63963 #define __noclone __attribute__((__noclone__))
63964
63965 #endif
63966 +
63967 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63968 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63969 +#define __bos0(ptr) __bos((ptr), 0)
63970 +#define __bos1(ptr) __bos((ptr), 1)
63971 #endif
63972
63973 #if __GNUC_MINOR__ >= 6
63974 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63975 index dd852b7..72924c0 100644
63976 --- a/include/linux/compiler.h
63977 +++ b/include/linux/compiler.h
63978 @@ -5,11 +5,14 @@
63979
63980 #ifdef __CHECKER__
63981 # define __user __attribute__((noderef, address_space(1)))
63982 +# define __force_user __force __user
63983 # define __kernel __attribute__((address_space(0)))
63984 +# define __force_kernel __force __kernel
63985 # define __safe __attribute__((safe))
63986 # define __force __attribute__((force))
63987 # define __nocast __attribute__((nocast))
63988 # define __iomem __attribute__((noderef, address_space(2)))
63989 +# define __force_iomem __force __iomem
63990 # define __must_hold(x) __attribute__((context(x,1,1)))
63991 # define __acquires(x) __attribute__((context(x,0,1)))
63992 # define __releases(x) __attribute__((context(x,1,0)))
63993 @@ -17,20 +20,48 @@
63994 # define __release(x) __context__(x,-1)
63995 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
63996 # define __percpu __attribute__((noderef, address_space(3)))
63997 +# define __force_percpu __force __percpu
63998 #ifdef CONFIG_SPARSE_RCU_POINTER
63999 # define __rcu __attribute__((noderef, address_space(4)))
64000 +# define __force_rcu __force __rcu
64001 #else
64002 # define __rcu
64003 +# define __force_rcu
64004 #endif
64005 extern void __chk_user_ptr(const volatile void __user *);
64006 extern void __chk_io_ptr(const volatile void __iomem *);
64007 +#elif defined(CHECKER_PLUGIN)
64008 +//# define __user
64009 +//# define __force_user
64010 +//# define __kernel
64011 +//# define __force_kernel
64012 +# define __safe
64013 +# define __force
64014 +# define __nocast
64015 +# define __iomem
64016 +# define __force_iomem
64017 +# define __chk_user_ptr(x) (void)0
64018 +# define __chk_io_ptr(x) (void)0
64019 +# define __builtin_warning(x, y...) (1)
64020 +# define __acquires(x)
64021 +# define __releases(x)
64022 +# define __acquire(x) (void)0
64023 +# define __release(x) (void)0
64024 +# define __cond_lock(x,c) (c)
64025 +# define __percpu
64026 +# define __force_percpu
64027 +# define __rcu
64028 +# define __force_rcu
64029 #else
64030 # define __user
64031 +# define __force_user
64032 # define __kernel
64033 +# define __force_kernel
64034 # define __safe
64035 # define __force
64036 # define __nocast
64037 # define __iomem
64038 +# define __force_iomem
64039 # define __chk_user_ptr(x) (void)0
64040 # define __chk_io_ptr(x) (void)0
64041 # define __builtin_warning(x, y...) (1)
64042 @@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
64043 # define __release(x) (void)0
64044 # define __cond_lock(x,c) (c)
64045 # define __percpu
64046 +# define __force_percpu
64047 # define __rcu
64048 +# define __force_rcu
64049 #endif
64050
64051 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
64052 @@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64053 # define __attribute_const__ /* unimplemented */
64054 #endif
64055
64056 +#ifndef __no_const
64057 +# define __no_const
64058 +#endif
64059 +
64060 +#ifndef __do_const
64061 +# define __do_const
64062 +#endif
64063 +
64064 +#ifndef __size_overflow
64065 +# define __size_overflow(...)
64066 +#endif
64067 +
64068 +#ifndef __intentional_overflow
64069 +# define __intentional_overflow(...)
64070 +#endif
64071 +
64072 +#ifndef __latent_entropy
64073 +# define __latent_entropy
64074 +#endif
64075 +
64076 /*
64077 * Tell gcc if a function is cold. The compiler will assume any path
64078 * directly leading to the call is unlikely.
64079 @@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64080 #define __cold
64081 #endif
64082
64083 +#ifndef __alloc_size
64084 +#define __alloc_size(...)
64085 +#endif
64086 +
64087 +#ifndef __bos
64088 +#define __bos(ptr, arg)
64089 +#endif
64090 +
64091 +#ifndef __bos0
64092 +#define __bos0(ptr)
64093 +#endif
64094 +
64095 +#ifndef __bos1
64096 +#define __bos1(ptr)
64097 +#endif
64098 +
64099 /* Simple shorthand for a section definition */
64100 #ifndef __section
64101 # define __section(S) __attribute__ ((__section__(#S)))
64102 @@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64103 * use is to mediate communication between process-level code and irq/NMI
64104 * handlers, all running on the same CPU.
64105 */
64106 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
64107 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
64108 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
64109
64110 #endif /* __LINUX_COMPILER_H */
64111 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
64112 index ce7a074..01ab8ac 100644
64113 --- a/include/linux/cpu.h
64114 +++ b/include/linux/cpu.h
64115 @@ -115,7 +115,7 @@ enum {
64116 /* Need to know about CPUs going up/down? */
64117 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
64118 #define cpu_notifier(fn, pri) { \
64119 - static struct notifier_block fn##_nb __cpuinitdata = \
64120 + static struct notifier_block fn##_nb = \
64121 { .notifier_call = fn, .priority = pri }; \
64122 register_cpu_notifier(&fn##_nb); \
64123 }
64124 diff --git a/include/linux/cred.h b/include/linux/cred.h
64125 index 04421e8..6bce4ef 100644
64126 --- a/include/linux/cred.h
64127 +++ b/include/linux/cred.h
64128 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
64129 static inline void validate_process_creds(void)
64130 {
64131 }
64132 +static inline void validate_task_creds(struct task_struct *task)
64133 +{
64134 +}
64135 #endif
64136
64137 /**
64138 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
64139 index b92eadf..b4ecdc1 100644
64140 --- a/include/linux/crypto.h
64141 +++ b/include/linux/crypto.h
64142 @@ -373,7 +373,7 @@ struct cipher_tfm {
64143 const u8 *key, unsigned int keylen);
64144 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64145 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64146 -};
64147 +} __no_const;
64148
64149 struct hash_tfm {
64150 int (*init)(struct hash_desc *desc);
64151 @@ -394,13 +394,13 @@ struct compress_tfm {
64152 int (*cot_decompress)(struct crypto_tfm *tfm,
64153 const u8 *src, unsigned int slen,
64154 u8 *dst, unsigned int *dlen);
64155 -};
64156 +} __no_const;
64157
64158 struct rng_tfm {
64159 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
64160 unsigned int dlen);
64161 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
64162 -};
64163 +} __no_const;
64164
64165 #define crt_ablkcipher crt_u.ablkcipher
64166 #define crt_aead crt_u.aead
64167 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
64168 index 7925bf0..d5143d2 100644
64169 --- a/include/linux/decompress/mm.h
64170 +++ b/include/linux/decompress/mm.h
64171 @@ -77,7 +77,7 @@ static void free(void *where)
64172 * warnings when not needed (indeed large_malloc / large_free are not
64173 * needed by inflate */
64174
64175 -#define malloc(a) kmalloc(a, GFP_KERNEL)
64176 +#define malloc(a) kmalloc((a), GFP_KERNEL)
64177 #define free(a) kfree(a)
64178
64179 #define large_malloc(a) vmalloc(a)
64180 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
64181 index 94af418..b1ca7a2 100644
64182 --- a/include/linux/dma-mapping.h
64183 +++ b/include/linux/dma-mapping.h
64184 @@ -54,7 +54,7 @@ struct dma_map_ops {
64185 u64 (*get_required_mask)(struct device *dev);
64186 #endif
64187 int is_phys;
64188 -};
64189 +} __do_const;
64190
64191 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
64192
64193 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
64194 index d3201e4..8281e63 100644
64195 --- a/include/linux/dmaengine.h
64196 +++ b/include/linux/dmaengine.h
64197 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
64198 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
64199 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
64200
64201 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64202 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64203 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
64204 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64205 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64206 struct dma_pinned_list *pinned_list, struct page *page,
64207 unsigned int offset, size_t len);
64208
64209 diff --git a/include/linux/efi.h b/include/linux/efi.h
64210 index 7a9498a..155713d 100644
64211 --- a/include/linux/efi.h
64212 +++ b/include/linux/efi.h
64213 @@ -733,6 +733,7 @@ struct efivar_operations {
64214 efi_set_variable_t *set_variable;
64215 efi_query_variable_info_t *query_variable_info;
64216 };
64217 +typedef struct efivar_operations __no_const efivar_operations_no_const;
64218
64219 struct efivars {
64220 /*
64221 diff --git a/include/linux/elf.h b/include/linux/elf.h
64222 index 8c9048e..16a4665 100644
64223 --- a/include/linux/elf.h
64224 +++ b/include/linux/elf.h
64225 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
64226 #define elf_note elf32_note
64227 #define elf_addr_t Elf32_Off
64228 #define Elf_Half Elf32_Half
64229 +#define elf_dyn Elf32_Dyn
64230
64231 #else
64232
64233 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
64234 #define elf_note elf64_note
64235 #define elf_addr_t Elf64_Off
64236 #define Elf_Half Elf64_Half
64237 +#define elf_dyn Elf64_Dyn
64238
64239 #endif
64240
64241 diff --git a/include/linux/filter.h b/include/linux/filter.h
64242 index c45eabc..baa0be5 100644
64243 --- a/include/linux/filter.h
64244 +++ b/include/linux/filter.h
64245 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
64246
64247 struct sk_buff;
64248 struct sock;
64249 +struct bpf_jit_work;
64250
64251 struct sk_filter
64252 {
64253 @@ -27,6 +28,9 @@ struct sk_filter
64254 unsigned int len; /* Number of filter blocks */
64255 unsigned int (*bpf_func)(const struct sk_buff *skb,
64256 const struct sock_filter *filter);
64257 +#ifdef CONFIG_BPF_JIT
64258 + struct bpf_jit_work *work;
64259 +#endif
64260 struct rcu_head rcu;
64261 struct sock_filter insns[0];
64262 };
64263 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
64264 index 3044254..9767f41 100644
64265 --- a/include/linux/frontswap.h
64266 +++ b/include/linux/frontswap.h
64267 @@ -11,7 +11,7 @@ struct frontswap_ops {
64268 int (*load)(unsigned, pgoff_t, struct page *);
64269 void (*invalidate_page)(unsigned, pgoff_t);
64270 void (*invalidate_area)(unsigned);
64271 -};
64272 +} __no_const;
64273
64274 extern bool frontswap_enabled;
64275 extern struct frontswap_ops
64276 diff --git a/include/linux/fs.h b/include/linux/fs.h
64277 index 7617ee0..b575199 100644
64278 --- a/include/linux/fs.h
64279 +++ b/include/linux/fs.h
64280 @@ -1541,7 +1541,8 @@ struct file_operations {
64281 long (*fallocate)(struct file *file, int mode, loff_t offset,
64282 loff_t len);
64283 int (*show_fdinfo)(struct seq_file *m, struct file *f);
64284 -};
64285 +} __do_const;
64286 +typedef struct file_operations __no_const file_operations_no_const;
64287
64288 struct inode_operations {
64289 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
64290 @@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
64291 inode->i_flags |= S_NOSEC;
64292 }
64293
64294 +static inline bool is_sidechannel_device(const struct inode *inode)
64295 +{
64296 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
64297 + umode_t mode = inode->i_mode;
64298 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
64299 +#else
64300 + return false;
64301 +#endif
64302 +}
64303 +
64304 #endif /* _LINUX_FS_H */
64305 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
64306 index d0ae3a8..0244b34 100644
64307 --- a/include/linux/fs_struct.h
64308 +++ b/include/linux/fs_struct.h
64309 @@ -6,7 +6,7 @@
64310 #include <linux/seqlock.h>
64311
64312 struct fs_struct {
64313 - int users;
64314 + atomic_t users;
64315 spinlock_t lock;
64316 seqcount_t seq;
64317 int umask;
64318 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
64319 index 5dfa0aa..6acf322 100644
64320 --- a/include/linux/fscache-cache.h
64321 +++ b/include/linux/fscache-cache.h
64322 @@ -112,7 +112,7 @@ struct fscache_operation {
64323 fscache_operation_release_t release;
64324 };
64325
64326 -extern atomic_t fscache_op_debug_id;
64327 +extern atomic_unchecked_t fscache_op_debug_id;
64328 extern void fscache_op_work_func(struct work_struct *work);
64329
64330 extern void fscache_enqueue_operation(struct fscache_operation *);
64331 @@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
64332 INIT_WORK(&op->work, fscache_op_work_func);
64333 atomic_set(&op->usage, 1);
64334 op->state = FSCACHE_OP_ST_INITIALISED;
64335 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
64336 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64337 op->processor = processor;
64338 op->release = release;
64339 INIT_LIST_HEAD(&op->pend_link);
64340 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
64341 index 0fbfb46..508eb0d 100644
64342 --- a/include/linux/fsnotify.h
64343 +++ b/include/linux/fsnotify.h
64344 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
64345 struct inode *inode = path->dentry->d_inode;
64346 __u32 mask = FS_ACCESS;
64347
64348 + if (is_sidechannel_device(inode))
64349 + return;
64350 +
64351 if (S_ISDIR(inode->i_mode))
64352 mask |= FS_ISDIR;
64353
64354 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
64355 struct inode *inode = path->dentry->d_inode;
64356 __u32 mask = FS_MODIFY;
64357
64358 + if (is_sidechannel_device(inode))
64359 + return;
64360 +
64361 if (S_ISDIR(inode->i_mode))
64362 mask |= FS_ISDIR;
64363
64364 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
64365 */
64366 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
64367 {
64368 - return kstrdup(name, GFP_KERNEL);
64369 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
64370 }
64371
64372 /*
64373 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
64374 index a3d4895..ddd2a50 100644
64375 --- a/include/linux/ftrace_event.h
64376 +++ b/include/linux/ftrace_event.h
64377 @@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
64378 extern int trace_add_event_call(struct ftrace_event_call *call);
64379 extern void trace_remove_event_call(struct ftrace_event_call *call);
64380
64381 -#define is_signed_type(type) (((type)(-1)) < 0)
64382 +#define is_signed_type(type) (((type)(-1)) < (type)1)
64383
64384 int trace_set_clr_event(const char *system, const char *event, int set);
64385
64386 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
64387 index 79b8bba..86b539e 100644
64388 --- a/include/linux/genhd.h
64389 +++ b/include/linux/genhd.h
64390 @@ -194,7 +194,7 @@ struct gendisk {
64391 struct kobject *slave_dir;
64392
64393 struct timer_rand_state *random;
64394 - atomic_t sync_io; /* RAID */
64395 + atomic_unchecked_t sync_io; /* RAID */
64396 struct disk_events *ev;
64397 #ifdef CONFIG_BLK_DEV_INTEGRITY
64398 struct blk_integrity *integrity;
64399 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
64400 index 0f615eb..5c3832f 100644
64401 --- a/include/linux/gfp.h
64402 +++ b/include/linux/gfp.h
64403 @@ -35,6 +35,13 @@ struct vm_area_struct;
64404 #define ___GFP_NO_KSWAPD 0x400000u
64405 #define ___GFP_OTHER_NODE 0x800000u
64406 #define ___GFP_WRITE 0x1000000u
64407 +
64408 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64409 +#define ___GFP_USERCOPY 0x2000000u
64410 +#else
64411 +#define ___GFP_USERCOPY 0
64412 +#endif
64413 +
64414 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
64415
64416 /*
64417 @@ -92,6 +99,7 @@ struct vm_area_struct;
64418 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
64419 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
64420 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
64421 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
64422
64423 /*
64424 * This may seem redundant, but it's a way of annotating false positives vs.
64425 @@ -99,7 +107,7 @@ struct vm_area_struct;
64426 */
64427 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
64428
64429 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
64430 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
64431 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
64432
64433 /* This equals 0, but use constants in case they ever change */
64434 @@ -153,6 +161,8 @@ struct vm_area_struct;
64435 /* 4GB DMA on some platforms */
64436 #define GFP_DMA32 __GFP_DMA32
64437
64438 +#define GFP_USERCOPY __GFP_USERCOPY
64439 +
64440 /* Convert GFP flags to their corresponding migrate type */
64441 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
64442 {
64443 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
64444 new file mode 100644
64445 index 0000000..ebe6d72
64446 --- /dev/null
64447 +++ b/include/linux/gracl.h
64448 @@ -0,0 +1,319 @@
64449 +#ifndef GR_ACL_H
64450 +#define GR_ACL_H
64451 +
64452 +#include <linux/grdefs.h>
64453 +#include <linux/resource.h>
64454 +#include <linux/capability.h>
64455 +#include <linux/dcache.h>
64456 +#include <asm/resource.h>
64457 +
64458 +/* Major status information */
64459 +
64460 +#define GR_VERSION "grsecurity 2.9.1"
64461 +#define GRSECURITY_VERSION 0x2901
64462 +
64463 +enum {
64464 + GR_SHUTDOWN = 0,
64465 + GR_ENABLE = 1,
64466 + GR_SPROLE = 2,
64467 + GR_RELOAD = 3,
64468 + GR_SEGVMOD = 4,
64469 + GR_STATUS = 5,
64470 + GR_UNSPROLE = 6,
64471 + GR_PASSSET = 7,
64472 + GR_SPROLEPAM = 8,
64473 +};
64474 +
64475 +/* Password setup definitions
64476 + * kernel/grhash.c */
64477 +enum {
64478 + GR_PW_LEN = 128,
64479 + GR_SALT_LEN = 16,
64480 + GR_SHA_LEN = 32,
64481 +};
64482 +
64483 +enum {
64484 + GR_SPROLE_LEN = 64,
64485 +};
64486 +
64487 +enum {
64488 + GR_NO_GLOB = 0,
64489 + GR_REG_GLOB,
64490 + GR_CREATE_GLOB
64491 +};
64492 +
64493 +#define GR_NLIMITS 32
64494 +
64495 +/* Begin Data Structures */
64496 +
64497 +struct sprole_pw {
64498 + unsigned char *rolename;
64499 + unsigned char salt[GR_SALT_LEN];
64500 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
64501 +};
64502 +
64503 +struct name_entry {
64504 + __u32 key;
64505 + ino_t inode;
64506 + dev_t device;
64507 + char *name;
64508 + __u16 len;
64509 + __u8 deleted;
64510 + struct name_entry *prev;
64511 + struct name_entry *next;
64512 +};
64513 +
64514 +struct inodev_entry {
64515 + struct name_entry *nentry;
64516 + struct inodev_entry *prev;
64517 + struct inodev_entry *next;
64518 +};
64519 +
64520 +struct acl_role_db {
64521 + struct acl_role_label **r_hash;
64522 + __u32 r_size;
64523 +};
64524 +
64525 +struct inodev_db {
64526 + struct inodev_entry **i_hash;
64527 + __u32 i_size;
64528 +};
64529 +
64530 +struct name_db {
64531 + struct name_entry **n_hash;
64532 + __u32 n_size;
64533 +};
64534 +
64535 +struct crash_uid {
64536 + uid_t uid;
64537 + unsigned long expires;
64538 +};
64539 +
64540 +struct gr_hash_struct {
64541 + void **table;
64542 + void **nametable;
64543 + void *first;
64544 + __u32 table_size;
64545 + __u32 used_size;
64546 + int type;
64547 +};
64548 +
64549 +/* Userspace Grsecurity ACL data structures */
64550 +
64551 +struct acl_subject_label {
64552 + char *filename;
64553 + ino_t inode;
64554 + dev_t device;
64555 + __u32 mode;
64556 + kernel_cap_t cap_mask;
64557 + kernel_cap_t cap_lower;
64558 + kernel_cap_t cap_invert_audit;
64559 +
64560 + struct rlimit res[GR_NLIMITS];
64561 + __u32 resmask;
64562 +
64563 + __u8 user_trans_type;
64564 + __u8 group_trans_type;
64565 + uid_t *user_transitions;
64566 + gid_t *group_transitions;
64567 + __u16 user_trans_num;
64568 + __u16 group_trans_num;
64569 +
64570 + __u32 sock_families[2];
64571 + __u32 ip_proto[8];
64572 + __u32 ip_type;
64573 + struct acl_ip_label **ips;
64574 + __u32 ip_num;
64575 + __u32 inaddr_any_override;
64576 +
64577 + __u32 crashes;
64578 + unsigned long expires;
64579 +
64580 + struct acl_subject_label *parent_subject;
64581 + struct gr_hash_struct *hash;
64582 + struct acl_subject_label *prev;
64583 + struct acl_subject_label *next;
64584 +
64585 + struct acl_object_label **obj_hash;
64586 + __u32 obj_hash_size;
64587 + __u16 pax_flags;
64588 +};
64589 +
64590 +struct role_allowed_ip {
64591 + __u32 addr;
64592 + __u32 netmask;
64593 +
64594 + struct role_allowed_ip *prev;
64595 + struct role_allowed_ip *next;
64596 +};
64597 +
64598 +struct role_transition {
64599 + char *rolename;
64600 +
64601 + struct role_transition *prev;
64602 + struct role_transition *next;
64603 +};
64604 +
64605 +struct acl_role_label {
64606 + char *rolename;
64607 + uid_t uidgid;
64608 + __u16 roletype;
64609 +
64610 + __u16 auth_attempts;
64611 + unsigned long expires;
64612 +
64613 + struct acl_subject_label *root_label;
64614 + struct gr_hash_struct *hash;
64615 +
64616 + struct acl_role_label *prev;
64617 + struct acl_role_label *next;
64618 +
64619 + struct role_transition *transitions;
64620 + struct role_allowed_ip *allowed_ips;
64621 + uid_t *domain_children;
64622 + __u16 domain_child_num;
64623 +
64624 + umode_t umask;
64625 +
64626 + struct acl_subject_label **subj_hash;
64627 + __u32 subj_hash_size;
64628 +};
64629 +
64630 +struct user_acl_role_db {
64631 + struct acl_role_label **r_table;
64632 + __u32 num_pointers; /* Number of allocations to track */
64633 + __u32 num_roles; /* Number of roles */
64634 + __u32 num_domain_children; /* Number of domain children */
64635 + __u32 num_subjects; /* Number of subjects */
64636 + __u32 num_objects; /* Number of objects */
64637 +};
64638 +
64639 +struct acl_object_label {
64640 + char *filename;
64641 + ino_t inode;
64642 + dev_t device;
64643 + __u32 mode;
64644 +
64645 + struct acl_subject_label *nested;
64646 + struct acl_object_label *globbed;
64647 +
64648 + /* next two structures not used */
64649 +
64650 + struct acl_object_label *prev;
64651 + struct acl_object_label *next;
64652 +};
64653 +
64654 +struct acl_ip_label {
64655 + char *iface;
64656 + __u32 addr;
64657 + __u32 netmask;
64658 + __u16 low, high;
64659 + __u8 mode;
64660 + __u32 type;
64661 + __u32 proto[8];
64662 +
64663 + /* next two structures not used */
64664 +
64665 + struct acl_ip_label *prev;
64666 + struct acl_ip_label *next;
64667 +};
64668 +
64669 +struct gr_arg {
64670 + struct user_acl_role_db role_db;
64671 + unsigned char pw[GR_PW_LEN];
64672 + unsigned char salt[GR_SALT_LEN];
64673 + unsigned char sum[GR_SHA_LEN];
64674 + unsigned char sp_role[GR_SPROLE_LEN];
64675 + struct sprole_pw *sprole_pws;
64676 + dev_t segv_device;
64677 + ino_t segv_inode;
64678 + uid_t segv_uid;
64679 + __u16 num_sprole_pws;
64680 + __u16 mode;
64681 +};
64682 +
64683 +struct gr_arg_wrapper {
64684 + struct gr_arg *arg;
64685 + __u32 version;
64686 + __u32 size;
64687 +};
64688 +
64689 +struct subject_map {
64690 + struct acl_subject_label *user;
64691 + struct acl_subject_label *kernel;
64692 + struct subject_map *prev;
64693 + struct subject_map *next;
64694 +};
64695 +
64696 +struct acl_subj_map_db {
64697 + struct subject_map **s_hash;
64698 + __u32 s_size;
64699 +};
64700 +
64701 +/* End Data Structures Section */
64702 +
64703 +/* Hash functions generated by empirical testing by Brad Spengler
64704 + Makes good use of the low bits of the inode. Generally 0-1 times
64705 + in loop for successful match. 0-3 for unsuccessful match.
64706 + Shift/add algorithm with modulus of table size and an XOR*/
64707 +
64708 +static __inline__ unsigned int
64709 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
64710 +{
64711 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
64712 +}
64713 +
64714 + static __inline__ unsigned int
64715 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64716 +{
64717 + return ((const unsigned long)userp % sz);
64718 +}
64719 +
64720 +static __inline__ unsigned int
64721 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64722 +{
64723 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64724 +}
64725 +
64726 +static __inline__ unsigned int
64727 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64728 +{
64729 + return full_name_hash((const unsigned char *)name, len) % sz;
64730 +}
64731 +
64732 +#define FOR_EACH_ROLE_START(role) \
64733 + role = role_list; \
64734 + while (role) {
64735 +
64736 +#define FOR_EACH_ROLE_END(role) \
64737 + role = role->prev; \
64738 + }
64739 +
64740 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64741 + subj = NULL; \
64742 + iter = 0; \
64743 + while (iter < role->subj_hash_size) { \
64744 + if (subj == NULL) \
64745 + subj = role->subj_hash[iter]; \
64746 + if (subj == NULL) { \
64747 + iter++; \
64748 + continue; \
64749 + }
64750 +
64751 +#define FOR_EACH_SUBJECT_END(subj,iter) \
64752 + subj = subj->next; \
64753 + if (subj == NULL) \
64754 + iter++; \
64755 + }
64756 +
64757 +
64758 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64759 + subj = role->hash->first; \
64760 + while (subj != NULL) {
64761 +
64762 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64763 + subj = subj->next; \
64764 + }
64765 +
64766 +#endif
64767 +
64768 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64769 new file mode 100644
64770 index 0000000..323ecf2
64771 --- /dev/null
64772 +++ b/include/linux/gralloc.h
64773 @@ -0,0 +1,9 @@
64774 +#ifndef __GRALLOC_H
64775 +#define __GRALLOC_H
64776 +
64777 +void acl_free_all(void);
64778 +int acl_alloc_stack_init(unsigned long size);
64779 +void *acl_alloc(unsigned long len);
64780 +void *acl_alloc_num(unsigned long num, unsigned long len);
64781 +
64782 +#endif
64783 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64784 new file mode 100644
64785 index 0000000..be66033
64786 --- /dev/null
64787 +++ b/include/linux/grdefs.h
64788 @@ -0,0 +1,140 @@
64789 +#ifndef GRDEFS_H
64790 +#define GRDEFS_H
64791 +
64792 +/* Begin grsecurity status declarations */
64793 +
64794 +enum {
64795 + GR_READY = 0x01,
64796 + GR_STATUS_INIT = 0x00 // disabled state
64797 +};
64798 +
64799 +/* Begin ACL declarations */
64800 +
64801 +/* Role flags */
64802 +
64803 +enum {
64804 + GR_ROLE_USER = 0x0001,
64805 + GR_ROLE_GROUP = 0x0002,
64806 + GR_ROLE_DEFAULT = 0x0004,
64807 + GR_ROLE_SPECIAL = 0x0008,
64808 + GR_ROLE_AUTH = 0x0010,
64809 + GR_ROLE_NOPW = 0x0020,
64810 + GR_ROLE_GOD = 0x0040,
64811 + GR_ROLE_LEARN = 0x0080,
64812 + GR_ROLE_TPE = 0x0100,
64813 + GR_ROLE_DOMAIN = 0x0200,
64814 + GR_ROLE_PAM = 0x0400,
64815 + GR_ROLE_PERSIST = 0x0800
64816 +};
64817 +
64818 +/* ACL Subject and Object mode flags */
64819 +enum {
64820 + GR_DELETED = 0x80000000
64821 +};
64822 +
64823 +/* ACL Object-only mode flags */
64824 +enum {
64825 + GR_READ = 0x00000001,
64826 + GR_APPEND = 0x00000002,
64827 + GR_WRITE = 0x00000004,
64828 + GR_EXEC = 0x00000008,
64829 + GR_FIND = 0x00000010,
64830 + GR_INHERIT = 0x00000020,
64831 + GR_SETID = 0x00000040,
64832 + GR_CREATE = 0x00000080,
64833 + GR_DELETE = 0x00000100,
64834 + GR_LINK = 0x00000200,
64835 + GR_AUDIT_READ = 0x00000400,
64836 + GR_AUDIT_APPEND = 0x00000800,
64837 + GR_AUDIT_WRITE = 0x00001000,
64838 + GR_AUDIT_EXEC = 0x00002000,
64839 + GR_AUDIT_FIND = 0x00004000,
64840 + GR_AUDIT_INHERIT= 0x00008000,
64841 + GR_AUDIT_SETID = 0x00010000,
64842 + GR_AUDIT_CREATE = 0x00020000,
64843 + GR_AUDIT_DELETE = 0x00040000,
64844 + GR_AUDIT_LINK = 0x00080000,
64845 + GR_PTRACERD = 0x00100000,
64846 + GR_NOPTRACE = 0x00200000,
64847 + GR_SUPPRESS = 0x00400000,
64848 + GR_NOLEARN = 0x00800000,
64849 + GR_INIT_TRANSFER= 0x01000000
64850 +};
64851 +
64852 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64853 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64854 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64855 +
64856 +/* ACL subject-only mode flags */
64857 +enum {
64858 + GR_KILL = 0x00000001,
64859 + GR_VIEW = 0x00000002,
64860 + GR_PROTECTED = 0x00000004,
64861 + GR_LEARN = 0x00000008,
64862 + GR_OVERRIDE = 0x00000010,
64863 + /* just a placeholder, this mode is only used in userspace */
64864 + GR_DUMMY = 0x00000020,
64865 + GR_PROTSHM = 0x00000040,
64866 + GR_KILLPROC = 0x00000080,
64867 + GR_KILLIPPROC = 0x00000100,
64868 + /* just a placeholder, this mode is only used in userspace */
64869 + GR_NOTROJAN = 0x00000200,
64870 + GR_PROTPROCFD = 0x00000400,
64871 + GR_PROCACCT = 0x00000800,
64872 + GR_RELAXPTRACE = 0x00001000,
64873 + //GR_NESTED = 0x00002000,
64874 + GR_INHERITLEARN = 0x00004000,
64875 + GR_PROCFIND = 0x00008000,
64876 + GR_POVERRIDE = 0x00010000,
64877 + GR_KERNELAUTH = 0x00020000,
64878 + GR_ATSECURE = 0x00040000,
64879 + GR_SHMEXEC = 0x00080000
64880 +};
64881 +
64882 +enum {
64883 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64884 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64885 + GR_PAX_ENABLE_MPROTECT = 0x0004,
64886 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
64887 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64888 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64889 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64890 + GR_PAX_DISABLE_MPROTECT = 0x0400,
64891 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
64892 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64893 +};
64894 +
64895 +enum {
64896 + GR_ID_USER = 0x01,
64897 + GR_ID_GROUP = 0x02,
64898 +};
64899 +
64900 +enum {
64901 + GR_ID_ALLOW = 0x01,
64902 + GR_ID_DENY = 0x02,
64903 +};
64904 +
64905 +#define GR_CRASH_RES 31
64906 +#define GR_UIDTABLE_MAX 500
64907 +
64908 +/* begin resource learning section */
64909 +enum {
64910 + GR_RLIM_CPU_BUMP = 60,
64911 + GR_RLIM_FSIZE_BUMP = 50000,
64912 + GR_RLIM_DATA_BUMP = 10000,
64913 + GR_RLIM_STACK_BUMP = 1000,
64914 + GR_RLIM_CORE_BUMP = 10000,
64915 + GR_RLIM_RSS_BUMP = 500000,
64916 + GR_RLIM_NPROC_BUMP = 1,
64917 + GR_RLIM_NOFILE_BUMP = 5,
64918 + GR_RLIM_MEMLOCK_BUMP = 50000,
64919 + GR_RLIM_AS_BUMP = 500000,
64920 + GR_RLIM_LOCKS_BUMP = 2,
64921 + GR_RLIM_SIGPENDING_BUMP = 5,
64922 + GR_RLIM_MSGQUEUE_BUMP = 10000,
64923 + GR_RLIM_NICE_BUMP = 1,
64924 + GR_RLIM_RTPRIO_BUMP = 1,
64925 + GR_RLIM_RTTIME_BUMP = 1000000
64926 +};
64927 +
64928 +#endif
64929 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
64930 new file mode 100644
64931 index 0000000..baa6e96
64932 --- /dev/null
64933 +++ b/include/linux/grinternal.h
64934 @@ -0,0 +1,215 @@
64935 +#ifndef __GRINTERNAL_H
64936 +#define __GRINTERNAL_H
64937 +
64938 +#ifdef CONFIG_GRKERNSEC
64939 +
64940 +#include <linux/fs.h>
64941 +#include <linux/mnt_namespace.h>
64942 +#include <linux/nsproxy.h>
64943 +#include <linux/gracl.h>
64944 +#include <linux/grdefs.h>
64945 +#include <linux/grmsg.h>
64946 +
64947 +void gr_add_learn_entry(const char *fmt, ...)
64948 + __attribute__ ((format (printf, 1, 2)));
64949 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64950 + const struct vfsmount *mnt);
64951 +__u32 gr_check_create(const struct dentry *new_dentry,
64952 + const struct dentry *parent,
64953 + const struct vfsmount *mnt, const __u32 mode);
64954 +int gr_check_protected_task(const struct task_struct *task);
64955 +__u32 to_gr_audit(const __u32 reqmode);
64956 +int gr_set_acls(const int type);
64957 +int gr_apply_subject_to_task(struct task_struct *task);
64958 +int gr_acl_is_enabled(void);
64959 +char gr_roletype_to_char(void);
64960 +
64961 +void gr_handle_alertkill(struct task_struct *task);
64962 +char *gr_to_filename(const struct dentry *dentry,
64963 + const struct vfsmount *mnt);
64964 +char *gr_to_filename1(const struct dentry *dentry,
64965 + const struct vfsmount *mnt);
64966 +char *gr_to_filename2(const struct dentry *dentry,
64967 + const struct vfsmount *mnt);
64968 +char *gr_to_filename3(const struct dentry *dentry,
64969 + const struct vfsmount *mnt);
64970 +
64971 +extern int grsec_enable_ptrace_readexec;
64972 +extern int grsec_enable_harden_ptrace;
64973 +extern int grsec_enable_link;
64974 +extern int grsec_enable_fifo;
64975 +extern int grsec_enable_execve;
64976 +extern int grsec_enable_shm;
64977 +extern int grsec_enable_execlog;
64978 +extern int grsec_enable_signal;
64979 +extern int grsec_enable_audit_ptrace;
64980 +extern int grsec_enable_forkfail;
64981 +extern int grsec_enable_time;
64982 +extern int grsec_enable_rofs;
64983 +extern int grsec_enable_chroot_shmat;
64984 +extern int grsec_enable_chroot_mount;
64985 +extern int grsec_enable_chroot_double;
64986 +extern int grsec_enable_chroot_pivot;
64987 +extern int grsec_enable_chroot_chdir;
64988 +extern int grsec_enable_chroot_chmod;
64989 +extern int grsec_enable_chroot_mknod;
64990 +extern int grsec_enable_chroot_fchdir;
64991 +extern int grsec_enable_chroot_nice;
64992 +extern int grsec_enable_chroot_execlog;
64993 +extern int grsec_enable_chroot_caps;
64994 +extern int grsec_enable_chroot_sysctl;
64995 +extern int grsec_enable_chroot_unix;
64996 +extern int grsec_enable_symlinkown;
64997 +extern int grsec_symlinkown_gid;
64998 +extern int grsec_enable_tpe;
64999 +extern int grsec_tpe_gid;
65000 +extern int grsec_enable_tpe_all;
65001 +extern int grsec_enable_tpe_invert;
65002 +extern int grsec_enable_socket_all;
65003 +extern int grsec_socket_all_gid;
65004 +extern int grsec_enable_socket_client;
65005 +extern int grsec_socket_client_gid;
65006 +extern int grsec_enable_socket_server;
65007 +extern int grsec_socket_server_gid;
65008 +extern int grsec_audit_gid;
65009 +extern int grsec_enable_group;
65010 +extern int grsec_enable_audit_textrel;
65011 +extern int grsec_enable_log_rwxmaps;
65012 +extern int grsec_enable_mount;
65013 +extern int grsec_enable_chdir;
65014 +extern int grsec_resource_logging;
65015 +extern int grsec_enable_blackhole;
65016 +extern int grsec_lastack_retries;
65017 +extern int grsec_enable_brute;
65018 +extern int grsec_lock;
65019 +
65020 +extern spinlock_t grsec_alert_lock;
65021 +extern unsigned long grsec_alert_wtime;
65022 +extern unsigned long grsec_alert_fyet;
65023 +
65024 +extern spinlock_t grsec_audit_lock;
65025 +
65026 +extern rwlock_t grsec_exec_file_lock;
65027 +
65028 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
65029 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
65030 + (tsk)->exec_file->f_vfsmnt) : "/")
65031 +
65032 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
65033 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
65034 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65035 +
65036 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
65037 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
65038 + (tsk)->exec_file->f_vfsmnt) : "/")
65039 +
65040 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
65041 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
65042 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65043 +
65044 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
65045 +
65046 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
65047 +
65048 +#define GR_CHROOT_CAPS {{ \
65049 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
65050 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
65051 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
65052 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
65053 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
65054 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
65055 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
65056 +
65057 +#define security_learn(normal_msg,args...) \
65058 +({ \
65059 + read_lock(&grsec_exec_file_lock); \
65060 + gr_add_learn_entry(normal_msg "\n", ## args); \
65061 + read_unlock(&grsec_exec_file_lock); \
65062 +})
65063 +
65064 +enum {
65065 + GR_DO_AUDIT,
65066 + GR_DONT_AUDIT,
65067 + /* used for non-audit messages that we shouldn't kill the task on */
65068 + GR_DONT_AUDIT_GOOD
65069 +};
65070 +
65071 +enum {
65072 + GR_TTYSNIFF,
65073 + GR_RBAC,
65074 + GR_RBAC_STR,
65075 + GR_STR_RBAC,
65076 + GR_RBAC_MODE2,
65077 + GR_RBAC_MODE3,
65078 + GR_FILENAME,
65079 + GR_SYSCTL_HIDDEN,
65080 + GR_NOARGS,
65081 + GR_ONE_INT,
65082 + GR_ONE_INT_TWO_STR,
65083 + GR_ONE_STR,
65084 + GR_STR_INT,
65085 + GR_TWO_STR_INT,
65086 + GR_TWO_INT,
65087 + GR_TWO_U64,
65088 + GR_THREE_INT,
65089 + GR_FIVE_INT_TWO_STR,
65090 + GR_TWO_STR,
65091 + GR_THREE_STR,
65092 + GR_FOUR_STR,
65093 + GR_STR_FILENAME,
65094 + GR_FILENAME_STR,
65095 + GR_FILENAME_TWO_INT,
65096 + GR_FILENAME_TWO_INT_STR,
65097 + GR_TEXTREL,
65098 + GR_PTRACE,
65099 + GR_RESOURCE,
65100 + GR_CAP,
65101 + GR_SIG,
65102 + GR_SIG2,
65103 + GR_CRASH1,
65104 + GR_CRASH2,
65105 + GR_PSACCT,
65106 + GR_RWXMAP
65107 +};
65108 +
65109 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
65110 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
65111 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
65112 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
65113 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
65114 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
65115 +#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)
65116 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
65117 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
65118 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
65119 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
65120 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
65121 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
65122 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
65123 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
65124 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
65125 +#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)
65126 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
65127 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
65128 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
65129 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
65130 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
65131 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
65132 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
65133 +#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)
65134 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
65135 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
65136 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
65137 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
65138 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
65139 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
65140 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
65141 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
65142 +#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)
65143 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
65144 +
65145 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
65146 +
65147 +#endif
65148 +
65149 +#endif
65150 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
65151 new file mode 100644
65152 index 0000000..2bd4c8d
65153 --- /dev/null
65154 +++ b/include/linux/grmsg.h
65155 @@ -0,0 +1,111 @@
65156 +#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"
65157 +#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"
65158 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
65159 +#define GR_STOPMOD_MSG "denied modification of module state by "
65160 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
65161 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
65162 +#define GR_IOPERM_MSG "denied use of ioperm() by "
65163 +#define GR_IOPL_MSG "denied use of iopl() by "
65164 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
65165 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
65166 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
65167 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
65168 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
65169 +#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"
65170 +#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"
65171 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
65172 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
65173 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
65174 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
65175 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
65176 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
65177 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
65178 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
65179 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
65180 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
65181 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
65182 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
65183 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
65184 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
65185 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
65186 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
65187 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
65188 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
65189 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
65190 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
65191 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
65192 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
65193 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
65194 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
65195 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
65196 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
65197 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
65198 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
65199 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
65200 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
65201 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
65202 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
65203 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
65204 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
65205 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
65206 +#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"
65207 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
65208 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
65209 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
65210 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
65211 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
65212 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
65213 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
65214 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
65215 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
65216 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
65217 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
65218 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
65219 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
65220 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
65221 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
65222 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
65223 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
65224 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
65225 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
65226 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
65227 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
65228 +#define GR_NICE_CHROOT_MSG "denied priority change by "
65229 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
65230 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
65231 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
65232 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
65233 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
65234 +#define GR_TIME_MSG "time set by "
65235 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
65236 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
65237 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
65238 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
65239 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
65240 +#define GR_BIND_MSG "denied bind() by "
65241 +#define GR_CONNECT_MSG "denied connect() by "
65242 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
65243 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
65244 +#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"
65245 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
65246 +#define GR_CAP_ACL_MSG "use of %s denied for "
65247 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
65248 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
65249 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
65250 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
65251 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
65252 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
65253 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
65254 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
65255 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
65256 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
65257 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
65258 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
65259 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
65260 +#define GR_VM86_MSG "denied use of vm86 by "
65261 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
65262 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
65263 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
65264 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
65265 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
65266 +#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 "
65267 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
65268 new file mode 100644
65269 index 0000000..c5e5913
65270 --- /dev/null
65271 +++ b/include/linux/grsecurity.h
65272 @@ -0,0 +1,257 @@
65273 +#ifndef GR_SECURITY_H
65274 +#define GR_SECURITY_H
65275 +#include <linux/fs.h>
65276 +#include <linux/fs_struct.h>
65277 +#include <linux/binfmts.h>
65278 +#include <linux/gracl.h>
65279 +
65280 +/* notify of brain-dead configs */
65281 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65282 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
65283 +#endif
65284 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
65285 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
65286 +#endif
65287 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
65288 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
65289 +#endif
65290 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
65291 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
65292 +#endif
65293 +
65294 +#include <linux/compat.h>
65295 +
65296 +struct user_arg_ptr {
65297 +#ifdef CONFIG_COMPAT
65298 + bool is_compat;
65299 +#endif
65300 + union {
65301 + const char __user *const __user *native;
65302 +#ifdef CONFIG_COMPAT
65303 + const compat_uptr_t __user *compat;
65304 +#endif
65305 + } ptr;
65306 +};
65307 +
65308 +void gr_handle_brute_attach(unsigned long mm_flags);
65309 +void gr_handle_brute_check(void);
65310 +void gr_handle_kernel_exploit(void);
65311 +int gr_process_user_ban(void);
65312 +
65313 +char gr_roletype_to_char(void);
65314 +
65315 +int gr_acl_enable_at_secure(void);
65316 +
65317 +int gr_check_user_change(int real, int effective, int fs);
65318 +int gr_check_group_change(int real, int effective, int fs);
65319 +
65320 +void gr_del_task_from_ip_table(struct task_struct *p);
65321 +
65322 +int gr_pid_is_chrooted(struct task_struct *p);
65323 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
65324 +int gr_handle_chroot_nice(void);
65325 +int gr_handle_chroot_sysctl(const int op);
65326 +int gr_handle_chroot_setpriority(struct task_struct *p,
65327 + const int niceval);
65328 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
65329 +int gr_handle_chroot_chroot(const struct dentry *dentry,
65330 + const struct vfsmount *mnt);
65331 +void gr_handle_chroot_chdir(struct path *path);
65332 +int gr_handle_chroot_chmod(const struct dentry *dentry,
65333 + const struct vfsmount *mnt, const int mode);
65334 +int gr_handle_chroot_mknod(const struct dentry *dentry,
65335 + const struct vfsmount *mnt, const int mode);
65336 +int gr_handle_chroot_mount(const struct dentry *dentry,
65337 + const struct vfsmount *mnt,
65338 + const char *dev_name);
65339 +int gr_handle_chroot_pivot(void);
65340 +int gr_handle_chroot_unix(const pid_t pid);
65341 +
65342 +int gr_handle_rawio(const struct inode *inode);
65343 +
65344 +void gr_handle_ioperm(void);
65345 +void gr_handle_iopl(void);
65346 +
65347 +umode_t gr_acl_umask(void);
65348 +
65349 +int gr_tpe_allow(const struct file *file);
65350 +
65351 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
65352 +void gr_clear_chroot_entries(struct task_struct *task);
65353 +
65354 +void gr_log_forkfail(const int retval);
65355 +void gr_log_timechange(void);
65356 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
65357 +void gr_log_chdir(const struct dentry *dentry,
65358 + const struct vfsmount *mnt);
65359 +void gr_log_chroot_exec(const struct dentry *dentry,
65360 + const struct vfsmount *mnt);
65361 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
65362 +void gr_log_remount(const char *devname, const int retval);
65363 +void gr_log_unmount(const char *devname, const int retval);
65364 +void gr_log_mount(const char *from, const char *to, const int retval);
65365 +void gr_log_textrel(struct vm_area_struct *vma);
65366 +void gr_log_rwxmmap(struct file *file);
65367 +void gr_log_rwxmprotect(struct file *file);
65368 +
65369 +int gr_handle_follow_link(const struct inode *parent,
65370 + const struct inode *inode,
65371 + const struct dentry *dentry,
65372 + const struct vfsmount *mnt);
65373 +int gr_handle_fifo(const struct dentry *dentry,
65374 + const struct vfsmount *mnt,
65375 + const struct dentry *dir, const int flag,
65376 + const int acc_mode);
65377 +int gr_handle_hardlink(const struct dentry *dentry,
65378 + const struct vfsmount *mnt,
65379 + struct inode *inode,
65380 + const int mode, const struct filename *to);
65381 +
65382 +int gr_is_capable(const int cap);
65383 +int gr_is_capable_nolog(const int cap);
65384 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65385 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
65386 +
65387 +void gr_copy_label(struct task_struct *tsk);
65388 +void gr_handle_crash(struct task_struct *task, const int sig);
65389 +int gr_handle_signal(const struct task_struct *p, const int sig);
65390 +int gr_check_crash_uid(const uid_t uid);
65391 +int gr_check_protected_task(const struct task_struct *task);
65392 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
65393 +int gr_acl_handle_mmap(const struct file *file,
65394 + const unsigned long prot);
65395 +int gr_acl_handle_mprotect(const struct file *file,
65396 + const unsigned long prot);
65397 +int gr_check_hidden_task(const struct task_struct *tsk);
65398 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
65399 + const struct vfsmount *mnt);
65400 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
65401 + const struct vfsmount *mnt);
65402 +__u32 gr_acl_handle_access(const struct dentry *dentry,
65403 + const struct vfsmount *mnt, const int fmode);
65404 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
65405 + const struct vfsmount *mnt, umode_t *mode);
65406 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
65407 + const struct vfsmount *mnt);
65408 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
65409 + const struct vfsmount *mnt);
65410 +int gr_handle_ptrace(struct task_struct *task, const long request);
65411 +int gr_handle_proc_ptrace(struct task_struct *task);
65412 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
65413 + const struct vfsmount *mnt);
65414 +int gr_check_crash_exec(const struct file *filp);
65415 +int gr_acl_is_enabled(void);
65416 +void gr_set_kernel_label(struct task_struct *task);
65417 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
65418 + const gid_t gid);
65419 +int gr_set_proc_label(const struct dentry *dentry,
65420 + const struct vfsmount *mnt,
65421 + const int unsafe_flags);
65422 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
65423 + const struct vfsmount *mnt);
65424 +__u32 gr_acl_handle_open(const struct dentry *dentry,
65425 + const struct vfsmount *mnt, int acc_mode);
65426 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
65427 + const struct dentry *p_dentry,
65428 + const struct vfsmount *p_mnt,
65429 + int open_flags, int acc_mode, const int imode);
65430 +void gr_handle_create(const struct dentry *dentry,
65431 + const struct vfsmount *mnt);
65432 +void gr_handle_proc_create(const struct dentry *dentry,
65433 + const struct inode *inode);
65434 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
65435 + const struct dentry *parent_dentry,
65436 + const struct vfsmount *parent_mnt,
65437 + const int mode);
65438 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
65439 + const struct dentry *parent_dentry,
65440 + const struct vfsmount *parent_mnt);
65441 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
65442 + const struct vfsmount *mnt);
65443 +void gr_handle_delete(const ino_t ino, const dev_t dev);
65444 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
65445 + const struct vfsmount *mnt);
65446 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
65447 + const struct dentry *parent_dentry,
65448 + const struct vfsmount *parent_mnt,
65449 + const struct filename *from);
65450 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
65451 + const struct dentry *parent_dentry,
65452 + const struct vfsmount *parent_mnt,
65453 + const struct dentry *old_dentry,
65454 + const struct vfsmount *old_mnt, const struct filename *to);
65455 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
65456 +int gr_acl_handle_rename(struct dentry *new_dentry,
65457 + struct dentry *parent_dentry,
65458 + const struct vfsmount *parent_mnt,
65459 + struct dentry *old_dentry,
65460 + struct inode *old_parent_inode,
65461 + struct vfsmount *old_mnt, const struct filename *newname);
65462 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65463 + struct dentry *old_dentry,
65464 + struct dentry *new_dentry,
65465 + struct vfsmount *mnt, const __u8 replace);
65466 +__u32 gr_check_link(const struct dentry *new_dentry,
65467 + const struct dentry *parent_dentry,
65468 + const struct vfsmount *parent_mnt,
65469 + const struct dentry *old_dentry,
65470 + const struct vfsmount *old_mnt);
65471 +int gr_acl_handle_filldir(const struct file *file, const char *name,
65472 + const unsigned int namelen, const ino_t ino);
65473 +
65474 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
65475 + const struct vfsmount *mnt);
65476 +void gr_acl_handle_exit(void);
65477 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
65478 +int gr_acl_handle_procpidmem(const struct task_struct *task);
65479 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
65480 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
65481 +void gr_audit_ptrace(struct task_struct *task);
65482 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
65483 +void gr_put_exec_file(struct task_struct *task);
65484 +
65485 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
65486 +
65487 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
65488 +extern void gr_learn_resource(const struct task_struct *task, const int res,
65489 + const unsigned long wanted, const int gt);
65490 +#else
65491 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
65492 + const unsigned long wanted, const int gt)
65493 +{
65494 +}
65495 +#endif
65496 +
65497 +#ifdef CONFIG_GRKERNSEC_RESLOG
65498 +extern void gr_log_resource(const struct task_struct *task, const int res,
65499 + const unsigned long wanted, const int gt);
65500 +#else
65501 +static inline void gr_log_resource(const struct task_struct *task, const int res,
65502 + const unsigned long wanted, const int gt)
65503 +{
65504 +}
65505 +#endif
65506 +
65507 +#ifdef CONFIG_GRKERNSEC
65508 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
65509 +void gr_handle_vm86(void);
65510 +void gr_handle_mem_readwrite(u64 from, u64 to);
65511 +
65512 +void gr_log_badprocpid(const char *entry);
65513 +
65514 +extern int grsec_enable_dmesg;
65515 +extern int grsec_disable_privio;
65516 +
65517 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65518 +extern int grsec_proc_gid;
65519 +#endif
65520 +
65521 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65522 +extern int grsec_enable_chroot_findtask;
65523 +#endif
65524 +#ifdef CONFIG_GRKERNSEC_SETXID
65525 +extern int grsec_enable_setxid;
65526 +#endif
65527 +#endif
65528 +
65529 +#endif
65530 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
65531 new file mode 100644
65532 index 0000000..e7ffaaf
65533 --- /dev/null
65534 +++ b/include/linux/grsock.h
65535 @@ -0,0 +1,19 @@
65536 +#ifndef __GRSOCK_H
65537 +#define __GRSOCK_H
65538 +
65539 +extern void gr_attach_curr_ip(const struct sock *sk);
65540 +extern int gr_handle_sock_all(const int family, const int type,
65541 + const int protocol);
65542 +extern int gr_handle_sock_server(const struct sockaddr *sck);
65543 +extern int gr_handle_sock_server_other(const struct sock *sck);
65544 +extern int gr_handle_sock_client(const struct sockaddr *sck);
65545 +extern int gr_search_connect(struct socket * sock,
65546 + struct sockaddr_in * addr);
65547 +extern int gr_search_bind(struct socket * sock,
65548 + struct sockaddr_in * addr);
65549 +extern int gr_search_listen(struct socket * sock);
65550 +extern int gr_search_accept(struct socket * sock);
65551 +extern int gr_search_socket(const int domain, const int type,
65552 + const int protocol);
65553 +
65554 +#endif
65555 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
65556 index ef788b5..ac41b7b 100644
65557 --- a/include/linux/highmem.h
65558 +++ b/include/linux/highmem.h
65559 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
65560 kunmap_atomic(kaddr);
65561 }
65562
65563 +static inline void sanitize_highpage(struct page *page)
65564 +{
65565 + void *kaddr;
65566 + unsigned long flags;
65567 +
65568 + local_irq_save(flags);
65569 + kaddr = kmap_atomic(page);
65570 + clear_page(kaddr);
65571 + kunmap_atomic(kaddr);
65572 + local_irq_restore(flags);
65573 +}
65574 +
65575 static inline void zero_user_segments(struct page *page,
65576 unsigned start1, unsigned end1,
65577 unsigned start2, unsigned end2)
65578 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
65579 index d0c4db7..61b3577 100644
65580 --- a/include/linux/i2c.h
65581 +++ b/include/linux/i2c.h
65582 @@ -369,6 +369,7 @@ struct i2c_algorithm {
65583 /* To determine what the adapter supports */
65584 u32 (*functionality) (struct i2c_adapter *);
65585 };
65586 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
65587
65588 /*
65589 * i2c_adapter is the structure used to identify a physical i2c bus along
65590 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
65591 index d23c3c2..eb63c81 100644
65592 --- a/include/linux/i2o.h
65593 +++ b/include/linux/i2o.h
65594 @@ -565,7 +565,7 @@ struct i2o_controller {
65595 struct i2o_device *exec; /* Executive */
65596 #if BITS_PER_LONG == 64
65597 spinlock_t context_list_lock; /* lock for context_list */
65598 - atomic_t context_list_counter; /* needed for unique contexts */
65599 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
65600 struct list_head context_list; /* list of context id's
65601 and pointers */
65602 #endif
65603 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
65604 index aff7ad8..3942bbd 100644
65605 --- a/include/linux/if_pppox.h
65606 +++ b/include/linux/if_pppox.h
65607 @@ -76,7 +76,7 @@ struct pppox_proto {
65608 int (*ioctl)(struct socket *sock, unsigned int cmd,
65609 unsigned long arg);
65610 struct module *owner;
65611 -};
65612 +} __do_const;
65613
65614 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
65615 extern void unregister_pppox_proto(int proto_num);
65616 diff --git a/include/linux/init.h b/include/linux/init.h
65617 index 10ed4f4..8e8490d 100644
65618 --- a/include/linux/init.h
65619 +++ b/include/linux/init.h
65620 @@ -39,9 +39,36 @@
65621 * Also note, that this data cannot be "const".
65622 */
65623
65624 +#ifdef MODULE
65625 +#define add_init_latent_entropy
65626 +#define add_devinit_latent_entropy
65627 +#define add_cpuinit_latent_entropy
65628 +#define add_meminit_latent_entropy
65629 +#else
65630 +#define add_init_latent_entropy __latent_entropy
65631 +
65632 +#ifdef CONFIG_HOTPLUG
65633 +#define add_devinit_latent_entropy
65634 +#else
65635 +#define add_devinit_latent_entropy __latent_entropy
65636 +#endif
65637 +
65638 +#ifdef CONFIG_HOTPLUG_CPU
65639 +#define add_cpuinit_latent_entropy
65640 +#else
65641 +#define add_cpuinit_latent_entropy __latent_entropy
65642 +#endif
65643 +
65644 +#ifdef CONFIG_MEMORY_HOTPLUG
65645 +#define add_meminit_latent_entropy
65646 +#else
65647 +#define add_meminit_latent_entropy __latent_entropy
65648 +#endif
65649 +#endif
65650 +
65651 /* These are for everybody (although not all archs will actually
65652 discard it in modules) */
65653 -#define __init __section(.init.text) __cold notrace
65654 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
65655 #define __initdata __section(.init.data)
65656 #define __initconst __constsection(.init.rodata)
65657 #define __exitdata __section(.exit.data)
65658 @@ -94,7 +121,7 @@
65659 #define __exit __section(.exit.text) __exitused __cold notrace
65660
65661 /* Used for HOTPLUG_CPU */
65662 -#define __cpuinit __section(.cpuinit.text) __cold notrace
65663 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
65664 #define __cpuinitdata __section(.cpuinit.data)
65665 #define __cpuinitconst __constsection(.cpuinit.rodata)
65666 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
65667 @@ -102,7 +129,7 @@
65668 #define __cpuexitconst __constsection(.cpuexit.rodata)
65669
65670 /* Used for MEMORY_HOTPLUG */
65671 -#define __meminit __section(.meminit.text) __cold notrace
65672 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
65673 #define __meminitdata __section(.meminit.data)
65674 #define __meminitconst __constsection(.meminit.rodata)
65675 #define __memexit __section(.memexit.text) __exitused __cold notrace
65676 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
65677 index 6d087c5..401cab8 100644
65678 --- a/include/linux/init_task.h
65679 +++ b/include/linux/init_task.h
65680 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
65681
65682 #define INIT_TASK_COMM "swapper"
65683
65684 +#ifdef CONFIG_X86
65685 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
65686 +#else
65687 +#define INIT_TASK_THREAD_INFO
65688 +#endif
65689 +
65690 /*
65691 * INIT_TASK is used to set up the first task table, touch at
65692 * your own risk!. Base=0, limit=0x1fffff (=2MB)
65693 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
65694 RCU_POINTER_INITIALIZER(cred, &init_cred), \
65695 .comm = INIT_TASK_COMM, \
65696 .thread = INIT_THREAD, \
65697 + INIT_TASK_THREAD_INFO \
65698 .fs = &init_fs, \
65699 .files = &init_files, \
65700 .signal = &init_signals, \
65701 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
65702 index 5fa5afe..ac55b25 100644
65703 --- a/include/linux/interrupt.h
65704 +++ b/include/linux/interrupt.h
65705 @@ -430,7 +430,7 @@ enum
65706 /* map softirq index to softirq name. update 'softirq_to_name' in
65707 * kernel/softirq.c when adding a new softirq.
65708 */
65709 -extern char *softirq_to_name[NR_SOFTIRQS];
65710 +extern const char * const softirq_to_name[NR_SOFTIRQS];
65711
65712 /* softirq mask and active fields moved to irq_cpustat_t in
65713 * asm/hardirq.h to get better cache usage. KAO
65714 @@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65715
65716 struct softirq_action
65717 {
65718 - void (*action)(struct softirq_action *);
65719 -};
65720 + void (*action)(void);
65721 +} __no_const;
65722
65723 asmlinkage void do_softirq(void);
65724 asmlinkage void __do_softirq(void);
65725 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65726 +extern void open_softirq(int nr, void (*action)(void));
65727 extern void softirq_init(void);
65728 extern void __raise_softirq_irqoff(unsigned int nr);
65729
65730 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65731 index 6883e19..06992b1 100644
65732 --- a/include/linux/kallsyms.h
65733 +++ b/include/linux/kallsyms.h
65734 @@ -15,7 +15,8 @@
65735
65736 struct module;
65737
65738 -#ifdef CONFIG_KALLSYMS
65739 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65740 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65741 /* Lookup the address for a symbol. Returns 0 if not found. */
65742 unsigned long kallsyms_lookup_name(const char *name);
65743
65744 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65745 /* Stupid that this does nothing, but I didn't create this mess. */
65746 #define __print_symbol(fmt, addr)
65747 #endif /*CONFIG_KALLSYMS*/
65748 +#else /* when included by kallsyms.c, vsnprintf.c, or
65749 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65750 +extern void __print_symbol(const char *fmt, unsigned long address);
65751 +extern int sprint_backtrace(char *buffer, unsigned long address);
65752 +extern int sprint_symbol(char *buffer, unsigned long address);
65753 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65754 +const char *kallsyms_lookup(unsigned long addr,
65755 + unsigned long *symbolsize,
65756 + unsigned long *offset,
65757 + char **modname, char *namebuf);
65758 +#endif
65759
65760 /* This macro allows us to keep printk typechecking */
65761 static __printf(1, 2)
65762 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65763 index 4dff0c6..1ca9b72 100644
65764 --- a/include/linux/kgdb.h
65765 +++ b/include/linux/kgdb.h
65766 @@ -53,7 +53,7 @@ extern int kgdb_connected;
65767 extern int kgdb_io_module_registered;
65768
65769 extern atomic_t kgdb_setting_breakpoint;
65770 -extern atomic_t kgdb_cpu_doing_single_step;
65771 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65772
65773 extern struct task_struct *kgdb_usethread;
65774 extern struct task_struct *kgdb_contthread;
65775 @@ -255,7 +255,7 @@ struct kgdb_arch {
65776 void (*correct_hw_break)(void);
65777
65778 void (*enable_nmi)(bool on);
65779 -};
65780 +} __do_const;
65781
65782 /**
65783 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65784 @@ -280,7 +280,7 @@ struct kgdb_io {
65785 void (*pre_exception) (void);
65786 void (*post_exception) (void);
65787 int is_console;
65788 -};
65789 +} __do_const;
65790
65791 extern struct kgdb_arch arch_kgdb_ops;
65792
65793 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65794 index 5398d58..5883a34 100644
65795 --- a/include/linux/kmod.h
65796 +++ b/include/linux/kmod.h
65797 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65798 * usually useless though. */
65799 extern __printf(2, 3)
65800 int __request_module(bool wait, const char *name, ...);
65801 +extern __printf(3, 4)
65802 +int ___request_module(bool wait, char *param_name, const char *name, ...);
65803 #define request_module(mod...) __request_module(true, mod)
65804 #define request_module_nowait(mod...) __request_module(false, mod)
65805 #define try_then_request_module(x, mod...) \
65806 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65807 index 939b112..90b7f44 100644
65808 --- a/include/linux/kobject.h
65809 +++ b/include/linux/kobject.h
65810 @@ -111,7 +111,7 @@ struct kobj_type {
65811 struct attribute **default_attrs;
65812 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65813 const void *(*namespace)(struct kobject *kobj);
65814 -};
65815 +} __do_const;
65816
65817 struct kobj_uevent_env {
65818 char *envp[UEVENT_NUM_ENVP];
65819 diff --git a/include/linux/kref.h b/include/linux/kref.h
65820 index 4972e6e..de4d19b 100644
65821 --- a/include/linux/kref.h
65822 +++ b/include/linux/kref.h
65823 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65824 static inline int kref_sub(struct kref *kref, unsigned int count,
65825 void (*release)(struct kref *kref))
65826 {
65827 - WARN_ON(release == NULL);
65828 + BUG_ON(release == NULL);
65829
65830 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65831 release(kref);
65832 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65833 index 2c497ab..afe32f5 100644
65834 --- a/include/linux/kvm_host.h
65835 +++ b/include/linux/kvm_host.h
65836 @@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65837 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65838 void vcpu_put(struct kvm_vcpu *vcpu);
65839
65840 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65841 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65842 struct module *module);
65843 void kvm_exit(void);
65844
65845 @@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65846 struct kvm_guest_debug *dbg);
65847 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65848
65849 -int kvm_arch_init(void *opaque);
65850 +int kvm_arch_init(const void *opaque);
65851 void kvm_arch_exit(void);
65852
65853 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65854 diff --git a/include/linux/libata.h b/include/linux/libata.h
65855 index 649e5f8..ead5194 100644
65856 --- a/include/linux/libata.h
65857 +++ b/include/linux/libata.h
65858 @@ -915,7 +915,7 @@ struct ata_port_operations {
65859 * fields must be pointers.
65860 */
65861 const struct ata_port_operations *inherits;
65862 -};
65863 +} __do_const;
65864
65865 struct ata_port_info {
65866 unsigned long flags;
65867 diff --git a/include/linux/list.h b/include/linux/list.h
65868 index cc6d2aa..71febca 100644
65869 --- a/include/linux/list.h
65870 +++ b/include/linux/list.h
65871 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65872 extern void list_del(struct list_head *entry);
65873 #endif
65874
65875 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65876 +extern void pax_list_del(struct list_head *entry);
65877 +
65878 /**
65879 * list_replace - replace old entry by new one
65880 * @old : the element to be replaced
65881 diff --git a/include/linux/mm.h b/include/linux/mm.h
65882 index 66e2f7c..ea88001 100644
65883 --- a/include/linux/mm.h
65884 +++ b/include/linux/mm.h
65885 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65886 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65887 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65888 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65889 +
65890 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65891 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65892 +#endif
65893 +
65894 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65895
65896 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65897 @@ -231,6 +236,7 @@ struct vm_operations_struct {
65898 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
65899 unsigned long size, pgoff_t pgoff);
65900 };
65901 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
65902
65903 struct mmu_gather;
65904 struct inode;
65905 @@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
65906 int set_page_dirty_lock(struct page *page);
65907 int clear_page_dirty_for_io(struct page *page);
65908
65909 -/* Is the vma a continuation of the stack vma above it? */
65910 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65911 -{
65912 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
65913 -}
65914 -
65915 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
65916 - unsigned long addr)
65917 -{
65918 - return (vma->vm_flags & VM_GROWSDOWN) &&
65919 - (vma->vm_start == addr) &&
65920 - !vma_growsdown(vma->vm_prev, addr);
65921 -}
65922 -
65923 -/* Is the vma a continuation of the stack vma below it? */
65924 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65925 -{
65926 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65927 -}
65928 -
65929 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
65930 - unsigned long addr)
65931 -{
65932 - return (vma->vm_flags & VM_GROWSUP) &&
65933 - (vma->vm_end == addr) &&
65934 - !vma_growsup(vma->vm_next, addr);
65935 -}
65936 -
65937 extern pid_t
65938 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65939
65940 @@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65941 }
65942 #endif
65943
65944 +#ifdef CONFIG_MMU
65945 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65946 +#else
65947 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65948 +{
65949 + return __pgprot(0);
65950 +}
65951 +#endif
65952 +
65953 int vma_wants_writenotify(struct vm_area_struct *vma);
65954
65955 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65956 @@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65957 {
65958 return 0;
65959 }
65960 +
65961 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65962 + unsigned long address)
65963 +{
65964 + return 0;
65965 +}
65966 #else
65967 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65968 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65969 #endif
65970
65971 #ifdef __PAGETABLE_PMD_FOLDED
65972 @@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65973 {
65974 return 0;
65975 }
65976 +
65977 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65978 + unsigned long address)
65979 +{
65980 + return 0;
65981 +}
65982 #else
65983 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65984 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65985 #endif
65986
65987 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
65988 @@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
65989 NULL: pud_offset(pgd, address);
65990 }
65991
65992 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
65993 +{
65994 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
65995 + NULL: pud_offset(pgd, address);
65996 +}
65997 +
65998 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65999 {
66000 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
66001 NULL: pmd_offset(pud, address);
66002 }
66003 +
66004 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
66005 +{
66006 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
66007 + NULL: pmd_offset(pud, address);
66008 +}
66009 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
66010
66011 #if USE_SPLIT_PTLOCKS
66012 @@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
66013 unsigned long, unsigned long,
66014 unsigned long, unsigned long);
66015 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
66016 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
66017
66018 /* These take the mm semaphore themselves */
66019 extern unsigned long vm_brk(unsigned long, unsigned long);
66020 @@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
66021 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
66022 struct vm_area_struct **pprev);
66023
66024 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
66025 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
66026 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
66027 +
66028 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
66029 NULL if none. Assume start_addr < end_addr. */
66030 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
66031 @@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
66032 return vma;
66033 }
66034
66035 -#ifdef CONFIG_MMU
66036 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
66037 -#else
66038 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
66039 -{
66040 - return __pgprot(0);
66041 -}
66042 -#endif
66043 -
66044 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
66045 unsigned long change_prot_numa(struct vm_area_struct *vma,
66046 unsigned long start, unsigned long end);
66047 @@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
66048 extern int sysctl_memory_failure_early_kill;
66049 extern int sysctl_memory_failure_recovery;
66050 extern void shake_page(struct page *p, int access);
66051 -extern atomic_long_t mce_bad_pages;
66052 +extern atomic_long_unchecked_t mce_bad_pages;
66053 extern int soft_offline_page(struct page *page, int flags);
66054
66055 extern void dump_page(struct page *page);
66056 @@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
66057 static inline bool page_is_guard(struct page *page) { return false; }
66058 #endif /* CONFIG_DEBUG_PAGEALLOC */
66059
66060 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66061 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
66062 +#else
66063 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
66064 +#endif
66065 +
66066 #endif /* __KERNEL__ */
66067 #endif /* _LINUX_MM_H */
66068 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
66069 index f8f5162..6276a36 100644
66070 --- a/include/linux/mm_types.h
66071 +++ b/include/linux/mm_types.h
66072 @@ -288,6 +288,8 @@ struct vm_area_struct {
66073 #ifdef CONFIG_NUMA
66074 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
66075 #endif
66076 +
66077 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
66078 };
66079
66080 struct core_thread {
66081 @@ -362,7 +364,7 @@ struct mm_struct {
66082 unsigned long def_flags;
66083 unsigned long nr_ptes; /* Page table pages */
66084 unsigned long start_code, end_code, start_data, end_data;
66085 - unsigned long start_brk, brk, start_stack;
66086 + unsigned long brk_gap, start_brk, brk, start_stack;
66087 unsigned long arg_start, arg_end, env_start, env_end;
66088
66089 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
66090 @@ -436,6 +438,24 @@ struct mm_struct {
66091 int first_nid;
66092 #endif
66093 struct uprobes_state uprobes_state;
66094 +
66095 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66096 + unsigned long pax_flags;
66097 +#endif
66098 +
66099 +#ifdef CONFIG_PAX_DLRESOLVE
66100 + unsigned long call_dl_resolve;
66101 +#endif
66102 +
66103 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
66104 + unsigned long call_syscall;
66105 +#endif
66106 +
66107 +#ifdef CONFIG_PAX_ASLR
66108 + unsigned long delta_mmap; /* randomized offset */
66109 + unsigned long delta_stack; /* randomized offset */
66110 +#endif
66111 +
66112 };
66113
66114 /* first nid will either be a valid NID or one of these values */
66115 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
66116 index c5d5278..f0b68c8 100644
66117 --- a/include/linux/mmiotrace.h
66118 +++ b/include/linux/mmiotrace.h
66119 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
66120 /* Called from ioremap.c */
66121 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
66122 void __iomem *addr);
66123 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
66124 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
66125
66126 /* For anyone to insert markers. Remember trailing newline. */
66127 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
66128 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
66129 {
66130 }
66131
66132 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
66133 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
66134 {
66135 }
66136
66137 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
66138 index 73b64a3..6562925 100644
66139 --- a/include/linux/mmzone.h
66140 +++ b/include/linux/mmzone.h
66141 @@ -412,7 +412,7 @@ struct zone {
66142 unsigned long flags; /* zone flags, see below */
66143
66144 /* Zone statistics */
66145 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66146 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66147
66148 /*
66149 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
66150 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
66151 index fed3def..7cc3f93 100644
66152 --- a/include/linux/mod_devicetable.h
66153 +++ b/include/linux/mod_devicetable.h
66154 @@ -12,7 +12,7 @@
66155 typedef unsigned long kernel_ulong_t;
66156 #endif
66157
66158 -#define PCI_ANY_ID (~0)
66159 +#define PCI_ANY_ID ((__u16)~0)
66160
66161 struct pci_device_id {
66162 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
66163 @@ -139,7 +139,7 @@ struct usb_device_id {
66164 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
66165 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
66166
66167 -#define HID_ANY_ID (~0)
66168 +#define HID_ANY_ID (~0U)
66169 #define HID_BUS_ANY 0xffff
66170 #define HID_GROUP_ANY 0x0000
66171
66172 diff --git a/include/linux/module.h b/include/linux/module.h
66173 index 1375ee3..d631af0 100644
66174 --- a/include/linux/module.h
66175 +++ b/include/linux/module.h
66176 @@ -17,9 +17,11 @@
66177 #include <linux/moduleparam.h>
66178 #include <linux/tracepoint.h>
66179 #include <linux/export.h>
66180 +#include <linux/fs.h>
66181
66182 #include <linux/percpu.h>
66183 #include <asm/module.h>
66184 +#include <asm/pgtable.h>
66185
66186 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
66187 #define MODULE_SIG_STRING "~Module signature appended~\n"
66188 @@ -281,19 +283,16 @@ struct module
66189 int (*init)(void);
66190
66191 /* If this is non-NULL, vfree after init() returns */
66192 - void *module_init;
66193 + void *module_init_rx, *module_init_rw;
66194
66195 /* Here is the actual code + data, vfree'd on unload. */
66196 - void *module_core;
66197 + void *module_core_rx, *module_core_rw;
66198
66199 /* Here are the sizes of the init and core sections */
66200 - unsigned int init_size, core_size;
66201 + unsigned int init_size_rw, core_size_rw;
66202
66203 /* The size of the executable code in each section. */
66204 - unsigned int init_text_size, core_text_size;
66205 -
66206 - /* Size of RO sections of the module (text+rodata) */
66207 - unsigned int init_ro_size, core_ro_size;
66208 + unsigned int init_size_rx, core_size_rx;
66209
66210 /* Arch-specific module values */
66211 struct mod_arch_specific arch;
66212 @@ -349,6 +348,10 @@ struct module
66213 #ifdef CONFIG_EVENT_TRACING
66214 struct ftrace_event_call **trace_events;
66215 unsigned int num_trace_events;
66216 + struct file_operations trace_id;
66217 + struct file_operations trace_enable;
66218 + struct file_operations trace_format;
66219 + struct file_operations trace_filter;
66220 #endif
66221 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
66222 unsigned int num_ftrace_callsites;
66223 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
66224 bool is_module_percpu_address(unsigned long addr);
66225 bool is_module_text_address(unsigned long addr);
66226
66227 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
66228 +{
66229 +
66230 +#ifdef CONFIG_PAX_KERNEXEC
66231 + if (ktla_ktva(addr) >= (unsigned long)start &&
66232 + ktla_ktva(addr) < (unsigned long)start + size)
66233 + return 1;
66234 +#endif
66235 +
66236 + return ((void *)addr >= start && (void *)addr < start + size);
66237 +}
66238 +
66239 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
66240 +{
66241 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
66242 +}
66243 +
66244 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
66245 +{
66246 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
66247 +}
66248 +
66249 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
66250 +{
66251 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
66252 +}
66253 +
66254 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
66255 +{
66256 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
66257 +}
66258 +
66259 static inline int within_module_core(unsigned long addr, struct module *mod)
66260 {
66261 - return (unsigned long)mod->module_core <= addr &&
66262 - addr < (unsigned long)mod->module_core + mod->core_size;
66263 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
66264 }
66265
66266 static inline int within_module_init(unsigned long addr, struct module *mod)
66267 {
66268 - return (unsigned long)mod->module_init <= addr &&
66269 - addr < (unsigned long)mod->module_init + mod->init_size;
66270 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
66271 }
66272
66273 /* Search for module by name: must hold module_mutex. */
66274 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
66275 index 560ca53..5ee8d73 100644
66276 --- a/include/linux/moduleloader.h
66277 +++ b/include/linux/moduleloader.h
66278 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
66279
66280 /* Allocator used for allocating struct module, core sections and init
66281 sections. Returns NULL on failure. */
66282 -void *module_alloc(unsigned long size);
66283 +void *module_alloc(unsigned long size) __size_overflow(1);
66284 +
66285 +#ifdef CONFIG_PAX_KERNEXEC
66286 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
66287 +#else
66288 +#define module_alloc_exec(x) module_alloc(x)
66289 +#endif
66290
66291 /* Free memory returned from module_alloc. */
66292 void module_free(struct module *mod, void *module_region);
66293
66294 +#ifdef CONFIG_PAX_KERNEXEC
66295 +void module_free_exec(struct module *mod, void *module_region);
66296 +#else
66297 +#define module_free_exec(x, y) module_free((x), (y))
66298 +#endif
66299 +
66300 /*
66301 * Apply the given relocation to the (simplified) ELF. Return -error
66302 * or 0.
66303 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
66304 unsigned int relsec,
66305 struct module *me)
66306 {
66307 +#ifdef CONFIG_MODULES
66308 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66309 +#endif
66310 return -ENOEXEC;
66311 }
66312 #endif
66313 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
66314 unsigned int relsec,
66315 struct module *me)
66316 {
66317 +#ifdef CONFIG_MODULES
66318 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66319 +#endif
66320 return -ENOEXEC;
66321 }
66322 #endif
66323 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
66324 index 137b419..fe663ec 100644
66325 --- a/include/linux/moduleparam.h
66326 +++ b/include/linux/moduleparam.h
66327 @@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
66328 * @len is usually just sizeof(string).
66329 */
66330 #define module_param_string(name, string, len, perm) \
66331 - static const struct kparam_string __param_string_##name \
66332 + static const struct kparam_string __param_string_##name __used \
66333 = { len, string }; \
66334 __module_param_call(MODULE_PARAM_PREFIX, name, \
66335 &param_ops_string, \
66336 @@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
66337 */
66338 #define module_param_array_named(name, array, type, nump, perm) \
66339 param_check_##type(name, &(array)[0]); \
66340 - static const struct kparam_array __param_arr_##name \
66341 + static const struct kparam_array __param_arr_##name __used \
66342 = { .max = ARRAY_SIZE(array), .num = nump, \
66343 .ops = &param_ops_##type, \
66344 .elemsize = sizeof(array[0]), .elem = array }; \
66345 diff --git a/include/linux/namei.h b/include/linux/namei.h
66346 index 5a5ff57..5ae5070 100644
66347 --- a/include/linux/namei.h
66348 +++ b/include/linux/namei.h
66349 @@ -19,7 +19,7 @@ struct nameidata {
66350 unsigned seq;
66351 int last_type;
66352 unsigned depth;
66353 - char *saved_names[MAX_NESTED_LINKS + 1];
66354 + const char *saved_names[MAX_NESTED_LINKS + 1];
66355 };
66356
66357 /*
66358 @@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
66359
66360 extern void nd_jump_link(struct nameidata *nd, struct path *path);
66361
66362 -static inline void nd_set_link(struct nameidata *nd, char *path)
66363 +static inline void nd_set_link(struct nameidata *nd, const char *path)
66364 {
66365 nd->saved_names[nd->depth] = path;
66366 }
66367
66368 -static inline char *nd_get_link(struct nameidata *nd)
66369 +static inline const char *nd_get_link(const struct nameidata *nd)
66370 {
66371 return nd->saved_names[nd->depth];
66372 }
66373 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
66374 index 9ef07d0..130a5d9 100644
66375 --- a/include/linux/netdevice.h
66376 +++ b/include/linux/netdevice.h
66377 @@ -1012,6 +1012,7 @@ struct net_device_ops {
66378 u32 pid, u32 seq,
66379 struct net_device *dev);
66380 };
66381 +typedef struct net_device_ops __no_const net_device_ops_no_const;
66382
66383 /*
66384 * The DEVICE structure.
66385 @@ -1078,7 +1079,7 @@ struct net_device {
66386 int iflink;
66387
66388 struct net_device_stats stats;
66389 - atomic_long_t rx_dropped; /* dropped packets by core network
66390 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
66391 * Do not use this in drivers.
66392 */
66393
66394 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
66395 index 7958e84..ed74d7a 100644
66396 --- a/include/linux/netfilter/ipset/ip_set.h
66397 +++ b/include/linux/netfilter/ipset/ip_set.h
66398 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
66399 /* Return true if "b" set is the same as "a"
66400 * according to the create set parameters */
66401 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
66402 -};
66403 +} __do_const;
66404
66405 /* The core set type structure */
66406 struct ip_set_type {
66407 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
66408 index 4966dde..7d8ce06 100644
66409 --- a/include/linux/netfilter/nfnetlink.h
66410 +++ b/include/linux/netfilter/nfnetlink.h
66411 @@ -16,7 +16,7 @@ struct nfnl_callback {
66412 const struct nlattr * const cda[]);
66413 const struct nla_policy *policy; /* netlink attribute policy */
66414 const u_int16_t attr_count; /* number of nlattr's */
66415 -};
66416 +} __do_const;
66417
66418 struct nfnetlink_subsystem {
66419 const char *name;
66420 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
66421 new file mode 100644
66422 index 0000000..33f4af8
66423 --- /dev/null
66424 +++ b/include/linux/netfilter/xt_gradm.h
66425 @@ -0,0 +1,9 @@
66426 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
66427 +#define _LINUX_NETFILTER_XT_GRADM_H 1
66428 +
66429 +struct xt_gradm_mtinfo {
66430 + __u16 flags;
66431 + __u16 invflags;
66432 +};
66433 +
66434 +#endif
66435 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
66436 index d65746e..62e72c2 100644
66437 --- a/include/linux/notifier.h
66438 +++ b/include/linux/notifier.h
66439 @@ -51,7 +51,8 @@ struct notifier_block {
66440 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
66441 struct notifier_block __rcu *next;
66442 int priority;
66443 -};
66444 +} __do_const;
66445 +typedef struct notifier_block __no_const notifier_block_no_const;
66446
66447 struct atomic_notifier_head {
66448 spinlock_t lock;
66449 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
66450 index a4c5624..79d6d88 100644
66451 --- a/include/linux/oprofile.h
66452 +++ b/include/linux/oprofile.h
66453 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
66454 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
66455 char const * name, ulong * val);
66456
66457 -/** Create a file for read-only access to an atomic_t. */
66458 +/** Create a file for read-only access to an atomic_unchecked_t. */
66459 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
66460 - char const * name, atomic_t * val);
66461 + char const * name, atomic_unchecked_t * val);
66462
66463 /** create a directory */
66464 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
66465 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
66466 index 6bfb2faa..e5bc5e5 100644
66467 --- a/include/linux/perf_event.h
66468 +++ b/include/linux/perf_event.h
66469 @@ -328,8 +328,8 @@ struct perf_event {
66470
66471 enum perf_event_active_state state;
66472 unsigned int attach_state;
66473 - local64_t count;
66474 - atomic64_t child_count;
66475 + local64_t count; /* PaX: fix it one day */
66476 + atomic64_unchecked_t child_count;
66477
66478 /*
66479 * These are the total time in nanoseconds that the event
66480 @@ -380,8 +380,8 @@ struct perf_event {
66481 * These accumulate total time (in nanoseconds) that children
66482 * events have been enabled and running, respectively.
66483 */
66484 - atomic64_t child_total_time_enabled;
66485 - atomic64_t child_total_time_running;
66486 + atomic64_unchecked_t child_total_time_enabled;
66487 + atomic64_unchecked_t child_total_time_running;
66488
66489 /*
66490 * Protect attach/detach and child_list:
66491 @@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
66492 */
66493 #define perf_cpu_notifier(fn) \
66494 do { \
66495 - static struct notifier_block fn##_nb __cpuinitdata = \
66496 + static struct notifier_block fn##_nb = \
66497 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
66498 unsigned long cpu = smp_processor_id(); \
66499 unsigned long flags; \
66500 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
66501 index ad1a427..6419649 100644
66502 --- a/include/linux/pipe_fs_i.h
66503 +++ b/include/linux/pipe_fs_i.h
66504 @@ -45,9 +45,9 @@ struct pipe_buffer {
66505 struct pipe_inode_info {
66506 wait_queue_head_t wait;
66507 unsigned int nrbufs, curbuf, buffers;
66508 - unsigned int readers;
66509 - unsigned int writers;
66510 - unsigned int waiting_writers;
66511 + atomic_t readers;
66512 + atomic_t writers;
66513 + atomic_t waiting_writers;
66514 unsigned int r_counter;
66515 unsigned int w_counter;
66516 struct page *tmp_page;
66517 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
66518 index 5f28cae..3d23723 100644
66519 --- a/include/linux/platform_data/usb-ehci-s5p.h
66520 +++ b/include/linux/platform_data/usb-ehci-s5p.h
66521 @@ -14,7 +14,7 @@
66522 struct s5p_ehci_platdata {
66523 int (*phy_init)(struct platform_device *pdev, int type);
66524 int (*phy_exit)(struct platform_device *pdev, int type);
66525 -};
66526 +} __no_const;
66527
66528 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
66529
66530 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
66531 index f271860..6b3bec5 100644
66532 --- a/include/linux/pm_runtime.h
66533 +++ b/include/linux/pm_runtime.h
66534 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
66535
66536 static inline void pm_runtime_mark_last_busy(struct device *dev)
66537 {
66538 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
66539 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
66540 }
66541
66542 #else /* !CONFIG_PM_RUNTIME */
66543 diff --git a/include/linux/poison.h b/include/linux/poison.h
66544 index 2110a81..13a11bb 100644
66545 --- a/include/linux/poison.h
66546 +++ b/include/linux/poison.h
66547 @@ -19,8 +19,8 @@
66548 * under normal circumstances, used to verify that nobody uses
66549 * non-initialized list entries.
66550 */
66551 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
66552 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
66553 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
66554 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
66555
66556 /********** include/linux/timer.h **********/
66557 /*
66558 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
66559 index c0f44c2..1572583 100644
66560 --- a/include/linux/power/smartreflex.h
66561 +++ b/include/linux/power/smartreflex.h
66562 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
66563 int (*notify)(struct omap_sr *sr, u32 status);
66564 u8 notify_flags;
66565 u8 class_type;
66566 -};
66567 +} __do_const;
66568
66569 /**
66570 * struct omap_sr_nvalue_table - Smartreflex n-target value info
66571 diff --git a/include/linux/printk.h b/include/linux/printk.h
66572 index 9afc01e..92c32e8 100644
66573 --- a/include/linux/printk.h
66574 +++ b/include/linux/printk.h
66575 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
66576 extern int printk_needs_cpu(int cpu);
66577 extern void printk_tick(void);
66578
66579 +extern int kptr_restrict;
66580 +
66581 #ifdef CONFIG_PRINTK
66582 asmlinkage __printf(5, 0)
66583 int vprintk_emit(int facility, int level,
66584 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
66585
66586 extern int printk_delay_msec;
66587 extern int dmesg_restrict;
66588 -extern int kptr_restrict;
66589
66590 void log_buf_kexec_setup(void);
66591 void __init setup_log_buf(int early);
66592 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
66593 index 32676b3..8f7a182 100644
66594 --- a/include/linux/proc_fs.h
66595 +++ b/include/linux/proc_fs.h
66596 @@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
66597 return proc_create_data(name, mode, parent, proc_fops, NULL);
66598 }
66599
66600 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
66601 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
66602 +{
66603 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66604 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
66605 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66606 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
66607 +#else
66608 + return proc_create_data(name, mode, parent, proc_fops, NULL);
66609 +#endif
66610 +}
66611 +
66612 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
66613 umode_t mode, struct proc_dir_entry *base,
66614 read_proc_t *read_proc, void * data)
66615 diff --git a/include/linux/random.h b/include/linux/random.h
66616 index d984608..d6f0042 100644
66617 --- a/include/linux/random.h
66618 +++ b/include/linux/random.h
66619 @@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
66620 u32 prandom_u32_state(struct rnd_state *);
66621 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
66622
66623 +static inline unsigned long pax_get_random_long(void)
66624 +{
66625 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
66626 +}
66627 +
66628 /*
66629 * Handle minimum values for seeds
66630 */
66631 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
66632 index 23b3630..e1bc12b 100644
66633 --- a/include/linux/reboot.h
66634 +++ b/include/linux/reboot.h
66635 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
66636 * Architecture-specific implementations of sys_reboot commands.
66637 */
66638
66639 -extern void machine_restart(char *cmd);
66640 -extern void machine_halt(void);
66641 -extern void machine_power_off(void);
66642 +extern void machine_restart(char *cmd) __noreturn;
66643 +extern void machine_halt(void) __noreturn;
66644 +extern void machine_power_off(void) __noreturn;
66645
66646 extern void machine_shutdown(void);
66647 struct pt_regs;
66648 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
66649 */
66650
66651 extern void kernel_restart_prepare(char *cmd);
66652 -extern void kernel_restart(char *cmd);
66653 -extern void kernel_halt(void);
66654 -extern void kernel_power_off(void);
66655 +extern void kernel_restart(char *cmd) __noreturn;
66656 +extern void kernel_halt(void) __noreturn;
66657 +extern void kernel_power_off(void) __noreturn;
66658
66659 extern int C_A_D; /* for sysctl */
66660 void ctrl_alt_del(void);
66661 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
66662 * Emergency restart, callable from an interrupt handler.
66663 */
66664
66665 -extern void emergency_restart(void);
66666 +extern void emergency_restart(void) __noreturn;
66667 #include <asm/emergency-restart.h>
66668
66669 #endif /* _LINUX_REBOOT_H */
66670 diff --git a/include/linux/regset.h b/include/linux/regset.h
66671 index 8e0c9fe..ac4d221 100644
66672 --- a/include/linux/regset.h
66673 +++ b/include/linux/regset.h
66674 @@ -161,7 +161,8 @@ struct user_regset {
66675 unsigned int align;
66676 unsigned int bias;
66677 unsigned int core_note_type;
66678 -};
66679 +} __do_const;
66680 +typedef struct user_regset __no_const user_regset_no_const;
66681
66682 /**
66683 * struct user_regset_view - available regsets
66684 diff --git a/include/linux/relay.h b/include/linux/relay.h
66685 index 91cacc3..b55ff74 100644
66686 --- a/include/linux/relay.h
66687 +++ b/include/linux/relay.h
66688 @@ -160,7 +160,7 @@ struct rchan_callbacks
66689 * The callback should return 0 if successful, negative if not.
66690 */
66691 int (*remove_buf_file)(struct dentry *dentry);
66692 -};
66693 +} __no_const;
66694
66695 /*
66696 * CONFIG_RELAY kernel API, kernel/relay.c
66697 diff --git a/include/linux/rio.h b/include/linux/rio.h
66698 index a3e7842..d973ca6 100644
66699 --- a/include/linux/rio.h
66700 +++ b/include/linux/rio.h
66701 @@ -339,7 +339,7 @@ struct rio_ops {
66702 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
66703 u64 rstart, u32 size, u32 flags);
66704 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
66705 -};
66706 +} __no_const;
66707
66708 #define RIO_RESOURCE_MEM 0x00000100
66709 #define RIO_RESOURCE_DOORBELL 0x00000200
66710 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
66711 index c20635c..2f5def4 100644
66712 --- a/include/linux/rmap.h
66713 +++ b/include/linux/rmap.h
66714 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
66715 void anon_vma_init(void); /* create anon_vma_cachep */
66716 int anon_vma_prepare(struct vm_area_struct *);
66717 void unlink_anon_vmas(struct vm_area_struct *);
66718 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66719 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66720 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66721 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66722
66723 static inline void anon_vma_merge(struct vm_area_struct *vma,
66724 struct vm_area_struct *next)
66725 diff --git a/include/linux/sched.h b/include/linux/sched.h
66726 index d211247..d64a165 100644
66727 --- a/include/linux/sched.h
66728 +++ b/include/linux/sched.h
66729 @@ -61,6 +61,7 @@ struct bio_list;
66730 struct fs_struct;
66731 struct perf_event_context;
66732 struct blk_plug;
66733 +struct linux_binprm;
66734
66735 /*
66736 * List of flags we want to share for kernel threads,
66737 @@ -354,10 +355,23 @@ struct user_namespace;
66738 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66739
66740 extern int sysctl_max_map_count;
66741 +extern unsigned long sysctl_heap_stack_gap;
66742
66743 #include <linux/aio.h>
66744
66745 #ifdef CONFIG_MMU
66746 +
66747 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66748 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66749 +#else
66750 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66751 +{
66752 + return 0;
66753 +}
66754 +#endif
66755 +
66756 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66757 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66758 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66759 extern unsigned long
66760 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66761 @@ -639,6 +653,17 @@ struct signal_struct {
66762 #ifdef CONFIG_TASKSTATS
66763 struct taskstats *stats;
66764 #endif
66765 +
66766 +#ifdef CONFIG_GRKERNSEC
66767 + u32 curr_ip;
66768 + u32 saved_ip;
66769 + u32 gr_saddr;
66770 + u32 gr_daddr;
66771 + u16 gr_sport;
66772 + u16 gr_dport;
66773 + u8 used_accept:1;
66774 +#endif
66775 +
66776 #ifdef CONFIG_AUDIT
66777 unsigned audit_tty;
66778 struct tty_audit_buf *tty_audit_buf;
66779 @@ -717,6 +742,11 @@ struct user_struct {
66780 struct key *session_keyring; /* UID's default session keyring */
66781 #endif
66782
66783 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66784 + unsigned int banned;
66785 + unsigned long ban_expires;
66786 +#endif
66787 +
66788 /* Hash table maintenance information */
66789 struct hlist_node uidhash_node;
66790 kuid_t uid;
66791 @@ -1360,8 +1390,8 @@ struct task_struct {
66792 struct list_head thread_group;
66793
66794 struct completion *vfork_done; /* for vfork() */
66795 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66796 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66797 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66798 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66799
66800 cputime_t utime, stime, utimescaled, stimescaled;
66801 cputime_t gtime;
66802 @@ -1377,11 +1407,6 @@ struct task_struct {
66803 struct task_cputime cputime_expires;
66804 struct list_head cpu_timers[3];
66805
66806 -/* process credentials */
66807 - const struct cred __rcu *real_cred; /* objective and real subjective task
66808 - * credentials (COW) */
66809 - const struct cred __rcu *cred; /* effective (overridable) subjective task
66810 - * credentials (COW) */
66811 char comm[TASK_COMM_LEN]; /* executable name excluding path
66812 - access with [gs]et_task_comm (which lock
66813 it with task_lock())
66814 @@ -1398,6 +1423,10 @@ struct task_struct {
66815 #endif
66816 /* CPU-specific state of this task */
66817 struct thread_struct thread;
66818 +/* thread_info moved to task_struct */
66819 +#ifdef CONFIG_X86
66820 + struct thread_info tinfo;
66821 +#endif
66822 /* filesystem information */
66823 struct fs_struct *fs;
66824 /* open file information */
66825 @@ -1471,6 +1500,10 @@ struct task_struct {
66826 gfp_t lockdep_reclaim_gfp;
66827 #endif
66828
66829 +/* process credentials */
66830 + const struct cred __rcu *real_cred; /* objective and real subjective task
66831 + * credentials (COW) */
66832 +
66833 /* journalling filesystem info */
66834 void *journal_info;
66835
66836 @@ -1509,6 +1542,10 @@ struct task_struct {
66837 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66838 struct list_head cg_list;
66839 #endif
66840 +
66841 + const struct cred __rcu *cred; /* effective (overridable) subjective task
66842 + * credentials (COW) */
66843 +
66844 #ifdef CONFIG_FUTEX
66845 struct robust_list_head __user *robust_list;
66846 #ifdef CONFIG_COMPAT
66847 @@ -1605,8 +1642,74 @@ struct task_struct {
66848 #ifdef CONFIG_UPROBES
66849 struct uprobe_task *utask;
66850 #endif
66851 +
66852 +#ifdef CONFIG_GRKERNSEC
66853 + /* grsecurity */
66854 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66855 + u64 exec_id;
66856 +#endif
66857 +#ifdef CONFIG_GRKERNSEC_SETXID
66858 + const struct cred *delayed_cred;
66859 +#endif
66860 + struct dentry *gr_chroot_dentry;
66861 + struct acl_subject_label *acl;
66862 + struct acl_role_label *role;
66863 + struct file *exec_file;
66864 + unsigned long brute_expires;
66865 + u16 acl_role_id;
66866 + /* is this the task that authenticated to the special role */
66867 + u8 acl_sp_role;
66868 + u8 is_writable;
66869 + u8 brute;
66870 + u8 gr_is_chrooted;
66871 +#endif
66872 +
66873 };
66874
66875 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66876 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66877 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66878 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66879 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66880 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66881 +
66882 +#ifdef CONFIG_PAX_SOFTMODE
66883 +extern int pax_softmode;
66884 +#endif
66885 +
66886 +extern int pax_check_flags(unsigned long *);
66887 +
66888 +/* if tsk != current then task_lock must be held on it */
66889 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66890 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
66891 +{
66892 + if (likely(tsk->mm))
66893 + return tsk->mm->pax_flags;
66894 + else
66895 + return 0UL;
66896 +}
66897 +
66898 +/* if tsk != current then task_lock must be held on it */
66899 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66900 +{
66901 + if (likely(tsk->mm)) {
66902 + tsk->mm->pax_flags = flags;
66903 + return 0;
66904 + }
66905 + return -EINVAL;
66906 +}
66907 +#endif
66908 +
66909 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66910 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
66911 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66912 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66913 +#endif
66914 +
66915 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66916 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66917 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
66918 +
66919 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66920 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66921
66922 @@ -2155,7 +2258,9 @@ void yield(void);
66923 extern struct exec_domain default_exec_domain;
66924
66925 union thread_union {
66926 +#ifndef CONFIG_X86
66927 struct thread_info thread_info;
66928 +#endif
66929 unsigned long stack[THREAD_SIZE/sizeof(long)];
66930 };
66931
66932 @@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
66933 */
66934
66935 extern struct task_struct *find_task_by_vpid(pid_t nr);
66936 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66937 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66938 struct pid_namespace *ns);
66939
66940 @@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66941 extern void exit_itimers(struct signal_struct *);
66942 extern void flush_itimer_signals(void);
66943
66944 -extern void do_group_exit(int);
66945 +extern __noreturn void do_group_exit(int);
66946
66947 extern int allow_signal(int);
66948 extern int disallow_signal(int);
66949 @@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66950
66951 #endif
66952
66953 -static inline int object_is_on_stack(void *obj)
66954 +static inline int object_starts_on_stack(void *obj)
66955 {
66956 - void *stack = task_stack_page(current);
66957 + const void *stack = task_stack_page(current);
66958
66959 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66960 }
66961 diff --git a/include/linux/security.h b/include/linux/security.h
66962 index eee7478..290f7ba 100644
66963 --- a/include/linux/security.h
66964 +++ b/include/linux/security.h
66965 @@ -26,6 +26,7 @@
66966 #include <linux/capability.h>
66967 #include <linux/slab.h>
66968 #include <linux/err.h>
66969 +#include <linux/grsecurity.h>
66970
66971 struct linux_binprm;
66972 struct cred;
66973 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66974 index 68a04a3..866e6a1 100644
66975 --- a/include/linux/seq_file.h
66976 +++ b/include/linux/seq_file.h
66977 @@ -26,6 +26,9 @@ struct seq_file {
66978 struct mutex lock;
66979 const struct seq_operations *op;
66980 int poll_event;
66981 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66982 + u64 exec_id;
66983 +#endif
66984 #ifdef CONFIG_USER_NS
66985 struct user_namespace *user_ns;
66986 #endif
66987 @@ -38,6 +41,7 @@ struct seq_operations {
66988 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66989 int (*show) (struct seq_file *m, void *v);
66990 };
66991 +typedef struct seq_operations __no_const seq_operations_no_const;
66992
66993 #define SEQ_SKIP 1
66994
66995 diff --git a/include/linux/shm.h b/include/linux/shm.h
66996 index 429c199..4d42e38 100644
66997 --- a/include/linux/shm.h
66998 +++ b/include/linux/shm.h
66999 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
67000
67001 /* The task created the shm object. NULL if the task is dead. */
67002 struct task_struct *shm_creator;
67003 +#ifdef CONFIG_GRKERNSEC
67004 + time_t shm_createtime;
67005 + pid_t shm_lapid;
67006 +#endif
67007 };
67008
67009 /* shm_mode upper byte flags */
67010 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
67011 index 320e976..fd52553 100644
67012 --- a/include/linux/skbuff.h
67013 +++ b/include/linux/skbuff.h
67014 @@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
67015 extern struct sk_buff *__alloc_skb(unsigned int size,
67016 gfp_t priority, int flags, int node);
67017 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
67018 -static inline struct sk_buff *alloc_skb(unsigned int size,
67019 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
67020 gfp_t priority)
67021 {
67022 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
67023 @@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
67024 */
67025 static inline int skb_queue_empty(const struct sk_buff_head *list)
67026 {
67027 - return list->next == (struct sk_buff *)list;
67028 + return list->next == (const struct sk_buff *)list;
67029 }
67030
67031 /**
67032 @@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
67033 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67034 const struct sk_buff *skb)
67035 {
67036 - return skb->next == (struct sk_buff *)list;
67037 + return skb->next == (const struct sk_buff *)list;
67038 }
67039
67040 /**
67041 @@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67042 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
67043 const struct sk_buff *skb)
67044 {
67045 - return skb->prev == (struct sk_buff *)list;
67046 + return skb->prev == (const struct sk_buff *)list;
67047 }
67048
67049 /**
67050 @@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
67051 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
67052 */
67053 #ifndef NET_SKB_PAD
67054 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
67055 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
67056 #endif
67057
67058 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
67059 @@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
67060 int noblock, int *err);
67061 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
67062 struct poll_table_struct *wait);
67063 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
67064 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
67065 int offset, struct iovec *to,
67066 int size);
67067 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
67068 diff --git a/include/linux/slab.h b/include/linux/slab.h
67069 index 5d168d7..720bff3 100644
67070 --- a/include/linux/slab.h
67071 +++ b/include/linux/slab.h
67072 @@ -12,13 +12,20 @@
67073 #include <linux/gfp.h>
67074 #include <linux/types.h>
67075 #include <linux/workqueue.h>
67076 -
67077 +#include <linux/err.h>
67078
67079 /*
67080 * Flags to pass to kmem_cache_create().
67081 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
67082 */
67083 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
67084 +
67085 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67086 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
67087 +#else
67088 +#define SLAB_USERCOPY 0x00000000UL
67089 +#endif
67090 +
67091 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
67092 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
67093 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
67094 @@ -89,10 +96,13 @@
67095 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
67096 * Both make kfree a no-op.
67097 */
67098 -#define ZERO_SIZE_PTR ((void *)16)
67099 +#define ZERO_SIZE_PTR \
67100 +({ \
67101 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
67102 + (void *)(-MAX_ERRNO-1L); \
67103 +})
67104
67105 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
67106 - (unsigned long)ZERO_SIZE_PTR)
67107 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
67108
67109 /*
67110 * Common fields provided in kmem_cache by all slab allocators
67111 @@ -112,7 +122,7 @@ struct kmem_cache {
67112 unsigned int align; /* Alignment as calculated */
67113 unsigned long flags; /* Active flags on the slab */
67114 const char *name; /* Slab name for sysfs */
67115 - int refcount; /* Use counter */
67116 + atomic_t refcount; /* Use counter */
67117 void (*ctor)(void *); /* Called on object slot creation */
67118 struct list_head list; /* List of all slab caches on the system */
67119 };
67120 @@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
67121 void kfree(const void *);
67122 void kzfree(const void *);
67123 size_t ksize(const void *);
67124 +const char *check_heap_object(const void *ptr, unsigned long n);
67125 +bool is_usercopy_object(const void *ptr);
67126
67127 /*
67128 * Allocator specific definitions. These are mainly used to establish optimized
67129 @@ -311,6 +323,7 @@ size_t ksize(const void *);
67130 * for general use, and so are not documented here. For a full list of
67131 * potential flags, always refer to linux/gfp.h.
67132 */
67133 +
67134 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
67135 {
67136 if (size != 0 && n > SIZE_MAX / size)
67137 @@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
67138 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67139 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67140 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67141 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67142 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
67143 #define kmalloc_track_caller(size, flags) \
67144 __kmalloc_track_caller(size, flags, _RET_IP_)
67145 #else
67146 @@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67147 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67148 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67149 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67150 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
67151 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
67152 #define kmalloc_node_track_caller(size, flags, node) \
67153 __kmalloc_node_track_caller(size, flags, node, \
67154 _RET_IP_)
67155 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
67156 index 8bb6e0e..8eb0dbe 100644
67157 --- a/include/linux/slab_def.h
67158 +++ b/include/linux/slab_def.h
67159 @@ -52,7 +52,7 @@ struct kmem_cache {
67160 /* 4) cache creation/removal */
67161 const char *name;
67162 struct list_head list;
67163 - int refcount;
67164 + atomic_t refcount;
67165 int object_size;
67166 int align;
67167
67168 @@ -68,10 +68,10 @@ struct kmem_cache {
67169 unsigned long node_allocs;
67170 unsigned long node_frees;
67171 unsigned long node_overflow;
67172 - atomic_t allochit;
67173 - atomic_t allocmiss;
67174 - atomic_t freehit;
67175 - atomic_t freemiss;
67176 + atomic_unchecked_t allochit;
67177 + atomic_unchecked_t allocmiss;
67178 + atomic_unchecked_t freehit;
67179 + atomic_unchecked_t freemiss;
67180
67181 /*
67182 * If debugging is enabled, then the allocator can add additional
67183 @@ -111,11 +111,16 @@ struct cache_sizes {
67184 #ifdef CONFIG_ZONE_DMA
67185 struct kmem_cache *cs_dmacachep;
67186 #endif
67187 +
67188 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67189 + struct kmem_cache *cs_usercopycachep;
67190 +#endif
67191 +
67192 };
67193 extern struct cache_sizes malloc_sizes[];
67194
67195 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67196 -void *__kmalloc(size_t size, gfp_t flags);
67197 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
67198
67199 #ifdef CONFIG_TRACING
67200 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
67201 @@ -152,6 +157,13 @@ found:
67202 cachep = malloc_sizes[i].cs_dmacachep;
67203 else
67204 #endif
67205 +
67206 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67207 + if (flags & GFP_USERCOPY)
67208 + cachep = malloc_sizes[i].cs_usercopycachep;
67209 + else
67210 +#endif
67211 +
67212 cachep = malloc_sizes[i].cs_cachep;
67213
67214 ret = kmem_cache_alloc_trace(cachep, flags, size);
67215 @@ -162,7 +174,7 @@ found:
67216 }
67217
67218 #ifdef CONFIG_NUMA
67219 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
67220 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67221 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67222
67223 #ifdef CONFIG_TRACING
67224 @@ -205,6 +217,13 @@ found:
67225 cachep = malloc_sizes[i].cs_dmacachep;
67226 else
67227 #endif
67228 +
67229 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67230 + if (flags & GFP_USERCOPY)
67231 + cachep = malloc_sizes[i].cs_usercopycachep;
67232 + else
67233 +#endif
67234 +
67235 cachep = malloc_sizes[i].cs_cachep;
67236
67237 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
67238 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
67239 index f28e14a..7831211 100644
67240 --- a/include/linux/slob_def.h
67241 +++ b/include/linux/slob_def.h
67242 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
67243 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
67244 }
67245
67246 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
67247 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67248
67249 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
67250 {
67251 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67252 return __kmalloc_node(size, flags, NUMA_NO_NODE);
67253 }
67254
67255 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
67256 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
67257 {
67258 return kmalloc(size, flags);
67259 }
67260 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
67261 index 9db4825..ed42fb5 100644
67262 --- a/include/linux/slub_def.h
67263 +++ b/include/linux/slub_def.h
67264 @@ -91,7 +91,7 @@ struct kmem_cache {
67265 struct kmem_cache_order_objects max;
67266 struct kmem_cache_order_objects min;
67267 gfp_t allocflags; /* gfp flags to use on each alloc */
67268 - int refcount; /* Refcount for slab cache destroy */
67269 + atomic_t refcount; /* Refcount for slab cache destroy */
67270 void (*ctor)(void *);
67271 int inuse; /* Offset to metadata */
67272 int align; /* Alignment */
67273 @@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
67274 * Sorry that the following has to be that ugly but some versions of GCC
67275 * have trouble with constant propagation and loops.
67276 */
67277 -static __always_inline int kmalloc_index(size_t size)
67278 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
67279 {
67280 if (!size)
67281 return 0;
67282 @@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
67283 }
67284
67285 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67286 -void *__kmalloc(size_t size, gfp_t flags);
67287 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
67288
67289 static __always_inline void *
67290 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
67291 @@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
67292 }
67293 #endif
67294
67295 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
67296 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
67297 {
67298 unsigned int order = get_order(size);
67299 return kmalloc_order_trace(size, flags, order);
67300 @@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67301 }
67302
67303 #ifdef CONFIG_NUMA
67304 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
67305 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67306 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67307
67308 #ifdef CONFIG_TRACING
67309 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
67310 index 680f9a3..f13aeb0 100644
67311 --- a/include/linux/sonet.h
67312 +++ b/include/linux/sonet.h
67313 @@ -7,7 +7,7 @@
67314 #include <uapi/linux/sonet.h>
67315
67316 struct k_sonet_stats {
67317 -#define __HANDLE_ITEM(i) atomic_t i
67318 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
67319 __SONET_ITEMS
67320 #undef __HANDLE_ITEM
67321 };
67322 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
67323 index 34206b8..f019e06 100644
67324 --- a/include/linux/sunrpc/clnt.h
67325 +++ b/include/linux/sunrpc/clnt.h
67326 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
67327 {
67328 switch (sap->sa_family) {
67329 case AF_INET:
67330 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
67331 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
67332 case AF_INET6:
67333 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
67334 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
67335 }
67336 return 0;
67337 }
67338 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
67339 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
67340 const struct sockaddr *src)
67341 {
67342 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
67343 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
67344 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
67345
67346 dsin->sin_family = ssin->sin_family;
67347 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
67348 if (sa->sa_family != AF_INET6)
67349 return 0;
67350
67351 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
67352 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
67353 }
67354
67355 #endif /* __KERNEL__ */
67356 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
67357 index 0b8e3e6..33e0a01 100644
67358 --- a/include/linux/sunrpc/svc_rdma.h
67359 +++ b/include/linux/sunrpc/svc_rdma.h
67360 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
67361 extern unsigned int svcrdma_max_requests;
67362 extern unsigned int svcrdma_max_req_size;
67363
67364 -extern atomic_t rdma_stat_recv;
67365 -extern atomic_t rdma_stat_read;
67366 -extern atomic_t rdma_stat_write;
67367 -extern atomic_t rdma_stat_sq_starve;
67368 -extern atomic_t rdma_stat_rq_starve;
67369 -extern atomic_t rdma_stat_rq_poll;
67370 -extern atomic_t rdma_stat_rq_prod;
67371 -extern atomic_t rdma_stat_sq_poll;
67372 -extern atomic_t rdma_stat_sq_prod;
67373 +extern atomic_unchecked_t rdma_stat_recv;
67374 +extern atomic_unchecked_t rdma_stat_read;
67375 +extern atomic_unchecked_t rdma_stat_write;
67376 +extern atomic_unchecked_t rdma_stat_sq_starve;
67377 +extern atomic_unchecked_t rdma_stat_rq_starve;
67378 +extern atomic_unchecked_t rdma_stat_rq_poll;
67379 +extern atomic_unchecked_t rdma_stat_rq_prod;
67380 +extern atomic_unchecked_t rdma_stat_sq_poll;
67381 +extern atomic_unchecked_t rdma_stat_sq_prod;
67382
67383 #define RPCRDMA_VERSION 1
67384
67385 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
67386 index 14a8ff2..21fe4c7 100644
67387 --- a/include/linux/sysctl.h
67388 +++ b/include/linux/sysctl.h
67389 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
67390
67391 extern int proc_dostring(struct ctl_table *, int,
67392 void __user *, size_t *, loff_t *);
67393 +extern int proc_dostring_modpriv(struct ctl_table *, int,
67394 + void __user *, size_t *, loff_t *);
67395 extern int proc_dointvec(struct ctl_table *, int,
67396 void __user *, size_t *, loff_t *);
67397 extern int proc_dointvec_minmax(struct ctl_table *, int,
67398 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
67399 index 7faf933..eb6f5e3 100644
67400 --- a/include/linux/sysrq.h
67401 +++ b/include/linux/sysrq.h
67402 @@ -36,7 +36,7 @@ struct sysrq_key_op {
67403 char *help_msg;
67404 char *action_msg;
67405 int enable_mask;
67406 -};
67407 +} __do_const;
67408
67409 #ifdef CONFIG_MAGIC_SYSRQ
67410
67411 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
67412 index e7e0473..39b7b52 100644
67413 --- a/include/linux/thread_info.h
67414 +++ b/include/linux/thread_info.h
67415 @@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
67416 #error "no set_restore_sigmask() provided and default one won't work"
67417 #endif
67418
67419 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
67420 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
67421 +{
67422 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
67423 + if (!__builtin_constant_p(n))
67424 +#endif
67425 + __check_object_size(ptr, n, to);
67426 +}
67427 +
67428 #endif /* __KERNEL__ */
67429
67430 #endif /* _LINUX_THREAD_INFO_H */
67431 diff --git a/include/linux/tty.h b/include/linux/tty.h
67432 index 8db1b56..c16a040 100644
67433 --- a/include/linux/tty.h
67434 +++ b/include/linux/tty.h
67435 @@ -194,7 +194,7 @@ struct tty_port {
67436 const struct tty_port_operations *ops; /* Port operations */
67437 spinlock_t lock; /* Lock protecting tty field */
67438 int blocked_open; /* Waiting to open */
67439 - int count; /* Usage count */
67440 + atomic_t count; /* Usage count */
67441 wait_queue_head_t open_wait; /* Open waiters */
67442 wait_queue_head_t close_wait; /* Close waiters */
67443 wait_queue_head_t delta_msr_wait; /* Modem status change */
67444 @@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
67445 struct tty_struct *tty, struct file *filp);
67446 static inline int tty_port_users(struct tty_port *port)
67447 {
67448 - return port->count + port->blocked_open;
67449 + return atomic_read(&port->count) + port->blocked_open;
67450 }
67451
67452 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
67453 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
67454 index dd976cf..e272742 100644
67455 --- a/include/linux/tty_driver.h
67456 +++ b/include/linux/tty_driver.h
67457 @@ -284,7 +284,7 @@ struct tty_operations {
67458 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
67459 #endif
67460 const struct file_operations *proc_fops;
67461 -};
67462 +} __do_const;
67463
67464 struct tty_driver {
67465 int magic; /* magic number for this structure */
67466 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
67467 index fb79dd8d..07d4773 100644
67468 --- a/include/linux/tty_ldisc.h
67469 +++ b/include/linux/tty_ldisc.h
67470 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
67471
67472 struct module *owner;
67473
67474 - int refcount;
67475 + atomic_t refcount;
67476 };
67477
67478 struct tty_ldisc {
67479 diff --git a/include/linux/types.h b/include/linux/types.h
67480 index 4d118ba..c3ee9bf 100644
67481 --- a/include/linux/types.h
67482 +++ b/include/linux/types.h
67483 @@ -176,10 +176,26 @@ typedef struct {
67484 int counter;
67485 } atomic_t;
67486
67487 +#ifdef CONFIG_PAX_REFCOUNT
67488 +typedef struct {
67489 + int counter;
67490 +} atomic_unchecked_t;
67491 +#else
67492 +typedef atomic_t atomic_unchecked_t;
67493 +#endif
67494 +
67495 #ifdef CONFIG_64BIT
67496 typedef struct {
67497 long counter;
67498 } atomic64_t;
67499 +
67500 +#ifdef CONFIG_PAX_REFCOUNT
67501 +typedef struct {
67502 + long counter;
67503 +} atomic64_unchecked_t;
67504 +#else
67505 +typedef atomic64_t atomic64_unchecked_t;
67506 +#endif
67507 #endif
67508
67509 struct list_head {
67510 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
67511 index 5ca0951..ab496a5 100644
67512 --- a/include/linux/uaccess.h
67513 +++ b/include/linux/uaccess.h
67514 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
67515 long ret; \
67516 mm_segment_t old_fs = get_fs(); \
67517 \
67518 - set_fs(KERNEL_DS); \
67519 pagefault_disable(); \
67520 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
67521 - pagefault_enable(); \
67522 + set_fs(KERNEL_DS); \
67523 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
67524 set_fs(old_fs); \
67525 + pagefault_enable(); \
67526 ret; \
67527 })
67528
67529 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
67530 index 99c1b4d..bb94261 100644
67531 --- a/include/linux/unaligned/access_ok.h
67532 +++ b/include/linux/unaligned/access_ok.h
67533 @@ -6,32 +6,32 @@
67534
67535 static inline u16 get_unaligned_le16(const void *p)
67536 {
67537 - return le16_to_cpup((__le16 *)p);
67538 + return le16_to_cpup((const __le16 *)p);
67539 }
67540
67541 static inline u32 get_unaligned_le32(const void *p)
67542 {
67543 - return le32_to_cpup((__le32 *)p);
67544 + return le32_to_cpup((const __le32 *)p);
67545 }
67546
67547 static inline u64 get_unaligned_le64(const void *p)
67548 {
67549 - return le64_to_cpup((__le64 *)p);
67550 + return le64_to_cpup((const __le64 *)p);
67551 }
67552
67553 static inline u16 get_unaligned_be16(const void *p)
67554 {
67555 - return be16_to_cpup((__be16 *)p);
67556 + return be16_to_cpup((const __be16 *)p);
67557 }
67558
67559 static inline u32 get_unaligned_be32(const void *p)
67560 {
67561 - return be32_to_cpup((__be32 *)p);
67562 + return be32_to_cpup((const __be32 *)p);
67563 }
67564
67565 static inline u64 get_unaligned_be64(const void *p)
67566 {
67567 - return be64_to_cpup((__be64 *)p);
67568 + return be64_to_cpup((const __be64 *)p);
67569 }
67570
67571 static inline void put_unaligned_le16(u16 val, void *p)
67572 diff --git a/include/linux/usb.h b/include/linux/usb.h
67573 index 4d22d0f..ac43c2f 100644
67574 --- a/include/linux/usb.h
67575 +++ b/include/linux/usb.h
67576 @@ -554,7 +554,7 @@ struct usb_device {
67577 int maxchild;
67578
67579 u32 quirks;
67580 - atomic_t urbnum;
67581 + atomic_unchecked_t urbnum;
67582
67583 unsigned long active_duration;
67584
67585 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
67586 index c5d36c6..108f4f9 100644
67587 --- a/include/linux/usb/renesas_usbhs.h
67588 +++ b/include/linux/usb/renesas_usbhs.h
67589 @@ -39,7 +39,7 @@ enum {
67590 */
67591 struct renesas_usbhs_driver_callback {
67592 int (*notify_hotplug)(struct platform_device *pdev);
67593 -};
67594 +} __no_const;
67595
67596 /*
67597 * callback functions for platform
67598 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
67599 index 6f8fbcf..8259001 100644
67600 --- a/include/linux/vermagic.h
67601 +++ b/include/linux/vermagic.h
67602 @@ -25,9 +25,35 @@
67603 #define MODULE_ARCH_VERMAGIC ""
67604 #endif
67605
67606 +#ifdef CONFIG_PAX_REFCOUNT
67607 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
67608 +#else
67609 +#define MODULE_PAX_REFCOUNT ""
67610 +#endif
67611 +
67612 +#ifdef CONSTIFY_PLUGIN
67613 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
67614 +#else
67615 +#define MODULE_CONSTIFY_PLUGIN ""
67616 +#endif
67617 +
67618 +#ifdef STACKLEAK_PLUGIN
67619 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
67620 +#else
67621 +#define MODULE_STACKLEAK_PLUGIN ""
67622 +#endif
67623 +
67624 +#ifdef CONFIG_GRKERNSEC
67625 +#define MODULE_GRSEC "GRSEC "
67626 +#else
67627 +#define MODULE_GRSEC ""
67628 +#endif
67629 +
67630 #define VERMAGIC_STRING \
67631 UTS_RELEASE " " \
67632 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
67633 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
67634 - MODULE_ARCH_VERMAGIC
67635 + MODULE_ARCH_VERMAGIC \
67636 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
67637 + MODULE_GRSEC
67638
67639 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
67640 index 6071e91..ca6a489 100644
67641 --- a/include/linux/vmalloc.h
67642 +++ b/include/linux/vmalloc.h
67643 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
67644 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
67645 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
67646 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
67647 +
67648 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67649 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
67650 +#endif
67651 +
67652 /* bits [20..32] reserved for arch specific ioremap internals */
67653
67654 /*
67655 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
67656 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
67657 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
67658 unsigned long start, unsigned long end, gfp_t gfp_mask,
67659 - pgprot_t prot, int node, const void *caller);
67660 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
67661 extern void vfree(const void *addr);
67662
67663 extern void *vmap(struct page **pages, unsigned int count,
67664 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
67665 extern void free_vm_area(struct vm_struct *area);
67666
67667 /* for /dev/kmem */
67668 -extern long vread(char *buf, char *addr, unsigned long count);
67669 -extern long vwrite(char *buf, char *addr, unsigned long count);
67670 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
67671 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
67672
67673 /*
67674 * Internals. Dont't use..
67675 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
67676 index a13291f..af51fa3 100644
67677 --- a/include/linux/vmstat.h
67678 +++ b/include/linux/vmstat.h
67679 @@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
67680 /*
67681 * Zone based page accounting with per cpu differentials.
67682 */
67683 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67684 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67685
67686 static inline void zone_page_state_add(long x, struct zone *zone,
67687 enum zone_stat_item item)
67688 {
67689 - atomic_long_add(x, &zone->vm_stat[item]);
67690 - atomic_long_add(x, &vm_stat[item]);
67691 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67692 + atomic_long_add_unchecked(x, &vm_stat[item]);
67693 }
67694
67695 static inline unsigned long global_page_state(enum zone_stat_item item)
67696 {
67697 - long x = atomic_long_read(&vm_stat[item]);
67698 + long x = atomic_long_read_unchecked(&vm_stat[item]);
67699 #ifdef CONFIG_SMP
67700 if (x < 0)
67701 x = 0;
67702 @@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67703 static inline unsigned long zone_page_state(struct zone *zone,
67704 enum zone_stat_item item)
67705 {
67706 - long x = atomic_long_read(&zone->vm_stat[item]);
67707 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67708 #ifdef CONFIG_SMP
67709 if (x < 0)
67710 x = 0;
67711 @@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67712 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67713 enum zone_stat_item item)
67714 {
67715 - long x = atomic_long_read(&zone->vm_stat[item]);
67716 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67717
67718 #ifdef CONFIG_SMP
67719 int cpu;
67720 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67721
67722 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67723 {
67724 - atomic_long_inc(&zone->vm_stat[item]);
67725 - atomic_long_inc(&vm_stat[item]);
67726 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
67727 + atomic_long_inc_unchecked(&vm_stat[item]);
67728 }
67729
67730 static inline void __inc_zone_page_state(struct page *page,
67731 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
67732
67733 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67734 {
67735 - atomic_long_dec(&zone->vm_stat[item]);
67736 - atomic_long_dec(&vm_stat[item]);
67737 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
67738 + atomic_long_dec_unchecked(&vm_stat[item]);
67739 }
67740
67741 static inline void __dec_zone_page_state(struct page *page,
67742 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67743 index 95d1c91..6798cca 100644
67744 --- a/include/media/v4l2-dev.h
67745 +++ b/include/media/v4l2-dev.h
67746 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
67747 int (*mmap) (struct file *, struct vm_area_struct *);
67748 int (*open) (struct file *);
67749 int (*release) (struct file *);
67750 -};
67751 +} __do_const;
67752
67753 /*
67754 * Newer version of video_device, handled by videodev2.c
67755 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67756 index 4118ad1..cb7e25f 100644
67757 --- a/include/media/v4l2-ioctl.h
67758 +++ b/include/media/v4l2-ioctl.h
67759 @@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
67760 bool valid_prio, int cmd, void *arg);
67761 };
67762
67763 -
67764 /* v4l debugging and diagnostics */
67765
67766 /* Debug bitmask flags to be used on V4L2 */
67767 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67768 index 9e5425b..8136ffc 100644
67769 --- a/include/net/caif/cfctrl.h
67770 +++ b/include/net/caif/cfctrl.h
67771 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
67772 void (*radioset_rsp)(void);
67773 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67774 struct cflayer *client_layer);
67775 -};
67776 +} __no_const;
67777
67778 /* Link Setup Parameters for CAIF-Links. */
67779 struct cfctrl_link_param {
67780 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
67781 struct cfctrl {
67782 struct cfsrvl serv;
67783 struct cfctrl_rsp res;
67784 - atomic_t req_seq_no;
67785 - atomic_t rsp_seq_no;
67786 + atomic_unchecked_t req_seq_no;
67787 + atomic_unchecked_t rsp_seq_no;
67788 struct list_head list;
67789 /* Protects from simultaneous access to first_req list */
67790 spinlock_t info_list_lock;
67791 diff --git a/include/net/flow.h b/include/net/flow.h
67792 index 628e11b..4c475df 100644
67793 --- a/include/net/flow.h
67794 +++ b/include/net/flow.h
67795 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67796
67797 extern void flow_cache_flush(void);
67798 extern void flow_cache_flush_deferred(void);
67799 -extern atomic_t flow_cache_genid;
67800 +extern atomic_unchecked_t flow_cache_genid;
67801
67802 #endif
67803 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67804 index e5062c9..48a9a4b 100644
67805 --- a/include/net/gro_cells.h
67806 +++ b/include/net/gro_cells.h
67807 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67808 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67809
67810 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67811 - atomic_long_inc(&dev->rx_dropped);
67812 + atomic_long_inc_unchecked(&dev->rx_dropped);
67813 kfree_skb(skb);
67814 return;
67815 }
67816 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67817 int i;
67818
67819 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67820 - gcells->cells = kcalloc(sizeof(struct gro_cell),
67821 - gcells->gro_cells_mask + 1,
67822 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67823 + sizeof(struct gro_cell),
67824 GFP_KERNEL);
67825 if (!gcells->cells)
67826 return -ENOMEM;
67827 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67828 index 1832927..ce39aea 100644
67829 --- a/include/net/inet_connection_sock.h
67830 +++ b/include/net/inet_connection_sock.h
67831 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67832 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67833 int (*bind_conflict)(const struct sock *sk,
67834 const struct inet_bind_bucket *tb, bool relax);
67835 -};
67836 +} __do_const;
67837
67838 /** inet_connection_sock - INET connection oriented sock
67839 *
67840 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67841 index 53f464d..ba76aaa 100644
67842 --- a/include/net/inetpeer.h
67843 +++ b/include/net/inetpeer.h
67844 @@ -47,8 +47,8 @@ struct inet_peer {
67845 */
67846 union {
67847 struct {
67848 - atomic_t rid; /* Frag reception counter */
67849 - atomic_t ip_id_count; /* IP ID for the next packet */
67850 + atomic_unchecked_t rid; /* Frag reception counter */
67851 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67852 };
67853 struct rcu_head rcu;
67854 struct inet_peer *gc_next;
67855 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67856 more++;
67857 inet_peer_refcheck(p);
67858 do {
67859 - old = atomic_read(&p->ip_id_count);
67860 + old = atomic_read_unchecked(&p->ip_id_count);
67861 new = old + more;
67862 if (!new)
67863 new = 1;
67864 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67865 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67866 return new;
67867 }
67868
67869 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67870 index 9497be1..5a4fafe 100644
67871 --- a/include/net/ip_fib.h
67872 +++ b/include/net/ip_fib.h
67873 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67874
67875 #define FIB_RES_SADDR(net, res) \
67876 ((FIB_RES_NH(res).nh_saddr_genid == \
67877 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67878 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67879 FIB_RES_NH(res).nh_saddr : \
67880 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67881 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67882 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67883 index 68c69d5..2ee192b 100644
67884 --- a/include/net/ip_vs.h
67885 +++ b/include/net/ip_vs.h
67886 @@ -599,7 +599,7 @@ struct ip_vs_conn {
67887 struct ip_vs_conn *control; /* Master control connection */
67888 atomic_t n_control; /* Number of controlled ones */
67889 struct ip_vs_dest *dest; /* real server */
67890 - atomic_t in_pkts; /* incoming packet counter */
67891 + atomic_unchecked_t in_pkts; /* incoming packet counter */
67892
67893 /* packet transmitter for different forwarding methods. If it
67894 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67895 @@ -737,7 +737,7 @@ struct ip_vs_dest {
67896 __be16 port; /* port number of the server */
67897 union nf_inet_addr addr; /* IP address of the server */
67898 volatile unsigned int flags; /* dest status flags */
67899 - atomic_t conn_flags; /* flags to copy to conn */
67900 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
67901 atomic_t weight; /* server weight */
67902
67903 atomic_t refcnt; /* reference counter */
67904 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67905 index 80ffde3..968b0f4 100644
67906 --- a/include/net/irda/ircomm_tty.h
67907 +++ b/include/net/irda/ircomm_tty.h
67908 @@ -35,6 +35,7 @@
67909 #include <linux/termios.h>
67910 #include <linux/timer.h>
67911 #include <linux/tty.h> /* struct tty_struct */
67912 +#include <asm/local.h>
67913
67914 #include <net/irda/irias_object.h>
67915 #include <net/irda/ircomm_core.h>
67916 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67917 index cc7c197..9f2da2a 100644
67918 --- a/include/net/iucv/af_iucv.h
67919 +++ b/include/net/iucv/af_iucv.h
67920 @@ -141,7 +141,7 @@ struct iucv_sock {
67921 struct iucv_sock_list {
67922 struct hlist_head head;
67923 rwlock_t lock;
67924 - atomic_t autobind_name;
67925 + atomic_unchecked_t autobind_name;
67926 };
67927
67928 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67929 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67930 index 0dab173..1b76af0 100644
67931 --- a/include/net/neighbour.h
67932 +++ b/include/net/neighbour.h
67933 @@ -123,7 +123,7 @@ struct neigh_ops {
67934 void (*error_report)(struct neighbour *, struct sk_buff *);
67935 int (*output)(struct neighbour *, struct sk_buff *);
67936 int (*connected_output)(struct neighbour *, struct sk_buff *);
67937 -};
67938 +} __do_const;
67939
67940 struct pneigh_entry {
67941 struct pneigh_entry *next;
67942 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67943 index de644bc..666aed3 100644
67944 --- a/include/net/net_namespace.h
67945 +++ b/include/net/net_namespace.h
67946 @@ -115,7 +115,7 @@ struct net {
67947 #endif
67948 struct netns_ipvs *ipvs;
67949 struct sock *diag_nlsk;
67950 - atomic_t rt_genid;
67951 + atomic_unchecked_t rt_genid;
67952 };
67953
67954 /*
67955 @@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67956
67957 static inline int rt_genid(struct net *net)
67958 {
67959 - return atomic_read(&net->rt_genid);
67960 + return atomic_read_unchecked(&net->rt_genid);
67961 }
67962
67963 static inline void rt_genid_bump(struct net *net)
67964 {
67965 - atomic_inc(&net->rt_genid);
67966 + atomic_inc_unchecked(&net->rt_genid);
67967 }
67968
67969 #endif /* __NET_NET_NAMESPACE_H */
67970 diff --git a/include/net/netdma.h b/include/net/netdma.h
67971 index 8ba8ce2..99b7fff 100644
67972 --- a/include/net/netdma.h
67973 +++ b/include/net/netdma.h
67974 @@ -24,7 +24,7 @@
67975 #include <linux/dmaengine.h>
67976 #include <linux/skbuff.h>
67977
67978 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67979 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67980 struct sk_buff *skb, int offset, struct iovec *to,
67981 size_t len, struct dma_pinned_list *pinned_list);
67982
67983 diff --git a/include/net/netlink.h b/include/net/netlink.h
67984 index 9690b0f..87aded7 100644
67985 --- a/include/net/netlink.h
67986 +++ b/include/net/netlink.h
67987 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67988 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67989 {
67990 if (mark)
67991 - skb_trim(skb, (unsigned char *) mark - skb->data);
67992 + skb_trim(skb, (const unsigned char *) mark - skb->data);
67993 }
67994
67995 /**
67996 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67997 index 2ae2b83..dbdc85e 100644
67998 --- a/include/net/netns/ipv4.h
67999 +++ b/include/net/netns/ipv4.h
68000 @@ -64,7 +64,7 @@ struct netns_ipv4 {
68001 kgid_t sysctl_ping_group_range[2];
68002 long sysctl_tcp_mem[3];
68003
68004 - atomic_t dev_addr_genid;
68005 + atomic_unchecked_t dev_addr_genid;
68006
68007 #ifdef CONFIG_IP_MROUTE
68008 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
68009 diff --git a/include/net/protocol.h b/include/net/protocol.h
68010 index 047c047..b9dad15 100644
68011 --- a/include/net/protocol.h
68012 +++ b/include/net/protocol.h
68013 @@ -44,7 +44,7 @@ struct net_protocol {
68014 void (*err_handler)(struct sk_buff *skb, u32 info);
68015 unsigned int no_policy:1,
68016 netns_ok:1;
68017 -};
68018 +} __do_const;
68019
68020 #if IS_ENABLED(CONFIG_IPV6)
68021 struct inet6_protocol {
68022 @@ -57,7 +57,7 @@ struct inet6_protocol {
68023 u8 type, u8 code, int offset,
68024 __be32 info);
68025 unsigned int flags; /* INET6_PROTO_xxx */
68026 -};
68027 +} __do_const;
68028
68029 #define INET6_PROTO_NOPOLICY 0x1
68030 #define INET6_PROTO_FINAL 0x2
68031 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
68032 index 7fdf298..197e9f7 100644
68033 --- a/include/net/sctp/sctp.h
68034 +++ b/include/net/sctp/sctp.h
68035 @@ -330,9 +330,9 @@ do { \
68036
68037 #else /* SCTP_DEBUG */
68038
68039 -#define SCTP_DEBUG_PRINTK(whatever...)
68040 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
68041 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
68042 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
68043 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
68044 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
68045 #define SCTP_ENABLE_DEBUG
68046 #define SCTP_DISABLE_DEBUG
68047 #define SCTP_ASSERT(expr, str, func)
68048 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
68049 index fdeb85a..0c554d5 100644
68050 --- a/include/net/sctp/structs.h
68051 +++ b/include/net/sctp/structs.h
68052 @@ -497,7 +497,7 @@ struct sctp_af {
68053 int sockaddr_len;
68054 sa_family_t sa_family;
68055 struct list_head list;
68056 -};
68057 +} __do_const;
68058
68059 struct sctp_af *sctp_get_af_specific(sa_family_t);
68060 int sctp_register_af(struct sctp_af *);
68061 @@ -517,7 +517,7 @@ struct sctp_pf {
68062 struct sctp_association *asoc);
68063 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
68064 struct sctp_af *af;
68065 -};
68066 +} __do_const;
68067
68068
68069 /* Structure to track chunk fragments that have been acked, but peer
68070 diff --git a/include/net/sock.h b/include/net/sock.h
68071 index 182ca99..b7dc290 100644
68072 --- a/include/net/sock.h
68073 +++ b/include/net/sock.h
68074 @@ -322,7 +322,7 @@ struct sock {
68075 #ifdef CONFIG_RPS
68076 __u32 sk_rxhash;
68077 #endif
68078 - atomic_t sk_drops;
68079 + atomic_unchecked_t sk_drops;
68080 int sk_rcvbuf;
68081
68082 struct sk_filter __rcu *sk_filter;
68083 @@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
68084 }
68085
68086 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
68087 - char __user *from, char *to,
68088 + char __user *from, unsigned char *to,
68089 int copy, int offset)
68090 {
68091 if (skb->ip_summed == CHECKSUM_NONE) {
68092 @@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
68093 }
68094 }
68095
68096 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68097 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68098
68099 /**
68100 * sk_page_frag - return an appropriate page_frag
68101 diff --git a/include/net/tcp.h b/include/net/tcp.h
68102 index aed42c7..43890c6 100644
68103 --- a/include/net/tcp.h
68104 +++ b/include/net/tcp.h
68105 @@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
68106 extern void tcp_xmit_retransmit_queue(struct sock *);
68107 extern void tcp_simple_retransmit(struct sock *);
68108 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
68109 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68110 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68111
68112 extern void tcp_send_probe0(struct sock *);
68113 extern void tcp_send_partial(struct sock *);
68114 @@ -701,8 +701,8 @@ struct tcp_skb_cb {
68115 struct inet6_skb_parm h6;
68116 #endif
68117 } header; /* For incoming frames */
68118 - __u32 seq; /* Starting sequence number */
68119 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
68120 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
68121 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
68122 __u32 when; /* used to compute rtt's */
68123 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
68124
68125 @@ -716,7 +716,7 @@ struct tcp_skb_cb {
68126
68127 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
68128 /* 1 byte hole */
68129 - __u32 ack_seq; /* Sequence number ACK'd */
68130 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
68131 };
68132
68133 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
68134 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
68135 index 63445ed..74ef61d 100644
68136 --- a/include/net/xfrm.h
68137 +++ b/include/net/xfrm.h
68138 @@ -423,7 +423,7 @@ struct xfrm_mode {
68139 struct module *owner;
68140 unsigned int encap;
68141 int flags;
68142 -};
68143 +} __do_const;
68144
68145 /* Flags for xfrm_mode. */
68146 enum {
68147 @@ -514,7 +514,7 @@ struct xfrm_policy {
68148 struct timer_list timer;
68149
68150 struct flow_cache_object flo;
68151 - atomic_t genid;
68152 + atomic_unchecked_t genid;
68153 u32 priority;
68154 u32 index;
68155 struct xfrm_mark mark;
68156 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
68157 index 1a046b1..ee0bef0 100644
68158 --- a/include/rdma/iw_cm.h
68159 +++ b/include/rdma/iw_cm.h
68160 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
68161 int backlog);
68162
68163 int (*destroy_listen)(struct iw_cm_id *cm_id);
68164 -};
68165 +} __no_const;
68166
68167 /**
68168 * iw_create_cm_id - Create an IW CM identifier.
68169 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
68170 index 399162b..b337f1a 100644
68171 --- a/include/scsi/libfc.h
68172 +++ b/include/scsi/libfc.h
68173 @@ -762,6 +762,7 @@ struct libfc_function_template {
68174 */
68175 void (*disc_stop_final) (struct fc_lport *);
68176 };
68177 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
68178
68179 /**
68180 * struct fc_disc - Discovery context
68181 @@ -866,7 +867,7 @@ struct fc_lport {
68182 struct fc_vport *vport;
68183
68184 /* Operational Information */
68185 - struct libfc_function_template tt;
68186 + libfc_function_template_no_const tt;
68187 u8 link_up;
68188 u8 qfull;
68189 enum fc_lport_state state;
68190 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
68191 index e65c62e..aa2e5a2 100644
68192 --- a/include/scsi/scsi_device.h
68193 +++ b/include/scsi/scsi_device.h
68194 @@ -170,9 +170,9 @@ struct scsi_device {
68195 unsigned int max_device_blocked; /* what device_blocked counts down from */
68196 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
68197
68198 - atomic_t iorequest_cnt;
68199 - atomic_t iodone_cnt;
68200 - atomic_t ioerr_cnt;
68201 + atomic_unchecked_t iorequest_cnt;
68202 + atomic_unchecked_t iodone_cnt;
68203 + atomic_unchecked_t ioerr_cnt;
68204
68205 struct device sdev_gendev,
68206 sdev_dev;
68207 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
68208 index b797e8f..8e2c3aa 100644
68209 --- a/include/scsi/scsi_transport_fc.h
68210 +++ b/include/scsi/scsi_transport_fc.h
68211 @@ -751,7 +751,8 @@ struct fc_function_template {
68212 unsigned long show_host_system_hostname:1;
68213
68214 unsigned long disable_target_scan:1;
68215 -};
68216 +} __do_const;
68217 +typedef struct fc_function_template __no_const fc_function_template_no_const;
68218
68219
68220 /**
68221 diff --git a/include/sound/soc.h b/include/sound/soc.h
68222 index bc56738..a4be132 100644
68223 --- a/include/sound/soc.h
68224 +++ b/include/sound/soc.h
68225 @@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
68226 /* probe ordering - for components with runtime dependencies */
68227 int probe_order;
68228 int remove_order;
68229 -};
68230 +} __do_const;
68231
68232 /* SoC platform interface */
68233 struct snd_soc_platform_driver {
68234 @@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
68235 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
68236 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
68237 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
68238 -};
68239 +} __do_const;
68240
68241 struct snd_soc_platform {
68242 const char *name;
68243 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
68244 index 663e34a..91b306a 100644
68245 --- a/include/target/target_core_base.h
68246 +++ b/include/target/target_core_base.h
68247 @@ -654,7 +654,7 @@ struct se_device {
68248 spinlock_t stats_lock;
68249 /* Active commands on this virtual SE device */
68250 atomic_t simple_cmds;
68251 - atomic_t dev_ordered_id;
68252 + atomic_unchecked_t dev_ordered_id;
68253 atomic_t dev_ordered_sync;
68254 atomic_t dev_qf_count;
68255 int export_count;
68256 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
68257 new file mode 100644
68258 index 0000000..fb634b7
68259 --- /dev/null
68260 +++ b/include/trace/events/fs.h
68261 @@ -0,0 +1,53 @@
68262 +#undef TRACE_SYSTEM
68263 +#define TRACE_SYSTEM fs
68264 +
68265 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
68266 +#define _TRACE_FS_H
68267 +
68268 +#include <linux/fs.h>
68269 +#include <linux/tracepoint.h>
68270 +
68271 +TRACE_EVENT(do_sys_open,
68272 +
68273 + TP_PROTO(const char *filename, int flags, int mode),
68274 +
68275 + TP_ARGS(filename, flags, mode),
68276 +
68277 + TP_STRUCT__entry(
68278 + __string( filename, filename )
68279 + __field( int, flags )
68280 + __field( int, mode )
68281 + ),
68282 +
68283 + TP_fast_assign(
68284 + __assign_str(filename, filename);
68285 + __entry->flags = flags;
68286 + __entry->mode = mode;
68287 + ),
68288 +
68289 + TP_printk("\"%s\" %x %o",
68290 + __get_str(filename), __entry->flags, __entry->mode)
68291 +);
68292 +
68293 +TRACE_EVENT(open_exec,
68294 +
68295 + TP_PROTO(const char *filename),
68296 +
68297 + TP_ARGS(filename),
68298 +
68299 + TP_STRUCT__entry(
68300 + __string( filename, filename )
68301 + ),
68302 +
68303 + TP_fast_assign(
68304 + __assign_str(filename, filename);
68305 + ),
68306 +
68307 + TP_printk("\"%s\"",
68308 + __get_str(filename))
68309 +);
68310 +
68311 +#endif /* _TRACE_FS_H */
68312 +
68313 +/* This part must be outside protection */
68314 +#include <trace/define_trace.h>
68315 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
68316 index 1c09820..7f5ec79 100644
68317 --- a/include/trace/events/irq.h
68318 +++ b/include/trace/events/irq.h
68319 @@ -36,7 +36,7 @@ struct softirq_action;
68320 */
68321 TRACE_EVENT(irq_handler_entry,
68322
68323 - TP_PROTO(int irq, struct irqaction *action),
68324 + TP_PROTO(int irq, const struct irqaction *action),
68325
68326 TP_ARGS(irq, action),
68327
68328 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
68329 */
68330 TRACE_EVENT(irq_handler_exit,
68331
68332 - TP_PROTO(int irq, struct irqaction *action, int ret),
68333 + TP_PROTO(int irq, const struct irqaction *action, int ret),
68334
68335 TP_ARGS(irq, action, ret),
68336
68337 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
68338 index 7caf44c..23c6f27 100644
68339 --- a/include/uapi/linux/a.out.h
68340 +++ b/include/uapi/linux/a.out.h
68341 @@ -39,6 +39,14 @@ enum machine_type {
68342 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
68343 };
68344
68345 +/* Constants for the N_FLAGS field */
68346 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68347 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
68348 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
68349 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
68350 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68351 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68352 +
68353 #if !defined (N_MAGIC)
68354 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
68355 #endif
68356 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
68357 index d876736..b36014e 100644
68358 --- a/include/uapi/linux/byteorder/little_endian.h
68359 +++ b/include/uapi/linux/byteorder/little_endian.h
68360 @@ -42,51 +42,51 @@
68361
68362 static inline __le64 __cpu_to_le64p(const __u64 *p)
68363 {
68364 - return (__force __le64)*p;
68365 + return (__force const __le64)*p;
68366 }
68367 static inline __u64 __le64_to_cpup(const __le64 *p)
68368 {
68369 - return (__force __u64)*p;
68370 + return (__force const __u64)*p;
68371 }
68372 static inline __le32 __cpu_to_le32p(const __u32 *p)
68373 {
68374 - return (__force __le32)*p;
68375 + return (__force const __le32)*p;
68376 }
68377 static inline __u32 __le32_to_cpup(const __le32 *p)
68378 {
68379 - return (__force __u32)*p;
68380 + return (__force const __u32)*p;
68381 }
68382 static inline __le16 __cpu_to_le16p(const __u16 *p)
68383 {
68384 - return (__force __le16)*p;
68385 + return (__force const __le16)*p;
68386 }
68387 static inline __u16 __le16_to_cpup(const __le16 *p)
68388 {
68389 - return (__force __u16)*p;
68390 + return (__force const __u16)*p;
68391 }
68392 static inline __be64 __cpu_to_be64p(const __u64 *p)
68393 {
68394 - return (__force __be64)__swab64p(p);
68395 + return (__force const __be64)__swab64p(p);
68396 }
68397 static inline __u64 __be64_to_cpup(const __be64 *p)
68398 {
68399 - return __swab64p((__u64 *)p);
68400 + return __swab64p((const __u64 *)p);
68401 }
68402 static inline __be32 __cpu_to_be32p(const __u32 *p)
68403 {
68404 - return (__force __be32)__swab32p(p);
68405 + return (__force const __be32)__swab32p(p);
68406 }
68407 static inline __u32 __be32_to_cpup(const __be32 *p)
68408 {
68409 - return __swab32p((__u32 *)p);
68410 + return __swab32p((const __u32 *)p);
68411 }
68412 static inline __be16 __cpu_to_be16p(const __u16 *p)
68413 {
68414 - return (__force __be16)__swab16p(p);
68415 + return (__force const __be16)__swab16p(p);
68416 }
68417 static inline __u16 __be16_to_cpup(const __be16 *p)
68418 {
68419 - return __swab16p((__u16 *)p);
68420 + return __swab16p((const __u16 *)p);
68421 }
68422 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
68423 #define __le64_to_cpus(x) do { (void)(x); } while (0)
68424 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
68425 index 126a817..d522bd1 100644
68426 --- a/include/uapi/linux/elf.h
68427 +++ b/include/uapi/linux/elf.h
68428 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
68429 #define PT_GNU_EH_FRAME 0x6474e550
68430
68431 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
68432 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
68433 +
68434 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
68435 +
68436 +/* Constants for the e_flags field */
68437 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68438 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
68439 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
68440 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
68441 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68442 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68443
68444 /*
68445 * Extended Numbering
68446 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
68447 #define DT_DEBUG 21
68448 #define DT_TEXTREL 22
68449 #define DT_JMPREL 23
68450 +#define DT_FLAGS 30
68451 + #define DF_TEXTREL 0x00000004
68452 #define DT_ENCODING 32
68453 #define OLD_DT_LOOS 0x60000000
68454 #define DT_LOOS 0x6000000d
68455 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
68456 #define PF_W 0x2
68457 #define PF_X 0x1
68458
68459 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
68460 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
68461 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
68462 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
68463 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
68464 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
68465 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
68466 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
68467 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
68468 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
68469 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
68470 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
68471 +
68472 typedef struct elf32_phdr{
68473 Elf32_Word p_type;
68474 Elf32_Off p_offset;
68475 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
68476 #define EI_OSABI 7
68477 #define EI_PAD 8
68478
68479 +#define EI_PAX 14
68480 +
68481 #define ELFMAG0 0x7f /* EI_MAG */
68482 #define ELFMAG1 'E'
68483 #define ELFMAG2 'L'
68484 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
68485 index aa169c4..6a2771d 100644
68486 --- a/include/uapi/linux/personality.h
68487 +++ b/include/uapi/linux/personality.h
68488 @@ -30,6 +30,7 @@ enum {
68489 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
68490 ADDR_NO_RANDOMIZE | \
68491 ADDR_COMPAT_LAYOUT | \
68492 + ADDR_LIMIT_3GB | \
68493 MMAP_PAGE_ZERO)
68494
68495 /*
68496 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
68497 index 7530e74..e714828 100644
68498 --- a/include/uapi/linux/screen_info.h
68499 +++ b/include/uapi/linux/screen_info.h
68500 @@ -43,7 +43,8 @@ struct screen_info {
68501 __u16 pages; /* 0x32 */
68502 __u16 vesa_attributes; /* 0x34 */
68503 __u32 capabilities; /* 0x36 */
68504 - __u8 _reserved[6]; /* 0x3a */
68505 + __u16 vesapm_size; /* 0x3a */
68506 + __u8 _reserved[4]; /* 0x3c */
68507 } __attribute__((packed));
68508
68509 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68510 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
68511 index 6d67213..8dab561 100644
68512 --- a/include/uapi/linux/sysctl.h
68513 +++ b/include/uapi/linux/sysctl.h
68514 @@ -155,7 +155,11 @@ enum
68515 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68516 };
68517
68518 -
68519 +#ifdef CONFIG_PAX_SOFTMODE
68520 +enum {
68521 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68522 +};
68523 +#endif
68524
68525 /* CTL_VM names: */
68526 enum
68527 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
68528 index 26607bd..588b65f 100644
68529 --- a/include/uapi/linux/xattr.h
68530 +++ b/include/uapi/linux/xattr.h
68531 @@ -60,5 +60,9 @@
68532 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
68533 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
68534
68535 +/* User namespace */
68536 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
68537 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
68538 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
68539
68540 #endif /* _UAPI_LINUX_XATTR_H */
68541 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
68542 index f9466fa..f4e2b81 100644
68543 --- a/include/video/udlfb.h
68544 +++ b/include/video/udlfb.h
68545 @@ -53,10 +53,10 @@ struct dlfb_data {
68546 u32 pseudo_palette[256];
68547 int blank_mode; /*one of FB_BLANK_ */
68548 /* blit-only rendering path metrics, exposed through sysfs */
68549 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68550 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
68551 - atomic_t bytes_sent; /* to usb, after compression including overhead */
68552 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
68553 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68554 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
68555 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
68556 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
68557 };
68558
68559 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
68560 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
68561 index 0993a22..32ba2fe 100644
68562 --- a/include/video/uvesafb.h
68563 +++ b/include/video/uvesafb.h
68564 @@ -177,6 +177,7 @@ struct uvesafb_par {
68565 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
68566 u8 pmi_setpal; /* PMI for palette changes */
68567 u16 *pmi_base; /* protected mode interface location */
68568 + u8 *pmi_code; /* protected mode code location */
68569 void *pmi_start;
68570 void *pmi_pal;
68571 u8 *vbe_state_orig; /*
68572 diff --git a/init/Kconfig b/init/Kconfig
68573 index be8b7f5..b13cb62 100644
68574 --- a/init/Kconfig
68575 +++ b/init/Kconfig
68576 @@ -990,6 +990,7 @@ endif # CGROUPS
68577
68578 config CHECKPOINT_RESTORE
68579 bool "Checkpoint/restore support" if EXPERT
68580 + depends on !GRKERNSEC
68581 default n
68582 help
68583 Enables additional kernel features in a sake of checkpoint/restore.
68584 @@ -1079,6 +1080,8 @@ config UIDGID_CONVERTED
68585 depends on OCFS2_FS = n
68586 depends on XFS_FS = n
68587
68588 + depends on GRKERNSEC = n
68589 +
68590 config UIDGID_STRICT_TYPE_CHECKS
68591 bool "Require conversions between uid/gids and their internal representation"
68592 depends on UIDGID_CONVERTED
68593 @@ -1468,7 +1471,7 @@ config SLUB_DEBUG
68594
68595 config COMPAT_BRK
68596 bool "Disable heap randomization"
68597 - default y
68598 + default n
68599 help
68600 Randomizing heap placement makes heap exploits harder, but it
68601 also breaks ancient binaries (including anything libc5 based).
68602 @@ -1711,7 +1714,7 @@ config INIT_ALL_POSSIBLE
68603 config STOP_MACHINE
68604 bool
68605 default y
68606 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
68607 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
68608 help
68609 Need stop_machine() primitive.
68610
68611 diff --git a/init/Makefile b/init/Makefile
68612 index 7bc47ee..6da2dc7 100644
68613 --- a/init/Makefile
68614 +++ b/init/Makefile
68615 @@ -2,6 +2,9 @@
68616 # Makefile for the linux kernel.
68617 #
68618
68619 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
68620 +asflags-y := $(GCC_PLUGINS_AFLAGS)
68621 +
68622 obj-y := main.o version.o mounts.o
68623 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
68624 obj-y += noinitramfs.o
68625 diff --git a/init/do_mounts.c b/init/do_mounts.c
68626 index 1d1b634..a1c810f 100644
68627 --- a/init/do_mounts.c
68628 +++ b/init/do_mounts.c
68629 @@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
68630 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
68631 {
68632 struct super_block *s;
68633 - int err = sys_mount(name, "/root", fs, flags, data);
68634 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
68635 if (err)
68636 return err;
68637
68638 - sys_chdir("/root");
68639 + sys_chdir((const char __force_user *)"/root");
68640 s = current->fs->pwd.dentry->d_sb;
68641 ROOT_DEV = s->s_dev;
68642 printk(KERN_INFO
68643 @@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
68644 va_start(args, fmt);
68645 vsprintf(buf, fmt, args);
68646 va_end(args);
68647 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
68648 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
68649 if (fd >= 0) {
68650 sys_ioctl(fd, FDEJECT, 0);
68651 sys_close(fd);
68652 }
68653 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
68654 - fd = sys_open("/dev/console", O_RDWR, 0);
68655 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
68656 if (fd >= 0) {
68657 sys_ioctl(fd, TCGETS, (long)&termios);
68658 termios.c_lflag &= ~ICANON;
68659 sys_ioctl(fd, TCSETSF, (long)&termios);
68660 - sys_read(fd, &c, 1);
68661 + sys_read(fd, (char __user *)&c, 1);
68662 termios.c_lflag |= ICANON;
68663 sys_ioctl(fd, TCSETSF, (long)&termios);
68664 sys_close(fd);
68665 @@ -585,6 +585,6 @@ void __init prepare_namespace(void)
68666 mount_root();
68667 out:
68668 devtmpfs_mount("dev");
68669 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
68670 - sys_chroot(".");
68671 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68672 + sys_chroot((const char __force_user *)".");
68673 }
68674 diff --git a/init/do_mounts.h b/init/do_mounts.h
68675 index f5b978a..69dbfe8 100644
68676 --- a/init/do_mounts.h
68677 +++ b/init/do_mounts.h
68678 @@ -15,15 +15,15 @@ extern int root_mountflags;
68679
68680 static inline int create_dev(char *name, dev_t dev)
68681 {
68682 - sys_unlink(name);
68683 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68684 + sys_unlink((char __force_user *)name);
68685 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68686 }
68687
68688 #if BITS_PER_LONG == 32
68689 static inline u32 bstat(char *name)
68690 {
68691 struct stat64 stat;
68692 - if (sys_stat64(name, &stat) != 0)
68693 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68694 return 0;
68695 if (!S_ISBLK(stat.st_mode))
68696 return 0;
68697 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68698 static inline u32 bstat(char *name)
68699 {
68700 struct stat stat;
68701 - if (sys_newstat(name, &stat) != 0)
68702 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68703 return 0;
68704 if (!S_ISBLK(stat.st_mode))
68705 return 0;
68706 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68707 index f9acf71..1e19144 100644
68708 --- a/init/do_mounts_initrd.c
68709 +++ b/init/do_mounts_initrd.c
68710 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68711 create_dev("/dev/root.old", Root_RAM0);
68712 /* mount initrd on rootfs' /root */
68713 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68714 - sys_mkdir("/old", 0700);
68715 - sys_chdir("/old");
68716 + sys_mkdir((const char __force_user *)"/old", 0700);
68717 + sys_chdir((const char __force_user *)"/old");
68718
68719 /*
68720 * In case that a resume from disk is carried out by linuxrc or one of
68721 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68722 current->flags &= ~PF_FREEZER_SKIP;
68723
68724 /* move initrd to rootfs' /old */
68725 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
68726 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68727 /* switch root and cwd back to / of rootfs */
68728 - sys_chroot("..");
68729 + sys_chroot((const char __force_user *)"..");
68730
68731 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68732 - sys_chdir("/old");
68733 + sys_chdir((const char __force_user *)"/old");
68734 return;
68735 }
68736
68737 - sys_chdir("/");
68738 + sys_chdir((const char __force_user *)"/");
68739 ROOT_DEV = new_decode_dev(real_root_dev);
68740 mount_root();
68741
68742 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68743 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68744 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68745 if (!error)
68746 printk("okay\n");
68747 else {
68748 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
68749 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68750 if (error == -ENOENT)
68751 printk("/initrd does not exist. Ignored.\n");
68752 else
68753 printk("failed\n");
68754 printk(KERN_NOTICE "Unmounting old root\n");
68755 - sys_umount("/old", MNT_DETACH);
68756 + sys_umount((char __force_user *)"/old", MNT_DETACH);
68757 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68758 if (fd < 0) {
68759 error = fd;
68760 @@ -120,11 +120,11 @@ int __init initrd_load(void)
68761 * mounted in the normal path.
68762 */
68763 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68764 - sys_unlink("/initrd.image");
68765 + sys_unlink((const char __force_user *)"/initrd.image");
68766 handle_initrd();
68767 return 1;
68768 }
68769 }
68770 - sys_unlink("/initrd.image");
68771 + sys_unlink((const char __force_user *)"/initrd.image");
68772 return 0;
68773 }
68774 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68775 index 8cb6db5..d729f50 100644
68776 --- a/init/do_mounts_md.c
68777 +++ b/init/do_mounts_md.c
68778 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68779 partitioned ? "_d" : "", minor,
68780 md_setup_args[ent].device_names);
68781
68782 - fd = sys_open(name, 0, 0);
68783 + fd = sys_open((char __force_user *)name, 0, 0);
68784 if (fd < 0) {
68785 printk(KERN_ERR "md: open failed - cannot start "
68786 "array %s\n", name);
68787 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68788 * array without it
68789 */
68790 sys_close(fd);
68791 - fd = sys_open(name, 0, 0);
68792 + fd = sys_open((char __force_user *)name, 0, 0);
68793 sys_ioctl(fd, BLKRRPART, 0);
68794 }
68795 sys_close(fd);
68796 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68797
68798 wait_for_device_probe();
68799
68800 - fd = sys_open("/dev/md0", 0, 0);
68801 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68802 if (fd >= 0) {
68803 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68804 sys_close(fd);
68805 diff --git a/init/init_task.c b/init/init_task.c
68806 index 8b2f399..f0797c9 100644
68807 --- a/init/init_task.c
68808 +++ b/init/init_task.c
68809 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68810 * Initial thread structure. Alignment of this is handled by a special
68811 * linker map entry.
68812 */
68813 +#ifdef CONFIG_X86
68814 +union thread_union init_thread_union __init_task_data;
68815 +#else
68816 union thread_union init_thread_union __init_task_data =
68817 { INIT_THREAD_INFO(init_task) };
68818 +#endif
68819 diff --git a/init/initramfs.c b/init/initramfs.c
68820 index 84c6bf1..8899338 100644
68821 --- a/init/initramfs.c
68822 +++ b/init/initramfs.c
68823 @@ -84,7 +84,7 @@ static void __init free_hash(void)
68824 }
68825 }
68826
68827 -static long __init do_utime(char *filename, time_t mtime)
68828 +static long __init do_utime(char __force_user *filename, time_t mtime)
68829 {
68830 struct timespec t[2];
68831
68832 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
68833 struct dir_entry *de, *tmp;
68834 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68835 list_del(&de->list);
68836 - do_utime(de->name, de->mtime);
68837 + do_utime((char __force_user *)de->name, de->mtime);
68838 kfree(de->name);
68839 kfree(de);
68840 }
68841 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
68842 if (nlink >= 2) {
68843 char *old = find_link(major, minor, ino, mode, collected);
68844 if (old)
68845 - return (sys_link(old, collected) < 0) ? -1 : 1;
68846 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68847 }
68848 return 0;
68849 }
68850 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68851 {
68852 struct stat st;
68853
68854 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68855 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68856 if (S_ISDIR(st.st_mode))
68857 - sys_rmdir(path);
68858 + sys_rmdir((char __force_user *)path);
68859 else
68860 - sys_unlink(path);
68861 + sys_unlink((char __force_user *)path);
68862 }
68863 }
68864
68865 @@ -315,7 +315,7 @@ static int __init do_name(void)
68866 int openflags = O_WRONLY|O_CREAT;
68867 if (ml != 1)
68868 openflags |= O_TRUNC;
68869 - wfd = sys_open(collected, openflags, mode);
68870 + wfd = sys_open((char __force_user *)collected, openflags, mode);
68871
68872 if (wfd >= 0) {
68873 sys_fchown(wfd, uid, gid);
68874 @@ -327,17 +327,17 @@ static int __init do_name(void)
68875 }
68876 }
68877 } else if (S_ISDIR(mode)) {
68878 - sys_mkdir(collected, mode);
68879 - sys_chown(collected, uid, gid);
68880 - sys_chmod(collected, mode);
68881 + sys_mkdir((char __force_user *)collected, mode);
68882 + sys_chown((char __force_user *)collected, uid, gid);
68883 + sys_chmod((char __force_user *)collected, mode);
68884 dir_add(collected, mtime);
68885 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68886 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68887 if (maybe_link() == 0) {
68888 - sys_mknod(collected, mode, rdev);
68889 - sys_chown(collected, uid, gid);
68890 - sys_chmod(collected, mode);
68891 - do_utime(collected, mtime);
68892 + sys_mknod((char __force_user *)collected, mode, rdev);
68893 + sys_chown((char __force_user *)collected, uid, gid);
68894 + sys_chmod((char __force_user *)collected, mode);
68895 + do_utime((char __force_user *)collected, mtime);
68896 }
68897 }
68898 return 0;
68899 @@ -346,15 +346,15 @@ static int __init do_name(void)
68900 static int __init do_copy(void)
68901 {
68902 if (count >= body_len) {
68903 - sys_write(wfd, victim, body_len);
68904 + sys_write(wfd, (char __force_user *)victim, body_len);
68905 sys_close(wfd);
68906 - do_utime(vcollected, mtime);
68907 + do_utime((char __force_user *)vcollected, mtime);
68908 kfree(vcollected);
68909 eat(body_len);
68910 state = SkipIt;
68911 return 0;
68912 } else {
68913 - sys_write(wfd, victim, count);
68914 + sys_write(wfd, (char __force_user *)victim, count);
68915 body_len -= count;
68916 eat(count);
68917 return 1;
68918 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
68919 {
68920 collected[N_ALIGN(name_len) + body_len] = '\0';
68921 clean_path(collected, 0);
68922 - sys_symlink(collected + N_ALIGN(name_len), collected);
68923 - sys_lchown(collected, uid, gid);
68924 - do_utime(collected, mtime);
68925 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68926 + sys_lchown((char __force_user *)collected, uid, gid);
68927 + do_utime((char __force_user *)collected, mtime);
68928 state = SkipIt;
68929 next_state = Reset;
68930 return 0;
68931 diff --git a/init/main.c b/init/main.c
68932 index cee4b5c..47f445e 100644
68933 --- a/init/main.c
68934 +++ b/init/main.c
68935 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68936 extern void tc_init(void);
68937 #endif
68938
68939 +extern void grsecurity_init(void);
68940 +
68941 /*
68942 * Debug helper: via this flag we know that we are in 'early bootup code'
68943 * where only the boot processor is running with IRQ disabled. This means
68944 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68945
68946 __setup("reset_devices", set_reset_devices);
68947
68948 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68949 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68950 +static int __init setup_grsec_proc_gid(char *str)
68951 +{
68952 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68953 + return 1;
68954 +}
68955 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68956 +#endif
68957 +
68958 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68959 +extern char pax_enter_kernel_user[];
68960 +extern char pax_exit_kernel_user[];
68961 +extern pgdval_t clone_pgd_mask;
68962 +#endif
68963 +
68964 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68965 +static int __init setup_pax_nouderef(char *str)
68966 +{
68967 +#ifdef CONFIG_X86_32
68968 + unsigned int cpu;
68969 + struct desc_struct *gdt;
68970 +
68971 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68972 + gdt = get_cpu_gdt_table(cpu);
68973 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68974 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68975 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68976 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68977 + }
68978 + loadsegment(ds, __KERNEL_DS);
68979 + loadsegment(es, __KERNEL_DS);
68980 + loadsegment(ss, __KERNEL_DS);
68981 +#else
68982 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68983 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68984 + clone_pgd_mask = ~(pgdval_t)0UL;
68985 +#endif
68986 +
68987 + return 0;
68988 +}
68989 +early_param("pax_nouderef", setup_pax_nouderef);
68990 +#endif
68991 +
68992 +#ifdef CONFIG_PAX_SOFTMODE
68993 +int pax_softmode;
68994 +
68995 +static int __init setup_pax_softmode(char *str)
68996 +{
68997 + get_option(&str, &pax_softmode);
68998 + return 1;
68999 +}
69000 +__setup("pax_softmode=", setup_pax_softmode);
69001 +#endif
69002 +
69003 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
69004 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
69005 static const char *panic_later, *panic_param;
69006 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
69007 {
69008 int count = preempt_count();
69009 int ret;
69010 + const char *msg1 = "", *msg2 = "";
69011
69012 if (initcall_debug)
69013 ret = do_one_initcall_debug(fn);
69014 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
69015 sprintf(msgbuf, "error code %d ", ret);
69016
69017 if (preempt_count() != count) {
69018 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
69019 + msg1 = " preemption imbalance";
69020 preempt_count() = count;
69021 }
69022 if (irqs_disabled()) {
69023 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
69024 + msg2 = " disabled interrupts";
69025 local_irq_enable();
69026 }
69027 - if (msgbuf[0]) {
69028 - printk("initcall %pF returned with %s\n", fn, msgbuf);
69029 + if (msgbuf[0] || *msg1 || *msg2) {
69030 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
69031 }
69032
69033 return ret;
69034 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
69035 "late",
69036 };
69037
69038 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69039 +u64 latent_entropy;
69040 +#endif
69041 +
69042 static void __init do_initcall_level(int level)
69043 {
69044 extern const struct kernel_param __start___param[], __stop___param[];
69045 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
69046 level, level,
69047 &repair_env_string);
69048
69049 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
69050 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
69051 do_one_initcall(*fn);
69052 +
69053 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69054 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69055 +#endif
69056 +
69057 + }
69058 }
69059
69060 static void __init do_initcalls(void)
69061 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
69062 {
69063 initcall_t *fn;
69064
69065 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
69066 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
69067 do_one_initcall(*fn);
69068 +
69069 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69070 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69071 +#endif
69072 +
69073 + }
69074 }
69075
69076 static int run_init_process(const char *init_filename)
69077 @@ -877,7 +951,7 @@ static noinline void __init kernel_init_freeable(void)
69078 do_basic_setup();
69079
69080 /* Open the /dev/console on the rootfs, this should never fail */
69081 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
69082 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
69083 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
69084
69085 (void) sys_dup(0);
69086 @@ -890,11 +964,13 @@ static noinline void __init kernel_init_freeable(void)
69087 if (!ramdisk_execute_command)
69088 ramdisk_execute_command = "/init";
69089
69090 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
69091 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
69092 ramdisk_execute_command = NULL;
69093 prepare_namespace();
69094 }
69095
69096 + grsecurity_init();
69097 +
69098 /*
69099 * Ok, we have completed the initial bootup, and
69100 * we're essentially up and running. Get rid of the
69101 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
69102 index 71a3ca1..cc330ee 100644
69103 --- a/ipc/mqueue.c
69104 +++ b/ipc/mqueue.c
69105 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
69106 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
69107 info->attr.mq_msgsize);
69108
69109 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
69110 spin_lock(&mq_lock);
69111 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
69112 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
69113 diff --git a/ipc/msg.c b/ipc/msg.c
69114 index 950572f..266c15f 100644
69115 --- a/ipc/msg.c
69116 +++ b/ipc/msg.c
69117 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
69118 return security_msg_queue_associate(msq, msgflg);
69119 }
69120
69121 +static struct ipc_ops msg_ops = {
69122 + .getnew = newque,
69123 + .associate = msg_security,
69124 + .more_checks = NULL
69125 +};
69126 +
69127 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
69128 {
69129 struct ipc_namespace *ns;
69130 - struct ipc_ops msg_ops;
69131 struct ipc_params msg_params;
69132
69133 ns = current->nsproxy->ipc_ns;
69134
69135 - msg_ops.getnew = newque;
69136 - msg_ops.associate = msg_security;
69137 - msg_ops.more_checks = NULL;
69138 -
69139 msg_params.key = key;
69140 msg_params.flg = msgflg;
69141
69142 diff --git a/ipc/sem.c b/ipc/sem.c
69143 index 58d31f1..cce7a55 100644
69144 --- a/ipc/sem.c
69145 +++ b/ipc/sem.c
69146 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
69147 return 0;
69148 }
69149
69150 +static struct ipc_ops sem_ops = {
69151 + .getnew = newary,
69152 + .associate = sem_security,
69153 + .more_checks = sem_more_checks
69154 +};
69155 +
69156 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69157 {
69158 struct ipc_namespace *ns;
69159 - struct ipc_ops sem_ops;
69160 struct ipc_params sem_params;
69161
69162 ns = current->nsproxy->ipc_ns;
69163 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69164 if (nsems < 0 || nsems > ns->sc_semmsl)
69165 return -EINVAL;
69166
69167 - sem_ops.getnew = newary;
69168 - sem_ops.associate = sem_security;
69169 - sem_ops.more_checks = sem_more_checks;
69170 -
69171 sem_params.key = key;
69172 sem_params.flg = semflg;
69173 sem_params.u.nsems = nsems;
69174 diff --git a/ipc/shm.c b/ipc/shm.c
69175 index 4fa6d8f..38dfd0c 100644
69176 --- a/ipc/shm.c
69177 +++ b/ipc/shm.c
69178 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
69179 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
69180 #endif
69181
69182 +#ifdef CONFIG_GRKERNSEC
69183 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69184 + const time_t shm_createtime, const uid_t cuid,
69185 + const int shmid);
69186 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69187 + const time_t shm_createtime);
69188 +#endif
69189 +
69190 void shm_init_ns(struct ipc_namespace *ns)
69191 {
69192 ns->shm_ctlmax = SHMMAX;
69193 @@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
69194 shp->shm_lprid = 0;
69195 shp->shm_atim = shp->shm_dtim = 0;
69196 shp->shm_ctim = get_seconds();
69197 +#ifdef CONFIG_GRKERNSEC
69198 + {
69199 + struct timespec timeval;
69200 + do_posix_clock_monotonic_gettime(&timeval);
69201 +
69202 + shp->shm_createtime = timeval.tv_sec;
69203 + }
69204 +#endif
69205 shp->shm_segsz = size;
69206 shp->shm_nattch = 0;
69207 shp->shm_file = file;
69208 @@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
69209 return 0;
69210 }
69211
69212 +static struct ipc_ops shm_ops = {
69213 + .getnew = newseg,
69214 + .associate = shm_security,
69215 + .more_checks = shm_more_checks
69216 +};
69217 +
69218 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
69219 {
69220 struct ipc_namespace *ns;
69221 - struct ipc_ops shm_ops;
69222 struct ipc_params shm_params;
69223
69224 ns = current->nsproxy->ipc_ns;
69225
69226 - shm_ops.getnew = newseg;
69227 - shm_ops.associate = shm_security;
69228 - shm_ops.more_checks = shm_more_checks;
69229 -
69230 shm_params.key = key;
69231 shm_params.flg = shmflg;
69232 shm_params.u.size = size;
69233 @@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69234 f_mode = FMODE_READ | FMODE_WRITE;
69235 }
69236 if (shmflg & SHM_EXEC) {
69237 +
69238 +#ifdef CONFIG_PAX_MPROTECT
69239 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
69240 + goto out;
69241 +#endif
69242 +
69243 prot |= PROT_EXEC;
69244 acc_mode |= S_IXUGO;
69245 }
69246 @@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69247 if (err)
69248 goto out_unlock;
69249
69250 +#ifdef CONFIG_GRKERNSEC
69251 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
69252 + shp->shm_perm.cuid, shmid) ||
69253 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
69254 + err = -EACCES;
69255 + goto out_unlock;
69256 + }
69257 +#endif
69258 +
69259 path = shp->shm_file->f_path;
69260 path_get(&path);
69261 shp->shm_nattch++;
69262 +#ifdef CONFIG_GRKERNSEC
69263 + shp->shm_lapid = current->pid;
69264 +#endif
69265 size = i_size_read(path.dentry->d_inode);
69266 shm_unlock(shp);
69267
69268 diff --git a/kernel/acct.c b/kernel/acct.c
69269 index 051e071..15e0920 100644
69270 --- a/kernel/acct.c
69271 +++ b/kernel/acct.c
69272 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
69273 */
69274 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
69275 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
69276 - file->f_op->write(file, (char *)&ac,
69277 + file->f_op->write(file, (char __force_user *)&ac,
69278 sizeof(acct_t), &file->f_pos);
69279 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
69280 set_fs(fs);
69281 diff --git a/kernel/audit.c b/kernel/audit.c
69282 index d596e53..dbef3c3 100644
69283 --- a/kernel/audit.c
69284 +++ b/kernel/audit.c
69285 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
69286 3) suppressed due to audit_rate_limit
69287 4) suppressed due to audit_backlog_limit
69288 */
69289 -static atomic_t audit_lost = ATOMIC_INIT(0);
69290 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
69291
69292 /* The netlink socket. */
69293 static struct sock *audit_sock;
69294 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
69295 unsigned long now;
69296 int print;
69297
69298 - atomic_inc(&audit_lost);
69299 + atomic_inc_unchecked(&audit_lost);
69300
69301 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
69302
69303 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
69304 printk(KERN_WARNING
69305 "audit: audit_lost=%d audit_rate_limit=%d "
69306 "audit_backlog_limit=%d\n",
69307 - atomic_read(&audit_lost),
69308 + atomic_read_unchecked(&audit_lost),
69309 audit_rate_limit,
69310 audit_backlog_limit);
69311 audit_panic(message);
69312 @@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
69313 status_set.pid = audit_pid;
69314 status_set.rate_limit = audit_rate_limit;
69315 status_set.backlog_limit = audit_backlog_limit;
69316 - status_set.lost = atomic_read(&audit_lost);
69317 + status_set.lost = atomic_read_unchecked(&audit_lost);
69318 status_set.backlog = skb_queue_len(&audit_skb_queue);
69319 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
69320 &status_set, sizeof(status_set));
69321 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
69322 index a371f85..da826c1 100644
69323 --- a/kernel/auditsc.c
69324 +++ b/kernel/auditsc.c
69325 @@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
69326 }
69327
69328 /* global counter which is incremented every time something logs in */
69329 -static atomic_t session_id = ATOMIC_INIT(0);
69330 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
69331
69332 /**
69333 * audit_set_loginuid - set current task's audit_context loginuid
69334 @@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
69335 return -EPERM;
69336 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
69337
69338 - sessionid = atomic_inc_return(&session_id);
69339 + sessionid = atomic_inc_return_unchecked(&session_id);
69340 if (context && context->in_syscall) {
69341 struct audit_buffer *ab;
69342
69343 diff --git a/kernel/capability.c b/kernel/capability.c
69344 index 493d972..f87dfbd 100644
69345 --- a/kernel/capability.c
69346 +++ b/kernel/capability.c
69347 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
69348 * before modification is attempted and the application
69349 * fails.
69350 */
69351 + if (tocopy > ARRAY_SIZE(kdata))
69352 + return -EFAULT;
69353 +
69354 if (copy_to_user(dataptr, kdata, tocopy
69355 * sizeof(struct __user_cap_data_struct))) {
69356 return -EFAULT;
69357 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
69358 int ret;
69359
69360 rcu_read_lock();
69361 - ret = security_capable(__task_cred(t), ns, cap);
69362 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
69363 + gr_task_is_capable(t, __task_cred(t), cap);
69364 rcu_read_unlock();
69365
69366 - return (ret == 0);
69367 + return ret;
69368 }
69369
69370 /**
69371 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
69372 int ret;
69373
69374 rcu_read_lock();
69375 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
69376 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
69377 rcu_read_unlock();
69378
69379 - return (ret == 0);
69380 + return ret;
69381 }
69382
69383 /**
69384 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
69385 BUG();
69386 }
69387
69388 - if (security_capable(current_cred(), ns, cap) == 0) {
69389 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
69390 current->flags |= PF_SUPERPRIV;
69391 return true;
69392 }
69393 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
69394 }
69395 EXPORT_SYMBOL(ns_capable);
69396
69397 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
69398 +{
69399 + if (unlikely(!cap_valid(cap))) {
69400 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
69401 + BUG();
69402 + }
69403 +
69404 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
69405 + current->flags |= PF_SUPERPRIV;
69406 + return true;
69407 + }
69408 + return false;
69409 +}
69410 +EXPORT_SYMBOL(ns_capable_nolog);
69411 +
69412 /**
69413 * capable - Determine if the current task has a superior capability in effect
69414 * @cap: The capability to be tested for
69415 @@ -408,6 +427,12 @@ bool capable(int cap)
69416 }
69417 EXPORT_SYMBOL(capable);
69418
69419 +bool capable_nolog(int cap)
69420 +{
69421 + return ns_capable_nolog(&init_user_ns, cap);
69422 +}
69423 +EXPORT_SYMBOL(capable_nolog);
69424 +
69425 /**
69426 * nsown_capable - Check superior capability to one's own user_ns
69427 * @cap: The capability in question
69428 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
69429
69430 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69431 }
69432 +
69433 +bool inode_capable_nolog(const struct inode *inode, int cap)
69434 +{
69435 + struct user_namespace *ns = current_user_ns();
69436 +
69437 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69438 +}
69439 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
69440 index 4855892..30d23b4 100644
69441 --- a/kernel/cgroup.c
69442 +++ b/kernel/cgroup.c
69443 @@ -5535,7 +5535,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
69444 struct css_set *cg = link->cg;
69445 struct task_struct *task;
69446 int count = 0;
69447 - seq_printf(seq, "css_set %p\n", cg);
69448 + seq_printf(seq, "css_set %pK\n", cg);
69449 list_for_each_entry(task, &cg->tasks, cg_list) {
69450 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
69451 seq_puts(seq, " ...\n");
69452 diff --git a/kernel/compat.c b/kernel/compat.c
69453 index 36700e9..73d770c 100644
69454 --- a/kernel/compat.c
69455 +++ b/kernel/compat.c
69456 @@ -13,6 +13,7 @@
69457
69458 #include <linux/linkage.h>
69459 #include <linux/compat.h>
69460 +#include <linux/module.h>
69461 #include <linux/errno.h>
69462 #include <linux/time.h>
69463 #include <linux/signal.h>
69464 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
69465 mm_segment_t oldfs;
69466 long ret;
69467
69468 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
69469 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
69470 oldfs = get_fs();
69471 set_fs(KERNEL_DS);
69472 ret = hrtimer_nanosleep_restart(restart);
69473 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
69474 oldfs = get_fs();
69475 set_fs(KERNEL_DS);
69476 ret = hrtimer_nanosleep(&tu,
69477 - rmtp ? (struct timespec __user *)&rmt : NULL,
69478 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
69479 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
69480 set_fs(oldfs);
69481
69482 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
69483 mm_segment_t old_fs = get_fs();
69484
69485 set_fs(KERNEL_DS);
69486 - ret = sys_sigpending((old_sigset_t __user *) &s);
69487 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
69488 set_fs(old_fs);
69489 if (ret == 0)
69490 ret = put_user(s, set);
69491 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
69492 mm_segment_t old_fs = get_fs();
69493
69494 set_fs(KERNEL_DS);
69495 - ret = sys_old_getrlimit(resource, &r);
69496 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
69497 set_fs(old_fs);
69498
69499 if (!ret) {
69500 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
69501 mm_segment_t old_fs = get_fs();
69502
69503 set_fs(KERNEL_DS);
69504 - ret = sys_getrusage(who, (struct rusage __user *) &r);
69505 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
69506 set_fs(old_fs);
69507
69508 if (ret)
69509 @@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
69510 set_fs (KERNEL_DS);
69511 ret = sys_wait4(pid,
69512 (stat_addr ?
69513 - (unsigned int __user *) &status : NULL),
69514 - options, (struct rusage __user *) &r);
69515 + (unsigned int __force_user *) &status : NULL),
69516 + options, (struct rusage __force_user *) &r);
69517 set_fs (old_fs);
69518
69519 if (ret > 0) {
69520 @@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
69521 memset(&info, 0, sizeof(info));
69522
69523 set_fs(KERNEL_DS);
69524 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
69525 - uru ? (struct rusage __user *)&ru : NULL);
69526 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
69527 + uru ? (struct rusage __force_user *)&ru : NULL);
69528 set_fs(old_fs);
69529
69530 if ((ret < 0) || (info.si_signo == 0))
69531 @@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
69532 oldfs = get_fs();
69533 set_fs(KERNEL_DS);
69534 err = sys_timer_settime(timer_id, flags,
69535 - (struct itimerspec __user *) &newts,
69536 - (struct itimerspec __user *) &oldts);
69537 + (struct itimerspec __force_user *) &newts,
69538 + (struct itimerspec __force_user *) &oldts);
69539 set_fs(oldfs);
69540 if (!err && old && put_compat_itimerspec(old, &oldts))
69541 return -EFAULT;
69542 @@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
69543 oldfs = get_fs();
69544 set_fs(KERNEL_DS);
69545 err = sys_timer_gettime(timer_id,
69546 - (struct itimerspec __user *) &ts);
69547 + (struct itimerspec __force_user *) &ts);
69548 set_fs(oldfs);
69549 if (!err && put_compat_itimerspec(setting, &ts))
69550 return -EFAULT;
69551 @@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
69552 oldfs = get_fs();
69553 set_fs(KERNEL_DS);
69554 err = sys_clock_settime(which_clock,
69555 - (struct timespec __user *) &ts);
69556 + (struct timespec __force_user *) &ts);
69557 set_fs(oldfs);
69558 return err;
69559 }
69560 @@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
69561 oldfs = get_fs();
69562 set_fs(KERNEL_DS);
69563 err = sys_clock_gettime(which_clock,
69564 - (struct timespec __user *) &ts);
69565 + (struct timespec __force_user *) &ts);
69566 set_fs(oldfs);
69567 if (!err && put_compat_timespec(&ts, tp))
69568 return -EFAULT;
69569 @@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
69570
69571 oldfs = get_fs();
69572 set_fs(KERNEL_DS);
69573 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
69574 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
69575 set_fs(oldfs);
69576
69577 err = compat_put_timex(utp, &txc);
69578 @@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
69579 oldfs = get_fs();
69580 set_fs(KERNEL_DS);
69581 err = sys_clock_getres(which_clock,
69582 - (struct timespec __user *) &ts);
69583 + (struct timespec __force_user *) &ts);
69584 set_fs(oldfs);
69585 if (!err && tp && put_compat_timespec(&ts, tp))
69586 return -EFAULT;
69587 @@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
69588 long err;
69589 mm_segment_t oldfs;
69590 struct timespec tu;
69591 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
69592 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
69593
69594 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
69595 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
69596 oldfs = get_fs();
69597 set_fs(KERNEL_DS);
69598 err = clock_nanosleep_restart(restart);
69599 @@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
69600 oldfs = get_fs();
69601 set_fs(KERNEL_DS);
69602 err = sys_clock_nanosleep(which_clock, flags,
69603 - (struct timespec __user *) &in,
69604 - (struct timespec __user *) &out);
69605 + (struct timespec __force_user *) &in,
69606 + (struct timespec __force_user *) &out);
69607 set_fs(oldfs);
69608
69609 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
69610 diff --git a/kernel/configs.c b/kernel/configs.c
69611 index 42e8fa0..9e7406b 100644
69612 --- a/kernel/configs.c
69613 +++ b/kernel/configs.c
69614 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
69615 struct proc_dir_entry *entry;
69616
69617 /* create the current config file */
69618 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
69619 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
69620 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
69621 + &ikconfig_file_ops);
69622 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69623 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
69624 + &ikconfig_file_ops);
69625 +#endif
69626 +#else
69627 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
69628 &ikconfig_file_ops);
69629 +#endif
69630 +
69631 if (!entry)
69632 return -ENOMEM;
69633
69634 diff --git a/kernel/cred.c b/kernel/cred.c
69635 index e0573a4..eefe488 100644
69636 --- a/kernel/cred.c
69637 +++ b/kernel/cred.c
69638 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
69639 validate_creds(cred);
69640 alter_cred_subscribers(cred, -1);
69641 put_cred(cred);
69642 +
69643 +#ifdef CONFIG_GRKERNSEC_SETXID
69644 + cred = (struct cred *) tsk->delayed_cred;
69645 + if (cred != NULL) {
69646 + tsk->delayed_cred = NULL;
69647 + validate_creds(cred);
69648 + alter_cred_subscribers(cred, -1);
69649 + put_cred(cred);
69650 + }
69651 +#endif
69652 }
69653
69654 /**
69655 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
69656 * Always returns 0 thus allowing this function to be tail-called at the end
69657 * of, say, sys_setgid().
69658 */
69659 -int commit_creds(struct cred *new)
69660 +static int __commit_creds(struct cred *new)
69661 {
69662 struct task_struct *task = current;
69663 const struct cred *old = task->real_cred;
69664 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
69665
69666 get_cred(new); /* we will require a ref for the subj creds too */
69667
69668 + gr_set_role_label(task, new->uid, new->gid);
69669 +
69670 /* dumpability changes */
69671 if (!uid_eq(old->euid, new->euid) ||
69672 !gid_eq(old->egid, new->egid) ||
69673 @@ -479,6 +491,101 @@ int commit_creds(struct cred *new)
69674 put_cred(old);
69675 return 0;
69676 }
69677 +#ifdef CONFIG_GRKERNSEC_SETXID
69678 +extern int set_user(struct cred *new);
69679 +
69680 +void gr_delayed_cred_worker(void)
69681 +{
69682 + const struct cred *new = current->delayed_cred;
69683 + struct cred *ncred;
69684 +
69685 + current->delayed_cred = NULL;
69686 +
69687 + if (current_uid() && new != NULL) {
69688 + // from doing get_cred on it when queueing this
69689 + put_cred(new);
69690 + return;
69691 + } else if (new == NULL)
69692 + return;
69693 +
69694 + ncred = prepare_creds();
69695 + if (!ncred)
69696 + goto die;
69697 + // uids
69698 + ncred->uid = new->uid;
69699 + ncred->euid = new->euid;
69700 + ncred->suid = new->suid;
69701 + ncred->fsuid = new->fsuid;
69702 + // gids
69703 + ncred->gid = new->gid;
69704 + ncred->egid = new->egid;
69705 + ncred->sgid = new->sgid;
69706 + ncred->fsgid = new->fsgid;
69707 + // groups
69708 + if (set_groups(ncred, new->group_info) < 0) {
69709 + abort_creds(ncred);
69710 + goto die;
69711 + }
69712 + // caps
69713 + ncred->securebits = new->securebits;
69714 + ncred->cap_inheritable = new->cap_inheritable;
69715 + ncred->cap_permitted = new->cap_permitted;
69716 + ncred->cap_effective = new->cap_effective;
69717 + ncred->cap_bset = new->cap_bset;
69718 +
69719 + if (set_user(ncred)) {
69720 + abort_creds(ncred);
69721 + goto die;
69722 + }
69723 +
69724 + // from doing get_cred on it when queueing this
69725 + put_cred(new);
69726 +
69727 + __commit_creds(ncred);
69728 + return;
69729 +die:
69730 + // from doing get_cred on it when queueing this
69731 + put_cred(new);
69732 + do_group_exit(SIGKILL);
69733 +}
69734 +#endif
69735 +
69736 +int commit_creds(struct cred *new)
69737 +{
69738 +#ifdef CONFIG_GRKERNSEC_SETXID
69739 + int ret;
69740 + int schedule_it = 0;
69741 + struct task_struct *t;
69742 +
69743 + /* we won't get called with tasklist_lock held for writing
69744 + and interrupts disabled as the cred struct in that case is
69745 + init_cred
69746 + */
69747 + if (grsec_enable_setxid && !current_is_single_threaded() &&
69748 + !current_uid() && new->uid) {
69749 + schedule_it = 1;
69750 + }
69751 + ret = __commit_creds(new);
69752 + if (schedule_it) {
69753 + rcu_read_lock();
69754 + read_lock(&tasklist_lock);
69755 + for (t = next_thread(current); t != current;
69756 + t = next_thread(t)) {
69757 + if (t->delayed_cred == NULL) {
69758 + t->delayed_cred = get_cred(new);
69759 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69760 + set_tsk_need_resched(t);
69761 + }
69762 + }
69763 + read_unlock(&tasklist_lock);
69764 + rcu_read_unlock();
69765 + }
69766 + return ret;
69767 +#else
69768 + return __commit_creds(new);
69769 +#endif
69770 +}
69771 +
69772 EXPORT_SYMBOL(commit_creds);
69773
69774 /**
69775 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69776 index 9a61738..c5c8f3a 100644
69777 --- a/kernel/debug/debug_core.c
69778 +++ b/kernel/debug/debug_core.c
69779 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69780 */
69781 static atomic_t masters_in_kgdb;
69782 static atomic_t slaves_in_kgdb;
69783 -static atomic_t kgdb_break_tasklet_var;
69784 +static atomic_unchecked_t kgdb_break_tasklet_var;
69785 atomic_t kgdb_setting_breakpoint;
69786
69787 struct task_struct *kgdb_usethread;
69788 @@ -132,7 +132,7 @@ int kgdb_single_step;
69789 static pid_t kgdb_sstep_pid;
69790
69791 /* to keep track of the CPU which is doing the single stepping*/
69792 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69793 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69794
69795 /*
69796 * If you are debugging a problem where roundup (the collection of
69797 @@ -540,7 +540,7 @@ return_normal:
69798 * kernel will only try for the value of sstep_tries before
69799 * giving up and continuing on.
69800 */
69801 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69802 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69803 (kgdb_info[cpu].task &&
69804 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69805 atomic_set(&kgdb_active, -1);
69806 @@ -634,8 +634,8 @@ cpu_master_loop:
69807 }
69808
69809 kgdb_restore:
69810 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69811 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69812 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69813 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69814 if (kgdb_info[sstep_cpu].task)
69815 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69816 else
69817 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69818 static void kgdb_tasklet_bpt(unsigned long ing)
69819 {
69820 kgdb_breakpoint();
69821 - atomic_set(&kgdb_break_tasklet_var, 0);
69822 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69823 }
69824
69825 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69826
69827 void kgdb_schedule_breakpoint(void)
69828 {
69829 - if (atomic_read(&kgdb_break_tasklet_var) ||
69830 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69831 atomic_read(&kgdb_active) != -1 ||
69832 atomic_read(&kgdb_setting_breakpoint))
69833 return;
69834 - atomic_inc(&kgdb_break_tasklet_var);
69835 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
69836 tasklet_schedule(&kgdb_tasklet_breakpoint);
69837 }
69838 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69839 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69840 index 8875254..7cf4928 100644
69841 --- a/kernel/debug/kdb/kdb_main.c
69842 +++ b/kernel/debug/kdb/kdb_main.c
69843 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69844 continue;
69845
69846 kdb_printf("%-20s%8u 0x%p ", mod->name,
69847 - mod->core_size, (void *)mod);
69848 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
69849 #ifdef CONFIG_MODULE_UNLOAD
69850 kdb_printf("%4ld ", module_refcount(mod));
69851 #endif
69852 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69853 kdb_printf(" (Loading)");
69854 else
69855 kdb_printf(" (Live)");
69856 - kdb_printf(" 0x%p", mod->module_core);
69857 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69858
69859 #ifdef CONFIG_MODULE_UNLOAD
69860 {
69861 diff --git a/kernel/events/core.c b/kernel/events/core.c
69862 index 7b6646a..3cb1135 100644
69863 --- a/kernel/events/core.c
69864 +++ b/kernel/events/core.c
69865 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69866 return 0;
69867 }
69868
69869 -static atomic64_t perf_event_id;
69870 +static atomic64_unchecked_t perf_event_id;
69871
69872 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69873 enum event_type_t event_type);
69874 @@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
69875
69876 static inline u64 perf_event_count(struct perf_event *event)
69877 {
69878 - return local64_read(&event->count) + atomic64_read(&event->child_count);
69879 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69880 }
69881
69882 static u64 perf_event_read(struct perf_event *event)
69883 @@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69884 mutex_lock(&event->child_mutex);
69885 total += perf_event_read(event);
69886 *enabled += event->total_time_enabled +
69887 - atomic64_read(&event->child_total_time_enabled);
69888 + atomic64_read_unchecked(&event->child_total_time_enabled);
69889 *running += event->total_time_running +
69890 - atomic64_read(&event->child_total_time_running);
69891 + atomic64_read_unchecked(&event->child_total_time_running);
69892
69893 list_for_each_entry(child, &event->child_list, child_list) {
69894 total += perf_event_read(child);
69895 @@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
69896 userpg->offset -= local64_read(&event->hw.prev_count);
69897
69898 userpg->time_enabled = enabled +
69899 - atomic64_read(&event->child_total_time_enabled);
69900 + atomic64_read_unchecked(&event->child_total_time_enabled);
69901
69902 userpg->time_running = running +
69903 - atomic64_read(&event->child_total_time_running);
69904 + atomic64_read_unchecked(&event->child_total_time_running);
69905
69906 arch_perf_update_userpage(userpg, now);
69907
69908 @@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69909 values[n++] = perf_event_count(event);
69910 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69911 values[n++] = enabled +
69912 - atomic64_read(&event->child_total_time_enabled);
69913 + atomic64_read_unchecked(&event->child_total_time_enabled);
69914 }
69915 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69916 values[n++] = running +
69917 - atomic64_read(&event->child_total_time_running);
69918 + atomic64_read_unchecked(&event->child_total_time_running);
69919 }
69920 if (read_format & PERF_FORMAT_ID)
69921 values[n++] = primary_event_id(event);
69922 @@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69923 * need to add enough zero bytes after the string to handle
69924 * the 64bit alignment we do later.
69925 */
69926 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69927 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
69928 if (!buf) {
69929 name = strncpy(tmp, "//enomem", sizeof(tmp));
69930 goto got_name;
69931 }
69932 - name = d_path(&file->f_path, buf, PATH_MAX);
69933 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69934 if (IS_ERR(name)) {
69935 name = strncpy(tmp, "//toolong", sizeof(tmp));
69936 goto got_name;
69937 @@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69938 event->parent = parent_event;
69939
69940 event->ns = get_pid_ns(task_active_pid_ns(current));
69941 - event->id = atomic64_inc_return(&perf_event_id);
69942 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
69943
69944 event->state = PERF_EVENT_STATE_INACTIVE;
69945
69946 @@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
69947 /*
69948 * Add back the child's count to the parent's count:
69949 */
69950 - atomic64_add(child_val, &parent_event->child_count);
69951 - atomic64_add(child_event->total_time_enabled,
69952 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69953 + atomic64_add_unchecked(child_event->total_time_enabled,
69954 &parent_event->child_total_time_enabled);
69955 - atomic64_add(child_event->total_time_running,
69956 + atomic64_add_unchecked(child_event->total_time_running,
69957 &parent_event->child_total_time_running);
69958
69959 /*
69960 diff --git a/kernel/exit.c b/kernel/exit.c
69961 index b4df219..f13c02d 100644
69962 --- a/kernel/exit.c
69963 +++ b/kernel/exit.c
69964 @@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
69965 struct task_struct *leader;
69966 int zap_leader;
69967 repeat:
69968 +#ifdef CONFIG_NET
69969 + gr_del_task_from_ip_table(p);
69970 +#endif
69971 +
69972 /* don't need to get the RCU readlock here - the process is dead and
69973 * can't be modifying its own credentials. But shut RCU-lockdep up */
69974 rcu_read_lock();
69975 @@ -338,7 +342,7 @@ int allow_signal(int sig)
69976 * know it'll be handled, so that they don't get converted to
69977 * SIGKILL or just silently dropped.
69978 */
69979 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69980 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69981 recalc_sigpending();
69982 spin_unlock_irq(&current->sighand->siglock);
69983 return 0;
69984 @@ -708,6 +712,8 @@ void do_exit(long code)
69985 struct task_struct *tsk = current;
69986 int group_dead;
69987
69988 + set_fs(USER_DS);
69989 +
69990 profile_task_exit(tsk);
69991
69992 WARN_ON(blk_needs_flush_plug(tsk));
69993 @@ -724,7 +730,6 @@ void do_exit(long code)
69994 * mm_release()->clear_child_tid() from writing to a user-controlled
69995 * kernel address.
69996 */
69997 - set_fs(USER_DS);
69998
69999 ptrace_event(PTRACE_EVENT_EXIT, code);
70000
70001 @@ -783,6 +788,9 @@ void do_exit(long code)
70002 tsk->exit_code = code;
70003 taskstats_exit(tsk, group_dead);
70004
70005 + gr_acl_handle_psacct(tsk, code);
70006 + gr_acl_handle_exit();
70007 +
70008 exit_mm(tsk);
70009
70010 if (group_dead)
70011 @@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
70012 * Take down every thread in the group. This is called by fatal signals
70013 * as well as by sys_exit_group (below).
70014 */
70015 -void
70016 +__noreturn void
70017 do_group_exit(int exit_code)
70018 {
70019 struct signal_struct *sig = current->signal;
70020 diff --git a/kernel/fork.c b/kernel/fork.c
70021 index c535f33..1d768f9 100644
70022 --- a/kernel/fork.c
70023 +++ b/kernel/fork.c
70024 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70025 *stackend = STACK_END_MAGIC; /* for overflow detection */
70026
70027 #ifdef CONFIG_CC_STACKPROTECTOR
70028 - tsk->stack_canary = get_random_int();
70029 + tsk->stack_canary = pax_get_random_long();
70030 #endif
70031
70032 /*
70033 @@ -344,13 +344,81 @@ free_tsk:
70034 }
70035
70036 #ifdef CONFIG_MMU
70037 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
70038 +{
70039 + struct vm_area_struct *tmp;
70040 + unsigned long charge;
70041 + struct mempolicy *pol;
70042 + struct file *file;
70043 +
70044 + charge = 0;
70045 + if (mpnt->vm_flags & VM_ACCOUNT) {
70046 + unsigned long len = vma_pages(mpnt);
70047 +
70048 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70049 + goto fail_nomem;
70050 + charge = len;
70051 + }
70052 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70053 + if (!tmp)
70054 + goto fail_nomem;
70055 + *tmp = *mpnt;
70056 + tmp->vm_mm = mm;
70057 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
70058 + pol = mpol_dup(vma_policy(mpnt));
70059 + if (IS_ERR(pol))
70060 + goto fail_nomem_policy;
70061 + vma_set_policy(tmp, pol);
70062 + if (anon_vma_fork(tmp, mpnt))
70063 + goto fail_nomem_anon_vma_fork;
70064 + tmp->vm_flags &= ~VM_LOCKED;
70065 + tmp->vm_next = tmp->vm_prev = NULL;
70066 + tmp->vm_mirror = NULL;
70067 + file = tmp->vm_file;
70068 + if (file) {
70069 + struct inode *inode = file->f_path.dentry->d_inode;
70070 + struct address_space *mapping = file->f_mapping;
70071 +
70072 + get_file(file);
70073 + if (tmp->vm_flags & VM_DENYWRITE)
70074 + atomic_dec(&inode->i_writecount);
70075 + mutex_lock(&mapping->i_mmap_mutex);
70076 + if (tmp->vm_flags & VM_SHARED)
70077 + mapping->i_mmap_writable++;
70078 + flush_dcache_mmap_lock(mapping);
70079 + /* insert tmp into the share list, just after mpnt */
70080 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70081 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
70082 + else
70083 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
70084 + flush_dcache_mmap_unlock(mapping);
70085 + mutex_unlock(&mapping->i_mmap_mutex);
70086 + }
70087 +
70088 + /*
70089 + * Clear hugetlb-related page reserves for children. This only
70090 + * affects MAP_PRIVATE mappings. Faults generated by the child
70091 + * are not guaranteed to succeed, even if read-only
70092 + */
70093 + if (is_vm_hugetlb_page(tmp))
70094 + reset_vma_resv_huge_pages(tmp);
70095 +
70096 + return tmp;
70097 +
70098 +fail_nomem_anon_vma_fork:
70099 + mpol_put(pol);
70100 +fail_nomem_policy:
70101 + kmem_cache_free(vm_area_cachep, tmp);
70102 +fail_nomem:
70103 + vm_unacct_memory(charge);
70104 + return NULL;
70105 +}
70106 +
70107 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70108 {
70109 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
70110 struct rb_node **rb_link, *rb_parent;
70111 int retval;
70112 - unsigned long charge;
70113 - struct mempolicy *pol;
70114
70115 uprobe_start_dup_mmap();
70116 down_write(&oldmm->mmap_sem);
70117 @@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70118 mm->locked_vm = 0;
70119 mm->mmap = NULL;
70120 mm->mmap_cache = NULL;
70121 - mm->free_area_cache = oldmm->mmap_base;
70122 - mm->cached_hole_size = ~0UL;
70123 + mm->free_area_cache = oldmm->free_area_cache;
70124 + mm->cached_hole_size = oldmm->cached_hole_size;
70125 mm->map_count = 0;
70126 cpumask_clear(mm_cpumask(mm));
70127 mm->mm_rb = RB_ROOT;
70128 @@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70129
70130 prev = NULL;
70131 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
70132 - struct file *file;
70133 -
70134 if (mpnt->vm_flags & VM_DONTCOPY) {
70135 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
70136 -vma_pages(mpnt));
70137 continue;
70138 }
70139 - charge = 0;
70140 - if (mpnt->vm_flags & VM_ACCOUNT) {
70141 - unsigned long len = vma_pages(mpnt);
70142 -
70143 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70144 - goto fail_nomem;
70145 - charge = len;
70146 - }
70147 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70148 - if (!tmp)
70149 - goto fail_nomem;
70150 - *tmp = *mpnt;
70151 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
70152 - pol = mpol_dup(vma_policy(mpnt));
70153 - retval = PTR_ERR(pol);
70154 - if (IS_ERR(pol))
70155 - goto fail_nomem_policy;
70156 - vma_set_policy(tmp, pol);
70157 - tmp->vm_mm = mm;
70158 - if (anon_vma_fork(tmp, mpnt))
70159 - goto fail_nomem_anon_vma_fork;
70160 - tmp->vm_flags &= ~VM_LOCKED;
70161 - tmp->vm_next = tmp->vm_prev = NULL;
70162 - file = tmp->vm_file;
70163 - if (file) {
70164 - struct inode *inode = file->f_path.dentry->d_inode;
70165 - struct address_space *mapping = file->f_mapping;
70166 -
70167 - get_file(file);
70168 - if (tmp->vm_flags & VM_DENYWRITE)
70169 - atomic_dec(&inode->i_writecount);
70170 - mutex_lock(&mapping->i_mmap_mutex);
70171 - if (tmp->vm_flags & VM_SHARED)
70172 - mapping->i_mmap_writable++;
70173 - flush_dcache_mmap_lock(mapping);
70174 - /* insert tmp into the share list, just after mpnt */
70175 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70176 - vma_nonlinear_insert(tmp,
70177 - &mapping->i_mmap_nonlinear);
70178 - else
70179 - vma_interval_tree_insert_after(tmp, mpnt,
70180 - &mapping->i_mmap);
70181 - flush_dcache_mmap_unlock(mapping);
70182 - mutex_unlock(&mapping->i_mmap_mutex);
70183 + tmp = dup_vma(mm, oldmm, mpnt);
70184 + if (!tmp) {
70185 + retval = -ENOMEM;
70186 + goto out;
70187 }
70188
70189 /*
70190 @@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70191 if (retval)
70192 goto out;
70193 }
70194 +
70195 +#ifdef CONFIG_PAX_SEGMEXEC
70196 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70197 + struct vm_area_struct *mpnt_m;
70198 +
70199 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70200 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70201 +
70202 + if (!mpnt->vm_mirror)
70203 + continue;
70204 +
70205 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70206 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70207 + mpnt->vm_mirror = mpnt_m;
70208 + } else {
70209 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70210 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70211 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70212 + mpnt->vm_mirror->vm_mirror = mpnt;
70213 + }
70214 + }
70215 + BUG_ON(mpnt_m);
70216 + }
70217 +#endif
70218 +
70219 /* a new mm has just been created */
70220 arch_dup_mmap(oldmm, mm);
70221 retval = 0;
70222 @@ -472,14 +523,6 @@ out:
70223 up_write(&oldmm->mmap_sem);
70224 uprobe_end_dup_mmap();
70225 return retval;
70226 -fail_nomem_anon_vma_fork:
70227 - mpol_put(pol);
70228 -fail_nomem_policy:
70229 - kmem_cache_free(vm_area_cachep, tmp);
70230 -fail_nomem:
70231 - retval = -ENOMEM;
70232 - vm_unacct_memory(charge);
70233 - goto out;
70234 }
70235
70236 static inline int mm_alloc_pgd(struct mm_struct *mm)
70237 @@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
70238 return ERR_PTR(err);
70239
70240 mm = get_task_mm(task);
70241 - if (mm && mm != current->mm &&
70242 - !ptrace_may_access(task, mode)) {
70243 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
70244 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
70245 mmput(mm);
70246 mm = ERR_PTR(-EACCES);
70247 }
70248 @@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70249 spin_unlock(&fs->lock);
70250 return -EAGAIN;
70251 }
70252 - fs->users++;
70253 + atomic_inc(&fs->users);
70254 spin_unlock(&fs->lock);
70255 return 0;
70256 }
70257 tsk->fs = copy_fs_struct(fs);
70258 if (!tsk->fs)
70259 return -ENOMEM;
70260 + /* Carry through gr_chroot_dentry and is_chrooted instead
70261 + of recomputing it here. Already copied when the task struct
70262 + is duplicated. This allows pivot_root to not be treated as
70263 + a chroot
70264 + */
70265 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
70266 +
70267 return 0;
70268 }
70269
70270 @@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70271 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70272 #endif
70273 retval = -EAGAIN;
70274 +
70275 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70276 +
70277 if (atomic_read(&p->real_cred->user->processes) >=
70278 task_rlimit(p, RLIMIT_NPROC)) {
70279 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70280 @@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70281 goto bad_fork_free_pid;
70282 }
70283
70284 + /* synchronizes with gr_set_acls()
70285 + we need to call this past the point of no return for fork()
70286 + */
70287 + gr_copy_label(p);
70288 +
70289 if (clone_flags & CLONE_THREAD) {
70290 current->signal->nr_threads++;
70291 atomic_inc(&current->signal->live);
70292 @@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
70293 bad_fork_free:
70294 free_task(p);
70295 fork_out:
70296 + gr_log_forkfail(retval);
70297 +
70298 return ERR_PTR(retval);
70299 }
70300
70301 @@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
70302 return -EINVAL;
70303 }
70304
70305 +#ifdef CONFIG_GRKERNSEC
70306 + if (clone_flags & CLONE_NEWUSER) {
70307 + /*
70308 + * This doesn't really inspire confidence:
70309 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
70310 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
70311 + * Increases kernel attack surface in areas developers
70312 + * previously cared little about ("low importance due
70313 + * to requiring "root" capability")
70314 + * To be removed when this code receives *proper* review
70315 + */
70316 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
70317 + !capable(CAP_SETGID))
70318 + return -EPERM;
70319 + }
70320 +#endif
70321 +
70322 /*
70323 * Determine whether and which event to report to ptracer. When
70324 * called from kernel_thread or CLONE_UNTRACED is explicitly
70325 @@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
70326 if (clone_flags & CLONE_PARENT_SETTID)
70327 put_user(nr, parent_tidptr);
70328
70329 + gr_handle_brute_check();
70330 +
70331 if (clone_flags & CLONE_VFORK) {
70332 p->vfork_done = &vfork;
70333 init_completion(&vfork);
70334 @@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
70335 return 0;
70336
70337 /* don't need lock here; in the worst case we'll do useless copy */
70338 - if (fs->users == 1)
70339 + if (atomic_read(&fs->users) == 1)
70340 return 0;
70341
70342 *new_fsp = copy_fs_struct(fs);
70343 @@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
70344 fs = current->fs;
70345 spin_lock(&fs->lock);
70346 current->fs = new_fs;
70347 - if (--fs->users)
70348 + gr_set_chroot_entries(current, &current->fs->root);
70349 + if (atomic_dec_return(&fs->users))
70350 new_fs = NULL;
70351 else
70352 new_fs = fs;
70353 diff --git a/kernel/futex.c b/kernel/futex.c
70354 index 19eb089..b8c65ea 100644
70355 --- a/kernel/futex.c
70356 +++ b/kernel/futex.c
70357 @@ -54,6 +54,7 @@
70358 #include <linux/mount.h>
70359 #include <linux/pagemap.h>
70360 #include <linux/syscalls.h>
70361 +#include <linux/ptrace.h>
70362 #include <linux/signal.h>
70363 #include <linux/export.h>
70364 #include <linux/magic.h>
70365 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
70366 struct page *page, *page_head;
70367 int err, ro = 0;
70368
70369 +#ifdef CONFIG_PAX_SEGMEXEC
70370 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
70371 + return -EFAULT;
70372 +#endif
70373 +
70374 /*
70375 * The futex address must be "naturally" aligned.
70376 */
70377 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
70378 {
70379 u32 curval;
70380 int i;
70381 + mm_segment_t oldfs;
70382
70383 /*
70384 * This will fail and we want it. Some arch implementations do
70385 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
70386 * implementation, the non-functional ones will return
70387 * -ENOSYS.
70388 */
70389 + oldfs = get_fs();
70390 + set_fs(USER_DS);
70391 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
70392 futex_cmpxchg_enabled = 1;
70393 + set_fs(oldfs);
70394
70395 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
70396 plist_head_init(&futex_queues[i].chain);
70397 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
70398 index 9b22d03..6295b62 100644
70399 --- a/kernel/gcov/base.c
70400 +++ b/kernel/gcov/base.c
70401 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
70402 }
70403
70404 #ifdef CONFIG_MODULES
70405 -static inline int within(void *addr, void *start, unsigned long size)
70406 -{
70407 - return ((addr >= start) && (addr < start + size));
70408 -}
70409 -
70410 /* Update list and generate events when modules are unloaded. */
70411 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70412 void *data)
70413 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70414 prev = NULL;
70415 /* Remove entries located in module from linked list. */
70416 for (info = gcov_info_head; info; info = info->next) {
70417 - if (within(info, mod->module_core, mod->core_size)) {
70418 + if (within_module_core_rw((unsigned long)info, mod)) {
70419 if (prev)
70420 prev->next = info->next;
70421 else
70422 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
70423 index 6db7a5e..0d600bd 100644
70424 --- a/kernel/hrtimer.c
70425 +++ b/kernel/hrtimer.c
70426 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
70427 local_irq_restore(flags);
70428 }
70429
70430 -static void run_hrtimer_softirq(struct softirq_action *h)
70431 +static void run_hrtimer_softirq(void)
70432 {
70433 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
70434
70435 @@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
70436 return NOTIFY_OK;
70437 }
70438
70439 -static struct notifier_block __cpuinitdata hrtimers_nb = {
70440 +static struct notifier_block hrtimers_nb = {
70441 .notifier_call = hrtimer_cpu_notify,
70442 };
70443
70444 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
70445 index 60f48fa..7f3a770 100644
70446 --- a/kernel/jump_label.c
70447 +++ b/kernel/jump_label.c
70448 @@ -13,6 +13,7 @@
70449 #include <linux/sort.h>
70450 #include <linux/err.h>
70451 #include <linux/static_key.h>
70452 +#include <linux/mm.h>
70453
70454 #ifdef HAVE_JUMP_LABEL
70455
70456 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
70457
70458 size = (((unsigned long)stop - (unsigned long)start)
70459 / sizeof(struct jump_entry));
70460 + pax_open_kernel();
70461 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
70462 + pax_close_kernel();
70463 }
70464
70465 static void jump_label_update(struct static_key *key, int enable);
70466 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
70467 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
70468 struct jump_entry *iter;
70469
70470 + pax_open_kernel();
70471 for (iter = iter_start; iter < iter_stop; iter++) {
70472 if (within_module_init(iter->code, mod))
70473 iter->code = 0;
70474 }
70475 + pax_close_kernel();
70476 }
70477
70478 static int
70479 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
70480 index 2169fee..45c017a 100644
70481 --- a/kernel/kallsyms.c
70482 +++ b/kernel/kallsyms.c
70483 @@ -11,6 +11,9 @@
70484 * Changed the compression method from stem compression to "table lookup"
70485 * compression (see scripts/kallsyms.c for a more complete description)
70486 */
70487 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70488 +#define __INCLUDED_BY_HIDESYM 1
70489 +#endif
70490 #include <linux/kallsyms.h>
70491 #include <linux/module.h>
70492 #include <linux/init.h>
70493 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
70494
70495 static inline int is_kernel_inittext(unsigned long addr)
70496 {
70497 + if (system_state != SYSTEM_BOOTING)
70498 + return 0;
70499 +
70500 if (addr >= (unsigned long)_sinittext
70501 && addr <= (unsigned long)_einittext)
70502 return 1;
70503 return 0;
70504 }
70505
70506 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70507 +#ifdef CONFIG_MODULES
70508 +static inline int is_module_text(unsigned long addr)
70509 +{
70510 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
70511 + return 1;
70512 +
70513 + addr = ktla_ktva(addr);
70514 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
70515 +}
70516 +#else
70517 +static inline int is_module_text(unsigned long addr)
70518 +{
70519 + return 0;
70520 +}
70521 +#endif
70522 +#endif
70523 +
70524 static inline int is_kernel_text(unsigned long addr)
70525 {
70526 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
70527 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
70528
70529 static inline int is_kernel(unsigned long addr)
70530 {
70531 +
70532 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70533 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
70534 + return 1;
70535 +
70536 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
70537 +#else
70538 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
70539 +#endif
70540 +
70541 return 1;
70542 return in_gate_area_no_mm(addr);
70543 }
70544
70545 static int is_ksym_addr(unsigned long addr)
70546 {
70547 +
70548 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70549 + if (is_module_text(addr))
70550 + return 0;
70551 +#endif
70552 +
70553 if (all_var)
70554 return is_kernel(addr);
70555
70556 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
70557
70558 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
70559 {
70560 - iter->name[0] = '\0';
70561 iter->nameoff = get_symbol_offset(new_pos);
70562 iter->pos = new_pos;
70563 }
70564 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
70565 {
70566 struct kallsym_iter *iter = m->private;
70567
70568 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70569 + if (current_uid())
70570 + return 0;
70571 +#endif
70572 +
70573 /* Some debugging symbols have no name. Ignore them. */
70574 if (!iter->name[0])
70575 return 0;
70576 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
70577 */
70578 type = iter->exported ? toupper(iter->type) :
70579 tolower(iter->type);
70580 +
70581 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
70582 type, iter->name, iter->module_name);
70583 } else
70584 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
70585 struct kallsym_iter *iter;
70586 int ret;
70587
70588 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
70589 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
70590 if (!iter)
70591 return -ENOMEM;
70592 reset_iter(iter, 0);
70593 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
70594 index e30ac0f..3528cac 100644
70595 --- a/kernel/kcmp.c
70596 +++ b/kernel/kcmp.c
70597 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
70598 struct task_struct *task1, *task2;
70599 int ret;
70600
70601 +#ifdef CONFIG_GRKERNSEC
70602 + return -ENOSYS;
70603 +#endif
70604 +
70605 rcu_read_lock();
70606
70607 /*
70608 diff --git a/kernel/kexec.c b/kernel/kexec.c
70609 index 5e4bd78..00c5b91 100644
70610 --- a/kernel/kexec.c
70611 +++ b/kernel/kexec.c
70612 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
70613 unsigned long flags)
70614 {
70615 struct compat_kexec_segment in;
70616 - struct kexec_segment out, __user *ksegments;
70617 + struct kexec_segment out;
70618 + struct kexec_segment __user *ksegments;
70619 unsigned long i, result;
70620
70621 /* Don't allow clients that don't understand the native
70622 diff --git a/kernel/kmod.c b/kernel/kmod.c
70623 index 0023a87..3fe3781 100644
70624 --- a/kernel/kmod.c
70625 +++ b/kernel/kmod.c
70626 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
70627 kfree(info->argv);
70628 }
70629
70630 -static int call_modprobe(char *module_name, int wait)
70631 +static int call_modprobe(char *module_name, char *module_param, int wait)
70632 {
70633 static char *envp[] = {
70634 "HOME=/",
70635 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
70636 NULL
70637 };
70638
70639 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
70640 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
70641 if (!argv)
70642 goto out;
70643
70644 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
70645 argv[1] = "-q";
70646 argv[2] = "--";
70647 argv[3] = module_name; /* check free_modprobe_argv() */
70648 - argv[4] = NULL;
70649 + argv[4] = module_param;
70650 + argv[5] = NULL;
70651
70652 return call_usermodehelper_fns(modprobe_path, argv, envp,
70653 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
70654 @@ -120,9 +121,8 @@ out:
70655 * If module auto-loading support is disabled then this function
70656 * becomes a no-operation.
70657 */
70658 -int __request_module(bool wait, const char *fmt, ...)
70659 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
70660 {
70661 - va_list args;
70662 char module_name[MODULE_NAME_LEN];
70663 unsigned int max_modprobes;
70664 int ret;
70665 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
70666 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
70667 static int kmod_loop_msg;
70668
70669 - va_start(args, fmt);
70670 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
70671 - va_end(args);
70672 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
70673 if (ret >= MODULE_NAME_LEN)
70674 return -ENAMETOOLONG;
70675
70676 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
70677 if (ret)
70678 return ret;
70679
70680 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70681 + if (!current_uid()) {
70682 + /* hack to workaround consolekit/udisks stupidity */
70683 + read_lock(&tasklist_lock);
70684 + if (!strcmp(current->comm, "mount") &&
70685 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
70686 + read_unlock(&tasklist_lock);
70687 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
70688 + return -EPERM;
70689 + }
70690 + read_unlock(&tasklist_lock);
70691 + }
70692 +#endif
70693 +
70694 /* If modprobe needs a service that is in a module, we get a recursive
70695 * loop. Limit the number of running kmod threads to max_threads/2 or
70696 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70697 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70698
70699 trace_module_request(module_name, wait, _RET_IP_);
70700
70701 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70702 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70703
70704 atomic_dec(&kmod_concurrent);
70705 return ret;
70706 }
70707 +
70708 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70709 +{
70710 + va_list args;
70711 + int ret;
70712 +
70713 + va_start(args, fmt);
70714 + ret = ____request_module(wait, module_param, fmt, args);
70715 + va_end(args);
70716 +
70717 + return ret;
70718 +}
70719 +
70720 +int __request_module(bool wait, const char *fmt, ...)
70721 +{
70722 + va_list args;
70723 + int ret;
70724 +
70725 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70726 + if (current_uid()) {
70727 + char module_param[MODULE_NAME_LEN];
70728 +
70729 + memset(module_param, 0, sizeof(module_param));
70730 +
70731 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70732 +
70733 + va_start(args, fmt);
70734 + ret = ____request_module(wait, module_param, fmt, args);
70735 + va_end(args);
70736 +
70737 + return ret;
70738 + }
70739 +#endif
70740 +
70741 + va_start(args, fmt);
70742 + ret = ____request_module(wait, NULL, fmt, args);
70743 + va_end(args);
70744 +
70745 + return ret;
70746 +}
70747 +
70748 EXPORT_SYMBOL(__request_module);
70749 #endif /* CONFIG_MODULES */
70750
70751 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70752 *
70753 * Thus the __user pointer cast is valid here.
70754 */
70755 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
70756 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70757
70758 /*
70759 * If ret is 0, either ____call_usermodehelper failed and the
70760 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70761 index 098f396..fe85ff1 100644
70762 --- a/kernel/kprobes.c
70763 +++ b/kernel/kprobes.c
70764 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70765 * kernel image and loaded module images reside. This is required
70766 * so x86_64 can correctly handle the %rip-relative fixups.
70767 */
70768 - kip->insns = module_alloc(PAGE_SIZE);
70769 + kip->insns = module_alloc_exec(PAGE_SIZE);
70770 if (!kip->insns) {
70771 kfree(kip);
70772 return NULL;
70773 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70774 */
70775 if (!list_is_singular(&kip->list)) {
70776 list_del(&kip->list);
70777 - module_free(NULL, kip->insns);
70778 + module_free_exec(NULL, kip->insns);
70779 kfree(kip);
70780 }
70781 return 1;
70782 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70783 {
70784 int i, err = 0;
70785 unsigned long offset = 0, size = 0;
70786 - char *modname, namebuf[128];
70787 + char *modname, namebuf[KSYM_NAME_LEN];
70788 const char *symbol_name;
70789 void *addr;
70790 struct kprobe_blackpoint *kb;
70791 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70792 kprobe_type = "k";
70793
70794 if (sym)
70795 - seq_printf(pi, "%p %s %s+0x%x %s ",
70796 + seq_printf(pi, "%pK %s %s+0x%x %s ",
70797 p->addr, kprobe_type, sym, offset,
70798 (modname ? modname : " "));
70799 else
70800 - seq_printf(pi, "%p %s %p ",
70801 + seq_printf(pi, "%pK %s %pK ",
70802 p->addr, kprobe_type, p->addr);
70803
70804 if (!pp)
70805 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70806 const char *sym = NULL;
70807 unsigned int i = *(loff_t *) v;
70808 unsigned long offset = 0;
70809 - char *modname, namebuf[128];
70810 + char *modname, namebuf[KSYM_NAME_LEN];
70811
70812 head = &kprobe_table[i];
70813 preempt_disable();
70814 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70815 index 6ada93c..55baf4d 100644
70816 --- a/kernel/ksysfs.c
70817 +++ b/kernel/ksysfs.c
70818 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70819 {
70820 if (count+1 > UEVENT_HELPER_PATH_LEN)
70821 return -ENOENT;
70822 + if (!capable(CAP_SYS_ADMIN))
70823 + return -EPERM;
70824 memcpy(uevent_helper, buf, count);
70825 uevent_helper[count] = '\0';
70826 if (count && uevent_helper[count-1] == '\n')
70827 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70828 index 7981e5b..7f2105c 100644
70829 --- a/kernel/lockdep.c
70830 +++ b/kernel/lockdep.c
70831 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
70832 end = (unsigned long) &_end,
70833 addr = (unsigned long) obj;
70834
70835 +#ifdef CONFIG_PAX_KERNEXEC
70836 + start = ktla_ktva(start);
70837 +#endif
70838 +
70839 /*
70840 * static variable?
70841 */
70842 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70843 if (!static_obj(lock->key)) {
70844 debug_locks_off();
70845 printk("INFO: trying to register non-static key.\n");
70846 + printk("lock:%pS key:%pS.\n", lock, lock->key);
70847 printk("the code is fine but needs lockdep annotation.\n");
70848 printk("turning off the locking correctness validator.\n");
70849 dump_stack();
70850 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70851 if (!class)
70852 return 0;
70853 }
70854 - atomic_inc((atomic_t *)&class->ops);
70855 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70856 if (very_verbose(class)) {
70857 printk("\nacquire class [%p] %s", class->key, class->name);
70858 if (class->name_version > 1)
70859 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70860 index b2c71c5..7b88d63 100644
70861 --- a/kernel/lockdep_proc.c
70862 +++ b/kernel/lockdep_proc.c
70863 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70864 return 0;
70865 }
70866
70867 - seq_printf(m, "%p", class->key);
70868 + seq_printf(m, "%pK", class->key);
70869 #ifdef CONFIG_DEBUG_LOCKDEP
70870 seq_printf(m, " OPS:%8ld", class->ops);
70871 #endif
70872 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70873
70874 list_for_each_entry(entry, &class->locks_after, entry) {
70875 if (entry->distance == 1) {
70876 - seq_printf(m, " -> [%p] ", entry->class->key);
70877 + seq_printf(m, " -> [%pK] ", entry->class->key);
70878 print_name(m, entry->class);
70879 seq_puts(m, "\n");
70880 }
70881 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70882 if (!class->key)
70883 continue;
70884
70885 - seq_printf(m, "[%p] ", class->key);
70886 + seq_printf(m, "[%pK] ", class->key);
70887 print_name(m, class);
70888 seq_puts(m, "\n");
70889 }
70890 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70891 if (!i)
70892 seq_line(m, '-', 40-namelen, namelen);
70893
70894 - snprintf(ip, sizeof(ip), "[<%p>]",
70895 + snprintf(ip, sizeof(ip), "[<%pK>]",
70896 (void *)class->contention_point[i]);
70897 seq_printf(m, "%40s %14lu %29s %pS\n",
70898 name, stats->contention_point[i],
70899 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70900 if (!i)
70901 seq_line(m, '-', 40-namelen, namelen);
70902
70903 - snprintf(ip, sizeof(ip), "[<%p>]",
70904 + snprintf(ip, sizeof(ip), "[<%pK>]",
70905 (void *)class->contending_point[i]);
70906 seq_printf(m, "%40s %14lu %29s %pS\n",
70907 name, stats->contending_point[i],
70908 diff --git a/kernel/module.c b/kernel/module.c
70909 index eab0827..75ede66 100644
70910 --- a/kernel/module.c
70911 +++ b/kernel/module.c
70912 @@ -61,6 +61,7 @@
70913 #include <linux/pfn.h>
70914 #include <linux/bsearch.h>
70915 #include <linux/fips.h>
70916 +#include <linux/grsecurity.h>
70917 #include <uapi/linux/module.h>
70918 #include "module-internal.h"
70919
70920 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70921
70922 /* Bounds of module allocation, for speeding __module_address.
70923 * Protected by module_mutex. */
70924 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70925 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70926 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70927
70928 int register_module_notifier(struct notifier_block * nb)
70929 {
70930 @@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70931 return true;
70932
70933 list_for_each_entry_rcu(mod, &modules, list) {
70934 - struct symsearch arr[] = {
70935 + struct symsearch modarr[] = {
70936 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70937 NOT_GPL_ONLY, false },
70938 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70939 @@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70940 if (mod->state == MODULE_STATE_UNFORMED)
70941 continue;
70942
70943 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70944 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70945 return true;
70946 }
70947 return false;
70948 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70949 static int percpu_modalloc(struct module *mod,
70950 unsigned long size, unsigned long align)
70951 {
70952 - if (align > PAGE_SIZE) {
70953 + if (align-1 >= PAGE_SIZE) {
70954 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70955 mod->name, align, PAGE_SIZE);
70956 align = PAGE_SIZE;
70957 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
70958 static ssize_t show_coresize(struct module_attribute *mattr,
70959 struct module_kobject *mk, char *buffer)
70960 {
70961 - return sprintf(buffer, "%u\n", mk->mod->core_size);
70962 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70963 }
70964
70965 static struct module_attribute modinfo_coresize =
70966 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
70967 static ssize_t show_initsize(struct module_attribute *mattr,
70968 struct module_kobject *mk, char *buffer)
70969 {
70970 - return sprintf(buffer, "%u\n", mk->mod->init_size);
70971 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70972 }
70973
70974 static struct module_attribute modinfo_initsize =
70975 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
70976 */
70977 #ifdef CONFIG_SYSFS
70978
70979 -#ifdef CONFIG_KALLSYMS
70980 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70981 static inline bool sect_empty(const Elf_Shdr *sect)
70982 {
70983 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70984 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
70985
70986 static void unset_module_core_ro_nx(struct module *mod)
70987 {
70988 - set_page_attributes(mod->module_core + mod->core_text_size,
70989 - mod->module_core + mod->core_size,
70990 + set_page_attributes(mod->module_core_rw,
70991 + mod->module_core_rw + mod->core_size_rw,
70992 set_memory_x);
70993 - set_page_attributes(mod->module_core,
70994 - mod->module_core + mod->core_ro_size,
70995 + set_page_attributes(mod->module_core_rx,
70996 + mod->module_core_rx + mod->core_size_rx,
70997 set_memory_rw);
70998 }
70999
71000 static void unset_module_init_ro_nx(struct module *mod)
71001 {
71002 - set_page_attributes(mod->module_init + mod->init_text_size,
71003 - mod->module_init + mod->init_size,
71004 + set_page_attributes(mod->module_init_rw,
71005 + mod->module_init_rw + mod->init_size_rw,
71006 set_memory_x);
71007 - set_page_attributes(mod->module_init,
71008 - mod->module_init + mod->init_ro_size,
71009 + set_page_attributes(mod->module_init_rx,
71010 + mod->module_init_rx + mod->init_size_rx,
71011 set_memory_rw);
71012 }
71013
71014 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
71015 list_for_each_entry_rcu(mod, &modules, list) {
71016 if (mod->state == MODULE_STATE_UNFORMED)
71017 continue;
71018 - if ((mod->module_core) && (mod->core_text_size)) {
71019 - set_page_attributes(mod->module_core,
71020 - mod->module_core + mod->core_text_size,
71021 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
71022 + set_page_attributes(mod->module_core_rx,
71023 + mod->module_core_rx + mod->core_size_rx,
71024 set_memory_rw);
71025 }
71026 - if ((mod->module_init) && (mod->init_text_size)) {
71027 - set_page_attributes(mod->module_init,
71028 - mod->module_init + mod->init_text_size,
71029 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
71030 + set_page_attributes(mod->module_init_rx,
71031 + mod->module_init_rx + mod->init_size_rx,
71032 set_memory_rw);
71033 }
71034 }
71035 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
71036 list_for_each_entry_rcu(mod, &modules, list) {
71037 if (mod->state == MODULE_STATE_UNFORMED)
71038 continue;
71039 - if ((mod->module_core) && (mod->core_text_size)) {
71040 - set_page_attributes(mod->module_core,
71041 - mod->module_core + mod->core_text_size,
71042 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
71043 + set_page_attributes(mod->module_core_rx,
71044 + mod->module_core_rx + mod->core_size_rx,
71045 set_memory_ro);
71046 }
71047 - if ((mod->module_init) && (mod->init_text_size)) {
71048 - set_page_attributes(mod->module_init,
71049 - mod->module_init + mod->init_text_size,
71050 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
71051 + set_page_attributes(mod->module_init_rx,
71052 + mod->module_init_rx + mod->init_size_rx,
71053 set_memory_ro);
71054 }
71055 }
71056 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
71057
71058 /* This may be NULL, but that's OK */
71059 unset_module_init_ro_nx(mod);
71060 - module_free(mod, mod->module_init);
71061 + module_free(mod, mod->module_init_rw);
71062 + module_free_exec(mod, mod->module_init_rx);
71063 kfree(mod->args);
71064 percpu_modfree(mod);
71065
71066 /* Free lock-classes: */
71067 - lockdep_free_key_range(mod->module_core, mod->core_size);
71068 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71069 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71070
71071 /* Finally, free the core (containing the module structure) */
71072 unset_module_core_ro_nx(mod);
71073 - module_free(mod, mod->module_core);
71074 + module_free_exec(mod, mod->module_core_rx);
71075 + module_free(mod, mod->module_core_rw);
71076
71077 #ifdef CONFIG_MPU
71078 update_protections(current->mm);
71079 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71080 int ret = 0;
71081 const struct kernel_symbol *ksym;
71082
71083 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71084 + int is_fs_load = 0;
71085 + int register_filesystem_found = 0;
71086 + char *p;
71087 +
71088 + p = strstr(mod->args, "grsec_modharden_fs");
71089 + if (p) {
71090 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
71091 + /* copy \0 as well */
71092 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71093 + is_fs_load = 1;
71094 + }
71095 +#endif
71096 +
71097 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
71098 const char *name = info->strtab + sym[i].st_name;
71099
71100 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71101 + /* it's a real shame this will never get ripped and copied
71102 + upstream! ;(
71103 + */
71104 + if (is_fs_load && !strcmp(name, "register_filesystem"))
71105 + register_filesystem_found = 1;
71106 +#endif
71107 +
71108 switch (sym[i].st_shndx) {
71109 case SHN_COMMON:
71110 /* We compiled with -fno-common. These are not
71111 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71112 ksym = resolve_symbol_wait(mod, info, name);
71113 /* Ok if resolved. */
71114 if (ksym && !IS_ERR(ksym)) {
71115 + pax_open_kernel();
71116 sym[i].st_value = ksym->value;
71117 + pax_close_kernel();
71118 break;
71119 }
71120
71121 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71122 secbase = (unsigned long)mod_percpu(mod);
71123 else
71124 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
71125 + pax_open_kernel();
71126 sym[i].st_value += secbase;
71127 + pax_close_kernel();
71128 break;
71129 }
71130 }
71131
71132 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71133 + if (is_fs_load && !register_filesystem_found) {
71134 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71135 + ret = -EPERM;
71136 + }
71137 +#endif
71138 +
71139 return ret;
71140 }
71141
71142 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
71143 || s->sh_entsize != ~0UL
71144 || strstarts(sname, ".init"))
71145 continue;
71146 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71147 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71148 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71149 + else
71150 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71151 pr_debug("\t%s\n", sname);
71152 }
71153 - switch (m) {
71154 - case 0: /* executable */
71155 - mod->core_size = debug_align(mod->core_size);
71156 - mod->core_text_size = mod->core_size;
71157 - break;
71158 - case 1: /* RO: text and ro-data */
71159 - mod->core_size = debug_align(mod->core_size);
71160 - mod->core_ro_size = mod->core_size;
71161 - break;
71162 - case 3: /* whole core */
71163 - mod->core_size = debug_align(mod->core_size);
71164 - break;
71165 - }
71166 }
71167
71168 pr_debug("Init section allocation order:\n");
71169 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
71170 || s->sh_entsize != ~0UL
71171 || !strstarts(sname, ".init"))
71172 continue;
71173 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71174 - | INIT_OFFSET_MASK);
71175 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71176 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71177 + else
71178 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71179 + s->sh_entsize |= INIT_OFFSET_MASK;
71180 pr_debug("\t%s\n", sname);
71181 }
71182 - switch (m) {
71183 - case 0: /* executable */
71184 - mod->init_size = debug_align(mod->init_size);
71185 - mod->init_text_size = mod->init_size;
71186 - break;
71187 - case 1: /* RO: text and ro-data */
71188 - mod->init_size = debug_align(mod->init_size);
71189 - mod->init_ro_size = mod->init_size;
71190 - break;
71191 - case 3: /* whole init */
71192 - mod->init_size = debug_align(mod->init_size);
71193 - break;
71194 - }
71195 }
71196 }
71197
71198 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71199
71200 /* Put symbol section at end of init part of module. */
71201 symsect->sh_flags |= SHF_ALLOC;
71202 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71203 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71204 info->index.sym) | INIT_OFFSET_MASK;
71205 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
71206
71207 @@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71208 }
71209
71210 /* Append room for core symbols at end of core part. */
71211 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71212 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
71213 - mod->core_size += strtab_size;
71214 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71215 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
71216 + mod->core_size_rx += strtab_size;
71217
71218 /* Put string table section at end of init part of module. */
71219 strsect->sh_flags |= SHF_ALLOC;
71220 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71221 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71222 info->index.str) | INIT_OFFSET_MASK;
71223 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
71224 }
71225 @@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71226 /* Make sure we get permanent strtab: don't use info->strtab. */
71227 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
71228
71229 + pax_open_kernel();
71230 +
71231 /* Set types up while we still have access to sections. */
71232 for (i = 0; i < mod->num_symtab; i++)
71233 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
71234
71235 - mod->core_symtab = dst = mod->module_core + info->symoffs;
71236 - mod->core_strtab = s = mod->module_core + info->stroffs;
71237 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
71238 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
71239 src = mod->symtab;
71240 for (ndst = i = 0; i < mod->num_symtab; i++) {
71241 if (i == 0 ||
71242 @@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71243 }
71244 }
71245 mod->core_num_syms = ndst;
71246 +
71247 + pax_close_kernel();
71248 }
71249 #else
71250 static inline void layout_symtab(struct module *mod, struct load_info *info)
71251 @@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
71252 return vmalloc_exec(size);
71253 }
71254
71255 -static void *module_alloc_update_bounds(unsigned long size)
71256 +static void *module_alloc_update_bounds_rw(unsigned long size)
71257 {
71258 void *ret = module_alloc(size);
71259
71260 if (ret) {
71261 mutex_lock(&module_mutex);
71262 /* Update module bounds. */
71263 - if ((unsigned long)ret < module_addr_min)
71264 - module_addr_min = (unsigned long)ret;
71265 - if ((unsigned long)ret + size > module_addr_max)
71266 - module_addr_max = (unsigned long)ret + size;
71267 + if ((unsigned long)ret < module_addr_min_rw)
71268 + module_addr_min_rw = (unsigned long)ret;
71269 + if ((unsigned long)ret + size > module_addr_max_rw)
71270 + module_addr_max_rw = (unsigned long)ret + size;
71271 + mutex_unlock(&module_mutex);
71272 + }
71273 + return ret;
71274 +}
71275 +
71276 +static void *module_alloc_update_bounds_rx(unsigned long size)
71277 +{
71278 + void *ret = module_alloc_exec(size);
71279 +
71280 + if (ret) {
71281 + mutex_lock(&module_mutex);
71282 + /* Update module bounds. */
71283 + if ((unsigned long)ret < module_addr_min_rx)
71284 + module_addr_min_rx = (unsigned long)ret;
71285 + if ((unsigned long)ret + size > module_addr_max_rx)
71286 + module_addr_max_rx = (unsigned long)ret + size;
71287 mutex_unlock(&module_mutex);
71288 }
71289 return ret;
71290 @@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
71291 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71292 {
71293 const char *modmagic = get_modinfo(info, "vermagic");
71294 + const char *license = get_modinfo(info, "license");
71295 int err;
71296
71297 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
71298 + if (!license || !license_is_gpl_compatible(license))
71299 + return -ENOEXEC;
71300 +#endif
71301 +
71302 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
71303 modmagic = NULL;
71304
71305 @@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71306 }
71307
71308 /* Set up license info based on the info section */
71309 - set_license(mod, get_modinfo(info, "license"));
71310 + set_license(mod, license);
71311
71312 return 0;
71313 }
71314 @@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
71315 void *ptr;
71316
71317 /* Do the allocs. */
71318 - ptr = module_alloc_update_bounds(mod->core_size);
71319 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
71320 /*
71321 * The pointer to this block is stored in the module structure
71322 * which is inside the block. Just mark it as not being a
71323 @@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
71324 if (!ptr)
71325 return -ENOMEM;
71326
71327 - memset(ptr, 0, mod->core_size);
71328 - mod->module_core = ptr;
71329 + memset(ptr, 0, mod->core_size_rw);
71330 + mod->module_core_rw = ptr;
71331
71332 - if (mod->init_size) {
71333 - ptr = module_alloc_update_bounds(mod->init_size);
71334 + if (mod->init_size_rw) {
71335 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
71336 /*
71337 * The pointer to this block is stored in the module structure
71338 * which is inside the block. This block doesn't need to be
71339 @@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
71340 */
71341 kmemleak_ignore(ptr);
71342 if (!ptr) {
71343 - module_free(mod, mod->module_core);
71344 + module_free(mod, mod->module_core_rw);
71345 return -ENOMEM;
71346 }
71347 - memset(ptr, 0, mod->init_size);
71348 - mod->module_init = ptr;
71349 + memset(ptr, 0, mod->init_size_rw);
71350 + mod->module_init_rw = ptr;
71351 } else
71352 - mod->module_init = NULL;
71353 + mod->module_init_rw = NULL;
71354 +
71355 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
71356 + kmemleak_not_leak(ptr);
71357 + if (!ptr) {
71358 + if (mod->module_init_rw)
71359 + module_free(mod, mod->module_init_rw);
71360 + module_free(mod, mod->module_core_rw);
71361 + return -ENOMEM;
71362 + }
71363 +
71364 + pax_open_kernel();
71365 + memset(ptr, 0, mod->core_size_rx);
71366 + pax_close_kernel();
71367 + mod->module_core_rx = ptr;
71368 +
71369 + if (mod->init_size_rx) {
71370 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
71371 + kmemleak_ignore(ptr);
71372 + if (!ptr && mod->init_size_rx) {
71373 + module_free_exec(mod, mod->module_core_rx);
71374 + if (mod->module_init_rw)
71375 + module_free(mod, mod->module_init_rw);
71376 + module_free(mod, mod->module_core_rw);
71377 + return -ENOMEM;
71378 + }
71379 +
71380 + pax_open_kernel();
71381 + memset(ptr, 0, mod->init_size_rx);
71382 + pax_close_kernel();
71383 + mod->module_init_rx = ptr;
71384 + } else
71385 + mod->module_init_rx = NULL;
71386
71387 /* Transfer each section which specifies SHF_ALLOC */
71388 pr_debug("final section addresses:\n");
71389 @@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
71390 if (!(shdr->sh_flags & SHF_ALLOC))
71391 continue;
71392
71393 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
71394 - dest = mod->module_init
71395 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71396 - else
71397 - dest = mod->module_core + shdr->sh_entsize;
71398 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
71399 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71400 + dest = mod->module_init_rw
71401 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71402 + else
71403 + dest = mod->module_init_rx
71404 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71405 + } else {
71406 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71407 + dest = mod->module_core_rw + shdr->sh_entsize;
71408 + else
71409 + dest = mod->module_core_rx + shdr->sh_entsize;
71410 + }
71411 +
71412 + if (shdr->sh_type != SHT_NOBITS) {
71413 +
71414 +#ifdef CONFIG_PAX_KERNEXEC
71415 +#ifdef CONFIG_X86_64
71416 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
71417 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
71418 +#endif
71419 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
71420 + pax_open_kernel();
71421 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71422 + pax_close_kernel();
71423 + } else
71424 +#endif
71425
71426 - if (shdr->sh_type != SHT_NOBITS)
71427 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71428 + }
71429 /* Update sh_addr to point to copy in image. */
71430 - shdr->sh_addr = (unsigned long)dest;
71431 +
71432 +#ifdef CONFIG_PAX_KERNEXEC
71433 + if (shdr->sh_flags & SHF_EXECINSTR)
71434 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
71435 + else
71436 +#endif
71437 +
71438 + shdr->sh_addr = (unsigned long)dest;
71439 pr_debug("\t0x%lx %s\n",
71440 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
71441 }
71442 @@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
71443 * Do it before processing of module parameters, so the module
71444 * can provide parameter accessor functions of its own.
71445 */
71446 - if (mod->module_init)
71447 - flush_icache_range((unsigned long)mod->module_init,
71448 - (unsigned long)mod->module_init
71449 - + mod->init_size);
71450 - flush_icache_range((unsigned long)mod->module_core,
71451 - (unsigned long)mod->module_core + mod->core_size);
71452 + if (mod->module_init_rx)
71453 + flush_icache_range((unsigned long)mod->module_init_rx,
71454 + (unsigned long)mod->module_init_rx
71455 + + mod->init_size_rx);
71456 + flush_icache_range((unsigned long)mod->module_core_rx,
71457 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
71458
71459 set_fs(old_fs);
71460 }
71461 @@ -2983,8 +3088,10 @@ out:
71462 static void module_deallocate(struct module *mod, struct load_info *info)
71463 {
71464 percpu_modfree(mod);
71465 - module_free(mod, mod->module_init);
71466 - module_free(mod, mod->module_core);
71467 + module_free_exec(mod, mod->module_init_rx);
71468 + module_free_exec(mod, mod->module_core_rx);
71469 + module_free(mod, mod->module_init_rw);
71470 + module_free(mod, mod->module_core_rw);
71471 }
71472
71473 int __weak module_finalize(const Elf_Ehdr *hdr,
71474 @@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
71475 static int post_relocation(struct module *mod, const struct load_info *info)
71476 {
71477 /* Sort exception table now relocations are done. */
71478 + pax_open_kernel();
71479 sort_extable(mod->extable, mod->extable + mod->num_exentries);
71480 + pax_close_kernel();
71481
71482 /* Copy relocated percpu area over. */
71483 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
71484 @@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
71485 MODULE_STATE_COMING, mod);
71486
71487 /* Set RO and NX regions for core */
71488 - set_section_ro_nx(mod->module_core,
71489 - mod->core_text_size,
71490 - mod->core_ro_size,
71491 - mod->core_size);
71492 + set_section_ro_nx(mod->module_core_rx,
71493 + mod->core_size_rx,
71494 + mod->core_size_rx,
71495 + mod->core_size_rx);
71496
71497 /* Set RO and NX regions for init */
71498 - set_section_ro_nx(mod->module_init,
71499 - mod->init_text_size,
71500 - mod->init_ro_size,
71501 - mod->init_size);
71502 + set_section_ro_nx(mod->module_init_rx,
71503 + mod->init_size_rx,
71504 + mod->init_size_rx,
71505 + mod->init_size_rx);
71506
71507 do_mod_ctors(mod);
71508 /* Start the module */
71509 @@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
71510 mod->strtab = mod->core_strtab;
71511 #endif
71512 unset_module_init_ro_nx(mod);
71513 - module_free(mod, mod->module_init);
71514 - mod->module_init = NULL;
71515 - mod->init_size = 0;
71516 - mod->init_ro_size = 0;
71517 - mod->init_text_size = 0;
71518 + module_free(mod, mod->module_init_rw);
71519 + module_free_exec(mod, mod->module_init_rx);
71520 + mod->module_init_rw = NULL;
71521 + mod->module_init_rx = NULL;
71522 + mod->init_size_rw = 0;
71523 + mod->init_size_rx = 0;
71524 mutex_unlock(&module_mutex);
71525 wake_up_all(&module_wq);
71526
71527 @@ -3209,9 +3319,38 @@ again:
71528 if (err)
71529 goto free_unload;
71530
71531 + /* Now copy in args */
71532 + mod->args = strndup_user(uargs, ~0UL >> 1);
71533 + if (IS_ERR(mod->args)) {
71534 + err = PTR_ERR(mod->args);
71535 + goto free_unload;
71536 + }
71537 +
71538 /* Set up MODINFO_ATTR fields */
71539 setup_modinfo(mod, info);
71540
71541 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71542 + {
71543 + char *p, *p2;
71544 +
71545 + if (strstr(mod->args, "grsec_modharden_netdev")) {
71546 + 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);
71547 + err = -EPERM;
71548 + goto free_modinfo;
71549 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
71550 + p += sizeof("grsec_modharden_normal") - 1;
71551 + p2 = strstr(p, "_");
71552 + if (p2) {
71553 + *p2 = '\0';
71554 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
71555 + *p2 = '_';
71556 + }
71557 + err = -EPERM;
71558 + goto free_modinfo;
71559 + }
71560 + }
71561 +#endif
71562 +
71563 /* Fix up syms, so that st_value is a pointer to location. */
71564 err = simplify_symbols(mod, info);
71565 if (err < 0)
71566 @@ -3227,13 +3366,6 @@ again:
71567
71568 flush_module_icache(mod);
71569
71570 - /* Now copy in args */
71571 - mod->args = strndup_user(uargs, ~0UL >> 1);
71572 - if (IS_ERR(mod->args)) {
71573 - err = PTR_ERR(mod->args);
71574 - goto free_arch_cleanup;
71575 - }
71576 -
71577 dynamic_debug_setup(info->debug, info->num_debug);
71578
71579 mutex_lock(&module_mutex);
71580 @@ -3278,11 +3410,10 @@ again:
71581 mutex_unlock(&module_mutex);
71582 dynamic_debug_remove(info->debug);
71583 synchronize_sched();
71584 - kfree(mod->args);
71585 - free_arch_cleanup:
71586 module_arch_cleanup(mod);
71587 free_modinfo:
71588 free_modinfo(mod);
71589 + kfree(mod->args);
71590 free_unload:
71591 module_unload_free(mod);
71592 unlink_mod:
71593 @@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
71594 unsigned long nextval;
71595
71596 /* At worse, next value is at end of module */
71597 - if (within_module_init(addr, mod))
71598 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
71599 + if (within_module_init_rx(addr, mod))
71600 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
71601 + else if (within_module_init_rw(addr, mod))
71602 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
71603 + else if (within_module_core_rx(addr, mod))
71604 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
71605 + else if (within_module_core_rw(addr, mod))
71606 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
71607 else
71608 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
71609 + return NULL;
71610
71611 /* Scan for closest preceding symbol, and next symbol. (ELF
71612 starts real symbols at 1). */
71613 @@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
71614 return 0;
71615
71616 seq_printf(m, "%s %u",
71617 - mod->name, mod->init_size + mod->core_size);
71618 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
71619 print_unload_info(m, mod);
71620
71621 /* Informative for users. */
71622 @@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
71623 mod->state == MODULE_STATE_COMING ? "Loading":
71624 "Live");
71625 /* Used by oprofile and other similar tools. */
71626 - seq_printf(m, " 0x%pK", mod->module_core);
71627 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
71628
71629 /* Taints info */
71630 if (mod->taints)
71631 @@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
71632
71633 static int __init proc_modules_init(void)
71634 {
71635 +#ifndef CONFIG_GRKERNSEC_HIDESYM
71636 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71637 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71638 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71639 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
71640 +#else
71641 proc_create("modules", 0, NULL, &proc_modules_operations);
71642 +#endif
71643 +#else
71644 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71645 +#endif
71646 return 0;
71647 }
71648 module_init(proc_modules_init);
71649 @@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
71650 {
71651 struct module *mod;
71652
71653 - if (addr < module_addr_min || addr > module_addr_max)
71654 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
71655 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
71656 return NULL;
71657
71658 list_for_each_entry_rcu(mod, &modules, list) {
71659 if (mod->state == MODULE_STATE_UNFORMED)
71660 continue;
71661 - if (within_module_core(addr, mod)
71662 - || within_module_init(addr, mod))
71663 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
71664 return mod;
71665 }
71666 return NULL;
71667 @@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
71668 */
71669 struct module *__module_text_address(unsigned long addr)
71670 {
71671 - struct module *mod = __module_address(addr);
71672 + struct module *mod;
71673 +
71674 +#ifdef CONFIG_X86_32
71675 + addr = ktla_ktva(addr);
71676 +#endif
71677 +
71678 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
71679 + return NULL;
71680 +
71681 + mod = __module_address(addr);
71682 +
71683 if (mod) {
71684 /* Make sure it's within the text section. */
71685 - if (!within(addr, mod->module_init, mod->init_text_size)
71686 - && !within(addr, mod->module_core, mod->core_text_size))
71687 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
71688 mod = NULL;
71689 }
71690 return mod;
71691 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
71692 index 7e3443f..b2a1e6b 100644
71693 --- a/kernel/mutex-debug.c
71694 +++ b/kernel/mutex-debug.c
71695 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
71696 }
71697
71698 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71699 - struct thread_info *ti)
71700 + struct task_struct *task)
71701 {
71702 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
71703
71704 /* Mark the current thread as blocked on the lock: */
71705 - ti->task->blocked_on = waiter;
71706 + task->blocked_on = waiter;
71707 }
71708
71709 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71710 - struct thread_info *ti)
71711 + struct task_struct *task)
71712 {
71713 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71714 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71715 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71716 - ti->task->blocked_on = NULL;
71717 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
71718 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71719 + task->blocked_on = NULL;
71720
71721 list_del_init(&waiter->list);
71722 waiter->task = NULL;
71723 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71724 index 0799fd3..d06ae3b 100644
71725 --- a/kernel/mutex-debug.h
71726 +++ b/kernel/mutex-debug.h
71727 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71728 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71729 extern void debug_mutex_add_waiter(struct mutex *lock,
71730 struct mutex_waiter *waiter,
71731 - struct thread_info *ti);
71732 + struct task_struct *task);
71733 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71734 - struct thread_info *ti);
71735 + struct task_struct *task);
71736 extern void debug_mutex_unlock(struct mutex *lock);
71737 extern void debug_mutex_init(struct mutex *lock, const char *name,
71738 struct lock_class_key *key);
71739 diff --git a/kernel/mutex.c b/kernel/mutex.c
71740 index a307cc9..27fd2e9 100644
71741 --- a/kernel/mutex.c
71742 +++ b/kernel/mutex.c
71743 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71744 spin_lock_mutex(&lock->wait_lock, flags);
71745
71746 debug_mutex_lock_common(lock, &waiter);
71747 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71748 + debug_mutex_add_waiter(lock, &waiter, task);
71749
71750 /* add waiting tasks to the end of the waitqueue (FIFO): */
71751 list_add_tail(&waiter.list, &lock->wait_list);
71752 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71753 * TASK_UNINTERRUPTIBLE case.)
71754 */
71755 if (unlikely(signal_pending_state(state, task))) {
71756 - mutex_remove_waiter(lock, &waiter,
71757 - task_thread_info(task));
71758 + mutex_remove_waiter(lock, &waiter, task);
71759 mutex_release(&lock->dep_map, 1, ip);
71760 spin_unlock_mutex(&lock->wait_lock, flags);
71761
71762 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71763 done:
71764 lock_acquired(&lock->dep_map, ip);
71765 /* got the lock - rejoice! */
71766 - mutex_remove_waiter(lock, &waiter, current_thread_info());
71767 + mutex_remove_waiter(lock, &waiter, task);
71768 mutex_set_owner(lock);
71769
71770 /* set it to 0 if there are no waiters left: */
71771 diff --git a/kernel/notifier.c b/kernel/notifier.c
71772 index 2d5cc4c..d9ea600 100644
71773 --- a/kernel/notifier.c
71774 +++ b/kernel/notifier.c
71775 @@ -5,6 +5,7 @@
71776 #include <linux/rcupdate.h>
71777 #include <linux/vmalloc.h>
71778 #include <linux/reboot.h>
71779 +#include <linux/mm.h>
71780
71781 /*
71782 * Notifier list for kernel code which wants to be called
71783 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71784 while ((*nl) != NULL) {
71785 if (n->priority > (*nl)->priority)
71786 break;
71787 - nl = &((*nl)->next);
71788 + nl = (struct notifier_block **)&((*nl)->next);
71789 }
71790 - n->next = *nl;
71791 + pax_open_kernel();
71792 + *(const void **)&n->next = *nl;
71793 rcu_assign_pointer(*nl, n);
71794 + pax_close_kernel();
71795 return 0;
71796 }
71797
71798 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71799 return 0;
71800 if (n->priority > (*nl)->priority)
71801 break;
71802 - nl = &((*nl)->next);
71803 + nl = (struct notifier_block **)&((*nl)->next);
71804 }
71805 - n->next = *nl;
71806 + pax_open_kernel();
71807 + *(const void **)&n->next = *nl;
71808 rcu_assign_pointer(*nl, n);
71809 + pax_close_kernel();
71810 return 0;
71811 }
71812
71813 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71814 {
71815 while ((*nl) != NULL) {
71816 if ((*nl) == n) {
71817 + pax_open_kernel();
71818 rcu_assign_pointer(*nl, n->next);
71819 + pax_close_kernel();
71820 return 0;
71821 }
71822 - nl = &((*nl)->next);
71823 + nl = (struct notifier_block **)&((*nl)->next);
71824 }
71825 return -ENOENT;
71826 }
71827 diff --git a/kernel/panic.c b/kernel/panic.c
71828 index e1b2822..5edc1d9 100644
71829 --- a/kernel/panic.c
71830 +++ b/kernel/panic.c
71831 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71832 const char *board;
71833
71834 printk(KERN_WARNING "------------[ cut here ]------------\n");
71835 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71836 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71837 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71838 if (board)
71839 printk(KERN_WARNING "Hardware name: %s\n", board);
71840 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71841 */
71842 void __stack_chk_fail(void)
71843 {
71844 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
71845 + dump_stack();
71846 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71847 __builtin_return_address(0));
71848 }
71849 EXPORT_SYMBOL(__stack_chk_fail);
71850 diff --git a/kernel/pid.c b/kernel/pid.c
71851 index f2c6a68..4922d97 100644
71852 --- a/kernel/pid.c
71853 +++ b/kernel/pid.c
71854 @@ -33,6 +33,7 @@
71855 #include <linux/rculist.h>
71856 #include <linux/bootmem.h>
71857 #include <linux/hash.h>
71858 +#include <linux/security.h>
71859 #include <linux/pid_namespace.h>
71860 #include <linux/init_task.h>
71861 #include <linux/syscalls.h>
71862 @@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71863
71864 int pid_max = PID_MAX_DEFAULT;
71865
71866 -#define RESERVED_PIDS 300
71867 +#define RESERVED_PIDS 500
71868
71869 int pid_max_min = RESERVED_PIDS + 1;
71870 int pid_max_max = PID_MAX_LIMIT;
71871 @@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
71872 */
71873 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71874 {
71875 + struct task_struct *task;
71876 +
71877 rcu_lockdep_assert(rcu_read_lock_held(),
71878 "find_task_by_pid_ns() needs rcu_read_lock()"
71879 " protection");
71880 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71881 +
71882 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71883 +
71884 + if (gr_pid_is_chrooted(task))
71885 + return NULL;
71886 +
71887 + return task;
71888 }
71889
71890 struct task_struct *find_task_by_vpid(pid_t vnr)
71891 @@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71892 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
71893 }
71894
71895 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71896 +{
71897 + rcu_lockdep_assert(rcu_read_lock_held(),
71898 + "find_task_by_pid_ns() needs rcu_read_lock()"
71899 + " protection");
71900 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
71901 +}
71902 +
71903 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71904 {
71905 struct pid *pid;
71906 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71907 index a278cad..bff5bd3 100644
71908 --- a/kernel/posix-cpu-timers.c
71909 +++ b/kernel/posix-cpu-timers.c
71910 @@ -1557,14 +1557,14 @@ struct k_clock clock_posix_cpu = {
71911
71912 static __init int init_posix_cpu_timers(void)
71913 {
71914 - struct k_clock process = {
71915 + static struct k_clock process = {
71916 .clock_getres = process_cpu_clock_getres,
71917 .clock_get = process_cpu_clock_get,
71918 .timer_create = process_cpu_timer_create,
71919 .nsleep = process_cpu_nsleep,
71920 .nsleep_restart = process_cpu_nsleep_restart,
71921 };
71922 - struct k_clock thread = {
71923 + static struct k_clock thread = {
71924 .clock_getres = thread_cpu_clock_getres,
71925 .clock_get = thread_cpu_clock_get,
71926 .timer_create = thread_cpu_timer_create,
71927 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71928 index 69185ae..cc2847a 100644
71929 --- a/kernel/posix-timers.c
71930 +++ b/kernel/posix-timers.c
71931 @@ -43,6 +43,7 @@
71932 #include <linux/idr.h>
71933 #include <linux/posix-clock.h>
71934 #include <linux/posix-timers.h>
71935 +#include <linux/grsecurity.h>
71936 #include <linux/syscalls.h>
71937 #include <linux/wait.h>
71938 #include <linux/workqueue.h>
71939 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71940 * which we beg off on and pass to do_sys_settimeofday().
71941 */
71942
71943 -static struct k_clock posix_clocks[MAX_CLOCKS];
71944 +static struct k_clock *posix_clocks[MAX_CLOCKS];
71945
71946 /*
71947 * These ones are defined below.
71948 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71949 */
71950 static __init int init_posix_timers(void)
71951 {
71952 - struct k_clock clock_realtime = {
71953 + static struct k_clock clock_realtime = {
71954 .clock_getres = hrtimer_get_res,
71955 .clock_get = posix_clock_realtime_get,
71956 .clock_set = posix_clock_realtime_set,
71957 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71958 .timer_get = common_timer_get,
71959 .timer_del = common_timer_del,
71960 };
71961 - struct k_clock clock_monotonic = {
71962 + static struct k_clock clock_monotonic = {
71963 .clock_getres = hrtimer_get_res,
71964 .clock_get = posix_ktime_get_ts,
71965 .nsleep = common_nsleep,
71966 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71967 .timer_get = common_timer_get,
71968 .timer_del = common_timer_del,
71969 };
71970 - struct k_clock clock_monotonic_raw = {
71971 + static struct k_clock clock_monotonic_raw = {
71972 .clock_getres = hrtimer_get_res,
71973 .clock_get = posix_get_monotonic_raw,
71974 };
71975 - struct k_clock clock_realtime_coarse = {
71976 + static struct k_clock clock_realtime_coarse = {
71977 .clock_getres = posix_get_coarse_res,
71978 .clock_get = posix_get_realtime_coarse,
71979 };
71980 - struct k_clock clock_monotonic_coarse = {
71981 + static struct k_clock clock_monotonic_coarse = {
71982 .clock_getres = posix_get_coarse_res,
71983 .clock_get = posix_get_monotonic_coarse,
71984 };
71985 - struct k_clock clock_boottime = {
71986 + static struct k_clock clock_boottime = {
71987 .clock_getres = hrtimer_get_res,
71988 .clock_get = posix_get_boottime,
71989 .nsleep = common_nsleep,
71990 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71991 return;
71992 }
71993
71994 - posix_clocks[clock_id] = *new_clock;
71995 + posix_clocks[clock_id] = new_clock;
71996 }
71997 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71998
71999 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
72000 return (id & CLOCKFD_MASK) == CLOCKFD ?
72001 &clock_posix_dynamic : &clock_posix_cpu;
72002
72003 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
72004 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
72005 return NULL;
72006 - return &posix_clocks[id];
72007 + return posix_clocks[id];
72008 }
72009
72010 static int common_timer_create(struct k_itimer *new_timer)
72011 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72012 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72013 return -EFAULT;
72014
72015 + /* only the CLOCK_REALTIME clock can be set, all other clocks
72016 + have their clock_set fptr set to a nosettime dummy function
72017 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72018 + call common_clock_set, which calls do_sys_settimeofday, which
72019 + we hook
72020 + */
72021 +
72022 return kc->clock_set(which_clock, &new_tp);
72023 }
72024
72025 diff --git a/kernel/power/process.c b/kernel/power/process.c
72026 index d5a258b..4271191 100644
72027 --- a/kernel/power/process.c
72028 +++ b/kernel/power/process.c
72029 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
72030 u64 elapsed_csecs64;
72031 unsigned int elapsed_csecs;
72032 bool wakeup = false;
72033 + bool timedout = false;
72034
72035 do_gettimeofday(&start);
72036
72037 @@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
72038
72039 while (true) {
72040 todo = 0;
72041 + if (time_after(jiffies, end_time))
72042 + timedout = true;
72043 read_lock(&tasklist_lock);
72044 do_each_thread(g, p) {
72045 if (p == current || !freeze_task(p))
72046 continue;
72047
72048 - if (!freezer_should_skip(p))
72049 + if (!freezer_should_skip(p)) {
72050 todo++;
72051 + if (timedout) {
72052 + printk(KERN_ERR "Task refusing to freeze:\n");
72053 + sched_show_task(p);
72054 + }
72055 + }
72056 } while_each_thread(g, p);
72057 read_unlock(&tasklist_lock);
72058
72059 @@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
72060 todo += wq_busy;
72061 }
72062
72063 - if (!todo || time_after(jiffies, end_time))
72064 + if (!todo || timedout)
72065 break;
72066
72067 if (pm_wakeup_pending()) {
72068 diff --git a/kernel/printk.c b/kernel/printk.c
72069 index 267ce78..952f8a8 100644
72070 --- a/kernel/printk.c
72071 +++ b/kernel/printk.c
72072 @@ -834,6 +834,11 @@ static int check_syslog_permissions(int type, bool from_file)
72073 if (from_file && type != SYSLOG_ACTION_OPEN)
72074 return 0;
72075
72076 +#ifdef CONFIG_GRKERNSEC_DMESG
72077 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
72078 + return -EPERM;
72079 +#endif
72080 +
72081 if (syslog_action_restricted(type)) {
72082 if (capable(CAP_SYSLOG))
72083 return 0;
72084 diff --git a/kernel/profile.c b/kernel/profile.c
72085 index 1f39181..86093471 100644
72086 --- a/kernel/profile.c
72087 +++ b/kernel/profile.c
72088 @@ -40,7 +40,7 @@ struct profile_hit {
72089 /* Oprofile timer tick hook */
72090 static int (*timer_hook)(struct pt_regs *) __read_mostly;
72091
72092 -static atomic_t *prof_buffer;
72093 +static atomic_unchecked_t *prof_buffer;
72094 static unsigned long prof_len, prof_shift;
72095
72096 int prof_on __read_mostly;
72097 @@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
72098 hits[i].pc = 0;
72099 continue;
72100 }
72101 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72102 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72103 hits[i].hits = hits[i].pc = 0;
72104 }
72105 }
72106 @@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72107 * Add the current hit(s) and flush the write-queue out
72108 * to the global buffer:
72109 */
72110 - atomic_add(nr_hits, &prof_buffer[pc]);
72111 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
72112 for (i = 0; i < NR_PROFILE_HIT; ++i) {
72113 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72114 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72115 hits[i].pc = hits[i].hits = 0;
72116 }
72117 out:
72118 @@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72119 {
72120 unsigned long pc;
72121 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
72122 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72123 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72124 }
72125 #endif /* !CONFIG_SMP */
72126
72127 @@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
72128 return -EFAULT;
72129 buf++; p++; count--; read++;
72130 }
72131 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
72132 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
72133 if (copy_to_user(buf, (void *)pnt, count))
72134 return -EFAULT;
72135 read += count;
72136 @@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
72137 }
72138 #endif
72139 profile_discard_flip_buffers();
72140 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
72141 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
72142 return count;
72143 }
72144
72145 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
72146 index 6cbeaae..363c48a 100644
72147 --- a/kernel/ptrace.c
72148 +++ b/kernel/ptrace.c
72149 @@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
72150 if (seize)
72151 flags |= PT_SEIZED;
72152 rcu_read_lock();
72153 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72154 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72155 flags |= PT_PTRACE_CAP;
72156 rcu_read_unlock();
72157 task->ptrace = flags;
72158 @@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
72159 break;
72160 return -EIO;
72161 }
72162 - if (copy_to_user(dst, buf, retval))
72163 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
72164 return -EFAULT;
72165 copied += retval;
72166 src += retval;
72167 @@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
72168 bool seized = child->ptrace & PT_SEIZED;
72169 int ret = -EIO;
72170 siginfo_t siginfo, *si;
72171 - void __user *datavp = (void __user *) data;
72172 + void __user *datavp = (__force void __user *) data;
72173 unsigned long __user *datalp = datavp;
72174 unsigned long flags;
72175
72176 @@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
72177 goto out;
72178 }
72179
72180 + if (gr_handle_ptrace(child, request)) {
72181 + ret = -EPERM;
72182 + goto out_put_task_struct;
72183 + }
72184 +
72185 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72186 ret = ptrace_attach(child, request, addr, data);
72187 /*
72188 * Some architectures need to do book-keeping after
72189 * a ptrace attach.
72190 */
72191 - if (!ret)
72192 + if (!ret) {
72193 arch_ptrace_attach(child);
72194 + gr_audit_ptrace(child);
72195 + }
72196 goto out_put_task_struct;
72197 }
72198
72199 @@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
72200 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
72201 if (copied != sizeof(tmp))
72202 return -EIO;
72203 - return put_user(tmp, (unsigned long __user *)data);
72204 + return put_user(tmp, (__force unsigned long __user *)data);
72205 }
72206
72207 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
72208 @@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72209 goto out;
72210 }
72211
72212 + if (gr_handle_ptrace(child, request)) {
72213 + ret = -EPERM;
72214 + goto out_put_task_struct;
72215 + }
72216 +
72217 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72218 ret = ptrace_attach(child, request, addr, data);
72219 /*
72220 * Some architectures need to do book-keeping after
72221 * a ptrace attach.
72222 */
72223 - if (!ret)
72224 + if (!ret) {
72225 arch_ptrace_attach(child);
72226 + gr_audit_ptrace(child);
72227 + }
72228 goto out_put_task_struct;
72229 }
72230
72231 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
72232 index e7dce58..ad0d7b7 100644
72233 --- a/kernel/rcutiny.c
72234 +++ b/kernel/rcutiny.c
72235 @@ -46,7 +46,7 @@
72236 struct rcu_ctrlblk;
72237 static void invoke_rcu_callbacks(void);
72238 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
72239 -static void rcu_process_callbacks(struct softirq_action *unused);
72240 +static void rcu_process_callbacks(void);
72241 static void __call_rcu(struct rcu_head *head,
72242 void (*func)(struct rcu_head *rcu),
72243 struct rcu_ctrlblk *rcp);
72244 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
72245 rcu_is_callbacks_kthread()));
72246 }
72247
72248 -static void rcu_process_callbacks(struct softirq_action *unused)
72249 +static void rcu_process_callbacks(void)
72250 {
72251 __rcu_process_callbacks(&rcu_sched_ctrlblk);
72252 __rcu_process_callbacks(&rcu_bh_ctrlblk);
72253 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
72254 index f85016a..91cb03b 100644
72255 --- a/kernel/rcutiny_plugin.h
72256 +++ b/kernel/rcutiny_plugin.h
72257 @@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
72258 have_rcu_kthread_work = morework;
72259 local_irq_restore(flags);
72260 if (work)
72261 - rcu_process_callbacks(NULL);
72262 + rcu_process_callbacks();
72263 schedule_timeout_interruptible(1); /* Leave CPU for others. */
72264 }
72265
72266 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
72267 index 31dea01..ad91ffb 100644
72268 --- a/kernel/rcutorture.c
72269 +++ b/kernel/rcutorture.c
72270 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
72271 { 0 };
72272 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
72273 { 0 };
72274 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72275 -static atomic_t n_rcu_torture_alloc;
72276 -static atomic_t n_rcu_torture_alloc_fail;
72277 -static atomic_t n_rcu_torture_free;
72278 -static atomic_t n_rcu_torture_mberror;
72279 -static atomic_t n_rcu_torture_error;
72280 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72281 +static atomic_unchecked_t n_rcu_torture_alloc;
72282 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
72283 +static atomic_unchecked_t n_rcu_torture_free;
72284 +static atomic_unchecked_t n_rcu_torture_mberror;
72285 +static atomic_unchecked_t n_rcu_torture_error;
72286 static long n_rcu_torture_barrier_error;
72287 static long n_rcu_torture_boost_ktrerror;
72288 static long n_rcu_torture_boost_rterror;
72289 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
72290
72291 spin_lock_bh(&rcu_torture_lock);
72292 if (list_empty(&rcu_torture_freelist)) {
72293 - atomic_inc(&n_rcu_torture_alloc_fail);
72294 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
72295 spin_unlock_bh(&rcu_torture_lock);
72296 return NULL;
72297 }
72298 - atomic_inc(&n_rcu_torture_alloc);
72299 + atomic_inc_unchecked(&n_rcu_torture_alloc);
72300 p = rcu_torture_freelist.next;
72301 list_del_init(p);
72302 spin_unlock_bh(&rcu_torture_lock);
72303 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
72304 static void
72305 rcu_torture_free(struct rcu_torture *p)
72306 {
72307 - atomic_inc(&n_rcu_torture_free);
72308 + atomic_inc_unchecked(&n_rcu_torture_free);
72309 spin_lock_bh(&rcu_torture_lock);
72310 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
72311 spin_unlock_bh(&rcu_torture_lock);
72312 @@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
72313 i = rp->rtort_pipe_count;
72314 if (i > RCU_TORTURE_PIPE_LEN)
72315 i = RCU_TORTURE_PIPE_LEN;
72316 - atomic_inc(&rcu_torture_wcount[i]);
72317 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72318 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72319 rp->rtort_mbtest = 0;
72320 rcu_torture_free(rp);
72321 @@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
72322 i = rp->rtort_pipe_count;
72323 if (i > RCU_TORTURE_PIPE_LEN)
72324 i = RCU_TORTURE_PIPE_LEN;
72325 - atomic_inc(&rcu_torture_wcount[i]);
72326 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72327 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72328 rp->rtort_mbtest = 0;
72329 list_del(&rp->rtort_free);
72330 @@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
72331 i = old_rp->rtort_pipe_count;
72332 if (i > RCU_TORTURE_PIPE_LEN)
72333 i = RCU_TORTURE_PIPE_LEN;
72334 - atomic_inc(&rcu_torture_wcount[i]);
72335 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72336 old_rp->rtort_pipe_count++;
72337 cur_ops->deferred_free(old_rp);
72338 }
72339 @@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
72340 }
72341 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72342 if (p->rtort_mbtest == 0)
72343 - atomic_inc(&n_rcu_torture_mberror);
72344 + atomic_inc_unchecked(&n_rcu_torture_mberror);
72345 spin_lock(&rand_lock);
72346 cur_ops->read_delay(&rand);
72347 n_rcu_torture_timers++;
72348 @@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
72349 }
72350 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72351 if (p->rtort_mbtest == 0)
72352 - atomic_inc(&n_rcu_torture_mberror);
72353 + atomic_inc_unchecked(&n_rcu_torture_mberror);
72354 cur_ops->read_delay(&rand);
72355 preempt_disable();
72356 pipe_count = p->rtort_pipe_count;
72357 @@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
72358 rcu_torture_current,
72359 rcu_torture_current_version,
72360 list_empty(&rcu_torture_freelist),
72361 - atomic_read(&n_rcu_torture_alloc),
72362 - atomic_read(&n_rcu_torture_alloc_fail),
72363 - atomic_read(&n_rcu_torture_free));
72364 + atomic_read_unchecked(&n_rcu_torture_alloc),
72365 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
72366 + atomic_read_unchecked(&n_rcu_torture_free));
72367 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
72368 - atomic_read(&n_rcu_torture_mberror),
72369 + atomic_read_unchecked(&n_rcu_torture_mberror),
72370 n_rcu_torture_boost_ktrerror,
72371 n_rcu_torture_boost_rterror);
72372 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
72373 @@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
72374 n_barrier_attempts,
72375 n_rcu_torture_barrier_error);
72376 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
72377 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
72378 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
72379 n_rcu_torture_barrier_error != 0 ||
72380 n_rcu_torture_boost_ktrerror != 0 ||
72381 n_rcu_torture_boost_rterror != 0 ||
72382 n_rcu_torture_boost_failure != 0 ||
72383 i > 1) {
72384 cnt += sprintf(&page[cnt], "!!! ");
72385 - atomic_inc(&n_rcu_torture_error);
72386 + atomic_inc_unchecked(&n_rcu_torture_error);
72387 WARN_ON_ONCE(1);
72388 }
72389 cnt += sprintf(&page[cnt], "Reader Pipe: ");
72390 @@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
72391 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
72392 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72393 cnt += sprintf(&page[cnt], " %d",
72394 - atomic_read(&rcu_torture_wcount[i]));
72395 + atomic_read_unchecked(&rcu_torture_wcount[i]));
72396 }
72397 cnt += sprintf(&page[cnt], "\n");
72398 if (cur_ops->stats)
72399 @@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
72400
72401 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72402
72403 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72404 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72405 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
72406 else if (n_online_successes != n_online_attempts ||
72407 n_offline_successes != n_offline_attempts)
72408 @@ -1989,18 +1989,18 @@ rcu_torture_init(void)
72409
72410 rcu_torture_current = NULL;
72411 rcu_torture_current_version = 0;
72412 - atomic_set(&n_rcu_torture_alloc, 0);
72413 - atomic_set(&n_rcu_torture_alloc_fail, 0);
72414 - atomic_set(&n_rcu_torture_free, 0);
72415 - atomic_set(&n_rcu_torture_mberror, 0);
72416 - atomic_set(&n_rcu_torture_error, 0);
72417 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
72418 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
72419 + atomic_set_unchecked(&n_rcu_torture_free, 0);
72420 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
72421 + atomic_set_unchecked(&n_rcu_torture_error, 0);
72422 n_rcu_torture_barrier_error = 0;
72423 n_rcu_torture_boost_ktrerror = 0;
72424 n_rcu_torture_boost_rterror = 0;
72425 n_rcu_torture_boost_failure = 0;
72426 n_rcu_torture_boosts = 0;
72427 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
72428 - atomic_set(&rcu_torture_wcount[i], 0);
72429 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
72430 for_each_possible_cpu(cpu) {
72431 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72432 per_cpu(rcu_torture_count, cpu)[i] = 0;
72433 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
72434 index e441b77..dd54f17 100644
72435 --- a/kernel/rcutree.c
72436 +++ b/kernel/rcutree.c
72437 @@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
72438 rcu_prepare_for_idle(smp_processor_id());
72439 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72440 smp_mb__before_atomic_inc(); /* See above. */
72441 - atomic_inc(&rdtp->dynticks);
72442 + atomic_inc_unchecked(&rdtp->dynticks);
72443 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
72444 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72445 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72446
72447 /*
72448 * It is illegal to enter an extended quiescent state while
72449 @@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
72450 int user)
72451 {
72452 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
72453 - atomic_inc(&rdtp->dynticks);
72454 + atomic_inc_unchecked(&rdtp->dynticks);
72455 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72456 smp_mb__after_atomic_inc(); /* See above. */
72457 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72458 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72459 rcu_cleanup_after_idle(smp_processor_id());
72460 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
72461 if (!user && !is_idle_task(current)) {
72462 @@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
72463 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
72464
72465 if (rdtp->dynticks_nmi_nesting == 0 &&
72466 - (atomic_read(&rdtp->dynticks) & 0x1))
72467 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
72468 return;
72469 rdtp->dynticks_nmi_nesting++;
72470 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
72471 - atomic_inc(&rdtp->dynticks);
72472 + atomic_inc_unchecked(&rdtp->dynticks);
72473 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72474 smp_mb__after_atomic_inc(); /* See above. */
72475 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72476 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72477 }
72478
72479 /**
72480 @@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
72481 return;
72482 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72483 smp_mb__before_atomic_inc(); /* See above. */
72484 - atomic_inc(&rdtp->dynticks);
72485 + atomic_inc_unchecked(&rdtp->dynticks);
72486 smp_mb__after_atomic_inc(); /* Force delay to next write. */
72487 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72488 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72489 }
72490
72491 /**
72492 @@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
72493 int ret;
72494
72495 preempt_disable();
72496 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72497 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72498 preempt_enable();
72499 return ret;
72500 }
72501 @@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
72502 */
72503 static int dyntick_save_progress_counter(struct rcu_data *rdp)
72504 {
72505 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
72506 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72507 return (rdp->dynticks_snap & 0x1) == 0;
72508 }
72509
72510 @@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
72511 unsigned int curr;
72512 unsigned int snap;
72513
72514 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
72515 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72516 snap = (unsigned int)rdp->dynticks_snap;
72517
72518 /*
72519 @@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
72520 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
72521 */
72522 if (till_stall_check < 3) {
72523 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
72524 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
72525 till_stall_check = 3;
72526 } else if (till_stall_check > 300) {
72527 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
72528 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
72529 till_stall_check = 300;
72530 }
72531 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
72532 @@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
72533 rsp->qlen += rdp->qlen;
72534 rdp->n_cbs_orphaned += rdp->qlen;
72535 rdp->qlen_lazy = 0;
72536 - ACCESS_ONCE(rdp->qlen) = 0;
72537 + ACCESS_ONCE_RW(rdp->qlen) = 0;
72538 }
72539
72540 /*
72541 @@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
72542 }
72543 smp_mb(); /* List handling before counting for rcu_barrier(). */
72544 rdp->qlen_lazy -= count_lazy;
72545 - ACCESS_ONCE(rdp->qlen) -= count;
72546 + ACCESS_ONCE_RW(rdp->qlen) -= count;
72547 rdp->n_cbs_invoked += count;
72548
72549 /* Reinstate batch limit if we have worked down the excess. */
72550 @@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
72551 /*
72552 * Do RCU core processing for the current CPU.
72553 */
72554 -static void rcu_process_callbacks(struct softirq_action *unused)
72555 +static void rcu_process_callbacks(void)
72556 {
72557 struct rcu_state *rsp;
72558
72559 @@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
72560 local_irq_restore(flags);
72561 return;
72562 }
72563 - ACCESS_ONCE(rdp->qlen)++;
72564 + ACCESS_ONCE_RW(rdp->qlen)++;
72565 if (lazy)
72566 rdp->qlen_lazy++;
72567 else
72568 @@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
72569 * counter wrap on a 32-bit system. Quite a few more CPUs would of
72570 * course be required on a 64-bit system.
72571 */
72572 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
72573 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
72574 (ulong)atomic_long_read(&rsp->expedited_done) +
72575 ULONG_MAX / 8)) {
72576 synchronize_sched();
72577 - atomic_long_inc(&rsp->expedited_wrap);
72578 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
72579 return;
72580 }
72581
72582 @@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
72583 * Take a ticket. Note that atomic_inc_return() implies a
72584 * full memory barrier.
72585 */
72586 - snap = atomic_long_inc_return(&rsp->expedited_start);
72587 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
72588 firstsnap = snap;
72589 get_online_cpus();
72590 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
72591 @@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
72592 synchronize_sched_expedited_cpu_stop,
72593 NULL) == -EAGAIN) {
72594 put_online_cpus();
72595 - atomic_long_inc(&rsp->expedited_tryfail);
72596 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
72597
72598 /* Check to see if someone else did our work for us. */
72599 s = atomic_long_read(&rsp->expedited_done);
72600 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72601 /* ensure test happens before caller kfree */
72602 smp_mb__before_atomic_inc(); /* ^^^ */
72603 - atomic_long_inc(&rsp->expedited_workdone1);
72604 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
72605 return;
72606 }
72607
72608 @@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
72609 udelay(trycount * num_online_cpus());
72610 } else {
72611 wait_rcu_gp(call_rcu_sched);
72612 - atomic_long_inc(&rsp->expedited_normal);
72613 + atomic_long_inc_unchecked(&rsp->expedited_normal);
72614 return;
72615 }
72616
72617 @@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
72618 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72619 /* ensure test happens before caller kfree */
72620 smp_mb__before_atomic_inc(); /* ^^^ */
72621 - atomic_long_inc(&rsp->expedited_workdone2);
72622 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
72623 return;
72624 }
72625
72626 @@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
72627 * period works for us.
72628 */
72629 get_online_cpus();
72630 - snap = atomic_long_read(&rsp->expedited_start);
72631 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
72632 smp_mb(); /* ensure read is before try_stop_cpus(). */
72633 }
72634 - atomic_long_inc(&rsp->expedited_stoppedcpus);
72635 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
72636
72637 /*
72638 * Everyone up to our most recent fetch is covered by our grace
72639 @@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
72640 * than we did already did their update.
72641 */
72642 do {
72643 - atomic_long_inc(&rsp->expedited_done_tries);
72644 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
72645 s = atomic_long_read(&rsp->expedited_done);
72646 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
72647 /* ensure test happens before caller kfree */
72648 smp_mb__before_atomic_inc(); /* ^^^ */
72649 - atomic_long_inc(&rsp->expedited_done_lost);
72650 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
72651 break;
72652 }
72653 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
72654 - atomic_long_inc(&rsp->expedited_done_exit);
72655 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
72656
72657 put_online_cpus();
72658 }
72659 @@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72660 * ACCESS_ONCE() to prevent the compiler from speculating
72661 * the increment to precede the early-exit check.
72662 */
72663 - ACCESS_ONCE(rsp->n_barrier_done)++;
72664 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72665 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
72666 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
72667 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
72668 @@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72669
72670 /* Increment ->n_barrier_done to prevent duplicate work. */
72671 smp_mb(); /* Keep increment after above mechanism. */
72672 - ACCESS_ONCE(rsp->n_barrier_done)++;
72673 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72674 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
72675 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
72676 smp_mb(); /* Keep increment before caller's subsequent code. */
72677 @@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
72678 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
72679 init_callback_list(rdp);
72680 rdp->qlen_lazy = 0;
72681 - ACCESS_ONCE(rdp->qlen) = 0;
72682 + ACCESS_ONCE_RW(rdp->qlen) = 0;
72683 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
72684 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
72685 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
72686 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
72687 #ifdef CONFIG_RCU_USER_QS
72688 WARN_ON_ONCE(rdp->dynticks->in_user);
72689 #endif
72690 @@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
72691 rdp->blimit = blimit;
72692 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
72693 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
72694 - atomic_set(&rdp->dynticks->dynticks,
72695 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
72696 + atomic_set_unchecked(&rdp->dynticks->dynticks,
72697 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
72698 rcu_prepare_for_idle_init(cpu);
72699 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
72700
72701 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
72702 index 4b69291..704c92e 100644
72703 --- a/kernel/rcutree.h
72704 +++ b/kernel/rcutree.h
72705 @@ -86,7 +86,7 @@ struct rcu_dynticks {
72706 long long dynticks_nesting; /* Track irq/process nesting level. */
72707 /* Process level is worth LLONG_MAX/2. */
72708 int dynticks_nmi_nesting; /* Track NMI nesting level. */
72709 - atomic_t dynticks; /* Even value for idle, else odd. */
72710 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
72711 #ifdef CONFIG_RCU_FAST_NO_HZ
72712 int dyntick_drain; /* Prepare-for-idle state variable. */
72713 unsigned long dyntick_holdoff;
72714 @@ -423,17 +423,17 @@ struct rcu_state {
72715 /* _rcu_barrier(). */
72716 /* End of fields guarded by barrier_mutex. */
72717
72718 - atomic_long_t expedited_start; /* Starting ticket. */
72719 - atomic_long_t expedited_done; /* Done ticket. */
72720 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
72721 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
72722 - atomic_long_t expedited_workdone1; /* # done by others #1. */
72723 - atomic_long_t expedited_workdone2; /* # done by others #2. */
72724 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
72725 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
72726 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
72727 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
72728 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
72729 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
72730 + atomic_long_t expedited_done; /* Done ticket. */
72731 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
72732 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
72733 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
72734 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
72735 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
72736 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
72737 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
72738 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
72739 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
72740
72741 unsigned long jiffies_force_qs; /* Time at which to invoke */
72742 /* force_quiescent_state(). */
72743 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
72744 index c1cc7e1..5043e0e 100644
72745 --- a/kernel/rcutree_plugin.h
72746 +++ b/kernel/rcutree_plugin.h
72747 @@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
72748
72749 /* Clean up and exit. */
72750 smp_mb(); /* ensure expedited GP seen before counter increment. */
72751 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72752 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72753 unlock_mb_ret:
72754 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72755 mb_ret:
72756 @@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72757 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72758 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72759 cpu, ticks_value, ticks_title,
72760 - atomic_read(&rdtp->dynticks) & 0xfff,
72761 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72762 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72763 fast_no_hz);
72764 }
72765 @@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
72766
72767 /* Enqueue the callback on the nocb list and update counts. */
72768 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
72769 - ACCESS_ONCE(*old_rhpp) = rhp;
72770 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
72771 atomic_long_add(rhcount, &rdp->nocb_q_count);
72772 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
72773
72774 @@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
72775 * Extract queued callbacks, update counts, and wait
72776 * for a grace period to elapse.
72777 */
72778 - ACCESS_ONCE(rdp->nocb_head) = NULL;
72779 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
72780 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
72781 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
72782 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
72783 - ACCESS_ONCE(rdp->nocb_p_count) += c;
72784 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
72785 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
72786 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
72787 wait_rcu_gp(rdp->rsp->call_remote);
72788
72789 /* Each pass through the following loop invokes a callback. */
72790 @@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
72791 list = next;
72792 }
72793 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
72794 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
72795 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
72796 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
72797 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
72798 rdp->n_nocbs_invoked += c;
72799 }
72800 return 0;
72801 @@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
72802 rdp = per_cpu_ptr(rsp->rda, cpu);
72803 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
72804 BUG_ON(IS_ERR(t));
72805 - ACCESS_ONCE(rdp->nocb_kthread) = t;
72806 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
72807 }
72808 }
72809
72810 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72811 index 0d095dc..1985b19 100644
72812 --- a/kernel/rcutree_trace.c
72813 +++ b/kernel/rcutree_trace.c
72814 @@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72815 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
72816 rdp->passed_quiesce, rdp->qs_pending);
72817 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72818 - atomic_read(&rdp->dynticks->dynticks),
72819 + atomic_read_unchecked(&rdp->dynticks->dynticks),
72820 rdp->dynticks->dynticks_nesting,
72821 rdp->dynticks->dynticks_nmi_nesting,
72822 rdp->dynticks_fqs);
72823 @@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
72824 struct rcu_state *rsp = (struct rcu_state *)m->private;
72825
72826 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",
72827 - atomic_long_read(&rsp->expedited_start),
72828 + atomic_long_read_unchecked(&rsp->expedited_start),
72829 atomic_long_read(&rsp->expedited_done),
72830 - atomic_long_read(&rsp->expedited_wrap),
72831 - atomic_long_read(&rsp->expedited_tryfail),
72832 - atomic_long_read(&rsp->expedited_workdone1),
72833 - atomic_long_read(&rsp->expedited_workdone2),
72834 - atomic_long_read(&rsp->expedited_normal),
72835 - atomic_long_read(&rsp->expedited_stoppedcpus),
72836 - atomic_long_read(&rsp->expedited_done_tries),
72837 - atomic_long_read(&rsp->expedited_done_lost),
72838 - atomic_long_read(&rsp->expedited_done_exit));
72839 + atomic_long_read_unchecked(&rsp->expedited_wrap),
72840 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
72841 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
72842 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
72843 + atomic_long_read_unchecked(&rsp->expedited_normal),
72844 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
72845 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
72846 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
72847 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
72848 return 0;
72849 }
72850
72851 diff --git a/kernel/resource.c b/kernel/resource.c
72852 index 73f35d4..4684fc4 100644
72853 --- a/kernel/resource.c
72854 +++ b/kernel/resource.c
72855 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
72856
72857 static int __init ioresources_init(void)
72858 {
72859 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72860 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72861 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
72862 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
72863 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72864 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
72865 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
72866 +#endif
72867 +#else
72868 proc_create("ioports", 0, NULL, &proc_ioports_operations);
72869 proc_create("iomem", 0, NULL, &proc_iomem_operations);
72870 +#endif
72871 return 0;
72872 }
72873 __initcall(ioresources_init);
72874 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
72875 index 98ec494..4241d6d 100644
72876 --- a/kernel/rtmutex-tester.c
72877 +++ b/kernel/rtmutex-tester.c
72878 @@ -20,7 +20,7 @@
72879 #define MAX_RT_TEST_MUTEXES 8
72880
72881 static spinlock_t rttest_lock;
72882 -static atomic_t rttest_event;
72883 +static atomic_unchecked_t rttest_event;
72884
72885 struct test_thread_data {
72886 int opcode;
72887 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72888
72889 case RTTEST_LOCKCONT:
72890 td->mutexes[td->opdata] = 1;
72891 - td->event = atomic_add_return(1, &rttest_event);
72892 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72893 return 0;
72894
72895 case RTTEST_RESET:
72896 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72897 return 0;
72898
72899 case RTTEST_RESETEVENT:
72900 - atomic_set(&rttest_event, 0);
72901 + atomic_set_unchecked(&rttest_event, 0);
72902 return 0;
72903
72904 default:
72905 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72906 return ret;
72907
72908 td->mutexes[id] = 1;
72909 - td->event = atomic_add_return(1, &rttest_event);
72910 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72911 rt_mutex_lock(&mutexes[id]);
72912 - td->event = atomic_add_return(1, &rttest_event);
72913 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72914 td->mutexes[id] = 4;
72915 return 0;
72916
72917 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72918 return ret;
72919
72920 td->mutexes[id] = 1;
72921 - td->event = atomic_add_return(1, &rttest_event);
72922 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72923 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
72924 - td->event = atomic_add_return(1, &rttest_event);
72925 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72926 td->mutexes[id] = ret ? 0 : 4;
72927 return ret ? -EINTR : 0;
72928
72929 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72930 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
72931 return ret;
72932
72933 - td->event = atomic_add_return(1, &rttest_event);
72934 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72935 rt_mutex_unlock(&mutexes[id]);
72936 - td->event = atomic_add_return(1, &rttest_event);
72937 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72938 td->mutexes[id] = 0;
72939 return 0;
72940
72941 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72942 break;
72943
72944 td->mutexes[dat] = 2;
72945 - td->event = atomic_add_return(1, &rttest_event);
72946 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72947 break;
72948
72949 default:
72950 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72951 return;
72952
72953 td->mutexes[dat] = 3;
72954 - td->event = atomic_add_return(1, &rttest_event);
72955 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72956 break;
72957
72958 case RTTEST_LOCKNOWAIT:
72959 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72960 return;
72961
72962 td->mutexes[dat] = 1;
72963 - td->event = atomic_add_return(1, &rttest_event);
72964 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72965 return;
72966
72967 default:
72968 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
72969 index 0984a21..939f183 100644
72970 --- a/kernel/sched/auto_group.c
72971 +++ b/kernel/sched/auto_group.c
72972 @@ -11,7 +11,7 @@
72973
72974 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
72975 static struct autogroup autogroup_default;
72976 -static atomic_t autogroup_seq_nr;
72977 +static atomic_unchecked_t autogroup_seq_nr;
72978
72979 void __init autogroup_init(struct task_struct *init_task)
72980 {
72981 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
72982
72983 kref_init(&ag->kref);
72984 init_rwsem(&ag->lock);
72985 - ag->id = atomic_inc_return(&autogroup_seq_nr);
72986 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
72987 ag->tg = tg;
72988 #ifdef CONFIG_RT_GROUP_SCHED
72989 /*
72990 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
72991 index 26058d0..06f15dd 100644
72992 --- a/kernel/sched/core.c
72993 +++ b/kernel/sched/core.c
72994 @@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
72995 /* convert nice value [19,-20] to rlimit style value [1,40] */
72996 int nice_rlim = 20 - nice;
72997
72998 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
72999 +
73000 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
73001 capable(CAP_SYS_NICE));
73002 }
73003 @@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73004 if (nice > 19)
73005 nice = 19;
73006
73007 - if (increment < 0 && !can_nice(current, nice))
73008 + if (increment < 0 && (!can_nice(current, nice) ||
73009 + gr_handle_chroot_nice()))
73010 return -EPERM;
73011
73012 retval = security_task_setnice(current, nice);
73013 @@ -3818,6 +3821,7 @@ recheck:
73014 unsigned long rlim_rtprio =
73015 task_rlimit(p, RLIMIT_RTPRIO);
73016
73017 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
73018 /* can't set/change the rt policy */
73019 if (policy != p->policy && !rlim_rtprio)
73020 return -EPERM;
73021 @@ -5162,7 +5166,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
73022 * happens before everything else. This has to be lower priority than
73023 * the notifier in the perf_event subsystem, though.
73024 */
73025 -static struct notifier_block __cpuinitdata migration_notifier = {
73026 +static struct notifier_block migration_notifier = {
73027 .notifier_call = migration_call,
73028 .priority = CPU_PRI_MIGRATION,
73029 };
73030 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
73031 index 81fa536..80fa821 100644
73032 --- a/kernel/sched/fair.c
73033 +++ b/kernel/sched/fair.c
73034 @@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
73035
73036 static void reset_ptenuma_scan(struct task_struct *p)
73037 {
73038 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
73039 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
73040 p->mm->numa_scan_offset = 0;
73041 }
73042
73043 @@ -5663,7 +5663,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
73044 * run_rebalance_domains is triggered when needed from the scheduler tick.
73045 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
73046 */
73047 -static void run_rebalance_domains(struct softirq_action *h)
73048 +static void run_rebalance_domains(void)
73049 {
73050 int this_cpu = smp_processor_id();
73051 struct rq *this_rq = cpu_rq(this_cpu);
73052 diff --git a/kernel/signal.c b/kernel/signal.c
73053 index 3d09cf6..a67d2c6 100644
73054 --- a/kernel/signal.c
73055 +++ b/kernel/signal.c
73056 @@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
73057
73058 int print_fatal_signals __read_mostly;
73059
73060 -static void __user *sig_handler(struct task_struct *t, int sig)
73061 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
73062 {
73063 return t->sighand->action[sig - 1].sa.sa_handler;
73064 }
73065
73066 -static int sig_handler_ignored(void __user *handler, int sig)
73067 +static int sig_handler_ignored(__sighandler_t handler, int sig)
73068 {
73069 /* Is it explicitly or implicitly ignored? */
73070 return handler == SIG_IGN ||
73071 @@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73072
73073 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
73074 {
73075 - void __user *handler;
73076 + __sighandler_t handler;
73077
73078 handler = sig_handler(t, sig);
73079
73080 @@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
73081 atomic_inc(&user->sigpending);
73082 rcu_read_unlock();
73083
73084 + if (!override_rlimit)
73085 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73086 +
73087 if (override_rlimit ||
73088 atomic_read(&user->sigpending) <=
73089 task_rlimit(t, RLIMIT_SIGPENDING)) {
73090 @@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73091
73092 int unhandled_signal(struct task_struct *tsk, int sig)
73093 {
73094 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73095 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73096 if (is_global_init(tsk))
73097 return 1;
73098 if (handler != SIG_IGN && handler != SIG_DFL)
73099 @@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73100 }
73101 }
73102
73103 + /* allow glibc communication via tgkill to other threads in our
73104 + thread group */
73105 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73106 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73107 + && gr_handle_signal(t, sig))
73108 + return -EPERM;
73109 +
73110 return security_task_kill(t, info, sig, 0);
73111 }
73112
73113 @@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73114 return send_signal(sig, info, p, 1);
73115 }
73116
73117 -static int
73118 +int
73119 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73120 {
73121 return send_signal(sig, info, t, 0);
73122 @@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73123 unsigned long int flags;
73124 int ret, blocked, ignored;
73125 struct k_sigaction *action;
73126 + int is_unhandled = 0;
73127
73128 spin_lock_irqsave(&t->sighand->siglock, flags);
73129 action = &t->sighand->action[sig-1];
73130 @@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73131 }
73132 if (action->sa.sa_handler == SIG_DFL)
73133 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73134 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73135 + is_unhandled = 1;
73136 ret = specific_send_sig_info(sig, info, t);
73137 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73138
73139 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
73140 + normal operation */
73141 + if (is_unhandled) {
73142 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73143 + gr_handle_crash(t, sig);
73144 + }
73145 +
73146 return ret;
73147 }
73148
73149 @@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73150 ret = check_kill_permission(sig, info, p);
73151 rcu_read_unlock();
73152
73153 - if (!ret && sig)
73154 + if (!ret && sig) {
73155 ret = do_send_sig_info(sig, info, p, true);
73156 + if (!ret)
73157 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73158 + }
73159
73160 return ret;
73161 }
73162 @@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73163 int error = -ESRCH;
73164
73165 rcu_read_lock();
73166 - p = find_task_by_vpid(pid);
73167 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73168 + /* allow glibc communication via tgkill to other threads in our
73169 + thread group */
73170 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73171 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
73172 + p = find_task_by_vpid_unrestricted(pid);
73173 + else
73174 +#endif
73175 + p = find_task_by_vpid(pid);
73176 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73177 error = check_kill_permission(sig, info, p);
73178 /*
73179 @@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
73180 }
73181 seg = get_fs();
73182 set_fs(KERNEL_DS);
73183 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
73184 - (stack_t __force __user *) &uoss,
73185 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
73186 + (stack_t __force_user *) &uoss,
73187 compat_user_stack_pointer());
73188 set_fs(seg);
73189 if (ret >= 0 && uoss_ptr) {
73190 diff --git a/kernel/smp.c b/kernel/smp.c
73191 index 69f38bd..77bbf12 100644
73192 --- a/kernel/smp.c
73193 +++ b/kernel/smp.c
73194 @@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
73195 return NOTIFY_OK;
73196 }
73197
73198 -static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
73199 +static struct notifier_block hotplug_cfd_notifier = {
73200 .notifier_call = hotplug_cfd,
73201 };
73202
73203 diff --git a/kernel/softirq.c b/kernel/softirq.c
73204 index ed567ba..dc61b61 100644
73205 --- a/kernel/softirq.c
73206 +++ b/kernel/softirq.c
73207 @@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
73208 EXPORT_SYMBOL(irq_stat);
73209 #endif
73210
73211 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
73212 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
73213
73214 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73215
73216 -char *softirq_to_name[NR_SOFTIRQS] = {
73217 +const char * const softirq_to_name[NR_SOFTIRQS] = {
73218 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73219 "TASKLET", "SCHED", "HRTIMER", "RCU"
73220 };
73221 @@ -244,7 +244,7 @@ restart:
73222 kstat_incr_softirqs_this_cpu(vec_nr);
73223
73224 trace_softirq_entry(vec_nr);
73225 - h->action(h);
73226 + h->action();
73227 trace_softirq_exit(vec_nr);
73228 if (unlikely(prev_count != preempt_count())) {
73229 printk(KERN_ERR "huh, entered softirq %u %s %p"
73230 @@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
73231 or_softirq_pending(1UL << nr);
73232 }
73233
73234 -void open_softirq(int nr, void (*action)(struct softirq_action *))
73235 +void __init open_softirq(int nr, void (*action)(void))
73236 {
73237 softirq_vec[nr].action = action;
73238 }
73239 @@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73240
73241 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73242
73243 -static void tasklet_action(struct softirq_action *a)
73244 +static void tasklet_action(void)
73245 {
73246 struct tasklet_struct *list;
73247
73248 @@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
73249 }
73250 }
73251
73252 -static void tasklet_hi_action(struct softirq_action *a)
73253 +static void tasklet_hi_action(void)
73254 {
73255 struct tasklet_struct *list;
73256
73257 @@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
73258 return NOTIFY_OK;
73259 }
73260
73261 -static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
73262 +static struct notifier_block remote_softirq_cpu_notifier = {
73263 .notifier_call = remote_softirq_cpu_notify,
73264 };
73265
73266 @@ -835,7 +835,7 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
73267 return NOTIFY_OK;
73268 }
73269
73270 -static struct notifier_block __cpuinitdata cpu_nfb = {
73271 +static struct notifier_block cpu_nfb = {
73272 .notifier_call = cpu_callback
73273 };
73274
73275 diff --git a/kernel/srcu.c b/kernel/srcu.c
73276 index 2b85982..d52ab26 100644
73277 --- a/kernel/srcu.c
73278 +++ b/kernel/srcu.c
73279 @@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
73280 preempt_disable();
73281 idx = rcu_dereference_index_check(sp->completed,
73282 rcu_read_lock_sched_held()) & 0x1;
73283 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73284 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73285 smp_mb(); /* B */ /* Avoid leaking the critical section. */
73286 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73287 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73288 preempt_enable();
73289 return idx;
73290 }
73291 @@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
73292 {
73293 preempt_disable();
73294 smp_mb(); /* C */ /* Avoid leaking the critical section. */
73295 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73296 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73297 preempt_enable();
73298 }
73299 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
73300 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
73301 index 2f194e9..2c05ea9 100644
73302 --- a/kernel/stop_machine.c
73303 +++ b/kernel/stop_machine.c
73304 @@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
73305 * cpu notifiers. It currently shares the same priority as sched
73306 * migration_notifier.
73307 */
73308 -static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
73309 +static struct notifier_block cpu_stop_cpu_notifier = {
73310 .notifier_call = cpu_stop_cpu_callback,
73311 .priority = 10,
73312 };
73313 diff --git a/kernel/sys.c b/kernel/sys.c
73314 index 265b376..b0cd50d 100644
73315 --- a/kernel/sys.c
73316 +++ b/kernel/sys.c
73317 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
73318 error = -EACCES;
73319 goto out;
73320 }
73321 +
73322 + if (gr_handle_chroot_setpriority(p, niceval)) {
73323 + error = -EACCES;
73324 + goto out;
73325 + }
73326 +
73327 no_nice = security_task_setnice(p, niceval);
73328 if (no_nice) {
73329 error = no_nice;
73330 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
73331 goto error;
73332 }
73333
73334 + if (gr_check_group_change(new->gid, new->egid, -1))
73335 + goto error;
73336 +
73337 if (rgid != (gid_t) -1 ||
73338 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
73339 new->sgid = new->egid;
73340 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
73341 old = current_cred();
73342
73343 retval = -EPERM;
73344 +
73345 + if (gr_check_group_change(kgid, kgid, kgid))
73346 + goto error;
73347 +
73348 if (nsown_capable(CAP_SETGID))
73349 new->gid = new->egid = new->sgid = new->fsgid = kgid;
73350 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
73351 @@ -647,7 +660,7 @@ error:
73352 /*
73353 * change the user struct in a credentials set to match the new UID
73354 */
73355 -static int set_user(struct cred *new)
73356 +int set_user(struct cred *new)
73357 {
73358 struct user_struct *new_user;
73359
73360 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
73361 goto error;
73362 }
73363
73364 + if (gr_check_user_change(new->uid, new->euid, -1))
73365 + goto error;
73366 +
73367 if (!uid_eq(new->uid, old->uid)) {
73368 retval = set_user(new);
73369 if (retval < 0)
73370 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
73371 old = current_cred();
73372
73373 retval = -EPERM;
73374 +
73375 + if (gr_check_crash_uid(kuid))
73376 + goto error;
73377 + if (gr_check_user_change(kuid, kuid, kuid))
73378 + goto error;
73379 +
73380 if (nsown_capable(CAP_SETUID)) {
73381 new->suid = new->uid = kuid;
73382 if (!uid_eq(kuid, old->uid)) {
73383 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
73384 goto error;
73385 }
73386
73387 + if (gr_check_user_change(kruid, keuid, -1))
73388 + goto error;
73389 +
73390 if (ruid != (uid_t) -1) {
73391 new->uid = kruid;
73392 if (!uid_eq(kruid, old->uid)) {
73393 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
73394 goto error;
73395 }
73396
73397 + if (gr_check_group_change(krgid, kegid, -1))
73398 + goto error;
73399 +
73400 if (rgid != (gid_t) -1)
73401 new->gid = krgid;
73402 if (egid != (gid_t) -1)
73403 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73404 if (!uid_valid(kuid))
73405 return old_fsuid;
73406
73407 + if (gr_check_user_change(-1, -1, kuid))
73408 + goto error;
73409 +
73410 new = prepare_creds();
73411 if (!new)
73412 return old_fsuid;
73413 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73414 }
73415 }
73416
73417 +error:
73418 abort_creds(new);
73419 return old_fsuid;
73420
73421 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
73422 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
73423 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
73424 nsown_capable(CAP_SETGID)) {
73425 + if (gr_check_group_change(-1, -1, kgid))
73426 + goto error;
73427 +
73428 if (!gid_eq(kgid, old->fsgid)) {
73429 new->fsgid = kgid;
73430 goto change_okay;
73431 }
73432 }
73433
73434 +error:
73435 abort_creds(new);
73436 return old_fsgid;
73437
73438 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
73439 return -EFAULT;
73440
73441 down_read(&uts_sem);
73442 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
73443 + error = __copy_to_user(name->sysname, &utsname()->sysname,
73444 __OLD_UTS_LEN);
73445 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
73446 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
73447 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
73448 __OLD_UTS_LEN);
73449 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
73450 - error |= __copy_to_user(&name->release, &utsname()->release,
73451 + error |= __copy_to_user(name->release, &utsname()->release,
73452 __OLD_UTS_LEN);
73453 error |= __put_user(0, name->release + __OLD_UTS_LEN);
73454 - error |= __copy_to_user(&name->version, &utsname()->version,
73455 + error |= __copy_to_user(name->version, &utsname()->version,
73456 __OLD_UTS_LEN);
73457 error |= __put_user(0, name->version + __OLD_UTS_LEN);
73458 - error |= __copy_to_user(&name->machine, &utsname()->machine,
73459 + error |= __copy_to_user(name->machine, &utsname()->machine,
73460 __OLD_UTS_LEN);
73461 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
73462 up_read(&uts_sem);
73463 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
73464 error = get_dumpable(me->mm);
73465 break;
73466 case PR_SET_DUMPABLE:
73467 - if (arg2 < 0 || arg2 > 1) {
73468 + if (arg2 > 1) {
73469 error = -EINVAL;
73470 break;
73471 }
73472 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
73473 index c88878d..99d321b 100644
73474 --- a/kernel/sysctl.c
73475 +++ b/kernel/sysctl.c
73476 @@ -92,7 +92,6 @@
73477
73478
73479 #if defined(CONFIG_SYSCTL)
73480 -
73481 /* External variables not in a header file. */
73482 extern int sysctl_overcommit_memory;
73483 extern int sysctl_overcommit_ratio;
73484 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
73485 void __user *buffer, size_t *lenp, loff_t *ppos);
73486 #endif
73487
73488 -#ifdef CONFIG_PRINTK
73489 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73490 void __user *buffer, size_t *lenp, loff_t *ppos);
73491 -#endif
73492
73493 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
73494 void __user *buffer, size_t *lenp, loff_t *ppos);
73495 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
73496
73497 #endif
73498
73499 +extern struct ctl_table grsecurity_table[];
73500 +
73501 static struct ctl_table kern_table[];
73502 static struct ctl_table vm_table[];
73503 static struct ctl_table fs_table[];
73504 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
73505 int sysctl_legacy_va_layout;
73506 #endif
73507
73508 +#ifdef CONFIG_PAX_SOFTMODE
73509 +static ctl_table pax_table[] = {
73510 + {
73511 + .procname = "softmode",
73512 + .data = &pax_softmode,
73513 + .maxlen = sizeof(unsigned int),
73514 + .mode = 0600,
73515 + .proc_handler = &proc_dointvec,
73516 + },
73517 +
73518 + { }
73519 +};
73520 +#endif
73521 +
73522 /* The default sysctl tables: */
73523
73524 static struct ctl_table sysctl_base_table[] = {
73525 @@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
73526 #endif
73527
73528 static struct ctl_table kern_table[] = {
73529 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
73530 + {
73531 + .procname = "grsecurity",
73532 + .mode = 0500,
73533 + .child = grsecurity_table,
73534 + },
73535 +#endif
73536 +
73537 +#ifdef CONFIG_PAX_SOFTMODE
73538 + {
73539 + .procname = "pax",
73540 + .mode = 0500,
73541 + .child = pax_table,
73542 + },
73543 +#endif
73544 +
73545 {
73546 .procname = "sched_child_runs_first",
73547 .data = &sysctl_sched_child_runs_first,
73548 @@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
73549 .data = &modprobe_path,
73550 .maxlen = KMOD_PATH_LEN,
73551 .mode = 0644,
73552 - .proc_handler = proc_dostring,
73553 + .proc_handler = proc_dostring_modpriv,
73554 },
73555 {
73556 .procname = "modules_disabled",
73557 @@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
73558 .extra1 = &zero,
73559 .extra2 = &one,
73560 },
73561 +#endif
73562 {
73563 .procname = "kptr_restrict",
73564 .data = &kptr_restrict,
73565 .maxlen = sizeof(int),
73566 .mode = 0644,
73567 .proc_handler = proc_dointvec_minmax_sysadmin,
73568 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73569 + .extra1 = &two,
73570 +#else
73571 .extra1 = &zero,
73572 +#endif
73573 .extra2 = &two,
73574 },
73575 -#endif
73576 {
73577 .procname = "ngroups_max",
73578 .data = &ngroups_max,
73579 @@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
73580 .proc_handler = proc_dointvec_minmax,
73581 .extra1 = &zero,
73582 },
73583 + {
73584 + .procname = "heap_stack_gap",
73585 + .data = &sysctl_heap_stack_gap,
73586 + .maxlen = sizeof(sysctl_heap_stack_gap),
73587 + .mode = 0644,
73588 + .proc_handler = proc_doulongvec_minmax,
73589 + },
73590 #else
73591 {
73592 .procname = "nr_trim_pages",
73593 @@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
73594 buffer, lenp, ppos);
73595 }
73596
73597 +int proc_dostring_modpriv(struct ctl_table *table, int write,
73598 + void __user *buffer, size_t *lenp, loff_t *ppos)
73599 +{
73600 + if (write && !capable(CAP_SYS_MODULE))
73601 + return -EPERM;
73602 +
73603 + return _proc_do_string(table->data, table->maxlen, write,
73604 + buffer, lenp, ppos);
73605 +}
73606 +
73607 static size_t proc_skip_spaces(char **buf)
73608 {
73609 size_t ret;
73610 @@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
73611 len = strlen(tmp);
73612 if (len > *size)
73613 len = *size;
73614 + if (len > sizeof(tmp))
73615 + len = sizeof(tmp);
73616 if (copy_to_user(*buf, tmp, len))
73617 return -EFAULT;
73618 *size -= len;
73619 @@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
73620 return err;
73621 }
73622
73623 -#ifdef CONFIG_PRINTK
73624 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73625 void __user *buffer, size_t *lenp, loff_t *ppos)
73626 {
73627 @@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73628
73629 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
73630 }
73631 -#endif
73632
73633 struct do_proc_dointvec_minmax_conv_param {
73634 int *min;
73635 @@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
73636 *i = val;
73637 } else {
73638 val = convdiv * (*i) / convmul;
73639 - if (!first)
73640 + if (!first) {
73641 err = proc_put_char(&buffer, &left, '\t');
73642 + if (err)
73643 + break;
73644 + }
73645 err = proc_put_long(&buffer, &left, val, false);
73646 if (err)
73647 break;
73648 @@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
73649 return -ENOSYS;
73650 }
73651
73652 +int proc_dostring_modpriv(struct ctl_table *table, int write,
73653 + void __user *buffer, size_t *lenp, loff_t *ppos)
73654 +{
73655 + return -ENOSYS;
73656 +}
73657 +
73658 int proc_dointvec(struct ctl_table *table, int write,
73659 void __user *buffer, size_t *lenp, loff_t *ppos)
73660 {
73661 @@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
73662 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
73663 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
73664 EXPORT_SYMBOL(proc_dostring);
73665 +EXPORT_SYMBOL(proc_dostring_modpriv);
73666 EXPORT_SYMBOL(proc_doulongvec_minmax);
73667 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
73668 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
73669 index 5a63844..25dfc5c 100644
73670 --- a/kernel/sysctl_binary.c
73671 +++ b/kernel/sysctl_binary.c
73672 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
73673 int i;
73674
73675 set_fs(KERNEL_DS);
73676 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73677 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73678 set_fs(old_fs);
73679 if (result < 0)
73680 goto out_kfree;
73681 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
73682 }
73683
73684 set_fs(KERNEL_DS);
73685 - result = vfs_write(file, buffer, str - buffer, &pos);
73686 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73687 set_fs(old_fs);
73688 if (result < 0)
73689 goto out_kfree;
73690 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
73691 int i;
73692
73693 set_fs(KERNEL_DS);
73694 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73695 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73696 set_fs(old_fs);
73697 if (result < 0)
73698 goto out_kfree;
73699 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
73700 }
73701
73702 set_fs(KERNEL_DS);
73703 - result = vfs_write(file, buffer, str - buffer, &pos);
73704 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73705 set_fs(old_fs);
73706 if (result < 0)
73707 goto out_kfree;
73708 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
73709 int i;
73710
73711 set_fs(KERNEL_DS);
73712 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73713 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73714 set_fs(old_fs);
73715 if (result < 0)
73716 goto out;
73717 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73718 __le16 dnaddr;
73719
73720 set_fs(KERNEL_DS);
73721 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73722 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73723 set_fs(old_fs);
73724 if (result < 0)
73725 goto out;
73726 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73727 le16_to_cpu(dnaddr) & 0x3ff);
73728
73729 set_fs(KERNEL_DS);
73730 - result = vfs_write(file, buf, len, &pos);
73731 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
73732 set_fs(old_fs);
73733 if (result < 0)
73734 goto out;
73735 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
73736 index 145bb4d..b2aa969 100644
73737 --- a/kernel/taskstats.c
73738 +++ b/kernel/taskstats.c
73739 @@ -28,9 +28,12 @@
73740 #include <linux/fs.h>
73741 #include <linux/file.h>
73742 #include <linux/pid_namespace.h>
73743 +#include <linux/grsecurity.h>
73744 #include <net/genetlink.h>
73745 #include <linux/atomic.h>
73746
73747 +extern int gr_is_taskstats_denied(int pid);
73748 +
73749 /*
73750 * Maximum length of a cpumask that can be specified in
73751 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
73752 @@ -570,6 +573,9 @@ err:
73753
73754 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
73755 {
73756 + if (gr_is_taskstats_denied(current->pid))
73757 + return -EACCES;
73758 +
73759 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
73760 return cmd_attr_register_cpumask(info);
73761 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
73762 diff --git a/kernel/time.c b/kernel/time.c
73763 index d226c6a..c7c0960 100644
73764 --- a/kernel/time.c
73765 +++ b/kernel/time.c
73766 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
73767 return error;
73768
73769 if (tz) {
73770 + /* we log in do_settimeofday called below, so don't log twice
73771 + */
73772 + if (!tv)
73773 + gr_log_timechange();
73774 +
73775 sys_tz = *tz;
73776 update_vsyscall_tz();
73777 if (firsttime) {
73778 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
73779 index f11d83b..d016d91 100644
73780 --- a/kernel/time/alarmtimer.c
73781 +++ b/kernel/time/alarmtimer.c
73782 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
73783 struct platform_device *pdev;
73784 int error = 0;
73785 int i;
73786 - struct k_clock alarm_clock = {
73787 + static struct k_clock alarm_clock = {
73788 .clock_getres = alarm_clock_getres,
73789 .clock_get = alarm_clock_get,
73790 .timer_create = alarm_timer_create,
73791 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
73792 index f113755..ec24223 100644
73793 --- a/kernel/time/tick-broadcast.c
73794 +++ b/kernel/time/tick-broadcast.c
73795 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
73796 * then clear the broadcast bit.
73797 */
73798 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
73799 - int cpu = smp_processor_id();
73800 + cpu = smp_processor_id();
73801
73802 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
73803 tick_broadcast_clear_oneshot(cpu);
73804 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
73805 index cbc6acb..3a77191 100644
73806 --- a/kernel/time/timekeeping.c
73807 +++ b/kernel/time/timekeeping.c
73808 @@ -15,6 +15,7 @@
73809 #include <linux/init.h>
73810 #include <linux/mm.h>
73811 #include <linux/sched.h>
73812 +#include <linux/grsecurity.h>
73813 #include <linux/syscore_ops.h>
73814 #include <linux/clocksource.h>
73815 #include <linux/jiffies.h>
73816 @@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
73817 if (!timespec_valid_strict(tv))
73818 return -EINVAL;
73819
73820 + gr_log_timechange();
73821 +
73822 write_seqlock_irqsave(&tk->lock, flags);
73823
73824 timekeeping_forward_now(tk);
73825 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
73826 index af5a7e9..715611a 100644
73827 --- a/kernel/time/timer_list.c
73828 +++ b/kernel/time/timer_list.c
73829 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
73830
73831 static void print_name_offset(struct seq_file *m, void *sym)
73832 {
73833 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73834 + SEQ_printf(m, "<%p>", NULL);
73835 +#else
73836 char symname[KSYM_NAME_LEN];
73837
73838 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
73839 SEQ_printf(m, "<%pK>", sym);
73840 else
73841 SEQ_printf(m, "%s", symname);
73842 +#endif
73843 }
73844
73845 static void
73846 @@ -112,7 +116,11 @@ next_one:
73847 static void
73848 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
73849 {
73850 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73851 + SEQ_printf(m, " .base: %p\n", NULL);
73852 +#else
73853 SEQ_printf(m, " .base: %pK\n", base);
73854 +#endif
73855 SEQ_printf(m, " .index: %d\n",
73856 base->index);
73857 SEQ_printf(m, " .resolution: %Lu nsecs\n",
73858 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
73859 {
73860 struct proc_dir_entry *pe;
73861
73862 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73863 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
73864 +#else
73865 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
73866 +#endif
73867 if (!pe)
73868 return -ENOMEM;
73869 return 0;
73870 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
73871 index 0b537f2..40d6c20 100644
73872 --- a/kernel/time/timer_stats.c
73873 +++ b/kernel/time/timer_stats.c
73874 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
73875 static unsigned long nr_entries;
73876 static struct entry entries[MAX_ENTRIES];
73877
73878 -static atomic_t overflow_count;
73879 +static atomic_unchecked_t overflow_count;
73880
73881 /*
73882 * The entries are in a hash-table, for fast lookup:
73883 @@ -140,7 +140,7 @@ static void reset_entries(void)
73884 nr_entries = 0;
73885 memset(entries, 0, sizeof(entries));
73886 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
73887 - atomic_set(&overflow_count, 0);
73888 + atomic_set_unchecked(&overflow_count, 0);
73889 }
73890
73891 static struct entry *alloc_entry(void)
73892 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73893 if (likely(entry))
73894 entry->count++;
73895 else
73896 - atomic_inc(&overflow_count);
73897 + atomic_inc_unchecked(&overflow_count);
73898
73899 out_unlock:
73900 raw_spin_unlock_irqrestore(lock, flags);
73901 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73902
73903 static void print_name_offset(struct seq_file *m, unsigned long addr)
73904 {
73905 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73906 + seq_printf(m, "<%p>", NULL);
73907 +#else
73908 char symname[KSYM_NAME_LEN];
73909
73910 if (lookup_symbol_name(addr, symname) < 0)
73911 - seq_printf(m, "<%p>", (void *)addr);
73912 + seq_printf(m, "<%pK>", (void *)addr);
73913 else
73914 seq_printf(m, "%s", symname);
73915 +#endif
73916 }
73917
73918 static int tstats_show(struct seq_file *m, void *v)
73919 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
73920
73921 seq_puts(m, "Timer Stats Version: v0.2\n");
73922 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
73923 - if (atomic_read(&overflow_count))
73924 + if (atomic_read_unchecked(&overflow_count))
73925 seq_printf(m, "Overflow: %d entries\n",
73926 - atomic_read(&overflow_count));
73927 + atomic_read_unchecked(&overflow_count));
73928
73929 for (i = 0; i < nr_entries; i++) {
73930 entry = entries + i;
73931 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
73932 {
73933 struct proc_dir_entry *pe;
73934
73935 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73936 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
73937 +#else
73938 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
73939 +#endif
73940 if (!pe)
73941 return -ENOMEM;
73942 return 0;
73943 diff --git a/kernel/timer.c b/kernel/timer.c
73944 index 367d008..1ee9ed9 100644
73945 --- a/kernel/timer.c
73946 +++ b/kernel/timer.c
73947 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
73948 /*
73949 * This function runs timers and the timer-tq in bottom half context.
73950 */
73951 -static void run_timer_softirq(struct softirq_action *h)
73952 +static void run_timer_softirq(void)
73953 {
73954 struct tvec_base *base = __this_cpu_read(tvec_bases);
73955
73956 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
73957 return NOTIFY_OK;
73958 }
73959
73960 -static struct notifier_block __cpuinitdata timers_nb = {
73961 +static struct notifier_block timers_nb = {
73962 .notifier_call = timer_cpu_notify,
73963 };
73964
73965 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
73966 index c0bd030..62a1927 100644
73967 --- a/kernel/trace/blktrace.c
73968 +++ b/kernel/trace/blktrace.c
73969 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
73970 struct blk_trace *bt = filp->private_data;
73971 char buf[16];
73972
73973 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
73974 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
73975
73976 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
73977 }
73978 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
73979 return 1;
73980
73981 bt = buf->chan->private_data;
73982 - atomic_inc(&bt->dropped);
73983 + atomic_inc_unchecked(&bt->dropped);
73984 return 0;
73985 }
73986
73987 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
73988
73989 bt->dir = dir;
73990 bt->dev = dev;
73991 - atomic_set(&bt->dropped, 0);
73992 + atomic_set_unchecked(&bt->dropped, 0);
73993
73994 ret = -EIO;
73995 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
73996 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
73997 index 41473b4..325fcfc 100644
73998 --- a/kernel/trace/ftrace.c
73999 +++ b/kernel/trace/ftrace.c
74000 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74001 if (unlikely(ftrace_disabled))
74002 return 0;
74003
74004 + ret = ftrace_arch_code_modify_prepare();
74005 + FTRACE_WARN_ON(ret);
74006 + if (ret)
74007 + return 0;
74008 +
74009 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74010 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74011 if (ret) {
74012 ftrace_bug(ret, ip);
74013 - return 0;
74014 }
74015 - return 1;
74016 + return ret ? 0 : 1;
74017 }
74018
74019 /*
74020 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
74021
74022 int
74023 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
74024 - void *data)
74025 + void *data)
74026 {
74027 struct ftrace_func_probe *entry;
74028 struct ftrace_page *pg;
74029 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
74030 if (!count)
74031 return 0;
74032
74033 + pax_open_kernel();
74034 sort(start, count, sizeof(*start),
74035 ftrace_cmp_ips, ftrace_swap_ips);
74036 + pax_close_kernel();
74037
74038 start_pg = ftrace_allocate_pages(count);
74039 if (!start_pg)
74040 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
74041 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
74042
74043 static int ftrace_graph_active;
74044 -static struct notifier_block ftrace_suspend_notifier;
74045 -
74046 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
74047 {
74048 return 0;
74049 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
74050 return NOTIFY_DONE;
74051 }
74052
74053 +static struct notifier_block ftrace_suspend_notifier = {
74054 + .notifier_call = ftrace_suspend_notifier_call
74055 +};
74056 +
74057 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74058 trace_func_graph_ent_t entryfunc)
74059 {
74060 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74061 goto out;
74062 }
74063
74064 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
74065 register_pm_notifier(&ftrace_suspend_notifier);
74066
74067 ftrace_graph_active++;
74068 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74069 index ce8514f..8233573 100644
74070 --- a/kernel/trace/ring_buffer.c
74071 +++ b/kernel/trace/ring_buffer.c
74072 @@ -346,9 +346,9 @@ struct buffer_data_page {
74073 */
74074 struct buffer_page {
74075 struct list_head list; /* list of buffer pages */
74076 - local_t write; /* index for next write */
74077 + local_unchecked_t write; /* index for next write */
74078 unsigned read; /* index for next read */
74079 - local_t entries; /* entries on this page */
74080 + local_unchecked_t entries; /* entries on this page */
74081 unsigned long real_end; /* real end of data */
74082 struct buffer_data_page *page; /* Actual data page */
74083 };
74084 @@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
74085 unsigned long last_overrun;
74086 local_t entries_bytes;
74087 local_t entries;
74088 - local_t overrun;
74089 - local_t commit_overrun;
74090 + local_unchecked_t overrun;
74091 + local_unchecked_t commit_overrun;
74092 local_t dropped_events;
74093 local_t committing;
74094 local_t commits;
74095 @@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74096 *
74097 * We add a counter to the write field to denote this.
74098 */
74099 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
74100 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
74101 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
74102 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
74103
74104 /*
74105 * Just make sure we have seen our old_write and synchronize
74106 @@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74107 * cmpxchg to only update if an interrupt did not already
74108 * do it for us. If the cmpxchg fails, we don't care.
74109 */
74110 - (void)local_cmpxchg(&next_page->write, old_write, val);
74111 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
74112 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
74113 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
74114
74115 /*
74116 * No need to worry about races with clearing out the commit.
74117 @@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
74118
74119 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
74120 {
74121 - return local_read(&bpage->entries) & RB_WRITE_MASK;
74122 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
74123 }
74124
74125 static inline unsigned long rb_page_write(struct buffer_page *bpage)
74126 {
74127 - return local_read(&bpage->write) & RB_WRITE_MASK;
74128 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
74129 }
74130
74131 static int
74132 @@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
74133 * bytes consumed in ring buffer from here.
74134 * Increment overrun to account for the lost events.
74135 */
74136 - local_add(page_entries, &cpu_buffer->overrun);
74137 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
74138 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74139 }
74140
74141 @@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74142 * it is our responsibility to update
74143 * the counters.
74144 */
74145 - local_add(entries, &cpu_buffer->overrun);
74146 + local_add_unchecked(entries, &cpu_buffer->overrun);
74147 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74148
74149 /*
74150 @@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74151 if (tail == BUF_PAGE_SIZE)
74152 tail_page->real_end = 0;
74153
74154 - local_sub(length, &tail_page->write);
74155 + local_sub_unchecked(length, &tail_page->write);
74156 return;
74157 }
74158
74159 @@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74160 rb_event_set_padding(event);
74161
74162 /* Set the write back to the previous setting */
74163 - local_sub(length, &tail_page->write);
74164 + local_sub_unchecked(length, &tail_page->write);
74165 return;
74166 }
74167
74168 @@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74169
74170 /* Set write to end of buffer */
74171 length = (tail + length) - BUF_PAGE_SIZE;
74172 - local_sub(length, &tail_page->write);
74173 + local_sub_unchecked(length, &tail_page->write);
74174 }
74175
74176 /*
74177 @@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74178 * about it.
74179 */
74180 if (unlikely(next_page == commit_page)) {
74181 - local_inc(&cpu_buffer->commit_overrun);
74182 + local_inc_unchecked(&cpu_buffer->commit_overrun);
74183 goto out_reset;
74184 }
74185
74186 @@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74187 cpu_buffer->tail_page) &&
74188 (cpu_buffer->commit_page ==
74189 cpu_buffer->reader_page))) {
74190 - local_inc(&cpu_buffer->commit_overrun);
74191 + local_inc_unchecked(&cpu_buffer->commit_overrun);
74192 goto out_reset;
74193 }
74194 }
74195 @@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74196 length += RB_LEN_TIME_EXTEND;
74197
74198 tail_page = cpu_buffer->tail_page;
74199 - write = local_add_return(length, &tail_page->write);
74200 + write = local_add_return_unchecked(length, &tail_page->write);
74201
74202 /* set write to only the index of the write */
74203 write &= RB_WRITE_MASK;
74204 @@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74205 kmemcheck_annotate_bitfield(event, bitfield);
74206 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
74207
74208 - local_inc(&tail_page->entries);
74209 + local_inc_unchecked(&tail_page->entries);
74210
74211 /*
74212 * If this is the first commit on the page, then update
74213 @@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74214
74215 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
74216 unsigned long write_mask =
74217 - local_read(&bpage->write) & ~RB_WRITE_MASK;
74218 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
74219 unsigned long event_length = rb_event_length(event);
74220 /*
74221 * This is on the tail page. It is possible that
74222 @@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74223 */
74224 old_index += write_mask;
74225 new_index += write_mask;
74226 - index = local_cmpxchg(&bpage->write, old_index, new_index);
74227 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
74228 if (index == old_index) {
74229 /* update counters */
74230 local_sub(event_length, &cpu_buffer->entries_bytes);
74231 @@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74232
74233 /* Do the likely case first */
74234 if (likely(bpage->page == (void *)addr)) {
74235 - local_dec(&bpage->entries);
74236 + local_dec_unchecked(&bpage->entries);
74237 return;
74238 }
74239
74240 @@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74241 start = bpage;
74242 do {
74243 if (bpage->page == (void *)addr) {
74244 - local_dec(&bpage->entries);
74245 + local_dec_unchecked(&bpage->entries);
74246 return;
74247 }
74248 rb_inc_page(cpu_buffer, &bpage);
74249 @@ -2926,7 +2926,7 @@ static inline unsigned long
74250 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
74251 {
74252 return local_read(&cpu_buffer->entries) -
74253 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
74254 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
74255 }
74256
74257 /**
74258 @@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
74259 return 0;
74260
74261 cpu_buffer = buffer->buffers[cpu];
74262 - ret = local_read(&cpu_buffer->overrun);
74263 + ret = local_read_unchecked(&cpu_buffer->overrun);
74264
74265 return ret;
74266 }
74267 @@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
74268 return 0;
74269
74270 cpu_buffer = buffer->buffers[cpu];
74271 - ret = local_read(&cpu_buffer->commit_overrun);
74272 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
74273
74274 return ret;
74275 }
74276 @@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
74277 /* if you care about this being correct, lock the buffer */
74278 for_each_buffer_cpu(buffer, cpu) {
74279 cpu_buffer = buffer->buffers[cpu];
74280 - overruns += local_read(&cpu_buffer->overrun);
74281 + overruns += local_read_unchecked(&cpu_buffer->overrun);
74282 }
74283
74284 return overruns;
74285 @@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74286 /*
74287 * Reset the reader page to size zero.
74288 */
74289 - local_set(&cpu_buffer->reader_page->write, 0);
74290 - local_set(&cpu_buffer->reader_page->entries, 0);
74291 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74292 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74293 local_set(&cpu_buffer->reader_page->page->commit, 0);
74294 cpu_buffer->reader_page->real_end = 0;
74295
74296 @@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74297 * want to compare with the last_overrun.
74298 */
74299 smp_mb();
74300 - overwrite = local_read(&(cpu_buffer->overrun));
74301 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
74302
74303 /*
74304 * Here's the tricky part.
74305 @@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74306
74307 cpu_buffer->head_page
74308 = list_entry(cpu_buffer->pages, struct buffer_page, list);
74309 - local_set(&cpu_buffer->head_page->write, 0);
74310 - local_set(&cpu_buffer->head_page->entries, 0);
74311 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
74312 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
74313 local_set(&cpu_buffer->head_page->page->commit, 0);
74314
74315 cpu_buffer->head_page->read = 0;
74316 @@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74317
74318 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
74319 INIT_LIST_HEAD(&cpu_buffer->new_pages);
74320 - local_set(&cpu_buffer->reader_page->write, 0);
74321 - local_set(&cpu_buffer->reader_page->entries, 0);
74322 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74323 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74324 local_set(&cpu_buffer->reader_page->page->commit, 0);
74325 cpu_buffer->reader_page->read = 0;
74326
74327 local_set(&cpu_buffer->entries_bytes, 0);
74328 - local_set(&cpu_buffer->overrun, 0);
74329 - local_set(&cpu_buffer->commit_overrun, 0);
74330 + local_set_unchecked(&cpu_buffer->overrun, 0);
74331 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
74332 local_set(&cpu_buffer->dropped_events, 0);
74333 local_set(&cpu_buffer->entries, 0);
74334 local_set(&cpu_buffer->committing, 0);
74335 @@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
74336 rb_init_page(bpage);
74337 bpage = reader->page;
74338 reader->page = *data_page;
74339 - local_set(&reader->write, 0);
74340 - local_set(&reader->entries, 0);
74341 + local_set_unchecked(&reader->write, 0);
74342 + local_set_unchecked(&reader->entries, 0);
74343 reader->read = 0;
74344 *data_page = bpage;
74345
74346 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74347 index 3c13e46..883d039 100644
74348 --- a/kernel/trace/trace.c
74349 +++ b/kernel/trace/trace.c
74350 @@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74351 };
74352 #endif
74353
74354 -static struct dentry *d_tracer;
74355 -
74356 struct dentry *tracing_init_dentry(void)
74357 {
74358 + static struct dentry *d_tracer;
74359 static int once;
74360
74361 if (d_tracer)
74362 @@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
74363 return d_tracer;
74364 }
74365
74366 -static struct dentry *d_percpu;
74367 -
74368 struct dentry *tracing_dentry_percpu(void)
74369 {
74370 + static struct dentry *d_percpu;
74371 static int once;
74372 struct dentry *d_tracer;
74373
74374 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74375 index 880073d..42db7c3 100644
74376 --- a/kernel/trace/trace_events.c
74377 +++ b/kernel/trace/trace_events.c
74378 @@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
74379 struct ftrace_module_file_ops {
74380 struct list_head list;
74381 struct module *mod;
74382 - struct file_operations id;
74383 - struct file_operations enable;
74384 - struct file_operations format;
74385 - struct file_operations filter;
74386 };
74387
74388 static struct ftrace_module_file_ops *
74389 @@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
74390
74391 file_ops->mod = mod;
74392
74393 - file_ops->id = ftrace_event_id_fops;
74394 - file_ops->id.owner = mod;
74395 -
74396 - file_ops->enable = ftrace_enable_fops;
74397 - file_ops->enable.owner = mod;
74398 -
74399 - file_ops->filter = ftrace_event_filter_fops;
74400 - file_ops->filter.owner = mod;
74401 -
74402 - file_ops->format = ftrace_event_format_fops;
74403 - file_ops->format.owner = mod;
74404 + pax_open_kernel();
74405 + mod->trace_id.owner = mod;
74406 + mod->trace_enable.owner = mod;
74407 + mod->trace_filter.owner = mod;
74408 + mod->trace_format.owner = mod;
74409 + pax_close_kernel();
74410
74411 list_add(&file_ops->list, &ftrace_module_file_list);
74412
74413 @@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
74414
74415 for_each_event(call, start, end) {
74416 __trace_add_event_call(*call, mod,
74417 - &file_ops->id, &file_ops->enable,
74418 - &file_ops->filter, &file_ops->format);
74419 + &mod->trace_id, &mod->trace_enable,
74420 + &mod->trace_filter, &mod->trace_format);
74421 }
74422 }
74423
74424 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74425 index fd3c8aa..5f324a6 100644
74426 --- a/kernel/trace/trace_mmiotrace.c
74427 +++ b/kernel/trace/trace_mmiotrace.c
74428 @@ -24,7 +24,7 @@ struct header_iter {
74429 static struct trace_array *mmio_trace_array;
74430 static bool overrun_detected;
74431 static unsigned long prev_overruns;
74432 -static atomic_t dropped_count;
74433 +static atomic_unchecked_t dropped_count;
74434
74435 static void mmio_reset_data(struct trace_array *tr)
74436 {
74437 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
74438
74439 static unsigned long count_overruns(struct trace_iterator *iter)
74440 {
74441 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
74442 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74443 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74444
74445 if (over > prev_overruns)
74446 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74447 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74448 sizeof(*entry), 0, pc);
74449 if (!event) {
74450 - atomic_inc(&dropped_count);
74451 + atomic_inc_unchecked(&dropped_count);
74452 return;
74453 }
74454 entry = ring_buffer_event_data(event);
74455 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74456 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74457 sizeof(*entry), 0, pc);
74458 if (!event) {
74459 - atomic_inc(&dropped_count);
74460 + atomic_inc_unchecked(&dropped_count);
74461 return;
74462 }
74463 entry = ring_buffer_event_data(event);
74464 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74465 index 194d796..76edb8f 100644
74466 --- a/kernel/trace/trace_output.c
74467 +++ b/kernel/trace/trace_output.c
74468 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
74469
74470 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74471 if (!IS_ERR(p)) {
74472 - p = mangle_path(s->buffer + s->len, p, "\n");
74473 + p = mangle_path(s->buffer + s->len, p, "\n\\");
74474 if (p) {
74475 s->len = p - s->buffer;
74476 return 1;
74477 @@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
74478 goto out;
74479 }
74480
74481 + pax_open_kernel();
74482 if (event->funcs->trace == NULL)
74483 - event->funcs->trace = trace_nop_print;
74484 + *(void **)&event->funcs->trace = trace_nop_print;
74485 if (event->funcs->raw == NULL)
74486 - event->funcs->raw = trace_nop_print;
74487 + *(void **)&event->funcs->raw = trace_nop_print;
74488 if (event->funcs->hex == NULL)
74489 - event->funcs->hex = trace_nop_print;
74490 + *(void **)&event->funcs->hex = trace_nop_print;
74491 if (event->funcs->binary == NULL)
74492 - event->funcs->binary = trace_nop_print;
74493 + *(void **)&event->funcs->binary = trace_nop_print;
74494 + pax_close_kernel();
74495
74496 key = event->type & (EVENT_HASHSIZE - 1);
74497
74498 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74499 index 42ca822..cdcacc6 100644
74500 --- a/kernel/trace/trace_stack.c
74501 +++ b/kernel/trace/trace_stack.c
74502 @@ -52,7 +52,7 @@ static inline void check_stack(void)
74503 return;
74504
74505 /* we do not handle interrupt stacks yet */
74506 - if (!object_is_on_stack(&this_size))
74507 + if (!object_starts_on_stack(&this_size))
74508 return;
74509
74510 local_irq_save(flags);
74511 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74512 index 67604e5..3ebb003 100644
74513 --- a/lib/Kconfig.debug
74514 +++ b/lib/Kconfig.debug
74515 @@ -1278,6 +1278,7 @@ config LATENCYTOP
74516 depends on DEBUG_KERNEL
74517 depends on STACKTRACE_SUPPORT
74518 depends on PROC_FS
74519 + depends on !GRKERNSEC_HIDESYM
74520 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
74521 select KALLSYMS
74522 select KALLSYMS_ALL
74523 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
74524
74525 config PROVIDE_OHCI1394_DMA_INIT
74526 bool "Remote debugging over FireWire early on boot"
74527 - depends on PCI && X86
74528 + depends on PCI && X86 && !GRKERNSEC
74529 help
74530 If you want to debug problems which hang or crash the kernel early
74531 on boot and the crashing machine has a FireWire port, you can use
74532 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
74533
74534 config FIREWIRE_OHCI_REMOTE_DMA
74535 bool "Remote debugging over FireWire with firewire-ohci"
74536 - depends on FIREWIRE_OHCI
74537 + depends on FIREWIRE_OHCI && !GRKERNSEC
74538 help
74539 This option lets you use the FireWire bus for remote debugging
74540 with help of the firewire-ohci driver. It enables unfiltered
74541 diff --git a/lib/Makefile b/lib/Makefile
74542 index 02ed6c0..bd243da 100644
74543 --- a/lib/Makefile
74544 +++ b/lib/Makefile
74545 @@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
74546
74547 obj-$(CONFIG_BTREE) += btree.o
74548 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
74549 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
74550 +obj-y += list_debug.o
74551 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
74552
74553 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
74554 diff --git a/lib/bitmap.c b/lib/bitmap.c
74555 index 06f7e4f..f3cf2b0 100644
74556 --- a/lib/bitmap.c
74557 +++ b/lib/bitmap.c
74558 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74559 {
74560 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74561 u32 chunk;
74562 - const char __user __force *ubuf = (const char __user __force *)buf;
74563 + const char __user *ubuf = (const char __force_user *)buf;
74564
74565 bitmap_zero(maskp, nmaskbits);
74566
74567 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
74568 {
74569 if (!access_ok(VERIFY_READ, ubuf, ulen))
74570 return -EFAULT;
74571 - return __bitmap_parse((const char __force *)ubuf,
74572 + return __bitmap_parse((const char __force_kernel *)ubuf,
74573 ulen, 1, maskp, nmaskbits);
74574
74575 }
74576 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
74577 {
74578 unsigned a, b;
74579 int c, old_c, totaldigits;
74580 - const char __user __force *ubuf = (const char __user __force *)buf;
74581 + const char __user *ubuf = (const char __force_user *)buf;
74582 int exp_digit, in_range;
74583
74584 totaldigits = c = 0;
74585 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
74586 {
74587 if (!access_ok(VERIFY_READ, ubuf, ulen))
74588 return -EFAULT;
74589 - return __bitmap_parselist((const char __force *)ubuf,
74590 + return __bitmap_parselist((const char __force_kernel *)ubuf,
74591 ulen, 1, maskp, nmaskbits);
74592 }
74593 EXPORT_SYMBOL(bitmap_parselist_user);
74594 diff --git a/lib/bug.c b/lib/bug.c
74595 index d0cdf14..4d07bd2 100644
74596 --- a/lib/bug.c
74597 +++ b/lib/bug.c
74598 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74599 return BUG_TRAP_TYPE_NONE;
74600
74601 bug = find_bug(bugaddr);
74602 + if (!bug)
74603 + return BUG_TRAP_TYPE_NONE;
74604
74605 file = NULL;
74606 line = 0;
74607 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74608 index d11808c..dc2d6f8 100644
74609 --- a/lib/debugobjects.c
74610 +++ b/lib/debugobjects.c
74611 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74612 if (limit > 4)
74613 return;
74614
74615 - is_on_stack = object_is_on_stack(addr);
74616 + is_on_stack = object_starts_on_stack(addr);
74617 if (is_on_stack == onstack)
74618 return;
74619
74620 diff --git a/lib/devres.c b/lib/devres.c
74621 index 80b9c76..9e32279 100644
74622 --- a/lib/devres.c
74623 +++ b/lib/devres.c
74624 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
74625 void devm_iounmap(struct device *dev, void __iomem *addr)
74626 {
74627 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74628 - (void *)addr));
74629 + (void __force *)addr));
74630 iounmap(addr);
74631 }
74632 EXPORT_SYMBOL(devm_iounmap);
74633 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
74634 {
74635 ioport_unmap(addr);
74636 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
74637 - devm_ioport_map_match, (void *)addr));
74638 + devm_ioport_map_match, (void __force *)addr));
74639 }
74640 EXPORT_SYMBOL(devm_ioport_unmap);
74641
74642 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
74643 index 5e396ac..58d5de1 100644
74644 --- a/lib/dma-debug.c
74645 +++ b/lib/dma-debug.c
74646 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
74647
74648 void dma_debug_add_bus(struct bus_type *bus)
74649 {
74650 - struct notifier_block *nb;
74651 + notifier_block_no_const *nb;
74652
74653 if (global_disable)
74654 return;
74655 @@ -942,7 +942,7 @@ out:
74656
74657 static void check_for_stack(struct device *dev, void *addr)
74658 {
74659 - if (object_is_on_stack(addr))
74660 + if (object_starts_on_stack(addr))
74661 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
74662 "stack [addr=%p]\n", addr);
74663 }
74664 diff --git a/lib/inflate.c b/lib/inflate.c
74665 index 013a761..c28f3fc 100644
74666 --- a/lib/inflate.c
74667 +++ b/lib/inflate.c
74668 @@ -269,7 +269,7 @@ static void free(void *where)
74669 malloc_ptr = free_mem_ptr;
74670 }
74671 #else
74672 -#define malloc(a) kmalloc(a, GFP_KERNEL)
74673 +#define malloc(a) kmalloc((a), GFP_KERNEL)
74674 #define free(a) kfree(a)
74675 #endif
74676
74677 diff --git a/lib/ioremap.c b/lib/ioremap.c
74678 index 0c9216c..863bd89 100644
74679 --- a/lib/ioremap.c
74680 +++ b/lib/ioremap.c
74681 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
74682 unsigned long next;
74683
74684 phys_addr -= addr;
74685 - pmd = pmd_alloc(&init_mm, pud, addr);
74686 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74687 if (!pmd)
74688 return -ENOMEM;
74689 do {
74690 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
74691 unsigned long next;
74692
74693 phys_addr -= addr;
74694 - pud = pud_alloc(&init_mm, pgd, addr);
74695 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
74696 if (!pud)
74697 return -ENOMEM;
74698 do {
74699 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
74700 index bd2bea9..6b3c95e 100644
74701 --- a/lib/is_single_threaded.c
74702 +++ b/lib/is_single_threaded.c
74703 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
74704 struct task_struct *p, *t;
74705 bool ret;
74706
74707 + if (!mm)
74708 + return true;
74709 +
74710 if (atomic_read(&task->signal->live) != 1)
74711 return false;
74712
74713 diff --git a/lib/list_debug.c b/lib/list_debug.c
74714 index c24c2f7..3fc5da0 100644
74715 --- a/lib/list_debug.c
74716 +++ b/lib/list_debug.c
74717 @@ -11,7 +11,9 @@
74718 #include <linux/bug.h>
74719 #include <linux/kernel.h>
74720 #include <linux/rculist.h>
74721 +#include <linux/mm.h>
74722
74723 +#ifdef CONFIG_DEBUG_LIST
74724 /*
74725 * Insert a new entry between two known consecutive entries.
74726 *
74727 @@ -19,21 +21,32 @@
74728 * the prev/next entries already!
74729 */
74730
74731 -void __list_add(struct list_head *new,
74732 - struct list_head *prev,
74733 - struct list_head *next)
74734 +static bool __list_add_debug(struct list_head *new,
74735 + struct list_head *prev,
74736 + struct list_head *next)
74737 {
74738 - WARN(next->prev != prev,
74739 + if (WARN(next->prev != prev,
74740 "list_add corruption. next->prev should be "
74741 "prev (%p), but was %p. (next=%p).\n",
74742 - prev, next->prev, next);
74743 - WARN(prev->next != next,
74744 + prev, next->prev, next) ||
74745 + WARN(prev->next != next,
74746 "list_add corruption. prev->next should be "
74747 "next (%p), but was %p. (prev=%p).\n",
74748 - next, prev->next, prev);
74749 - WARN(new == prev || new == next,
74750 + next, prev->next, prev) ||
74751 + WARN(new == prev || new == next,
74752 "list_add double add: new=%p, prev=%p, next=%p.\n",
74753 - new, prev, next);
74754 + new, prev, next))
74755 + return false;
74756 + return true;
74757 +}
74758 +
74759 +void __list_add(struct list_head *new,
74760 + struct list_head *prev,
74761 + struct list_head *next)
74762 +{
74763 + if (!__list_add_debug(new, prev, next))
74764 + return;
74765 +
74766 next->prev = new;
74767 new->next = next;
74768 new->prev = prev;
74769 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
74770 }
74771 EXPORT_SYMBOL(__list_add);
74772
74773 -void __list_del_entry(struct list_head *entry)
74774 +static bool __list_del_entry_debug(struct list_head *entry)
74775 {
74776 struct list_head *prev, *next;
74777
74778 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
74779 WARN(next->prev != entry,
74780 "list_del corruption. next->prev should be %p, "
74781 "but was %p\n", entry, next->prev))
74782 + return false;
74783 + return true;
74784 +}
74785 +
74786 +void __list_del_entry(struct list_head *entry)
74787 +{
74788 + if (!__list_del_entry_debug(entry))
74789 return;
74790
74791 - __list_del(prev, next);
74792 + __list_del(entry->prev, entry->next);
74793 }
74794 EXPORT_SYMBOL(__list_del_entry);
74795
74796 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
74797 void __list_add_rcu(struct list_head *new,
74798 struct list_head *prev, struct list_head *next)
74799 {
74800 - WARN(next->prev != prev,
74801 + if (WARN(next->prev != prev,
74802 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
74803 - prev, next->prev, next);
74804 - WARN(prev->next != next,
74805 + prev, next->prev, next) ||
74806 + WARN(prev->next != next,
74807 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
74808 - next, prev->next, prev);
74809 + next, prev->next, prev))
74810 + return;
74811 +
74812 new->next = next;
74813 new->prev = prev;
74814 rcu_assign_pointer(list_next_rcu(prev), new);
74815 next->prev = new;
74816 }
74817 EXPORT_SYMBOL(__list_add_rcu);
74818 +#endif
74819 +
74820 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
74821 +{
74822 + struct list_head *prev, *next;
74823 +
74824 + prev = head->prev;
74825 + next = head;
74826 +
74827 +#ifdef CONFIG_DEBUG_LIST
74828 + if (!__list_add_debug(new, prev, next))
74829 + return;
74830 +#endif
74831 +
74832 + pax_open_kernel();
74833 + next->prev = new;
74834 + new->next = next;
74835 + new->prev = prev;
74836 + prev->next = new;
74837 + pax_close_kernel();
74838 +}
74839 +EXPORT_SYMBOL(pax_list_add_tail);
74840 +
74841 +void pax_list_del(struct list_head *entry)
74842 +{
74843 +#ifdef CONFIG_DEBUG_LIST
74844 + if (!__list_del_entry_debug(entry))
74845 + return;
74846 +#endif
74847 +
74848 + pax_open_kernel();
74849 + __list_del(entry->prev, entry->next);
74850 + entry->next = LIST_POISON1;
74851 + entry->prev = LIST_POISON2;
74852 + pax_close_kernel();
74853 +}
74854 +EXPORT_SYMBOL(pax_list_del);
74855 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
74856 index e796429..6e38f9f 100644
74857 --- a/lib/radix-tree.c
74858 +++ b/lib/radix-tree.c
74859 @@ -92,7 +92,7 @@ struct radix_tree_preload {
74860 int nr;
74861 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
74862 };
74863 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
74864 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
74865
74866 static inline void *ptr_to_indirect(void *ptr)
74867 {
74868 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
74869 index bb2b201..46abaf9 100644
74870 --- a/lib/strncpy_from_user.c
74871 +++ b/lib/strncpy_from_user.c
74872 @@ -21,7 +21,7 @@
74873 */
74874 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
74875 {
74876 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74877 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74878 long res = 0;
74879
74880 /*
74881 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
74882 index a28df52..3d55877 100644
74883 --- a/lib/strnlen_user.c
74884 +++ b/lib/strnlen_user.c
74885 @@ -26,7 +26,7 @@
74886 */
74887 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
74888 {
74889 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74890 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74891 long align, res = 0;
74892 unsigned long c;
74893
74894 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
74895 index fab33a9..3b5fe68 100644
74896 --- a/lib/vsprintf.c
74897 +++ b/lib/vsprintf.c
74898 @@ -16,6 +16,9 @@
74899 * - scnprintf and vscnprintf
74900 */
74901
74902 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74903 +#define __INCLUDED_BY_HIDESYM 1
74904 +#endif
74905 #include <stdarg.h>
74906 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
74907 #include <linux/types.h>
74908 @@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
74909 char sym[KSYM_SYMBOL_LEN];
74910 if (ext == 'B')
74911 sprint_backtrace(sym, value);
74912 - else if (ext != 'f' && ext != 's')
74913 + else if (ext != 'f' && ext != 's' && ext != 'a')
74914 sprint_symbol(sym, value);
74915 else
74916 sprint_symbol_no_offset(sym, value);
74917 @@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
74918 return number(buf, end, *(const netdev_features_t *)addr, spec);
74919 }
74920
74921 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74922 +int kptr_restrict __read_mostly = 2;
74923 +#else
74924 int kptr_restrict __read_mostly;
74925 +#endif
74926
74927 /*
74928 * Show a '%p' thing. A kernel extension is that the '%p' is followed
74929 @@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
74930 * - 'S' For symbolic direct pointers with offset
74931 * - 's' For symbolic direct pointers without offset
74932 * - 'B' For backtraced symbolic direct pointers with offset
74933 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
74934 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
74935 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
74936 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
74937 * - 'M' For a 6-byte MAC address, it prints the address in the
74938 @@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74939
74940 if (!ptr && *fmt != 'K') {
74941 /*
74942 - * Print (null) with the same width as a pointer so it makes
74943 + * Print (nil) with the same width as a pointer so it makes
74944 * tabular output look nice.
74945 */
74946 if (spec.field_width == -1)
74947 spec.field_width = default_width;
74948 - return string(buf, end, "(null)", spec);
74949 + return string(buf, end, "(nil)", spec);
74950 }
74951
74952 switch (*fmt) {
74953 @@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74954 /* Fallthrough */
74955 case 'S':
74956 case 's':
74957 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74958 + break;
74959 +#else
74960 + return symbol_string(buf, end, ptr, spec, *fmt);
74961 +#endif
74962 + case 'A':
74963 + case 'a':
74964 case 'B':
74965 return symbol_string(buf, end, ptr, spec, *fmt);
74966 case 'R':
74967 @@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74968 va_end(va);
74969 return buf;
74970 }
74971 + case 'P':
74972 + break;
74973 case 'K':
74974 /*
74975 * %pK cannot be used in IRQ context because its test
74976 @@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74977 }
74978 break;
74979 }
74980 +
74981 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74982 + /* 'P' = approved pointers to copy to userland,
74983 + as in the /proc/kallsyms case, as we make it display nothing
74984 + for non-root users, and the real contents for root users
74985 + Also ignore 'K' pointers, since we force their NULLing for non-root users
74986 + above
74987 + */
74988 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
74989 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
74990 + dump_stack();
74991 + ptr = NULL;
74992 + }
74993 +#endif
74994 +
74995 spec.flags |= SMALL;
74996 if (spec.field_width == -1) {
74997 spec.field_width = default_width;
74998 @@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74999 typeof(type) value; \
75000 if (sizeof(type) == 8) { \
75001 args = PTR_ALIGN(args, sizeof(u32)); \
75002 - *(u32 *)&value = *(u32 *)args; \
75003 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75004 + *(u32 *)&value = *(const u32 *)args; \
75005 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75006 } else { \
75007 args = PTR_ALIGN(args, sizeof(type)); \
75008 - value = *(typeof(type) *)args; \
75009 + value = *(const typeof(type) *)args; \
75010 } \
75011 args += sizeof(type); \
75012 value; \
75013 @@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75014 case FORMAT_TYPE_STR: {
75015 const char *str_arg = args;
75016 args += strlen(str_arg) + 1;
75017 - str = string(str, end, (char *)str_arg, spec);
75018 + str = string(str, end, str_arg, spec);
75019 break;
75020 }
75021
75022 diff --git a/localversion-grsec b/localversion-grsec
75023 new file mode 100644
75024 index 0000000..7cd6065
75025 --- /dev/null
75026 +++ b/localversion-grsec
75027 @@ -0,0 +1 @@
75028 +-grsec
75029 diff --git a/mm/Kconfig b/mm/Kconfig
75030 index 278e3ab..87c384d 100644
75031 --- a/mm/Kconfig
75032 +++ b/mm/Kconfig
75033 @@ -286,10 +286,10 @@ config KSM
75034 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
75035
75036 config DEFAULT_MMAP_MIN_ADDR
75037 - int "Low address space to protect from user allocation"
75038 + int "Low address space to protect from user allocation"
75039 depends on MMU
75040 - default 4096
75041 - help
75042 + default 65536
75043 + help
75044 This is the portion of low virtual memory which should be protected
75045 from userspace allocation. Keeping a user from writing to low pages
75046 can help reduce the impact of kernel NULL pointer bugs.
75047 @@ -320,7 +320,7 @@ config MEMORY_FAILURE
75048
75049 config HWPOISON_INJECT
75050 tristate "HWPoison pages injector"
75051 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
75052 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
75053 select PROC_PAGE_MONITOR
75054
75055 config NOMMU_INITIAL_TRIM_EXCESS
75056 diff --git a/mm/filemap.c b/mm/filemap.c
75057 index 83efee7..3f99381 100644
75058 --- a/mm/filemap.c
75059 +++ b/mm/filemap.c
75060 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75061 struct address_space *mapping = file->f_mapping;
75062
75063 if (!mapping->a_ops->readpage)
75064 - return -ENOEXEC;
75065 + return -ENODEV;
75066 file_accessed(file);
75067 vma->vm_ops = &generic_file_vm_ops;
75068 return 0;
75069 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75070 *pos = i_size_read(inode);
75071
75072 if (limit != RLIM_INFINITY) {
75073 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75074 if (*pos >= limit) {
75075 send_sig(SIGXFSZ, current, 0);
75076 return -EFBIG;
75077 diff --git a/mm/fremap.c b/mm/fremap.c
75078 index a0aaf0e..20325c3 100644
75079 --- a/mm/fremap.c
75080 +++ b/mm/fremap.c
75081 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75082 retry:
75083 vma = find_vma(mm, start);
75084
75085 +#ifdef CONFIG_PAX_SEGMEXEC
75086 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75087 + goto out;
75088 +#endif
75089 +
75090 /*
75091 * Make sure the vma is shared, that it supports prefaulting,
75092 * and that the remapped range is valid and fully within
75093 diff --git a/mm/highmem.c b/mm/highmem.c
75094 index b32b70c..e512eb0 100644
75095 --- a/mm/highmem.c
75096 +++ b/mm/highmem.c
75097 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
75098 * So no dangers, even with speculative execution.
75099 */
75100 page = pte_page(pkmap_page_table[i]);
75101 + pax_open_kernel();
75102 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
75103 -
75104 + pax_close_kernel();
75105 set_page_address(page, NULL);
75106 need_flush = 1;
75107 }
75108 @@ -198,9 +199,11 @@ start:
75109 }
75110 }
75111 vaddr = PKMAP_ADDR(last_pkmap_nr);
75112 +
75113 + pax_open_kernel();
75114 set_pte_at(&init_mm, vaddr,
75115 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75116 -
75117 + pax_close_kernel();
75118 pkmap_count[last_pkmap_nr] = 1;
75119 set_page_address(page, (void *)vaddr);
75120
75121 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75122 index 546db81..01d5c53 100644
75123 --- a/mm/hugetlb.c
75124 +++ b/mm/hugetlb.c
75125 @@ -2511,6 +2511,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75126 return 1;
75127 }
75128
75129 +#ifdef CONFIG_PAX_SEGMEXEC
75130 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75131 +{
75132 + struct mm_struct *mm = vma->vm_mm;
75133 + struct vm_area_struct *vma_m;
75134 + unsigned long address_m;
75135 + pte_t *ptep_m;
75136 +
75137 + vma_m = pax_find_mirror_vma(vma);
75138 + if (!vma_m)
75139 + return;
75140 +
75141 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75142 + address_m = address + SEGMEXEC_TASK_SIZE;
75143 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75144 + get_page(page_m);
75145 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
75146 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75147 +}
75148 +#endif
75149 +
75150 /*
75151 * Hugetlb_cow() should be called with page lock of the original hugepage held.
75152 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
75153 @@ -2629,6 +2650,11 @@ retry_avoidcopy:
75154 make_huge_pte(vma, new_page, 1));
75155 page_remove_rmap(old_page);
75156 hugepage_add_new_anon_rmap(new_page, vma, address);
75157 +
75158 +#ifdef CONFIG_PAX_SEGMEXEC
75159 + pax_mirror_huge_pte(vma, address, new_page);
75160 +#endif
75161 +
75162 /* Make the old page be freed below */
75163 new_page = old_page;
75164 }
75165 @@ -2788,6 +2814,10 @@ retry:
75166 && (vma->vm_flags & VM_SHARED)));
75167 set_huge_pte_at(mm, address, ptep, new_pte);
75168
75169 +#ifdef CONFIG_PAX_SEGMEXEC
75170 + pax_mirror_huge_pte(vma, address, page);
75171 +#endif
75172 +
75173 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75174 /* Optimization, do the COW without a second fault */
75175 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75176 @@ -2817,6 +2847,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75177 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75178 struct hstate *h = hstate_vma(vma);
75179
75180 +#ifdef CONFIG_PAX_SEGMEXEC
75181 + struct vm_area_struct *vma_m;
75182 +#endif
75183 +
75184 address &= huge_page_mask(h);
75185
75186 ptep = huge_pte_offset(mm, address);
75187 @@ -2830,6 +2864,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75188 VM_FAULT_SET_HINDEX(hstate_index(h));
75189 }
75190
75191 +#ifdef CONFIG_PAX_SEGMEXEC
75192 + vma_m = pax_find_mirror_vma(vma);
75193 + if (vma_m) {
75194 + unsigned long address_m;
75195 +
75196 + if (vma->vm_start > vma_m->vm_start) {
75197 + address_m = address;
75198 + address -= SEGMEXEC_TASK_SIZE;
75199 + vma = vma_m;
75200 + h = hstate_vma(vma);
75201 + } else
75202 + address_m = address + SEGMEXEC_TASK_SIZE;
75203 +
75204 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75205 + return VM_FAULT_OOM;
75206 + address_m &= HPAGE_MASK;
75207 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75208 + }
75209 +#endif
75210 +
75211 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75212 if (!ptep)
75213 return VM_FAULT_OOM;
75214 diff --git a/mm/internal.h b/mm/internal.h
75215 index 9ba2110..eaf0674 100644
75216 --- a/mm/internal.h
75217 +++ b/mm/internal.h
75218 @@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
75219 * in mm/page_alloc.c
75220 */
75221 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75222 +extern void free_compound_page(struct page *page);
75223 extern void prep_compound_page(struct page *page, unsigned long order);
75224 #ifdef CONFIG_MEMORY_FAILURE
75225 extern bool is_free_buddy_page(struct page *page);
75226 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75227 index 752a705..6c3102e 100644
75228 --- a/mm/kmemleak.c
75229 +++ b/mm/kmemleak.c
75230 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
75231
75232 for (i = 0; i < object->trace_len; i++) {
75233 void *ptr = (void *)object->trace[i];
75234 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75235 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
75236 }
75237 }
75238
75239 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
75240 return -ENOMEM;
75241 }
75242
75243 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
75244 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
75245 &kmemleak_fops);
75246 if (!dentry)
75247 pr_warning("Failed to create the debugfs kmemleak file\n");
75248 diff --git a/mm/maccess.c b/mm/maccess.c
75249 index d53adf9..03a24bf 100644
75250 --- a/mm/maccess.c
75251 +++ b/mm/maccess.c
75252 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
75253 set_fs(KERNEL_DS);
75254 pagefault_disable();
75255 ret = __copy_from_user_inatomic(dst,
75256 - (__force const void __user *)src, size);
75257 + (const void __force_user *)src, size);
75258 pagefault_enable();
75259 set_fs(old_fs);
75260
75261 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
75262
75263 set_fs(KERNEL_DS);
75264 pagefault_disable();
75265 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75266 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75267 pagefault_enable();
75268 set_fs(old_fs);
75269
75270 diff --git a/mm/madvise.c b/mm/madvise.c
75271 index 03dfa5c..b032917 100644
75272 --- a/mm/madvise.c
75273 +++ b/mm/madvise.c
75274 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75275 pgoff_t pgoff;
75276 unsigned long new_flags = vma->vm_flags;
75277
75278 +#ifdef CONFIG_PAX_SEGMEXEC
75279 + struct vm_area_struct *vma_m;
75280 +#endif
75281 +
75282 switch (behavior) {
75283 case MADV_NORMAL:
75284 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75285 @@ -123,6 +127,13 @@ success:
75286 /*
75287 * vm_flags is protected by the mmap_sem held in write mode.
75288 */
75289 +
75290 +#ifdef CONFIG_PAX_SEGMEXEC
75291 + vma_m = pax_find_mirror_vma(vma);
75292 + if (vma_m)
75293 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75294 +#endif
75295 +
75296 vma->vm_flags = new_flags;
75297
75298 out:
75299 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75300 struct vm_area_struct ** prev,
75301 unsigned long start, unsigned long end)
75302 {
75303 +
75304 +#ifdef CONFIG_PAX_SEGMEXEC
75305 + struct vm_area_struct *vma_m;
75306 +#endif
75307 +
75308 *prev = vma;
75309 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75310 return -EINVAL;
75311 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75312 zap_page_range(vma, start, end - start, &details);
75313 } else
75314 zap_page_range(vma, start, end - start, NULL);
75315 +
75316 +#ifdef CONFIG_PAX_SEGMEXEC
75317 + vma_m = pax_find_mirror_vma(vma);
75318 + if (vma_m) {
75319 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75320 + struct zap_details details = {
75321 + .nonlinear_vma = vma_m,
75322 + .last_index = ULONG_MAX,
75323 + };
75324 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75325 + } else
75326 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75327 + }
75328 +#endif
75329 +
75330 return 0;
75331 }
75332
75333 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75334 if (end < start)
75335 goto out;
75336
75337 +#ifdef CONFIG_PAX_SEGMEXEC
75338 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75339 + if (end > SEGMEXEC_TASK_SIZE)
75340 + goto out;
75341 + } else
75342 +#endif
75343 +
75344 + if (end > TASK_SIZE)
75345 + goto out;
75346 +
75347 error = 0;
75348 if (end == start)
75349 goto out;
75350 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75351 index c6e4dd3..fdb2ca6 100644
75352 --- a/mm/memory-failure.c
75353 +++ b/mm/memory-failure.c
75354 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75355
75356 int sysctl_memory_failure_recovery __read_mostly = 1;
75357
75358 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75359 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75360
75361 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
75362
75363 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
75364 pfn, t->comm, t->pid);
75365 si.si_signo = SIGBUS;
75366 si.si_errno = 0;
75367 - si.si_addr = (void *)addr;
75368 + si.si_addr = (void __user *)addr;
75369 #ifdef __ARCH_SI_TRAPNO
75370 si.si_trapno = trapno;
75371 #endif
75372 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75373 }
75374
75375 nr_pages = 1 << compound_trans_order(hpage);
75376 - atomic_long_add(nr_pages, &mce_bad_pages);
75377 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
75378
75379 /*
75380 * We need/can do nothing about count=0 pages.
75381 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75382 if (!PageHWPoison(hpage)
75383 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
75384 || (p != hpage && TestSetPageHWPoison(hpage))) {
75385 - atomic_long_sub(nr_pages, &mce_bad_pages);
75386 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75387 return 0;
75388 }
75389 set_page_hwpoison_huge_page(hpage);
75390 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75391 }
75392 if (hwpoison_filter(p)) {
75393 if (TestClearPageHWPoison(p))
75394 - atomic_long_sub(nr_pages, &mce_bad_pages);
75395 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75396 unlock_page(hpage);
75397 put_page(hpage);
75398 return 0;
75399 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
75400 return 0;
75401 }
75402 if (TestClearPageHWPoison(p))
75403 - atomic_long_sub(nr_pages, &mce_bad_pages);
75404 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75405 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
75406 return 0;
75407 }
75408 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
75409 */
75410 if (TestClearPageHWPoison(page)) {
75411 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
75412 - atomic_long_sub(nr_pages, &mce_bad_pages);
75413 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75414 freeit = 1;
75415 if (PageHuge(page))
75416 clear_page_hwpoison_huge_page(page);
75417 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
75418 }
75419 done:
75420 if (!PageHWPoison(hpage))
75421 - atomic_long_add(1 << compound_trans_order(hpage),
75422 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
75423 &mce_bad_pages);
75424 set_page_hwpoison_huge_page(hpage);
75425 dequeue_hwpoisoned_huge_page(hpage);
75426 @@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
75427 return ret;
75428
75429 done:
75430 - atomic_long_add(1, &mce_bad_pages);
75431 + atomic_long_add_unchecked(1, &mce_bad_pages);
75432 SetPageHWPoison(page);
75433 /* keep elevated page count for bad page */
75434 return ret;
75435 diff --git a/mm/memory.c b/mm/memory.c
75436 index bb1369f..efb96b5 100644
75437 --- a/mm/memory.c
75438 +++ b/mm/memory.c
75439 @@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75440 free_pte_range(tlb, pmd, addr);
75441 } while (pmd++, addr = next, addr != end);
75442
75443 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75444 start &= PUD_MASK;
75445 if (start < floor)
75446 return;
75447 @@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75448 pmd = pmd_offset(pud, start);
75449 pud_clear(pud);
75450 pmd_free_tlb(tlb, pmd, start);
75451 +#endif
75452 +
75453 }
75454
75455 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75456 @@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75457 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
75458 } while (pud++, addr = next, addr != end);
75459
75460 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75461 start &= PGDIR_MASK;
75462 if (start < floor)
75463 return;
75464 @@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75465 pud = pud_offset(pgd, start);
75466 pgd_clear(pgd);
75467 pud_free_tlb(tlb, pud, start);
75468 +#endif
75469 +
75470 }
75471
75472 /*
75473 @@ -1618,12 +1624,6 @@ no_page_table:
75474 return page;
75475 }
75476
75477 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
75478 -{
75479 - return stack_guard_page_start(vma, addr) ||
75480 - stack_guard_page_end(vma, addr+PAGE_SIZE);
75481 -}
75482 -
75483 /**
75484 * __get_user_pages() - pin user pages in memory
75485 * @tsk: task_struct of target task
75486 @@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75487
75488 i = 0;
75489
75490 - do {
75491 + while (nr_pages) {
75492 struct vm_area_struct *vma;
75493
75494 - vma = find_extend_vma(mm, start);
75495 + vma = find_vma(mm, start);
75496 if (!vma && in_gate_area(mm, start)) {
75497 unsigned long pg = start & PAGE_MASK;
75498 pgd_t *pgd;
75499 @@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75500 goto next_page;
75501 }
75502
75503 - if (!vma ||
75504 + if (!vma || start < vma->vm_start ||
75505 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75506 !(vm_flags & vma->vm_flags))
75507 return i ? : -EFAULT;
75508 @@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75509 int ret;
75510 unsigned int fault_flags = 0;
75511
75512 - /* For mlock, just skip the stack guard page. */
75513 - if (foll_flags & FOLL_MLOCK) {
75514 - if (stack_guard_page(vma, start))
75515 - goto next_page;
75516 - }
75517 if (foll_flags & FOLL_WRITE)
75518 fault_flags |= FAULT_FLAG_WRITE;
75519 if (nonblocking)
75520 @@ -1865,7 +1860,7 @@ next_page:
75521 start += PAGE_SIZE;
75522 nr_pages--;
75523 } while (nr_pages && start < vma->vm_end);
75524 - } while (nr_pages);
75525 + }
75526 return i;
75527 }
75528 EXPORT_SYMBOL(__get_user_pages);
75529 @@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75530 page_add_file_rmap(page);
75531 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75532
75533 +#ifdef CONFIG_PAX_SEGMEXEC
75534 + pax_mirror_file_pte(vma, addr, page, ptl);
75535 +#endif
75536 +
75537 retval = 0;
75538 pte_unmap_unlock(pte, ptl);
75539 return retval;
75540 @@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75541 if (!page_count(page))
75542 return -EINVAL;
75543 if (!(vma->vm_flags & VM_MIXEDMAP)) {
75544 +
75545 +#ifdef CONFIG_PAX_SEGMEXEC
75546 + struct vm_area_struct *vma_m;
75547 +#endif
75548 +
75549 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
75550 BUG_ON(vma->vm_flags & VM_PFNMAP);
75551 vma->vm_flags |= VM_MIXEDMAP;
75552 +
75553 +#ifdef CONFIG_PAX_SEGMEXEC
75554 + vma_m = pax_find_mirror_vma(vma);
75555 + if (vma_m)
75556 + vma_m->vm_flags |= VM_MIXEDMAP;
75557 +#endif
75558 +
75559 }
75560 return insert_page(vma, addr, page, vma->vm_page_prot);
75561 }
75562 @@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75563 unsigned long pfn)
75564 {
75565 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75566 + BUG_ON(vma->vm_mirror);
75567
75568 if (addr < vma->vm_start || addr >= vma->vm_end)
75569 return -EFAULT;
75570 @@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
75571
75572 BUG_ON(pud_huge(*pud));
75573
75574 - pmd = pmd_alloc(mm, pud, addr);
75575 + pmd = (mm == &init_mm) ?
75576 + pmd_alloc_kernel(mm, pud, addr) :
75577 + pmd_alloc(mm, pud, addr);
75578 if (!pmd)
75579 return -ENOMEM;
75580 do {
75581 @@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
75582 unsigned long next;
75583 int err;
75584
75585 - pud = pud_alloc(mm, pgd, addr);
75586 + pud = (mm == &init_mm) ?
75587 + pud_alloc_kernel(mm, pgd, addr) :
75588 + pud_alloc(mm, pgd, addr);
75589 if (!pud)
75590 return -ENOMEM;
75591 do {
75592 @@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75593 copy_user_highpage(dst, src, va, vma);
75594 }
75595
75596 +#ifdef CONFIG_PAX_SEGMEXEC
75597 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75598 +{
75599 + struct mm_struct *mm = vma->vm_mm;
75600 + spinlock_t *ptl;
75601 + pte_t *pte, entry;
75602 +
75603 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75604 + entry = *pte;
75605 + if (!pte_present(entry)) {
75606 + if (!pte_none(entry)) {
75607 + BUG_ON(pte_file(entry));
75608 + free_swap_and_cache(pte_to_swp_entry(entry));
75609 + pte_clear_not_present_full(mm, address, pte, 0);
75610 + }
75611 + } else {
75612 + struct page *page;
75613 +
75614 + flush_cache_page(vma, address, pte_pfn(entry));
75615 + entry = ptep_clear_flush(vma, address, pte);
75616 + BUG_ON(pte_dirty(entry));
75617 + page = vm_normal_page(vma, address, entry);
75618 + if (page) {
75619 + update_hiwater_rss(mm);
75620 + if (PageAnon(page))
75621 + dec_mm_counter_fast(mm, MM_ANONPAGES);
75622 + else
75623 + dec_mm_counter_fast(mm, MM_FILEPAGES);
75624 + page_remove_rmap(page);
75625 + page_cache_release(page);
75626 + }
75627 + }
75628 + pte_unmap_unlock(pte, ptl);
75629 +}
75630 +
75631 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
75632 + *
75633 + * the ptl of the lower mapped page is held on entry and is not released on exit
75634 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75635 + */
75636 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75637 +{
75638 + struct mm_struct *mm = vma->vm_mm;
75639 + unsigned long address_m;
75640 + spinlock_t *ptl_m;
75641 + struct vm_area_struct *vma_m;
75642 + pmd_t *pmd_m;
75643 + pte_t *pte_m, entry_m;
75644 +
75645 + BUG_ON(!page_m || !PageAnon(page_m));
75646 +
75647 + vma_m = pax_find_mirror_vma(vma);
75648 + if (!vma_m)
75649 + return;
75650 +
75651 + BUG_ON(!PageLocked(page_m));
75652 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75653 + address_m = address + SEGMEXEC_TASK_SIZE;
75654 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75655 + pte_m = pte_offset_map(pmd_m, address_m);
75656 + ptl_m = pte_lockptr(mm, pmd_m);
75657 + if (ptl != ptl_m) {
75658 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75659 + if (!pte_none(*pte_m))
75660 + goto out;
75661 + }
75662 +
75663 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75664 + page_cache_get(page_m);
75665 + page_add_anon_rmap(page_m, vma_m, address_m);
75666 + inc_mm_counter_fast(mm, MM_ANONPAGES);
75667 + set_pte_at(mm, address_m, pte_m, entry_m);
75668 + update_mmu_cache(vma_m, address_m, entry_m);
75669 +out:
75670 + if (ptl != ptl_m)
75671 + spin_unlock(ptl_m);
75672 + pte_unmap(pte_m);
75673 + unlock_page(page_m);
75674 +}
75675 +
75676 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75677 +{
75678 + struct mm_struct *mm = vma->vm_mm;
75679 + unsigned long address_m;
75680 + spinlock_t *ptl_m;
75681 + struct vm_area_struct *vma_m;
75682 + pmd_t *pmd_m;
75683 + pte_t *pte_m, entry_m;
75684 +
75685 + BUG_ON(!page_m || PageAnon(page_m));
75686 +
75687 + vma_m = pax_find_mirror_vma(vma);
75688 + if (!vma_m)
75689 + return;
75690 +
75691 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75692 + address_m = address + SEGMEXEC_TASK_SIZE;
75693 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75694 + pte_m = pte_offset_map(pmd_m, address_m);
75695 + ptl_m = pte_lockptr(mm, pmd_m);
75696 + if (ptl != ptl_m) {
75697 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75698 + if (!pte_none(*pte_m))
75699 + goto out;
75700 + }
75701 +
75702 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75703 + page_cache_get(page_m);
75704 + page_add_file_rmap(page_m);
75705 + inc_mm_counter_fast(mm, MM_FILEPAGES);
75706 + set_pte_at(mm, address_m, pte_m, entry_m);
75707 + update_mmu_cache(vma_m, address_m, entry_m);
75708 +out:
75709 + if (ptl != ptl_m)
75710 + spin_unlock(ptl_m);
75711 + pte_unmap(pte_m);
75712 +}
75713 +
75714 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
75715 +{
75716 + struct mm_struct *mm = vma->vm_mm;
75717 + unsigned long address_m;
75718 + spinlock_t *ptl_m;
75719 + struct vm_area_struct *vma_m;
75720 + pmd_t *pmd_m;
75721 + pte_t *pte_m, entry_m;
75722 +
75723 + vma_m = pax_find_mirror_vma(vma);
75724 + if (!vma_m)
75725 + return;
75726 +
75727 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75728 + address_m = address + SEGMEXEC_TASK_SIZE;
75729 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75730 + pte_m = pte_offset_map(pmd_m, address_m);
75731 + ptl_m = pte_lockptr(mm, pmd_m);
75732 + if (ptl != ptl_m) {
75733 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75734 + if (!pte_none(*pte_m))
75735 + goto out;
75736 + }
75737 +
75738 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
75739 + set_pte_at(mm, address_m, pte_m, entry_m);
75740 +out:
75741 + if (ptl != ptl_m)
75742 + spin_unlock(ptl_m);
75743 + pte_unmap(pte_m);
75744 +}
75745 +
75746 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
75747 +{
75748 + struct page *page_m;
75749 + pte_t entry;
75750 +
75751 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
75752 + goto out;
75753 +
75754 + entry = *pte;
75755 + page_m = vm_normal_page(vma, address, entry);
75756 + if (!page_m)
75757 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
75758 + else if (PageAnon(page_m)) {
75759 + if (pax_find_mirror_vma(vma)) {
75760 + pte_unmap_unlock(pte, ptl);
75761 + lock_page(page_m);
75762 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
75763 + if (pte_same(entry, *pte))
75764 + pax_mirror_anon_pte(vma, address, page_m, ptl);
75765 + else
75766 + unlock_page(page_m);
75767 + }
75768 + } else
75769 + pax_mirror_file_pte(vma, address, page_m, ptl);
75770 +
75771 +out:
75772 + pte_unmap_unlock(pte, ptl);
75773 +}
75774 +#endif
75775 +
75776 /*
75777 * This routine handles present pages, when users try to write
75778 * to a shared page. It is done by copying the page to a new address
75779 @@ -2725,6 +2921,12 @@ gotten:
75780 */
75781 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75782 if (likely(pte_same(*page_table, orig_pte))) {
75783 +
75784 +#ifdef CONFIG_PAX_SEGMEXEC
75785 + if (pax_find_mirror_vma(vma))
75786 + BUG_ON(!trylock_page(new_page));
75787 +#endif
75788 +
75789 if (old_page) {
75790 if (!PageAnon(old_page)) {
75791 dec_mm_counter_fast(mm, MM_FILEPAGES);
75792 @@ -2776,6 +2978,10 @@ gotten:
75793 page_remove_rmap(old_page);
75794 }
75795
75796 +#ifdef CONFIG_PAX_SEGMEXEC
75797 + pax_mirror_anon_pte(vma, address, new_page, ptl);
75798 +#endif
75799 +
75800 /* Free the old page.. */
75801 new_page = old_page;
75802 ret |= VM_FAULT_WRITE;
75803 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75804 swap_free(entry);
75805 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
75806 try_to_free_swap(page);
75807 +
75808 +#ifdef CONFIG_PAX_SEGMEXEC
75809 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
75810 +#endif
75811 +
75812 unlock_page(page);
75813 if (swapcache) {
75814 /*
75815 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
75816
75817 /* No need to invalidate - it was non-present before */
75818 update_mmu_cache(vma, address, page_table);
75819 +
75820 +#ifdef CONFIG_PAX_SEGMEXEC
75821 + pax_mirror_anon_pte(vma, address, page, ptl);
75822 +#endif
75823 +
75824 unlock:
75825 pte_unmap_unlock(page_table, ptl);
75826 out:
75827 @@ -3093,40 +3309,6 @@ out_release:
75828 }
75829
75830 /*
75831 - * This is like a special single-page "expand_{down|up}wards()",
75832 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
75833 - * doesn't hit another vma.
75834 - */
75835 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
75836 -{
75837 - address &= PAGE_MASK;
75838 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
75839 - struct vm_area_struct *prev = vma->vm_prev;
75840 -
75841 - /*
75842 - * Is there a mapping abutting this one below?
75843 - *
75844 - * That's only ok if it's the same stack mapping
75845 - * that has gotten split..
75846 - */
75847 - if (prev && prev->vm_end == address)
75848 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
75849 -
75850 - expand_downwards(vma, address - PAGE_SIZE);
75851 - }
75852 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
75853 - struct vm_area_struct *next = vma->vm_next;
75854 -
75855 - /* As VM_GROWSDOWN but s/below/above/ */
75856 - if (next && next->vm_start == address + PAGE_SIZE)
75857 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
75858 -
75859 - expand_upwards(vma, address + PAGE_SIZE);
75860 - }
75861 - return 0;
75862 -}
75863 -
75864 -/*
75865 * We enter with non-exclusive mmap_sem (to exclude vma changes,
75866 * but allow concurrent faults), and pte mapped but not yet locked.
75867 * We return with mmap_sem still held, but pte unmapped and unlocked.
75868 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75869 unsigned long address, pte_t *page_table, pmd_t *pmd,
75870 unsigned int flags)
75871 {
75872 - struct page *page;
75873 + struct page *page = NULL;
75874 spinlock_t *ptl;
75875 pte_t entry;
75876
75877 - pte_unmap(page_table);
75878 -
75879 - /* Check if we need to add a guard page to the stack */
75880 - if (check_stack_guard_page(vma, address) < 0)
75881 - return VM_FAULT_SIGBUS;
75882 -
75883 - /* Use the zero-page for reads */
75884 if (!(flags & FAULT_FLAG_WRITE)) {
75885 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
75886 vma->vm_page_prot));
75887 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75888 + ptl = pte_lockptr(mm, pmd);
75889 + spin_lock(ptl);
75890 if (!pte_none(*page_table))
75891 goto unlock;
75892 goto setpte;
75893 }
75894
75895 /* Allocate our own private page. */
75896 + pte_unmap(page_table);
75897 +
75898 if (unlikely(anon_vma_prepare(vma)))
75899 goto oom;
75900 page = alloc_zeroed_user_highpage_movable(vma, address);
75901 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75902 if (!pte_none(*page_table))
75903 goto release;
75904
75905 +#ifdef CONFIG_PAX_SEGMEXEC
75906 + if (pax_find_mirror_vma(vma))
75907 + BUG_ON(!trylock_page(page));
75908 +#endif
75909 +
75910 inc_mm_counter_fast(mm, MM_ANONPAGES);
75911 page_add_new_anon_rmap(page, vma, address);
75912 setpte:
75913 @@ -3181,6 +3364,12 @@ setpte:
75914
75915 /* No need to invalidate - it was non-present before */
75916 update_mmu_cache(vma, address, page_table);
75917 +
75918 +#ifdef CONFIG_PAX_SEGMEXEC
75919 + if (page)
75920 + pax_mirror_anon_pte(vma, address, page, ptl);
75921 +#endif
75922 +
75923 unlock:
75924 pte_unmap_unlock(page_table, ptl);
75925 return 0;
75926 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75927 */
75928 /* Only go through if we didn't race with anybody else... */
75929 if (likely(pte_same(*page_table, orig_pte))) {
75930 +
75931 +#ifdef CONFIG_PAX_SEGMEXEC
75932 + if (anon && pax_find_mirror_vma(vma))
75933 + BUG_ON(!trylock_page(page));
75934 +#endif
75935 +
75936 flush_icache_page(vma, page);
75937 entry = mk_pte(page, vma->vm_page_prot);
75938 if (flags & FAULT_FLAG_WRITE)
75939 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75940
75941 /* no need to invalidate: a not-present page won't be cached */
75942 update_mmu_cache(vma, address, page_table);
75943 +
75944 +#ifdef CONFIG_PAX_SEGMEXEC
75945 + if (anon)
75946 + pax_mirror_anon_pte(vma, address, page, ptl);
75947 + else
75948 + pax_mirror_file_pte(vma, address, page, ptl);
75949 +#endif
75950 +
75951 } else {
75952 if (cow_page)
75953 mem_cgroup_uncharge_page(cow_page);
75954 @@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
75955 if (flags & FAULT_FLAG_WRITE)
75956 flush_tlb_fix_spurious_fault(vma, address);
75957 }
75958 +
75959 +#ifdef CONFIG_PAX_SEGMEXEC
75960 + pax_mirror_pte(vma, address, pte, pmd, ptl);
75961 + return 0;
75962 +#endif
75963 +
75964 unlock:
75965 pte_unmap_unlock(pte, ptl);
75966 return 0;
75967 @@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75968 pmd_t *pmd;
75969 pte_t *pte;
75970
75971 +#ifdef CONFIG_PAX_SEGMEXEC
75972 + struct vm_area_struct *vma_m;
75973 +#endif
75974 +
75975 __set_current_state(TASK_RUNNING);
75976
75977 count_vm_event(PGFAULT);
75978 @@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75979 if (unlikely(is_vm_hugetlb_page(vma)))
75980 return hugetlb_fault(mm, vma, address, flags);
75981
75982 +#ifdef CONFIG_PAX_SEGMEXEC
75983 + vma_m = pax_find_mirror_vma(vma);
75984 + if (vma_m) {
75985 + unsigned long address_m;
75986 + pgd_t *pgd_m;
75987 + pud_t *pud_m;
75988 + pmd_t *pmd_m;
75989 +
75990 + if (vma->vm_start > vma_m->vm_start) {
75991 + address_m = address;
75992 + address -= SEGMEXEC_TASK_SIZE;
75993 + vma = vma_m;
75994 + } else
75995 + address_m = address + SEGMEXEC_TASK_SIZE;
75996 +
75997 + pgd_m = pgd_offset(mm, address_m);
75998 + pud_m = pud_alloc(mm, pgd_m, address_m);
75999 + if (!pud_m)
76000 + return VM_FAULT_OOM;
76001 + pmd_m = pmd_alloc(mm, pud_m, address_m);
76002 + if (!pmd_m)
76003 + return VM_FAULT_OOM;
76004 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
76005 + return VM_FAULT_OOM;
76006 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76007 + }
76008 +#endif
76009 +
76010 retry:
76011 pgd = pgd_offset(mm, address);
76012 pud = pud_alloc(mm, pgd, address);
76013 @@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76014 spin_unlock(&mm->page_table_lock);
76015 return 0;
76016 }
76017 +
76018 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76019 +{
76020 + pud_t *new = pud_alloc_one(mm, address);
76021 + if (!new)
76022 + return -ENOMEM;
76023 +
76024 + smp_wmb(); /* See comment in __pte_alloc */
76025 +
76026 + spin_lock(&mm->page_table_lock);
76027 + if (pgd_present(*pgd)) /* Another has populated it */
76028 + pud_free(mm, new);
76029 + else
76030 + pgd_populate_kernel(mm, pgd, new);
76031 + spin_unlock(&mm->page_table_lock);
76032 + return 0;
76033 +}
76034 #endif /* __PAGETABLE_PUD_FOLDED */
76035
76036 #ifndef __PAGETABLE_PMD_FOLDED
76037 @@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76038 spin_unlock(&mm->page_table_lock);
76039 return 0;
76040 }
76041 +
76042 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76043 +{
76044 + pmd_t *new = pmd_alloc_one(mm, address);
76045 + if (!new)
76046 + return -ENOMEM;
76047 +
76048 + smp_wmb(); /* See comment in __pte_alloc */
76049 +
76050 + spin_lock(&mm->page_table_lock);
76051 +#ifndef __ARCH_HAS_4LEVEL_HACK
76052 + if (pud_present(*pud)) /* Another has populated it */
76053 + pmd_free(mm, new);
76054 + else
76055 + pud_populate_kernel(mm, pud, new);
76056 +#else
76057 + if (pgd_present(*pud)) /* Another has populated it */
76058 + pmd_free(mm, new);
76059 + else
76060 + pgd_populate_kernel(mm, pud, new);
76061 +#endif /* __ARCH_HAS_4LEVEL_HACK */
76062 + spin_unlock(&mm->page_table_lock);
76063 + return 0;
76064 +}
76065 #endif /* __PAGETABLE_PMD_FOLDED */
76066
76067 int make_pages_present(unsigned long addr, unsigned long end)
76068 @@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
76069 gate_vma.vm_start = FIXADDR_USER_START;
76070 gate_vma.vm_end = FIXADDR_USER_END;
76071 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76072 - gate_vma.vm_page_prot = __P101;
76073 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76074
76075 return 0;
76076 }
76077 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76078 index e2df1c1..1e31d57 100644
76079 --- a/mm/mempolicy.c
76080 +++ b/mm/mempolicy.c
76081 @@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76082 unsigned long vmstart;
76083 unsigned long vmend;
76084
76085 +#ifdef CONFIG_PAX_SEGMEXEC
76086 + struct vm_area_struct *vma_m;
76087 +#endif
76088 +
76089 vma = find_vma(mm, start);
76090 if (!vma || vma->vm_start > start)
76091 return -EFAULT;
76092 @@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76093 if (err)
76094 goto out;
76095 }
76096 +
76097 err = vma_replace_policy(vma, new_pol);
76098 if (err)
76099 goto out;
76100 +
76101 +#ifdef CONFIG_PAX_SEGMEXEC
76102 + vma_m = pax_find_mirror_vma(vma);
76103 + if (vma_m) {
76104 + err = vma_replace_policy(vma_m, new_pol);
76105 + if (err)
76106 + goto out;
76107 + }
76108 +#endif
76109 +
76110 }
76111
76112 out:
76113 @@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76114
76115 if (end < start)
76116 return -EINVAL;
76117 +
76118 +#ifdef CONFIG_PAX_SEGMEXEC
76119 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76120 + if (end > SEGMEXEC_TASK_SIZE)
76121 + return -EINVAL;
76122 + } else
76123 +#endif
76124 +
76125 + if (end > TASK_SIZE)
76126 + return -EINVAL;
76127 +
76128 if (end == start)
76129 return 0;
76130
76131 @@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76132 */
76133 tcred = __task_cred(task);
76134 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76135 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76136 - !capable(CAP_SYS_NICE)) {
76137 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76138 rcu_read_unlock();
76139 err = -EPERM;
76140 goto out_put;
76141 @@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76142 goto out;
76143 }
76144
76145 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76146 + if (mm != current->mm &&
76147 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76148 + mmput(mm);
76149 + err = -EPERM;
76150 + goto out;
76151 + }
76152 +#endif
76153 +
76154 err = do_migrate_pages(mm, old, new,
76155 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
76156
76157 diff --git a/mm/migrate.c b/mm/migrate.c
76158 index 2fd8b4a..d70358f 100644
76159 --- a/mm/migrate.c
76160 +++ b/mm/migrate.c
76161 @@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76162 */
76163 tcred = __task_cred(task);
76164 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76165 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76166 - !capable(CAP_SYS_NICE)) {
76167 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76168 rcu_read_unlock();
76169 err = -EPERM;
76170 goto out;
76171 diff --git a/mm/mlock.c b/mm/mlock.c
76172 index c9bd528..da8d069 100644
76173 --- a/mm/mlock.c
76174 +++ b/mm/mlock.c
76175 @@ -13,6 +13,7 @@
76176 #include <linux/pagemap.h>
76177 #include <linux/mempolicy.h>
76178 #include <linux/syscalls.h>
76179 +#include <linux/security.h>
76180 #include <linux/sched.h>
76181 #include <linux/export.h>
76182 #include <linux/rmap.h>
76183 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76184 {
76185 unsigned long nstart, end, tmp;
76186 struct vm_area_struct * vma, * prev;
76187 - int error;
76188 + int error = 0;
76189
76190 VM_BUG_ON(start & ~PAGE_MASK);
76191 VM_BUG_ON(len != PAGE_ALIGN(len));
76192 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76193 return -EINVAL;
76194 if (end == start)
76195 return 0;
76196 + if (end > TASK_SIZE)
76197 + return -EINVAL;
76198 +
76199 vma = find_vma(current->mm, start);
76200 if (!vma || vma->vm_start > start)
76201 return -ENOMEM;
76202 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76203 for (nstart = start ; ; ) {
76204 vm_flags_t newflags;
76205
76206 +#ifdef CONFIG_PAX_SEGMEXEC
76207 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76208 + break;
76209 +#endif
76210 +
76211 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76212
76213 newflags = vma->vm_flags | VM_LOCKED;
76214 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76215 lock_limit >>= PAGE_SHIFT;
76216
76217 /* check against resource limits */
76218 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76219 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76220 error = do_mlock(start, len, 1);
76221 up_write(&current->mm->mmap_sem);
76222 @@ -528,6 +538,12 @@ static int do_mlockall(int flags)
76223 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76224 vm_flags_t newflags;
76225
76226 +#ifdef CONFIG_PAX_SEGMEXEC
76227 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76228 + break;
76229 +#endif
76230 +
76231 + BUG_ON(vma->vm_end > TASK_SIZE);
76232 newflags = vma->vm_flags | VM_LOCKED;
76233 if (!(flags & MCL_CURRENT))
76234 newflags &= ~VM_LOCKED;
76235 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76236 lock_limit >>= PAGE_SHIFT;
76237
76238 ret = -ENOMEM;
76239 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76240 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76241 capable(CAP_IPC_LOCK))
76242 ret = do_mlockall(flags);
76243 diff --git a/mm/mmap.c b/mm/mmap.c
76244 index d1e4124..32a6988 100644
76245 --- a/mm/mmap.c
76246 +++ b/mm/mmap.c
76247 @@ -32,6 +32,7 @@
76248 #include <linux/khugepaged.h>
76249 #include <linux/uprobes.h>
76250 #include <linux/rbtree_augmented.h>
76251 +#include <linux/random.h>
76252
76253 #include <asm/uaccess.h>
76254 #include <asm/cacheflush.h>
76255 @@ -48,6 +49,16 @@
76256 #define arch_rebalance_pgtables(addr, len) (addr)
76257 #endif
76258
76259 +static inline void verify_mm_writelocked(struct mm_struct *mm)
76260 +{
76261 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76262 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76263 + up_read(&mm->mmap_sem);
76264 + BUG();
76265 + }
76266 +#endif
76267 +}
76268 +
76269 static void unmap_region(struct mm_struct *mm,
76270 struct vm_area_struct *vma, struct vm_area_struct *prev,
76271 unsigned long start, unsigned long end);
76272 @@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
76273 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76274 *
76275 */
76276 -pgprot_t protection_map[16] = {
76277 +pgprot_t protection_map[16] __read_only = {
76278 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76279 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76280 };
76281
76282 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
76283 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76284 {
76285 - return __pgprot(pgprot_val(protection_map[vm_flags &
76286 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76287 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76288 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76289 +
76290 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76291 + if (!(__supported_pte_mask & _PAGE_NX) &&
76292 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76293 + (vm_flags & (VM_READ | VM_WRITE)))
76294 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76295 +#endif
76296 +
76297 + return prot;
76298 }
76299 EXPORT_SYMBOL(vm_get_page_prot);
76300
76301 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
76302 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
76303 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76304 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76305 /*
76306 * Make sure vm_committed_as in one cacheline and not cacheline shared with
76307 * other variables. It can be updated by several CPUs frequently.
76308 @@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76309 struct vm_area_struct *next = vma->vm_next;
76310
76311 might_sleep();
76312 + BUG_ON(vma->vm_mirror);
76313 if (vma->vm_ops && vma->vm_ops->close)
76314 vma->vm_ops->close(vma);
76315 if (vma->vm_file)
76316 @@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76317 * not page aligned -Ram Gupta
76318 */
76319 rlim = rlimit(RLIMIT_DATA);
76320 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76321 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76322 (mm->end_data - mm->start_data) > rlim)
76323 goto out;
76324 @@ -888,6 +911,12 @@ static int
76325 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76326 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76327 {
76328 +
76329 +#ifdef CONFIG_PAX_SEGMEXEC
76330 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76331 + return 0;
76332 +#endif
76333 +
76334 if (is_mergeable_vma(vma, file, vm_flags) &&
76335 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76336 if (vma->vm_pgoff == vm_pgoff)
76337 @@ -907,6 +936,12 @@ static int
76338 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76339 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76340 {
76341 +
76342 +#ifdef CONFIG_PAX_SEGMEXEC
76343 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76344 + return 0;
76345 +#endif
76346 +
76347 if (is_mergeable_vma(vma, file, vm_flags) &&
76348 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76349 pgoff_t vm_pglen;
76350 @@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76351 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76352 struct vm_area_struct *prev, unsigned long addr,
76353 unsigned long end, unsigned long vm_flags,
76354 - struct anon_vma *anon_vma, struct file *file,
76355 + struct anon_vma *anon_vma, struct file *file,
76356 pgoff_t pgoff, struct mempolicy *policy)
76357 {
76358 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76359 struct vm_area_struct *area, *next;
76360 int err;
76361
76362 +#ifdef CONFIG_PAX_SEGMEXEC
76363 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76364 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76365 +
76366 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76367 +#endif
76368 +
76369 /*
76370 * We later require that vma->vm_flags == vm_flags,
76371 * so this tests vma->vm_flags & VM_SPECIAL, too.
76372 @@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76373 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76374 next = next->vm_next;
76375
76376 +#ifdef CONFIG_PAX_SEGMEXEC
76377 + if (prev)
76378 + prev_m = pax_find_mirror_vma(prev);
76379 + if (area)
76380 + area_m = pax_find_mirror_vma(area);
76381 + if (next)
76382 + next_m = pax_find_mirror_vma(next);
76383 +#endif
76384 +
76385 /*
76386 * Can it merge with the predecessor?
76387 */
76388 @@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76389 /* cases 1, 6 */
76390 err = vma_adjust(prev, prev->vm_start,
76391 next->vm_end, prev->vm_pgoff, NULL);
76392 - } else /* cases 2, 5, 7 */
76393 +
76394 +#ifdef CONFIG_PAX_SEGMEXEC
76395 + if (!err && prev_m)
76396 + err = vma_adjust(prev_m, prev_m->vm_start,
76397 + next_m->vm_end, prev_m->vm_pgoff, NULL);
76398 +#endif
76399 +
76400 + } else { /* cases 2, 5, 7 */
76401 err = vma_adjust(prev, prev->vm_start,
76402 end, prev->vm_pgoff, NULL);
76403 +
76404 +#ifdef CONFIG_PAX_SEGMEXEC
76405 + if (!err && prev_m)
76406 + err = vma_adjust(prev_m, prev_m->vm_start,
76407 + end_m, prev_m->vm_pgoff, NULL);
76408 +#endif
76409 +
76410 + }
76411 if (err)
76412 return NULL;
76413 khugepaged_enter_vma_merge(prev);
76414 @@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76415 mpol_equal(policy, vma_policy(next)) &&
76416 can_vma_merge_before(next, vm_flags,
76417 anon_vma, file, pgoff+pglen)) {
76418 - if (prev && addr < prev->vm_end) /* case 4 */
76419 + if (prev && addr < prev->vm_end) { /* case 4 */
76420 err = vma_adjust(prev, prev->vm_start,
76421 addr, prev->vm_pgoff, NULL);
76422 - else /* cases 3, 8 */
76423 +
76424 +#ifdef CONFIG_PAX_SEGMEXEC
76425 + if (!err && prev_m)
76426 + err = vma_adjust(prev_m, prev_m->vm_start,
76427 + addr_m, prev_m->vm_pgoff, NULL);
76428 +#endif
76429 +
76430 + } else { /* cases 3, 8 */
76431 err = vma_adjust(area, addr, next->vm_end,
76432 next->vm_pgoff - pglen, NULL);
76433 +
76434 +#ifdef CONFIG_PAX_SEGMEXEC
76435 + if (!err && area_m)
76436 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
76437 + next_m->vm_pgoff - pglen, NULL);
76438 +#endif
76439 +
76440 + }
76441 if (err)
76442 return NULL;
76443 khugepaged_enter_vma_merge(area);
76444 @@ -1120,16 +1201,13 @@ none:
76445 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76446 struct file *file, long pages)
76447 {
76448 - const unsigned long stack_flags
76449 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76450 -
76451 mm->total_vm += pages;
76452
76453 if (file) {
76454 mm->shared_vm += pages;
76455 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76456 mm->exec_vm += pages;
76457 - } else if (flags & stack_flags)
76458 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76459 mm->stack_vm += pages;
76460 }
76461 #endif /* CONFIG_PROC_FS */
76462 @@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76463 * (the exception is when the underlying filesystem is noexec
76464 * mounted, in which case we dont add PROT_EXEC.)
76465 */
76466 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76467 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76468 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76469 prot |= PROT_EXEC;
76470
76471 @@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76472 /* Obtain the address to map to. we verify (or select) it and ensure
76473 * that it represents a valid section of the address space.
76474 */
76475 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
76476 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76477 if (addr & ~PAGE_MASK)
76478 return addr;
76479
76480 @@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76481 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76482 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76483
76484 +#ifdef CONFIG_PAX_MPROTECT
76485 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76486 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76487 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76488 + gr_log_rwxmmap(file);
76489 +
76490 +#ifdef CONFIG_PAX_EMUPLT
76491 + vm_flags &= ~VM_EXEC;
76492 +#else
76493 + return -EPERM;
76494 +#endif
76495 +
76496 + }
76497 +
76498 + if (!(vm_flags & VM_EXEC))
76499 + vm_flags &= ~VM_MAYEXEC;
76500 +#else
76501 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76502 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76503 +#endif
76504 + else
76505 + vm_flags &= ~VM_MAYWRITE;
76506 + }
76507 +#endif
76508 +
76509 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76510 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76511 + vm_flags &= ~VM_PAGEEXEC;
76512 +#endif
76513 +
76514 if (flags & MAP_LOCKED)
76515 if (!can_do_mlock())
76516 return -EPERM;
76517 @@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76518 locked += mm->locked_vm;
76519 lock_limit = rlimit(RLIMIT_MEMLOCK);
76520 lock_limit >>= PAGE_SHIFT;
76521 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76522 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76523 return -EAGAIN;
76524 }
76525 @@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76526 }
76527 }
76528
76529 + if (!gr_acl_handle_mmap(file, prot))
76530 + return -EACCES;
76531 +
76532 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76533 }
76534
76535 @@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
76536 vm_flags_t vm_flags = vma->vm_flags;
76537
76538 /* If it was private or non-writable, the write bit is already clear */
76539 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76540 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76541 return 0;
76542
76543 /* The backer wishes to know when pages are first written to? */
76544 @@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76545 unsigned long charged = 0;
76546 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76547
76548 +#ifdef CONFIG_PAX_SEGMEXEC
76549 + struct vm_area_struct *vma_m = NULL;
76550 +#endif
76551 +
76552 + /*
76553 + * mm->mmap_sem is required to protect against another thread
76554 + * changing the mappings in case we sleep.
76555 + */
76556 + verify_mm_writelocked(mm);
76557 +
76558 /* Clear old maps */
76559 error = -ENOMEM;
76560 -munmap_back:
76561 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76562 if (do_munmap(mm, addr, len))
76563 return -ENOMEM;
76564 - goto munmap_back;
76565 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76566 }
76567
76568 /* Check against address space limit. */
76569 @@ -1460,6 +1581,16 @@ munmap_back:
76570 goto unacct_error;
76571 }
76572
76573 +#ifdef CONFIG_PAX_SEGMEXEC
76574 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76575 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76576 + if (!vma_m) {
76577 + error = -ENOMEM;
76578 + goto free_vma;
76579 + }
76580 + }
76581 +#endif
76582 +
76583 vma->vm_mm = mm;
76584 vma->vm_start = addr;
76585 vma->vm_end = addr + len;
76586 @@ -1484,6 +1615,13 @@ munmap_back:
76587 if (error)
76588 goto unmap_and_free_vma;
76589
76590 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76591 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76592 + vma->vm_flags |= VM_PAGEEXEC;
76593 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76594 + }
76595 +#endif
76596 +
76597 /* Can addr have changed??
76598 *
76599 * Answer: Yes, several device drivers can do it in their
76600 @@ -1522,6 +1660,11 @@ munmap_back:
76601 vma_link(mm, vma, prev, rb_link, rb_parent);
76602 file = vma->vm_file;
76603
76604 +#ifdef CONFIG_PAX_SEGMEXEC
76605 + if (vma_m)
76606 + BUG_ON(pax_mirror_vma(vma_m, vma));
76607 +#endif
76608 +
76609 /* Once vma denies write, undo our temporary denial count */
76610 if (correct_wcount)
76611 atomic_inc(&inode->i_writecount);
76612 @@ -1529,6 +1672,7 @@ out:
76613 perf_event_mmap(vma);
76614
76615 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76616 + track_exec_limit(mm, addr, addr + len, vm_flags);
76617 if (vm_flags & VM_LOCKED) {
76618 if (!mlock_vma_pages_range(vma, addr, addr + len))
76619 mm->locked_vm += (len >> PAGE_SHIFT);
76620 @@ -1550,6 +1694,12 @@ unmap_and_free_vma:
76621 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76622 charged = 0;
76623 free_vma:
76624 +
76625 +#ifdef CONFIG_PAX_SEGMEXEC
76626 + if (vma_m)
76627 + kmem_cache_free(vm_area_cachep, vma_m);
76628 +#endif
76629 +
76630 kmem_cache_free(vm_area_cachep, vma);
76631 unacct_error:
76632 if (charged)
76633 @@ -1557,6 +1707,62 @@ unacct_error:
76634 return error;
76635 }
76636
76637 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76638 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76639 +{
76640 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
76641 + return (random32() & 0xFF) << PAGE_SHIFT;
76642 +
76643 + return 0;
76644 +}
76645 +#endif
76646 +
76647 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
76648 +{
76649 + if (!vma) {
76650 +#ifdef CONFIG_STACK_GROWSUP
76651 + if (addr > sysctl_heap_stack_gap)
76652 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76653 + else
76654 + vma = find_vma(current->mm, 0);
76655 + if (vma && (vma->vm_flags & VM_GROWSUP))
76656 + return false;
76657 +#endif
76658 + return true;
76659 + }
76660 +
76661 + if (addr + len > vma->vm_start)
76662 + return false;
76663 +
76664 + if (vma->vm_flags & VM_GROWSDOWN)
76665 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76666 +#ifdef CONFIG_STACK_GROWSUP
76667 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76668 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76669 +#endif
76670 + else if (offset)
76671 + return offset <= vma->vm_start - addr - len;
76672 +
76673 + return true;
76674 +}
76675 +
76676 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
76677 +{
76678 + if (vma->vm_start < len)
76679 + return -ENOMEM;
76680 +
76681 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
76682 + if (offset <= vma->vm_start - len)
76683 + return vma->vm_start - len - offset;
76684 + else
76685 + return -ENOMEM;
76686 + }
76687 +
76688 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
76689 + return vma->vm_start - len - sysctl_heap_stack_gap;
76690 + return -ENOMEM;
76691 +}
76692 +
76693 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
76694 {
76695 /*
76696 @@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76697 struct mm_struct *mm = current->mm;
76698 struct vm_area_struct *vma;
76699 struct vm_unmapped_area_info info;
76700 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76701
76702 if (len > TASK_SIZE)
76703 return -ENOMEM;
76704 @@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76705 if (flags & MAP_FIXED)
76706 return addr;
76707
76708 +#ifdef CONFIG_PAX_RANDMMAP
76709 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76710 +#endif
76711 +
76712 if (addr) {
76713 addr = PAGE_ALIGN(addr);
76714 vma = find_vma(mm, addr);
76715 - if (TASK_SIZE - len >= addr &&
76716 - (!vma || addr + len <= vma->vm_start))
76717 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76718 return addr;
76719 }
76720
76721 info.flags = 0;
76722 info.length = len;
76723 info.low_limit = TASK_UNMAPPED_BASE;
76724 +
76725 +#ifdef CONFIG_PAX_RANDMMAP
76726 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76727 + info.low_limit += mm->delta_mmap;
76728 +#endif
76729 +
76730 info.high_limit = TASK_SIZE;
76731 info.align_mask = 0;
76732 return vm_unmapped_area(&info);
76733 @@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76734
76735 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
76736 {
76737 +
76738 +#ifdef CONFIG_PAX_SEGMEXEC
76739 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76740 + return;
76741 +#endif
76742 +
76743 /*
76744 * Is this a new hole at the lowest possible address?
76745 */
76746 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
76747 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
76748 mm->free_area_cache = addr;
76749 }
76750
76751 @@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76752 struct mm_struct *mm = current->mm;
76753 unsigned long addr = addr0;
76754 struct vm_unmapped_area_info info;
76755 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76756
76757 /* requested length too big for entire address space */
76758 if (len > TASK_SIZE)
76759 @@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76760 if (flags & MAP_FIXED)
76761 return addr;
76762
76763 +#ifdef CONFIG_PAX_RANDMMAP
76764 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76765 +#endif
76766 +
76767 /* requesting a specific address */
76768 if (addr) {
76769 addr = PAGE_ALIGN(addr);
76770 vma = find_vma(mm, addr);
76771 - if (TASK_SIZE - len >= addr &&
76772 - (!vma || addr + len <= vma->vm_start))
76773 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76774 return addr;
76775 }
76776
76777 @@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76778 VM_BUG_ON(addr != -ENOMEM);
76779 info.flags = 0;
76780 info.low_limit = TASK_UNMAPPED_BASE;
76781 +
76782 +#ifdef CONFIG_PAX_RANDMMAP
76783 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76784 + info.low_limit += mm->delta_mmap;
76785 +#endif
76786 +
76787 info.high_limit = TASK_SIZE;
76788 addr = vm_unmapped_area(&info);
76789 }
76790 @@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
76791
76792 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76793 {
76794 +
76795 +#ifdef CONFIG_PAX_SEGMEXEC
76796 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76797 + return;
76798 +#endif
76799 +
76800 /*
76801 * Is this a new hole at the highest possible address?
76802 */
76803 @@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76804 mm->free_area_cache = addr;
76805
76806 /* dont allow allocations above current base */
76807 - if (mm->free_area_cache > mm->mmap_base)
76808 + if (mm->free_area_cache > mm->mmap_base) {
76809 mm->free_area_cache = mm->mmap_base;
76810 + mm->cached_hole_size = ~0UL;
76811 + }
76812 }
76813
76814 unsigned long
76815 @@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
76816 return vma;
76817 }
76818
76819 +#ifdef CONFIG_PAX_SEGMEXEC
76820 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
76821 +{
76822 + struct vm_area_struct *vma_m;
76823 +
76824 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
76825 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
76826 + BUG_ON(vma->vm_mirror);
76827 + return NULL;
76828 + }
76829 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
76830 + vma_m = vma->vm_mirror;
76831 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
76832 + BUG_ON(vma->vm_file != vma_m->vm_file);
76833 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
76834 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
76835 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
76836 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
76837 + return vma_m;
76838 +}
76839 +#endif
76840 +
76841 /*
76842 * Verify that the stack growth is acceptable and
76843 * update accounting. This is shared with both the
76844 @@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76845 return -ENOMEM;
76846
76847 /* Stack limit test */
76848 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
76849 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
76850 return -ENOMEM;
76851
76852 @@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76853 locked = mm->locked_vm + grow;
76854 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
76855 limit >>= PAGE_SHIFT;
76856 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76857 if (locked > limit && !capable(CAP_IPC_LOCK))
76858 return -ENOMEM;
76859 }
76860 @@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76861 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76862 * vma is the last one with address > vma->vm_end. Have to extend vma.
76863 */
76864 +#ifndef CONFIG_IA64
76865 +static
76866 +#endif
76867 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76868 {
76869 int error;
76870 + bool locknext;
76871
76872 if (!(vma->vm_flags & VM_GROWSUP))
76873 return -EFAULT;
76874
76875 + /* Also guard against wrapping around to address 0. */
76876 + if (address < PAGE_ALIGN(address+1))
76877 + address = PAGE_ALIGN(address+1);
76878 + else
76879 + return -ENOMEM;
76880 +
76881 /*
76882 * We must make sure the anon_vma is allocated
76883 * so that the anon_vma locking is not a noop.
76884 */
76885 if (unlikely(anon_vma_prepare(vma)))
76886 return -ENOMEM;
76887 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
76888 + if (locknext && anon_vma_prepare(vma->vm_next))
76889 + return -ENOMEM;
76890 vma_lock_anon_vma(vma);
76891 + if (locknext)
76892 + vma_lock_anon_vma(vma->vm_next);
76893
76894 /*
76895 * vma->vm_start/vm_end cannot change under us because the caller
76896 * is required to hold the mmap_sem in read mode. We need the
76897 - * anon_vma lock to serialize against concurrent expand_stacks.
76898 - * Also guard against wrapping around to address 0.
76899 + * anon_vma locks to serialize against concurrent expand_stacks
76900 + * and expand_upwards.
76901 */
76902 - if (address < PAGE_ALIGN(address+4))
76903 - address = PAGE_ALIGN(address+4);
76904 - else {
76905 - vma_unlock_anon_vma(vma);
76906 - return -ENOMEM;
76907 - }
76908 error = 0;
76909
76910 /* Somebody else might have raced and expanded it already */
76911 - if (address > vma->vm_end) {
76912 + 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)
76913 + error = -ENOMEM;
76914 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
76915 unsigned long size, grow;
76916
76917 size = address - vma->vm_start;
76918 @@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76919 }
76920 }
76921 }
76922 + if (locknext)
76923 + vma_unlock_anon_vma(vma->vm_next);
76924 vma_unlock_anon_vma(vma);
76925 khugepaged_enter_vma_merge(vma);
76926 validate_mm(vma->vm_mm);
76927 @@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
76928 unsigned long address)
76929 {
76930 int error;
76931 + bool lockprev = false;
76932 + struct vm_area_struct *prev;
76933
76934 /*
76935 * We must make sure the anon_vma is allocated
76936 @@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
76937 if (error)
76938 return error;
76939
76940 + prev = vma->vm_prev;
76941 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
76942 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
76943 +#endif
76944 + if (lockprev && anon_vma_prepare(prev))
76945 + return -ENOMEM;
76946 + if (lockprev)
76947 + vma_lock_anon_vma(prev);
76948 +
76949 vma_lock_anon_vma(vma);
76950
76951 /*
76952 @@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
76953 */
76954
76955 /* Somebody else might have raced and expanded it already */
76956 - if (address < vma->vm_start) {
76957 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
76958 + error = -ENOMEM;
76959 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
76960 unsigned long size, grow;
76961
76962 +#ifdef CONFIG_PAX_SEGMEXEC
76963 + struct vm_area_struct *vma_m;
76964 +
76965 + vma_m = pax_find_mirror_vma(vma);
76966 +#endif
76967 +
76968 size = vma->vm_end - address;
76969 grow = (vma->vm_start - address) >> PAGE_SHIFT;
76970
76971 @@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
76972 vma->vm_pgoff -= grow;
76973 anon_vma_interval_tree_post_update_vma(vma);
76974 vma_gap_update(vma);
76975 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
76976 +
76977 +#ifdef CONFIG_PAX_SEGMEXEC
76978 + if (vma_m) {
76979 + anon_vma_interval_tree_pre_update_vma(vma_m);
76980 + vma_m->vm_start -= grow << PAGE_SHIFT;
76981 + vma_m->vm_pgoff -= grow;
76982 + anon_vma_interval_tree_post_update_vma(vma_m);
76983 + vma_gap_update(vma_m);
76984 + }
76985 +#endif
76986 +
76987 spin_unlock(&vma->vm_mm->page_table_lock);
76988
76989 perf_event_mmap(vma);
76990 @@ -2236,6 +2544,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
76991 do {
76992 long nrpages = vma_pages(vma);
76993
76994 +#ifdef CONFIG_PAX_SEGMEXEC
76995 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
76996 + vma = remove_vma(vma);
76997 + continue;
76998 + }
76999 +#endif
77000 +
77001 if (vma->vm_flags & VM_ACCOUNT)
77002 nr_accounted += nrpages;
77003 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77004 @@ -2281,6 +2596,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77005 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77006 vma->vm_prev = NULL;
77007 do {
77008 +
77009 +#ifdef CONFIG_PAX_SEGMEXEC
77010 + if (vma->vm_mirror) {
77011 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77012 + vma->vm_mirror->vm_mirror = NULL;
77013 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
77014 + vma->vm_mirror = NULL;
77015 + }
77016 +#endif
77017 +
77018 vma_rb_erase(vma, &mm->mm_rb);
77019 mm->map_count--;
77020 tail_vma = vma;
77021 @@ -2312,14 +2637,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77022 struct vm_area_struct *new;
77023 int err = -ENOMEM;
77024
77025 +#ifdef CONFIG_PAX_SEGMEXEC
77026 + struct vm_area_struct *vma_m, *new_m = NULL;
77027 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77028 +#endif
77029 +
77030 if (is_vm_hugetlb_page(vma) && (addr &
77031 ~(huge_page_mask(hstate_vma(vma)))))
77032 return -EINVAL;
77033
77034 +#ifdef CONFIG_PAX_SEGMEXEC
77035 + vma_m = pax_find_mirror_vma(vma);
77036 +#endif
77037 +
77038 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77039 if (!new)
77040 goto out_err;
77041
77042 +#ifdef CONFIG_PAX_SEGMEXEC
77043 + if (vma_m) {
77044 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77045 + if (!new_m) {
77046 + kmem_cache_free(vm_area_cachep, new);
77047 + goto out_err;
77048 + }
77049 + }
77050 +#endif
77051 +
77052 /* most fields are the same, copy all, and then fixup */
77053 *new = *vma;
77054
77055 @@ -2332,6 +2676,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77056 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77057 }
77058
77059 +#ifdef CONFIG_PAX_SEGMEXEC
77060 + if (vma_m) {
77061 + *new_m = *vma_m;
77062 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
77063 + new_m->vm_mirror = new;
77064 + new->vm_mirror = new_m;
77065 +
77066 + if (new_below)
77067 + new_m->vm_end = addr_m;
77068 + else {
77069 + new_m->vm_start = addr_m;
77070 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77071 + }
77072 + }
77073 +#endif
77074 +
77075 pol = mpol_dup(vma_policy(vma));
77076 if (IS_ERR(pol)) {
77077 err = PTR_ERR(pol);
77078 @@ -2354,6 +2714,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77079 else
77080 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77081
77082 +#ifdef CONFIG_PAX_SEGMEXEC
77083 + if (!err && vma_m) {
77084 + if (anon_vma_clone(new_m, vma_m))
77085 + goto out_free_mpol;
77086 +
77087 + mpol_get(pol);
77088 + vma_set_policy(new_m, pol);
77089 +
77090 + if (new_m->vm_file)
77091 + get_file(new_m->vm_file);
77092 +
77093 + if (new_m->vm_ops && new_m->vm_ops->open)
77094 + new_m->vm_ops->open(new_m);
77095 +
77096 + if (new_below)
77097 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77098 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77099 + else
77100 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77101 +
77102 + if (err) {
77103 + if (new_m->vm_ops && new_m->vm_ops->close)
77104 + new_m->vm_ops->close(new_m);
77105 + if (new_m->vm_file)
77106 + fput(new_m->vm_file);
77107 + mpol_put(pol);
77108 + }
77109 + }
77110 +#endif
77111 +
77112 /* Success. */
77113 if (!err)
77114 return 0;
77115 @@ -2363,10 +2753,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77116 new->vm_ops->close(new);
77117 if (new->vm_file)
77118 fput(new->vm_file);
77119 - unlink_anon_vmas(new);
77120 out_free_mpol:
77121 mpol_put(pol);
77122 out_free_vma:
77123 +
77124 +#ifdef CONFIG_PAX_SEGMEXEC
77125 + if (new_m) {
77126 + unlink_anon_vmas(new_m);
77127 + kmem_cache_free(vm_area_cachep, new_m);
77128 + }
77129 +#endif
77130 +
77131 + unlink_anon_vmas(new);
77132 kmem_cache_free(vm_area_cachep, new);
77133 out_err:
77134 return err;
77135 @@ -2379,6 +2777,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77136 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77137 unsigned long addr, int new_below)
77138 {
77139 +
77140 +#ifdef CONFIG_PAX_SEGMEXEC
77141 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77142 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77143 + if (mm->map_count >= sysctl_max_map_count-1)
77144 + return -ENOMEM;
77145 + } else
77146 +#endif
77147 +
77148 if (mm->map_count >= sysctl_max_map_count)
77149 return -ENOMEM;
77150
77151 @@ -2390,11 +2797,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77152 * work. This now handles partial unmappings.
77153 * Jeremy Fitzhardinge <jeremy@goop.org>
77154 */
77155 +#ifdef CONFIG_PAX_SEGMEXEC
77156 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77157 {
77158 + int ret = __do_munmap(mm, start, len);
77159 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77160 + return ret;
77161 +
77162 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77163 +}
77164 +
77165 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77166 +#else
77167 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77168 +#endif
77169 +{
77170 unsigned long end;
77171 struct vm_area_struct *vma, *prev, *last;
77172
77173 + /*
77174 + * mm->mmap_sem is required to protect against another thread
77175 + * changing the mappings in case we sleep.
77176 + */
77177 + verify_mm_writelocked(mm);
77178 +
77179 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77180 return -EINVAL;
77181
77182 @@ -2469,6 +2895,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77183 /* Fix up all other VM information */
77184 remove_vma_list(mm, vma);
77185
77186 + track_exec_limit(mm, start, end, 0UL);
77187 +
77188 return 0;
77189 }
77190
77191 @@ -2477,6 +2905,13 @@ int vm_munmap(unsigned long start, size_t len)
77192 int ret;
77193 struct mm_struct *mm = current->mm;
77194
77195 +
77196 +#ifdef CONFIG_PAX_SEGMEXEC
77197 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77198 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
77199 + return -EINVAL;
77200 +#endif
77201 +
77202 down_write(&mm->mmap_sem);
77203 ret = do_munmap(mm, start, len);
77204 up_write(&mm->mmap_sem);
77205 @@ -2490,16 +2925,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77206 return vm_munmap(addr, len);
77207 }
77208
77209 -static inline void verify_mm_writelocked(struct mm_struct *mm)
77210 -{
77211 -#ifdef CONFIG_DEBUG_VM
77212 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77213 - WARN_ON(1);
77214 - up_read(&mm->mmap_sem);
77215 - }
77216 -#endif
77217 -}
77218 -
77219 /*
77220 * this is really a simplified "do_mmap". it only handles
77221 * anonymous maps. eventually we may be able to do some
77222 @@ -2513,6 +2938,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77223 struct rb_node ** rb_link, * rb_parent;
77224 pgoff_t pgoff = addr >> PAGE_SHIFT;
77225 int error;
77226 + unsigned long charged;
77227
77228 len = PAGE_ALIGN(len);
77229 if (!len)
77230 @@ -2520,16 +2946,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77231
77232 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77233
77234 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77235 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77236 + flags &= ~VM_EXEC;
77237 +
77238 +#ifdef CONFIG_PAX_MPROTECT
77239 + if (mm->pax_flags & MF_PAX_MPROTECT)
77240 + flags &= ~VM_MAYEXEC;
77241 +#endif
77242 +
77243 + }
77244 +#endif
77245 +
77246 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77247 if (error & ~PAGE_MASK)
77248 return error;
77249
77250 + charged = len >> PAGE_SHIFT;
77251 +
77252 /*
77253 * mlock MCL_FUTURE?
77254 */
77255 if (mm->def_flags & VM_LOCKED) {
77256 unsigned long locked, lock_limit;
77257 - locked = len >> PAGE_SHIFT;
77258 + locked = charged;
77259 locked += mm->locked_vm;
77260 lock_limit = rlimit(RLIMIT_MEMLOCK);
77261 lock_limit >>= PAGE_SHIFT;
77262 @@ -2546,21 +2986,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77263 /*
77264 * Clear old maps. this also does some error checking for us
77265 */
77266 - munmap_back:
77267 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
77268 if (do_munmap(mm, addr, len))
77269 return -ENOMEM;
77270 - goto munmap_back;
77271 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
77272 }
77273
77274 /* Check against address space limits *after* clearing old maps... */
77275 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77276 + if (!may_expand_vm(mm, charged))
77277 return -ENOMEM;
77278
77279 if (mm->map_count > sysctl_max_map_count)
77280 return -ENOMEM;
77281
77282 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
77283 + if (security_vm_enough_memory_mm(mm, charged))
77284 return -ENOMEM;
77285
77286 /* Can we just expand an old private anonymous mapping? */
77287 @@ -2574,7 +3013,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77288 */
77289 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77290 if (!vma) {
77291 - vm_unacct_memory(len >> PAGE_SHIFT);
77292 + vm_unacct_memory(charged);
77293 return -ENOMEM;
77294 }
77295
77296 @@ -2588,11 +3027,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77297 vma_link(mm, vma, prev, rb_link, rb_parent);
77298 out:
77299 perf_event_mmap(vma);
77300 - mm->total_vm += len >> PAGE_SHIFT;
77301 + mm->total_vm += charged;
77302 if (flags & VM_LOCKED) {
77303 if (!mlock_vma_pages_range(vma, addr, addr + len))
77304 - mm->locked_vm += (len >> PAGE_SHIFT);
77305 + mm->locked_vm += charged;
77306 }
77307 + track_exec_limit(mm, addr, addr + len, flags);
77308 return addr;
77309 }
77310
77311 @@ -2650,6 +3090,7 @@ void exit_mmap(struct mm_struct *mm)
77312 while (vma) {
77313 if (vma->vm_flags & VM_ACCOUNT)
77314 nr_accounted += vma_pages(vma);
77315 + vma->vm_mirror = NULL;
77316 vma = remove_vma(vma);
77317 }
77318 vm_unacct_memory(nr_accounted);
77319 @@ -2666,6 +3107,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77320 struct vm_area_struct *prev;
77321 struct rb_node **rb_link, *rb_parent;
77322
77323 +#ifdef CONFIG_PAX_SEGMEXEC
77324 + struct vm_area_struct *vma_m = NULL;
77325 +#endif
77326 +
77327 + if (security_mmap_addr(vma->vm_start))
77328 + return -EPERM;
77329 +
77330 /*
77331 * The vm_pgoff of a purely anonymous vma should be irrelevant
77332 * until its first write fault, when page's anon_vma and index
77333 @@ -2689,7 +3137,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77334 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77335 return -ENOMEM;
77336
77337 +#ifdef CONFIG_PAX_SEGMEXEC
77338 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77339 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77340 + if (!vma_m)
77341 + return -ENOMEM;
77342 + }
77343 +#endif
77344 +
77345 vma_link(mm, vma, prev, rb_link, rb_parent);
77346 +
77347 +#ifdef CONFIG_PAX_SEGMEXEC
77348 + if (vma_m)
77349 + BUG_ON(pax_mirror_vma(vma_m, vma));
77350 +#endif
77351 +
77352 return 0;
77353 }
77354
77355 @@ -2709,6 +3171,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77356 struct mempolicy *pol;
77357 bool faulted_in_anon_vma = true;
77358
77359 + BUG_ON(vma->vm_mirror);
77360 +
77361 /*
77362 * If anonymous vma has not yet been faulted, update new pgoff
77363 * to match new location, to increase its chance of merging.
77364 @@ -2775,6 +3239,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77365 return NULL;
77366 }
77367
77368 +#ifdef CONFIG_PAX_SEGMEXEC
77369 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77370 +{
77371 + struct vm_area_struct *prev_m;
77372 + struct rb_node **rb_link_m, *rb_parent_m;
77373 + struct mempolicy *pol_m;
77374 +
77375 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77376 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77377 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77378 + *vma_m = *vma;
77379 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
77380 + if (anon_vma_clone(vma_m, vma))
77381 + return -ENOMEM;
77382 + pol_m = vma_policy(vma_m);
77383 + mpol_get(pol_m);
77384 + vma_set_policy(vma_m, pol_m);
77385 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77386 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77387 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77388 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77389 + if (vma_m->vm_file)
77390 + get_file(vma_m->vm_file);
77391 + if (vma_m->vm_ops && vma_m->vm_ops->open)
77392 + vma_m->vm_ops->open(vma_m);
77393 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
77394 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77395 + vma_m->vm_mirror = vma;
77396 + vma->vm_mirror = vma_m;
77397 + return 0;
77398 +}
77399 +#endif
77400 +
77401 /*
77402 * Return true if the calling process may expand its vm space by the passed
77403 * number of pages
77404 @@ -2786,6 +3283,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77405
77406 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
77407
77408 +#ifdef CONFIG_PAX_RANDMMAP
77409 + if (mm->pax_flags & MF_PAX_RANDMMAP)
77410 + cur -= mm->brk_gap;
77411 +#endif
77412 +
77413 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77414 if (cur + npages > lim)
77415 return 0;
77416 return 1;
77417 @@ -2856,6 +3359,22 @@ int install_special_mapping(struct mm_struct *mm,
77418 vma->vm_start = addr;
77419 vma->vm_end = addr + len;
77420
77421 +#ifdef CONFIG_PAX_MPROTECT
77422 + if (mm->pax_flags & MF_PAX_MPROTECT) {
77423 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
77424 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77425 + return -EPERM;
77426 + if (!(vm_flags & VM_EXEC))
77427 + vm_flags &= ~VM_MAYEXEC;
77428 +#else
77429 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77430 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77431 +#endif
77432 + else
77433 + vm_flags &= ~VM_MAYWRITE;
77434 + }
77435 +#endif
77436 +
77437 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77438 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77439
77440 diff --git a/mm/mprotect.c b/mm/mprotect.c
77441 index 94722a4..9837984 100644
77442 --- a/mm/mprotect.c
77443 +++ b/mm/mprotect.c
77444 @@ -23,10 +23,17 @@
77445 #include <linux/mmu_notifier.h>
77446 #include <linux/migrate.h>
77447 #include <linux/perf_event.h>
77448 +
77449 +#ifdef CONFIG_PAX_MPROTECT
77450 +#include <linux/elf.h>
77451 +#include <linux/binfmts.h>
77452 +#endif
77453 +
77454 #include <asm/uaccess.h>
77455 #include <asm/pgtable.h>
77456 #include <asm/cacheflush.h>
77457 #include <asm/tlbflush.h>
77458 +#include <asm/mmu_context.h>
77459
77460 #ifndef pgprot_modify
77461 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77462 @@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
77463 return pages;
77464 }
77465
77466 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77467 +/* called while holding the mmap semaphor for writing except stack expansion */
77468 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77469 +{
77470 + unsigned long oldlimit, newlimit = 0UL;
77471 +
77472 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
77473 + return;
77474 +
77475 + spin_lock(&mm->page_table_lock);
77476 + oldlimit = mm->context.user_cs_limit;
77477 + if ((prot & VM_EXEC) && oldlimit < end)
77478 + /* USER_CS limit moved up */
77479 + newlimit = end;
77480 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77481 + /* USER_CS limit moved down */
77482 + newlimit = start;
77483 +
77484 + if (newlimit) {
77485 + mm->context.user_cs_limit = newlimit;
77486 +
77487 +#ifdef CONFIG_SMP
77488 + wmb();
77489 + cpus_clear(mm->context.cpu_user_cs_mask);
77490 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77491 +#endif
77492 +
77493 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77494 + }
77495 + spin_unlock(&mm->page_table_lock);
77496 + if (newlimit == end) {
77497 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
77498 +
77499 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
77500 + if (is_vm_hugetlb_page(vma))
77501 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77502 + else
77503 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
77504 + }
77505 +}
77506 +#endif
77507 +
77508 int
77509 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77510 unsigned long start, unsigned long end, unsigned long newflags)
77511 @@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77512 int error;
77513 int dirty_accountable = 0;
77514
77515 +#ifdef CONFIG_PAX_SEGMEXEC
77516 + struct vm_area_struct *vma_m = NULL;
77517 + unsigned long start_m, end_m;
77518 +
77519 + start_m = start + SEGMEXEC_TASK_SIZE;
77520 + end_m = end + SEGMEXEC_TASK_SIZE;
77521 +#endif
77522 +
77523 if (newflags == oldflags) {
77524 *pprev = vma;
77525 return 0;
77526 }
77527
77528 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77529 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77530 +
77531 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77532 + return -ENOMEM;
77533 +
77534 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77535 + return -ENOMEM;
77536 + }
77537 +
77538 /*
77539 * If we make a private mapping writable we increase our commit;
77540 * but (without finer accounting) cannot reduce our commit if we
77541 @@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77542 }
77543 }
77544
77545 +#ifdef CONFIG_PAX_SEGMEXEC
77546 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77547 + if (start != vma->vm_start) {
77548 + error = split_vma(mm, vma, start, 1);
77549 + if (error)
77550 + goto fail;
77551 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77552 + *pprev = (*pprev)->vm_next;
77553 + }
77554 +
77555 + if (end != vma->vm_end) {
77556 + error = split_vma(mm, vma, end, 0);
77557 + if (error)
77558 + goto fail;
77559 + }
77560 +
77561 + if (pax_find_mirror_vma(vma)) {
77562 + error = __do_munmap(mm, start_m, end_m - start_m);
77563 + if (error)
77564 + goto fail;
77565 + } else {
77566 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77567 + if (!vma_m) {
77568 + error = -ENOMEM;
77569 + goto fail;
77570 + }
77571 + vma->vm_flags = newflags;
77572 + error = pax_mirror_vma(vma_m, vma);
77573 + if (error) {
77574 + vma->vm_flags = oldflags;
77575 + goto fail;
77576 + }
77577 + }
77578 + }
77579 +#endif
77580 +
77581 /*
77582 * First try to merge with previous and/or next vma.
77583 */
77584 @@ -296,9 +399,21 @@ success:
77585 * vm_flags and vm_page_prot are protected by the mmap_sem
77586 * held in write mode.
77587 */
77588 +
77589 +#ifdef CONFIG_PAX_SEGMEXEC
77590 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77591 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77592 +#endif
77593 +
77594 vma->vm_flags = newflags;
77595 +
77596 +#ifdef CONFIG_PAX_MPROTECT
77597 + if (mm->binfmt && mm->binfmt->handle_mprotect)
77598 + mm->binfmt->handle_mprotect(vma, newflags);
77599 +#endif
77600 +
77601 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
77602 - vm_get_page_prot(newflags));
77603 + vm_get_page_prot(vma->vm_flags));
77604
77605 if (vma_wants_writenotify(vma)) {
77606 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
77607 @@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77608 end = start + len;
77609 if (end <= start)
77610 return -ENOMEM;
77611 +
77612 +#ifdef CONFIG_PAX_SEGMEXEC
77613 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
77614 + if (end > SEGMEXEC_TASK_SIZE)
77615 + return -EINVAL;
77616 + } else
77617 +#endif
77618 +
77619 + if (end > TASK_SIZE)
77620 + return -EINVAL;
77621 +
77622 if (!arch_validate_prot(prot))
77623 return -EINVAL;
77624
77625 @@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77626 /*
77627 * Does the application expect PROT_READ to imply PROT_EXEC:
77628 */
77629 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
77630 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
77631 prot |= PROT_EXEC;
77632
77633 vm_flags = calc_vm_prot_bits(prot);
77634 @@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77635 if (start > vma->vm_start)
77636 prev = vma;
77637
77638 +#ifdef CONFIG_PAX_MPROTECT
77639 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
77640 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
77641 +#endif
77642 +
77643 for (nstart = start ; ; ) {
77644 unsigned long newflags;
77645
77646 @@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77647
77648 /* newflags >> 4 shift VM_MAY% in place of VM_% */
77649 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
77650 + if (prot & (PROT_WRITE | PROT_EXEC))
77651 + gr_log_rwxmprotect(vma->vm_file);
77652 +
77653 + error = -EACCES;
77654 + goto out;
77655 + }
77656 +
77657 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
77658 error = -EACCES;
77659 goto out;
77660 }
77661 @@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
77662 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
77663 if (error)
77664 goto out;
77665 +
77666 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
77667 +
77668 nstart = tmp;
77669
77670 if (nstart < prev->vm_end)
77671 diff --git a/mm/mremap.c b/mm/mremap.c
77672 index e1031e1..1f2a0a1 100644
77673 --- a/mm/mremap.c
77674 +++ b/mm/mremap.c
77675 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
77676 continue;
77677 pte = ptep_get_and_clear(mm, old_addr, old_pte);
77678 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
77679 +
77680 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77681 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
77682 + pte = pte_exprotect(pte);
77683 +#endif
77684 +
77685 set_pte_at(mm, new_addr, new_pte, pte);
77686 }
77687
77688 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
77689 if (is_vm_hugetlb_page(vma))
77690 goto Einval;
77691
77692 +#ifdef CONFIG_PAX_SEGMEXEC
77693 + if (pax_find_mirror_vma(vma))
77694 + goto Einval;
77695 +#endif
77696 +
77697 /* We can't remap across vm area boundaries */
77698 if (old_len > vma->vm_end - addr)
77699 goto Efault;
77700 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
77701 unsigned long ret = -EINVAL;
77702 unsigned long charged = 0;
77703 unsigned long map_flags;
77704 + unsigned long pax_task_size = TASK_SIZE;
77705
77706 if (new_addr & ~PAGE_MASK)
77707 goto out;
77708
77709 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
77710 +#ifdef CONFIG_PAX_SEGMEXEC
77711 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
77712 + pax_task_size = SEGMEXEC_TASK_SIZE;
77713 +#endif
77714 +
77715 + pax_task_size -= PAGE_SIZE;
77716 +
77717 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
77718 goto out;
77719
77720 /* Check if the location we're moving into overlaps the
77721 * old location at all, and fail if it does.
77722 */
77723 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
77724 - goto out;
77725 -
77726 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
77727 + if (addr + old_len > new_addr && new_addr + new_len > addr)
77728 goto out;
77729
77730 ret = do_munmap(mm, new_addr, new_len);
77731 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77732 struct vm_area_struct *vma;
77733 unsigned long ret = -EINVAL;
77734 unsigned long charged = 0;
77735 + unsigned long pax_task_size = TASK_SIZE;
77736
77737 down_write(&current->mm->mmap_sem);
77738
77739 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77740 if (!new_len)
77741 goto out;
77742
77743 +#ifdef CONFIG_PAX_SEGMEXEC
77744 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
77745 + pax_task_size = SEGMEXEC_TASK_SIZE;
77746 +#endif
77747 +
77748 + pax_task_size -= PAGE_SIZE;
77749 +
77750 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
77751 + old_len > pax_task_size || addr > pax_task_size-old_len)
77752 + goto out;
77753 +
77754 if (flags & MREMAP_FIXED) {
77755 if (flags & MREMAP_MAYMOVE)
77756 ret = mremap_to(addr, old_len, new_addr, new_len);
77757 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77758 addr + new_len);
77759 }
77760 ret = addr;
77761 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
77762 goto out;
77763 }
77764 }
77765 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77766 goto out;
77767 }
77768
77769 + map_flags = vma->vm_flags;
77770 ret = move_vma(vma, addr, old_len, new_len, new_addr);
77771 + if (!(ret & ~PAGE_MASK)) {
77772 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
77773 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
77774 + }
77775 }
77776 out:
77777 if (ret & ~PAGE_MASK)
77778 diff --git a/mm/nommu.c b/mm/nommu.c
77779 index 79c3cac..4d357e0 100644
77780 --- a/mm/nommu.c
77781 +++ b/mm/nommu.c
77782 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77783 int sysctl_overcommit_ratio = 50; /* default is 50% */
77784 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77785 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77786 -int heap_stack_gap = 0;
77787
77788 atomic_long_t mmap_pages_allocated;
77789
77790 @@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77791 EXPORT_SYMBOL(find_vma);
77792
77793 /*
77794 - * find a VMA
77795 - * - we don't extend stack VMAs under NOMMU conditions
77796 - */
77797 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77798 -{
77799 - return find_vma(mm, addr);
77800 -}
77801 -
77802 -/*
77803 * expand a stack to a given address
77804 * - not supported under NOMMU conditions
77805 */
77806 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77807
77808 /* most fields are the same, copy all, and then fixup */
77809 *new = *vma;
77810 + INIT_LIST_HEAD(&new->anon_vma_chain);
77811 *region = *vma->vm_region;
77812 new->vm_region = region;
77813
77814 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
77815 index 0713bfb..e3774e0 100644
77816 --- a/mm/page-writeback.c
77817 +++ b/mm/page-writeback.c
77818 @@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
77819 }
77820 }
77821
77822 -static struct notifier_block __cpuinitdata ratelimit_nb = {
77823 +static struct notifier_block ratelimit_nb = {
77824 .notifier_call = ratelimit_handler,
77825 .next = NULL,
77826 };
77827 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
77828 index 6a83cd3..bc2dcb6 100644
77829 --- a/mm/page_alloc.c
77830 +++ b/mm/page_alloc.c
77831 @@ -338,7 +338,7 @@ out:
77832 * This usage means that zero-order pages may not be compound.
77833 */
77834
77835 -static void free_compound_page(struct page *page)
77836 +void free_compound_page(struct page *page)
77837 {
77838 __free_pages_ok(page, compound_order(page));
77839 }
77840 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77841 int i;
77842 int bad = 0;
77843
77844 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77845 + unsigned long index = 1UL << order;
77846 +#endif
77847 +
77848 trace_mm_page_free(page, order);
77849 kmemcheck_free_shadow(page, order);
77850
77851 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77852 debug_check_no_obj_freed(page_address(page),
77853 PAGE_SIZE << order);
77854 }
77855 +
77856 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77857 + for (; index; --index)
77858 + sanitize_highpage(page + index - 1);
77859 +#endif
77860 +
77861 arch_free_page(page, order);
77862 kernel_map_pages(page, 1 << order, 0);
77863
77864 @@ -861,8 +871,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
77865 arch_alloc_page(page, order);
77866 kernel_map_pages(page, 1 << order, 1);
77867
77868 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
77869 if (gfp_flags & __GFP_ZERO)
77870 prep_zero_page(page, order, gfp_flags);
77871 +#endif
77872
77873 if (order && (gfp_flags & __GFP_COMP))
77874 prep_compound_page(page, order);
77875 @@ -3752,7 +3764,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
77876 unsigned long pfn;
77877
77878 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
77879 +#ifdef CONFIG_X86_32
77880 + /* boot failures in VMware 8 on 32bit vanilla since
77881 + this change */
77882 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
77883 +#else
77884 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
77885 +#endif
77886 return 1;
77887 }
77888 return 0;
77889 diff --git a/mm/percpu.c b/mm/percpu.c
77890 index 8c8e08f..73a5cda 100644
77891 --- a/mm/percpu.c
77892 +++ b/mm/percpu.c
77893 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77894 static unsigned int pcpu_high_unit_cpu __read_mostly;
77895
77896 /* the address of the first chunk which starts with the kernel static area */
77897 -void *pcpu_base_addr __read_mostly;
77898 +void *pcpu_base_addr __read_only;
77899 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77900
77901 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77902 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
77903 index 926b466..b23df53 100644
77904 --- a/mm/process_vm_access.c
77905 +++ b/mm/process_vm_access.c
77906 @@ -13,6 +13,7 @@
77907 #include <linux/uio.h>
77908 #include <linux/sched.h>
77909 #include <linux/highmem.h>
77910 +#include <linux/security.h>
77911 #include <linux/ptrace.h>
77912 #include <linux/slab.h>
77913 #include <linux/syscalls.h>
77914 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77915 size_t iov_l_curr_offset = 0;
77916 ssize_t iov_len;
77917
77918 + return -ENOSYS; // PaX: until properly audited
77919 +
77920 /*
77921 * Work out how many pages of struct pages we're going to need
77922 * when eventually calling get_user_pages
77923 */
77924 for (i = 0; i < riovcnt; i++) {
77925 iov_len = rvec[i].iov_len;
77926 - if (iov_len > 0) {
77927 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
77928 - + iov_len)
77929 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
77930 - / PAGE_SIZE + 1;
77931 - nr_pages = max(nr_pages, nr_pages_iov);
77932 - }
77933 + if (iov_len <= 0)
77934 + continue;
77935 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
77936 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
77937 + nr_pages = max(nr_pages, nr_pages_iov);
77938 }
77939
77940 if (nr_pages == 0)
77941 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77942 goto free_proc_pages;
77943 }
77944
77945 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
77946 + rc = -EPERM;
77947 + goto put_task_struct;
77948 + }
77949 +
77950 mm = mm_access(task, PTRACE_MODE_ATTACH);
77951 if (!mm || IS_ERR(mm)) {
77952 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
77953 diff --git a/mm/rmap.c b/mm/rmap.c
77954 index 2c78f8c..9e9c624 100644
77955 --- a/mm/rmap.c
77956 +++ b/mm/rmap.c
77957 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77958 struct anon_vma *anon_vma = vma->anon_vma;
77959 struct anon_vma_chain *avc;
77960
77961 +#ifdef CONFIG_PAX_SEGMEXEC
77962 + struct anon_vma_chain *avc_m = NULL;
77963 +#endif
77964 +
77965 might_sleep();
77966 if (unlikely(!anon_vma)) {
77967 struct mm_struct *mm = vma->vm_mm;
77968 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77969 if (!avc)
77970 goto out_enomem;
77971
77972 +#ifdef CONFIG_PAX_SEGMEXEC
77973 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
77974 + if (!avc_m)
77975 + goto out_enomem_free_avc;
77976 +#endif
77977 +
77978 anon_vma = find_mergeable_anon_vma(vma);
77979 allocated = NULL;
77980 if (!anon_vma) {
77981 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77982 /* page_table_lock to protect against threads */
77983 spin_lock(&mm->page_table_lock);
77984 if (likely(!vma->anon_vma)) {
77985 +
77986 +#ifdef CONFIG_PAX_SEGMEXEC
77987 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
77988 +
77989 + if (vma_m) {
77990 + BUG_ON(vma_m->anon_vma);
77991 + vma_m->anon_vma = anon_vma;
77992 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
77993 + avc_m = NULL;
77994 + }
77995 +#endif
77996 +
77997 vma->anon_vma = anon_vma;
77998 anon_vma_chain_link(vma, avc, anon_vma);
77999 allocated = NULL;
78000 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78001
78002 if (unlikely(allocated))
78003 put_anon_vma(allocated);
78004 +
78005 +#ifdef CONFIG_PAX_SEGMEXEC
78006 + if (unlikely(avc_m))
78007 + anon_vma_chain_free(avc_m);
78008 +#endif
78009 +
78010 if (unlikely(avc))
78011 anon_vma_chain_free(avc);
78012 }
78013 return 0;
78014
78015 out_enomem_free_avc:
78016 +
78017 +#ifdef CONFIG_PAX_SEGMEXEC
78018 + if (avc_m)
78019 + anon_vma_chain_free(avc_m);
78020 +#endif
78021 +
78022 anon_vma_chain_free(avc);
78023 out_enomem:
78024 return -ENOMEM;
78025 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
78026 * Attach the anon_vmas from src to dst.
78027 * Returns 0 on success, -ENOMEM on failure.
78028 */
78029 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78030 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
78031 {
78032 struct anon_vma_chain *avc, *pavc;
78033 struct anon_vma *root = NULL;
78034 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78035 * the corresponding VMA in the parent process is attached to.
78036 * Returns 0 on success, non-zero on failure.
78037 */
78038 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
78039 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
78040 {
78041 struct anon_vma_chain *avc;
78042 struct anon_vma *anon_vma;
78043 diff --git a/mm/shmem.c b/mm/shmem.c
78044 index 5dd56f6..7c51725 100644
78045 --- a/mm/shmem.c
78046 +++ b/mm/shmem.c
78047 @@ -31,7 +31,7 @@
78048 #include <linux/export.h>
78049 #include <linux/swap.h>
78050
78051 -static struct vfsmount *shm_mnt;
78052 +struct vfsmount *shm_mnt;
78053
78054 #ifdef CONFIG_SHMEM
78055 /*
78056 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
78057 #define BOGO_DIRENT_SIZE 20
78058
78059 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
78060 -#define SHORT_SYMLINK_LEN 128
78061 +#define SHORT_SYMLINK_LEN 64
78062
78063 /*
78064 * shmem_fallocate and shmem_writepage communicate via inode->i_private
78065 @@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
78066 static int shmem_xattr_validate(const char *name)
78067 {
78068 struct { const char *prefix; size_t len; } arr[] = {
78069 +
78070 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78071 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
78072 +#endif
78073 +
78074 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
78075 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
78076 };
78077 @@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
78078 if (err)
78079 return err;
78080
78081 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78082 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
78083 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
78084 + return -EOPNOTSUPP;
78085 + if (size > 8)
78086 + return -EINVAL;
78087 + }
78088 +#endif
78089 +
78090 return simple_xattr_set(&info->xattrs, name, value, size, flags);
78091 }
78092
78093 @@ -2556,8 +2570,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78094 int err = -ENOMEM;
78095
78096 /* Round up to L1_CACHE_BYTES to resist false sharing */
78097 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78098 - L1_CACHE_BYTES), GFP_KERNEL);
78099 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78100 if (!sbinfo)
78101 return -ENOMEM;
78102
78103 diff --git a/mm/slab.c b/mm/slab.c
78104 index e7667a3..b62c169 100644
78105 --- a/mm/slab.c
78106 +++ b/mm/slab.c
78107 @@ -306,7 +306,7 @@ struct kmem_list3 {
78108 * Need this for bootstrapping a per node allocator.
78109 */
78110 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78111 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78112 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78113 #define CACHE_CACHE 0
78114 #define SIZE_AC MAX_NUMNODES
78115 #define SIZE_L3 (2 * MAX_NUMNODES)
78116 @@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78117 if ((x)->max_freeable < i) \
78118 (x)->max_freeable = i; \
78119 } while (0)
78120 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78121 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78122 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78123 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78124 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78125 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78126 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78127 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78128 #else
78129 #define STATS_INC_ACTIVE(x) do { } while (0)
78130 #define STATS_DEC_ACTIVE(x) do { } while (0)
78131 @@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78132 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78133 */
78134 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78135 - const struct slab *slab, void *obj)
78136 + const struct slab *slab, const void *obj)
78137 {
78138 u32 offset = (obj - slab->s_mem);
78139 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78140 @@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
78141 struct cache_names {
78142 char *name;
78143 char *name_dma;
78144 + char *name_usercopy;
78145 };
78146
78147 static struct cache_names __initdata cache_names[] = {
78148 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
78149 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
78150 #include <linux/kmalloc_sizes.h>
78151 - {NULL,}
78152 + {NULL}
78153 #undef CACHE
78154 };
78155
78156 @@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
78157 if (unlikely(gfpflags & GFP_DMA))
78158 return csizep->cs_dmacachep;
78159 #endif
78160 +
78161 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78162 + if (unlikely(gfpflags & GFP_USERCOPY))
78163 + return csizep->cs_usercopycachep;
78164 +#endif
78165 +
78166 return csizep->cs_cachep;
78167 }
78168
78169 @@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
78170 return notifier_from_errno(err);
78171 }
78172
78173 -static struct notifier_block __cpuinitdata cpucache_notifier = {
78174 +static struct notifier_block cpucache_notifier = {
78175 &cpuup_callback, NULL, 0
78176 };
78177
78178 @@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
78179 */
78180
78181 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
78182 - sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
78183 + sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78184
78185 if (INDEX_AC != INDEX_L3)
78186 sizes[INDEX_L3].cs_cachep =
78187 create_kmalloc_cache(names[INDEX_L3].name,
78188 - sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
78189 + sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78190
78191 slab_early_init = 0;
78192
78193 @@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
78194 */
78195 if (!sizes->cs_cachep)
78196 sizes->cs_cachep = create_kmalloc_cache(names->name,
78197 - sizes->cs_size, ARCH_KMALLOC_FLAGS);
78198 + sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78199
78200 #ifdef CONFIG_ZONE_DMA
78201 sizes->cs_dmacachep = create_kmalloc_cache(
78202 names->name_dma, sizes->cs_size,
78203 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
78204 #endif
78205 +
78206 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78207 + sizes->cs_usercopycachep = create_kmalloc_cache(
78208 + names->name_usercopy, sizes->cs_size,
78209 + ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78210 +#endif
78211 +
78212 sizes++;
78213 names++;
78214 }
78215 @@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
78216 }
78217 /* cpu stats */
78218 {
78219 - unsigned long allochit = atomic_read(&cachep->allochit);
78220 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78221 - unsigned long freehit = atomic_read(&cachep->freehit);
78222 - unsigned long freemiss = atomic_read(&cachep->freemiss);
78223 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78224 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78225 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78226 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78227
78228 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78229 allochit, allocmiss, freehit, freemiss);
78230 @@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
78231 static int __init slab_proc_init(void)
78232 {
78233 #ifdef CONFIG_DEBUG_SLAB_LEAK
78234 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78235 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
78236 #endif
78237 return 0;
78238 }
78239 module_init(slab_proc_init);
78240 #endif
78241
78242 +bool is_usercopy_object(const void *ptr)
78243 +{
78244 + struct page *page;
78245 + struct kmem_cache *cachep;
78246 +
78247 + if (ZERO_OR_NULL_PTR(ptr))
78248 + return false;
78249 +
78250 + if (!slab_is_available())
78251 + return false;
78252 +
78253 + if (!virt_addr_valid(ptr))
78254 + return false;
78255 +
78256 + page = virt_to_head_page(ptr);
78257 +
78258 + if (!PageSlab(page))
78259 + return false;
78260 +
78261 + cachep = page->slab_cache;
78262 + return cachep->flags & SLAB_USERCOPY;
78263 +}
78264 +
78265 +#ifdef CONFIG_PAX_USERCOPY
78266 +const char *check_heap_object(const void *ptr, unsigned long n)
78267 +{
78268 + struct page *page;
78269 + struct kmem_cache *cachep;
78270 + struct slab *slabp;
78271 + unsigned int objnr;
78272 + unsigned long offset;
78273 +
78274 + if (ZERO_OR_NULL_PTR(ptr))
78275 + return "<null>";
78276 +
78277 + if (!virt_addr_valid(ptr))
78278 + return NULL;
78279 +
78280 + page = virt_to_head_page(ptr);
78281 +
78282 + if (!PageSlab(page))
78283 + return NULL;
78284 +
78285 + cachep = page->slab_cache;
78286 + if (!(cachep->flags & SLAB_USERCOPY))
78287 + return cachep->name;
78288 +
78289 + slabp = page->slab_page;
78290 + objnr = obj_to_index(cachep, slabp, ptr);
78291 + BUG_ON(objnr >= cachep->num);
78292 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78293 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
78294 + return NULL;
78295 +
78296 + return cachep->name;
78297 +}
78298 +#endif
78299 +
78300 /**
78301 * ksize - get the actual amount of memory allocated for a given object
78302 * @objp: Pointer to the object
78303 diff --git a/mm/slab.h b/mm/slab.h
78304 index 34a98d6..73633d1 100644
78305 --- a/mm/slab.h
78306 +++ b/mm/slab.h
78307 @@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78308
78309 /* Legal flag mask for kmem_cache_create(), for various configurations */
78310 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
78311 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
78312 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
78313
78314 #if defined(CONFIG_DEBUG_SLAB)
78315 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
78316 @@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
78317 return s;
78318
78319 page = virt_to_head_page(x);
78320 +
78321 + BUG_ON(!PageSlab(page));
78322 +
78323 cachep = page->slab_cache;
78324 if (slab_equal_or_root(cachep, s))
78325 return cachep;
78326 diff --git a/mm/slab_common.c b/mm/slab_common.c
78327 index 3f3cd97..e050794 100644
78328 --- a/mm/slab_common.c
78329 +++ b/mm/slab_common.c
78330 @@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
78331
78332 err = __kmem_cache_create(s, flags);
78333 if (!err) {
78334 - s->refcount = 1;
78335 + atomic_set(&s->refcount, 1);
78336 list_add(&s->list, &slab_caches);
78337 memcg_cache_list_add(memcg, s);
78338 } else {
78339 @@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
78340
78341 get_online_cpus();
78342 mutex_lock(&slab_mutex);
78343 - s->refcount--;
78344 - if (!s->refcount) {
78345 + if (atomic_dec_and_test(&s->refcount)) {
78346 list_del(&s->list);
78347
78348 if (!__kmem_cache_shutdown(s)) {
78349 @@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
78350 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
78351 name, size, err);
78352
78353 - s->refcount = -1; /* Exempt from merging for now */
78354 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
78355 }
78356
78357 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78358 @@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78359
78360 create_boot_cache(s, name, size, flags);
78361 list_add(&s->list, &slab_caches);
78362 - s->refcount = 1;
78363 + atomic_set(&s->refcount, 1);
78364 return s;
78365 }
78366
78367 diff --git a/mm/slob.c b/mm/slob.c
78368 index a99fdf7..f5b6577 100644
78369 --- a/mm/slob.c
78370 +++ b/mm/slob.c
78371 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78372 /*
78373 * Return the size of a slob block.
78374 */
78375 -static slobidx_t slob_units(slob_t *s)
78376 +static slobidx_t slob_units(const slob_t *s)
78377 {
78378 if (s->units > 0)
78379 return s->units;
78380 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
78381 /*
78382 * Return the next free slob block pointer after this one.
78383 */
78384 -static slob_t *slob_next(slob_t *s)
78385 +static slob_t *slob_next(const slob_t *s)
78386 {
78387 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78388 slobidx_t next;
78389 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
78390 /*
78391 * Returns true if s is the last free block in its page.
78392 */
78393 -static int slob_last(slob_t *s)
78394 +static int slob_last(const slob_t *s)
78395 {
78396 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78397 }
78398
78399 -static void *slob_new_pages(gfp_t gfp, int order, int node)
78400 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
78401 {
78402 - void *page;
78403 + struct page *page;
78404
78405 #ifdef CONFIG_NUMA
78406 if (node != NUMA_NO_NODE)
78407 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78408 if (!page)
78409 return NULL;
78410
78411 - return page_address(page);
78412 + __SetPageSlab(page);
78413 + return page;
78414 }
78415
78416 -static void slob_free_pages(void *b, int order)
78417 +static void slob_free_pages(struct page *sp, int order)
78418 {
78419 if (current->reclaim_state)
78420 current->reclaim_state->reclaimed_slab += 1 << order;
78421 - free_pages((unsigned long)b, order);
78422 + __ClearPageSlab(sp);
78423 + reset_page_mapcount(sp);
78424 + sp->private = 0;
78425 + __free_pages(sp, order);
78426 }
78427
78428 /*
78429 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78430
78431 /* Not enough space: must allocate a new page */
78432 if (!b) {
78433 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78434 - if (!b)
78435 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78436 + if (!sp)
78437 return NULL;
78438 - sp = virt_to_page(b);
78439 - __SetPageSlab(sp);
78440 + b = page_address(sp);
78441
78442 spin_lock_irqsave(&slob_lock, flags);
78443 sp->units = SLOB_UNITS(PAGE_SIZE);
78444 sp->freelist = b;
78445 + sp->private = 0;
78446 INIT_LIST_HEAD(&sp->list);
78447 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78448 set_slob_page_free(sp, slob_list);
78449 @@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
78450 if (slob_page_free(sp))
78451 clear_slob_page_free(sp);
78452 spin_unlock_irqrestore(&slob_lock, flags);
78453 - __ClearPageSlab(sp);
78454 - reset_page_mapcount(sp);
78455 - slob_free_pages(b, 0);
78456 + slob_free_pages(sp, 0);
78457 return;
78458 }
78459
78460 @@ -424,11 +426,10 @@ out:
78461 */
78462
78463 static __always_inline void *
78464 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78465 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
78466 {
78467 - unsigned int *m;
78468 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78469 - void *ret;
78470 + slob_t *m;
78471 + void *ret = NULL;
78472
78473 gfp &= gfp_allowed_mask;
78474
78475 @@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78476
78477 if (!m)
78478 return NULL;
78479 - *m = size;
78480 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78481 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78482 + m[0].units = size;
78483 + m[1].units = align;
78484 ret = (void *)m + align;
78485
78486 trace_kmalloc_node(caller, ret,
78487 size, size + align, gfp, node);
78488 } else {
78489 unsigned int order = get_order(size);
78490 + struct page *page;
78491
78492 if (likely(order))
78493 gfp |= __GFP_COMP;
78494 - ret = slob_new_pages(gfp, order, node);
78495 + page = slob_new_pages(gfp, order, node);
78496 + if (page) {
78497 + ret = page_address(page);
78498 + page->private = size;
78499 + }
78500
78501 trace_kmalloc_node(caller, ret,
78502 size, PAGE_SIZE << order, gfp, node);
78503 }
78504
78505 - kmemleak_alloc(ret, size, 1, gfp);
78506 + return ret;
78507 +}
78508 +
78509 +static __always_inline void *
78510 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78511 +{
78512 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78513 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
78514 +
78515 + if (!ZERO_OR_NULL_PTR(ret))
78516 + kmemleak_alloc(ret, size, 1, gfp);
78517 return ret;
78518 }
78519
78520 @@ -494,33 +513,110 @@ void kfree(const void *block)
78521 kmemleak_free(block);
78522
78523 sp = virt_to_page(block);
78524 - if (PageSlab(sp)) {
78525 + VM_BUG_ON(!PageSlab(sp));
78526 + if (!sp->private) {
78527 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78528 - unsigned int *m = (unsigned int *)(block - align);
78529 - slob_free(m, *m + align);
78530 - } else
78531 + slob_t *m = (slob_t *)(block - align);
78532 + slob_free(m, m[0].units + align);
78533 + } else {
78534 + __ClearPageSlab(sp);
78535 + reset_page_mapcount(sp);
78536 + sp->private = 0;
78537 __free_pages(sp, compound_order(sp));
78538 + }
78539 }
78540 EXPORT_SYMBOL(kfree);
78541
78542 +bool is_usercopy_object(const void *ptr)
78543 +{
78544 + if (!slab_is_available())
78545 + return false;
78546 +
78547 + // PAX: TODO
78548 +
78549 + return false;
78550 +}
78551 +
78552 +#ifdef CONFIG_PAX_USERCOPY
78553 +const char *check_heap_object(const void *ptr, unsigned long n)
78554 +{
78555 + struct page *page;
78556 + const slob_t *free;
78557 + const void *base;
78558 + unsigned long flags;
78559 +
78560 + if (ZERO_OR_NULL_PTR(ptr))
78561 + return "<null>";
78562 +
78563 + if (!virt_addr_valid(ptr))
78564 + return NULL;
78565 +
78566 + page = virt_to_head_page(ptr);
78567 + if (!PageSlab(page))
78568 + return NULL;
78569 +
78570 + if (page->private) {
78571 + base = page;
78572 + if (base <= ptr && n <= page->private - (ptr - base))
78573 + return NULL;
78574 + return "<slob>";
78575 + }
78576 +
78577 + /* some tricky double walking to find the chunk */
78578 + spin_lock_irqsave(&slob_lock, flags);
78579 + base = (void *)((unsigned long)ptr & PAGE_MASK);
78580 + free = page->freelist;
78581 +
78582 + while (!slob_last(free) && (void *)free <= ptr) {
78583 + base = free + slob_units(free);
78584 + free = slob_next(free);
78585 + }
78586 +
78587 + while (base < (void *)free) {
78588 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
78589 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
78590 + int offset;
78591 +
78592 + if (ptr < base + align)
78593 + break;
78594 +
78595 + offset = ptr - base - align;
78596 + if (offset >= m) {
78597 + base += size;
78598 + continue;
78599 + }
78600 +
78601 + if (n > m - offset)
78602 + break;
78603 +
78604 + spin_unlock_irqrestore(&slob_lock, flags);
78605 + return NULL;
78606 + }
78607 +
78608 + spin_unlock_irqrestore(&slob_lock, flags);
78609 + return "<slob>";
78610 +}
78611 +#endif
78612 +
78613 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
78614 size_t ksize(const void *block)
78615 {
78616 struct page *sp;
78617 int align;
78618 - unsigned int *m;
78619 + slob_t *m;
78620
78621 BUG_ON(!block);
78622 if (unlikely(block == ZERO_SIZE_PTR))
78623 return 0;
78624
78625 sp = virt_to_page(block);
78626 - if (unlikely(!PageSlab(sp)))
78627 - return PAGE_SIZE << compound_order(sp);
78628 + VM_BUG_ON(!PageSlab(sp));
78629 + if (sp->private)
78630 + return sp->private;
78631
78632 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78633 - m = (unsigned int *)(block - align);
78634 - return SLOB_UNITS(*m) * SLOB_UNIT;
78635 + m = (slob_t *)(block - align);
78636 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
78637 }
78638 EXPORT_SYMBOL(ksize);
78639
78640 @@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
78641
78642 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
78643 {
78644 - void *b;
78645 + void *b = NULL;
78646
78647 flags &= gfp_allowed_mask;
78648
78649 lockdep_trace_alloc(flags);
78650
78651 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78652 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
78653 +#else
78654 if (c->size < PAGE_SIZE) {
78655 b = slob_alloc(c->size, flags, c->align, node);
78656 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
78657 SLOB_UNITS(c->size) * SLOB_UNIT,
78658 flags, node);
78659 } else {
78660 - b = slob_new_pages(flags, get_order(c->size), node);
78661 + struct page *sp;
78662 +
78663 + sp = slob_new_pages(flags, get_order(c->size), node);
78664 + if (sp) {
78665 + b = page_address(sp);
78666 + sp->private = c->size;
78667 + }
78668 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
78669 PAGE_SIZE << get_order(c->size),
78670 flags, node);
78671 }
78672 +#endif
78673
78674 if (c->ctor)
78675 c->ctor(b);
78676 @@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
78677
78678 static void __kmem_cache_free(void *b, int size)
78679 {
78680 - if (size < PAGE_SIZE)
78681 + struct page *sp;
78682 +
78683 + sp = virt_to_page(b);
78684 + BUG_ON(!PageSlab(sp));
78685 + if (!sp->private)
78686 slob_free(b, size);
78687 else
78688 - slob_free_pages(b, get_order(size));
78689 + slob_free_pages(sp, get_order(size));
78690 }
78691
78692 static void kmem_rcu_free(struct rcu_head *head)
78693 @@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
78694
78695 void kmem_cache_free(struct kmem_cache *c, void *b)
78696 {
78697 + int size = c->size;
78698 +
78699 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78700 + if (size + c->align < PAGE_SIZE) {
78701 + size += c->align;
78702 + b -= c->align;
78703 + }
78704 +#endif
78705 +
78706 kmemleak_free_recursive(b, c->flags);
78707 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
78708 struct slob_rcu *slob_rcu;
78709 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
78710 - slob_rcu->size = c->size;
78711 + slob_rcu = b + (size - sizeof(struct slob_rcu));
78712 + slob_rcu->size = size;
78713 call_rcu(&slob_rcu->head, kmem_rcu_free);
78714 } else {
78715 - __kmem_cache_free(b, c->size);
78716 + __kmem_cache_free(b, size);
78717 }
78718
78719 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78720 + trace_kfree(_RET_IP_, b);
78721 +#else
78722 trace_kmem_cache_free(_RET_IP_, b);
78723 +#endif
78724 +
78725 }
78726 EXPORT_SYMBOL(kmem_cache_free);
78727
78728 diff --git a/mm/slub.c b/mm/slub.c
78729 index ba2ca53..00b1f4e 100644
78730 --- a/mm/slub.c
78731 +++ b/mm/slub.c
78732 @@ -197,7 +197,7 @@ struct track {
78733
78734 enum track_item { TRACK_ALLOC, TRACK_FREE };
78735
78736 -#ifdef CONFIG_SYSFS
78737 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78738 static int sysfs_slab_add(struct kmem_cache *);
78739 static int sysfs_slab_alias(struct kmem_cache *, const char *);
78740 static void sysfs_slab_remove(struct kmem_cache *);
78741 @@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
78742 if (!t->addr)
78743 return;
78744
78745 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
78746 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
78747 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
78748 #ifdef CONFIG_STACKTRACE
78749 {
78750 @@ -2653,7 +2653,7 @@ static int slub_min_objects;
78751 * Merge control. If this is set then no merging of slab caches will occur.
78752 * (Could be removed. This was introduced to pacify the merge skeptics.)
78753 */
78754 -static int slub_nomerge;
78755 +static int slub_nomerge = 1;
78756
78757 /*
78758 * Calculate the order of allocation given an slab object size.
78759 @@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
78760 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
78761 #endif
78762
78763 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78764 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
78765 +#endif
78766 +
78767 static int __init setup_slub_min_order(char *str)
78768 {
78769 get_option(&str, &slub_min_order);
78770 @@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
78771 return kmalloc_dma_caches[index];
78772
78773 #endif
78774 +
78775 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78776 + if (flags & SLAB_USERCOPY)
78777 + return kmalloc_usercopy_caches[index];
78778 +
78779 +#endif
78780 +
78781 return kmalloc_caches[index];
78782 }
78783
78784 @@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78785 EXPORT_SYMBOL(__kmalloc_node);
78786 #endif
78787
78788 +bool is_usercopy_object(const void *ptr)
78789 +{
78790 + struct page *page;
78791 + struct kmem_cache *s;
78792 +
78793 + if (ZERO_OR_NULL_PTR(ptr))
78794 + return false;
78795 +
78796 + if (!slab_is_available())
78797 + return false;
78798 +
78799 + if (!virt_addr_valid(ptr))
78800 + return false;
78801 +
78802 + page = virt_to_head_page(ptr);
78803 +
78804 + if (!PageSlab(page))
78805 + return false;
78806 +
78807 + s = page->slab_cache;
78808 + return s->flags & SLAB_USERCOPY;
78809 +}
78810 +
78811 +#ifdef CONFIG_PAX_USERCOPY
78812 +const char *check_heap_object(const void *ptr, unsigned long n)
78813 +{
78814 + struct page *page;
78815 + struct kmem_cache *s;
78816 + unsigned long offset;
78817 +
78818 + if (ZERO_OR_NULL_PTR(ptr))
78819 + return "<null>";
78820 +
78821 + if (!virt_addr_valid(ptr))
78822 + return NULL;
78823 +
78824 + page = virt_to_head_page(ptr);
78825 +
78826 + if (!PageSlab(page))
78827 + return NULL;
78828 +
78829 + s = page->slab_cache;
78830 + if (!(s->flags & SLAB_USERCOPY))
78831 + return s->name;
78832 +
78833 + offset = (ptr - page_address(page)) % s->size;
78834 + if (offset <= s->object_size && n <= s->object_size - offset)
78835 + return NULL;
78836 +
78837 + return s->name;
78838 +}
78839 +#endif
78840 +
78841 size_t ksize(const void *object)
78842 {
78843 struct page *page;
78844 @@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
78845
78846 /* Caches that are not of the two-to-the-power-of size */
78847 if (KMALLOC_MIN_SIZE <= 32) {
78848 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
78849 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
78850 caches++;
78851 }
78852
78853 if (KMALLOC_MIN_SIZE <= 64) {
78854 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
78855 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
78856 caches++;
78857 }
78858
78859 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78860 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
78861 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
78862 caches++;
78863 }
78864
78865 @@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
78866 }
78867 }
78868 #endif
78869 +
78870 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78871 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
78872 + struct kmem_cache *s = kmalloc_caches[i];
78873 +
78874 + if (s && s->size) {
78875 + char *name = kasprintf(GFP_NOWAIT,
78876 + "usercopy-kmalloc-%d", s->object_size);
78877 +
78878 + BUG_ON(!name);
78879 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
78880 + s->object_size, SLAB_USERCOPY);
78881 + }
78882 + }
78883 +#endif
78884 +
78885 printk(KERN_INFO
78886 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
78887 " CPUs=%d, Nodes=%d\n",
78888 @@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78889 /*
78890 * We may have set a slab to be unmergeable during bootstrap.
78891 */
78892 - if (s->refcount < 0)
78893 + if (atomic_read(&s->refcount) < 0)
78894 return 1;
78895
78896 return 0;
78897 @@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78898
78899 s = find_mergeable(memcg, size, align, flags, name, ctor);
78900 if (s) {
78901 - s->refcount++;
78902 + atomic_inc(&s->refcount);
78903 /*
78904 * Adjust the object sizes so that we clear
78905 * the complete object on kzalloc.
78906 @@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78907 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
78908
78909 if (sysfs_slab_alias(s, name)) {
78910 - s->refcount--;
78911 + atomic_dec(&s->refcount);
78912 s = NULL;
78913 }
78914 }
78915 @@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
78916 return NOTIFY_OK;
78917 }
78918
78919 -static struct notifier_block __cpuinitdata slab_notifier = {
78920 +static struct notifier_block slab_notifier = {
78921 .notifier_call = slab_cpuup_callback
78922 };
78923
78924 @@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
78925 }
78926 #endif
78927
78928 -#ifdef CONFIG_SYSFS
78929 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78930 static int count_inuse(struct page *page)
78931 {
78932 return page->inuse;
78933 @@ -4364,12 +4444,12 @@ static void resiliency_test(void)
78934 validate_slab_cache(kmalloc_caches[9]);
78935 }
78936 #else
78937 -#ifdef CONFIG_SYSFS
78938 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78939 static void resiliency_test(void) {};
78940 #endif
78941 #endif
78942
78943 -#ifdef CONFIG_SYSFS
78944 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78945 enum slab_stat_type {
78946 SL_ALL, /* All slabs */
78947 SL_PARTIAL, /* Only partially allocated slabs */
78948 @@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
78949
78950 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78951 {
78952 - return sprintf(buf, "%d\n", s->refcount - 1);
78953 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78954 }
78955 SLAB_ATTR_RO(aliases);
78956
78957 @@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
78958 return name;
78959 }
78960
78961 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78962 static int sysfs_slab_add(struct kmem_cache *s)
78963 {
78964 int err;
78965 @@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78966 kobject_del(&s->kobj);
78967 kobject_put(&s->kobj);
78968 }
78969 +#endif
78970
78971 /*
78972 * Need to buffer aliases during bootup until sysfs becomes
78973 @@ -5336,6 +5418,7 @@ struct saved_alias {
78974
78975 static struct saved_alias *alias_list;
78976
78977 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78978 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78979 {
78980 struct saved_alias *al;
78981 @@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78982 alias_list = al;
78983 return 0;
78984 }
78985 +#endif
78986
78987 static int __init slab_sysfs_init(void)
78988 {
78989 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
78990 index 1b7e22a..3fcd4f3 100644
78991 --- a/mm/sparse-vmemmap.c
78992 +++ b/mm/sparse-vmemmap.c
78993 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
78994 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78995 if (!p)
78996 return NULL;
78997 - pud_populate(&init_mm, pud, p);
78998 + pud_populate_kernel(&init_mm, pud, p);
78999 }
79000 return pud;
79001 }
79002 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
79003 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79004 if (!p)
79005 return NULL;
79006 - pgd_populate(&init_mm, pgd, p);
79007 + pgd_populate_kernel(&init_mm, pgd, p);
79008 }
79009 return pgd;
79010 }
79011 diff --git a/mm/sparse.c b/mm/sparse.c
79012 index 6b5fb76..db0c190 100644
79013 --- a/mm/sparse.c
79014 +++ b/mm/sparse.c
79015 @@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
79016
79017 for (i = 0; i < PAGES_PER_SECTION; i++) {
79018 if (PageHWPoison(&memmap[i])) {
79019 - atomic_long_sub(1, &mce_bad_pages);
79020 + atomic_long_sub_unchecked(1, &mce_bad_pages);
79021 ClearPageHWPoison(&memmap[i]);
79022 }
79023 }
79024 diff --git a/mm/swap.c b/mm/swap.c
79025 index 6310dc2..3662b3f 100644
79026 --- a/mm/swap.c
79027 +++ b/mm/swap.c
79028 @@ -30,6 +30,7 @@
79029 #include <linux/backing-dev.h>
79030 #include <linux/memcontrol.h>
79031 #include <linux/gfp.h>
79032 +#include <linux/hugetlb.h>
79033
79034 #include "internal.h"
79035
79036 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
79037
79038 __page_cache_release(page);
79039 dtor = get_compound_page_dtor(page);
79040 + if (!PageHuge(page))
79041 + BUG_ON(dtor != free_compound_page);
79042 (*dtor)(page);
79043 }
79044
79045 diff --git a/mm/swapfile.c b/mm/swapfile.c
79046 index e97a0e5..b50e796 100644
79047 --- a/mm/swapfile.c
79048 +++ b/mm/swapfile.c
79049 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
79050
79051 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
79052 /* Activity counter to indicate that a swapon or swapoff has occurred */
79053 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
79054 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
79055
79056 static inline unsigned char swap_count(unsigned char ent)
79057 {
79058 @@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
79059 }
79060 filp_close(swap_file, NULL);
79061 err = 0;
79062 - atomic_inc(&proc_poll_event);
79063 + atomic_inc_unchecked(&proc_poll_event);
79064 wake_up_interruptible(&proc_poll_wait);
79065
79066 out_dput:
79067 @@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
79068
79069 poll_wait(file, &proc_poll_wait, wait);
79070
79071 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
79072 - seq->poll_event = atomic_read(&proc_poll_event);
79073 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
79074 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79075 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
79076 }
79077
79078 @@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
79079 return ret;
79080
79081 seq = file->private_data;
79082 - seq->poll_event = atomic_read(&proc_poll_event);
79083 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79084 return 0;
79085 }
79086
79087 @@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
79088 (frontswap_map) ? "FS" : "");
79089
79090 mutex_unlock(&swapon_mutex);
79091 - atomic_inc(&proc_poll_event);
79092 + atomic_inc_unchecked(&proc_poll_event);
79093 wake_up_interruptible(&proc_poll_wait);
79094
79095 if (S_ISREG(inode->i_mode))
79096 diff --git a/mm/util.c b/mm/util.c
79097 index c55e26b..3f913a9 100644
79098 --- a/mm/util.c
79099 +++ b/mm/util.c
79100 @@ -292,6 +292,12 @@ done:
79101 void arch_pick_mmap_layout(struct mm_struct *mm)
79102 {
79103 mm->mmap_base = TASK_UNMAPPED_BASE;
79104 +
79105 +#ifdef CONFIG_PAX_RANDMMAP
79106 + if (mm->pax_flags & MF_PAX_RANDMMAP)
79107 + mm->mmap_base += mm->delta_mmap;
79108 +#endif
79109 +
79110 mm->get_unmapped_area = arch_get_unmapped_area;
79111 mm->unmap_area = arch_unmap_area;
79112 }
79113 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79114 index 5123a16..f234a48 100644
79115 --- a/mm/vmalloc.c
79116 +++ b/mm/vmalloc.c
79117 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79118
79119 pte = pte_offset_kernel(pmd, addr);
79120 do {
79121 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79122 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79123 +
79124 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79125 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79126 + BUG_ON(!pte_exec(*pte));
79127 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79128 + continue;
79129 + }
79130 +#endif
79131 +
79132 + {
79133 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79134 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79135 + }
79136 } while (pte++, addr += PAGE_SIZE, addr != end);
79137 }
79138
79139 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79140 pte = pte_alloc_kernel(pmd, addr);
79141 if (!pte)
79142 return -ENOMEM;
79143 +
79144 + pax_open_kernel();
79145 do {
79146 struct page *page = pages[*nr];
79147
79148 - if (WARN_ON(!pte_none(*pte)))
79149 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79150 + if (pgprot_val(prot) & _PAGE_NX)
79151 +#endif
79152 +
79153 + if (!pte_none(*pte)) {
79154 + pax_close_kernel();
79155 + WARN_ON(1);
79156 return -EBUSY;
79157 - if (WARN_ON(!page))
79158 + }
79159 + if (!page) {
79160 + pax_close_kernel();
79161 + WARN_ON(1);
79162 return -ENOMEM;
79163 + }
79164 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79165 (*nr)++;
79166 } while (pte++, addr += PAGE_SIZE, addr != end);
79167 + pax_close_kernel();
79168 return 0;
79169 }
79170
79171 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79172 pmd_t *pmd;
79173 unsigned long next;
79174
79175 - pmd = pmd_alloc(&init_mm, pud, addr);
79176 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79177 if (!pmd)
79178 return -ENOMEM;
79179 do {
79180 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
79181 pud_t *pud;
79182 unsigned long next;
79183
79184 - pud = pud_alloc(&init_mm, pgd, addr);
79185 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
79186 if (!pud)
79187 return -ENOMEM;
79188 do {
79189 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
79190 * and fall back on vmalloc() if that fails. Others
79191 * just put it in the vmalloc space.
79192 */
79193 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79194 +#ifdef CONFIG_MODULES
79195 +#ifdef MODULES_VADDR
79196 unsigned long addr = (unsigned long)x;
79197 if (addr >= MODULES_VADDR && addr < MODULES_END)
79198 return 1;
79199 #endif
79200 +
79201 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79202 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79203 + return 1;
79204 +#endif
79205 +
79206 +#endif
79207 +
79208 return is_vmalloc_addr(x);
79209 }
79210
79211 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79212
79213 if (!pgd_none(*pgd)) {
79214 pud_t *pud = pud_offset(pgd, addr);
79215 +#ifdef CONFIG_X86
79216 + if (!pud_large(*pud))
79217 +#endif
79218 if (!pud_none(*pud)) {
79219 pmd_t *pmd = pmd_offset(pud, addr);
79220 +#ifdef CONFIG_X86
79221 + if (!pmd_large(*pmd))
79222 +#endif
79223 if (!pmd_none(*pmd)) {
79224 pte_t *ptep, pte;
79225
79226 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
79227 * Allocate a region of KVA of the specified size and alignment, within the
79228 * vstart and vend.
79229 */
79230 -static struct vmap_area *alloc_vmap_area(unsigned long size,
79231 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
79232 unsigned long align,
79233 unsigned long vstart, unsigned long vend,
79234 int node, gfp_t gfp_mask)
79235 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79236 struct vm_struct *area;
79237
79238 BUG_ON(in_interrupt());
79239 +
79240 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79241 + if (flags & VM_KERNEXEC) {
79242 + if (start != VMALLOC_START || end != VMALLOC_END)
79243 + return NULL;
79244 + start = (unsigned long)MODULES_EXEC_VADDR;
79245 + end = (unsigned long)MODULES_EXEC_END;
79246 + }
79247 +#endif
79248 +
79249 if (flags & VM_IOREMAP) {
79250 int bit = fls(size);
79251
79252 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
79253 if (count > totalram_pages)
79254 return NULL;
79255
79256 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79257 + if (!(pgprot_val(prot) & _PAGE_NX))
79258 + flags |= VM_KERNEXEC;
79259 +#endif
79260 +
79261 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79262 __builtin_return_address(0));
79263 if (!area)
79264 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
79265 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79266 goto fail;
79267
79268 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79269 + if (!(pgprot_val(prot) & _PAGE_NX))
79270 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79271 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
79272 + else
79273 +#endif
79274 +
79275 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79276 start, end, node, gfp_mask, caller);
79277 if (!area)
79278 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
79279 * For tight control over page level allocator and protection flags
79280 * use __vmalloc() instead.
79281 */
79282 -
79283 void *vmalloc_exec(unsigned long size)
79284 {
79285 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79286 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79287 -1, __builtin_return_address(0));
79288 }
79289
79290 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79291 unsigned long uaddr = vma->vm_start;
79292 unsigned long usize = vma->vm_end - vma->vm_start;
79293
79294 + BUG_ON(vma->vm_mirror);
79295 +
79296 if ((PAGE_SIZE-1) & (unsigned long)addr)
79297 return -EINVAL;
79298
79299 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
79300 v->addr, v->addr + v->size, v->size);
79301
79302 if (v->caller)
79303 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79304 + seq_printf(m, " %pK", v->caller);
79305 +#else
79306 seq_printf(m, " %pS", v->caller);
79307 +#endif
79308
79309 if (v->nr_pages)
79310 seq_printf(m, " pages=%d", v->nr_pages);
79311 diff --git a/mm/vmstat.c b/mm/vmstat.c
79312 index 9800306..76b4b27 100644
79313 --- a/mm/vmstat.c
79314 +++ b/mm/vmstat.c
79315 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
79316 *
79317 * vm_stat contains the global counters
79318 */
79319 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79320 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79321 EXPORT_SYMBOL(vm_stat);
79322
79323 #ifdef CONFIG_SMP
79324 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
79325 v = p->vm_stat_diff[i];
79326 p->vm_stat_diff[i] = 0;
79327 local_irq_restore(flags);
79328 - atomic_long_add(v, &zone->vm_stat[i]);
79329 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79330 global_diff[i] += v;
79331 #ifdef CONFIG_NUMA
79332 /* 3 seconds idle till flush */
79333 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
79334
79335 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79336 if (global_diff[i])
79337 - atomic_long_add(global_diff[i], &vm_stat[i]);
79338 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79339 }
79340
79341 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79342 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79343 if (pset->vm_stat_diff[i]) {
79344 int v = pset->vm_stat_diff[i];
79345 pset->vm_stat_diff[i] = 0;
79346 - atomic_long_add(v, &zone->vm_stat[i]);
79347 - atomic_long_add(v, &vm_stat[i]);
79348 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79349 + atomic_long_add_unchecked(v, &vm_stat[i]);
79350 }
79351 }
79352 #endif
79353 @@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
79354 return NOTIFY_OK;
79355 }
79356
79357 -static struct notifier_block __cpuinitdata vmstat_notifier =
79358 +static struct notifier_block vmstat_notifier =
79359 { &vmstat_cpuup_callback, NULL, 0 };
79360 #endif
79361
79362 @@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
79363 start_cpu_timer(cpu);
79364 #endif
79365 #ifdef CONFIG_PROC_FS
79366 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79367 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79368 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79369 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79370 + {
79371 + mode_t gr_mode = S_IRUGO;
79372 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
79373 + gr_mode = S_IRUSR;
79374 +#endif
79375 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79376 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79377 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79378 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79379 +#else
79380 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79381 +#endif
79382 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79383 + }
79384 #endif
79385 return 0;
79386 }
79387 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79388 index a292e80..785ee68 100644
79389 --- a/net/8021q/vlan.c
79390 +++ b/net/8021q/vlan.c
79391 @@ -485,7 +485,7 @@ out:
79392 return NOTIFY_DONE;
79393 }
79394
79395 -static struct notifier_block vlan_notifier_block __read_mostly = {
79396 +static struct notifier_block vlan_notifier_block = {
79397 .notifier_call = vlan_device_event,
79398 };
79399
79400 @@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79401 err = -EPERM;
79402 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
79403 break;
79404 - if ((args.u.name_type >= 0) &&
79405 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79406 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79407 struct vlan_net *vn;
79408
79409 vn = net_generic(net, vlan_net_id);
79410 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79411 index 02efb25..41541a9 100644
79412 --- a/net/9p/trans_fd.c
79413 +++ b/net/9p/trans_fd.c
79414 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79415 oldfs = get_fs();
79416 set_fs(get_ds());
79417 /* The cast to a user pointer is valid due to the set_fs() */
79418 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79419 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79420 set_fs(oldfs);
79421
79422 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79423 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79424 index 876fbe8..8bbea9f 100644
79425 --- a/net/atm/atm_misc.c
79426 +++ b/net/atm/atm_misc.c
79427 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
79428 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79429 return 1;
79430 atm_return(vcc, truesize);
79431 - atomic_inc(&vcc->stats->rx_drop);
79432 + atomic_inc_unchecked(&vcc->stats->rx_drop);
79433 return 0;
79434 }
79435 EXPORT_SYMBOL(atm_charge);
79436 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
79437 }
79438 }
79439 atm_return(vcc, guess);
79440 - atomic_inc(&vcc->stats->rx_drop);
79441 + atomic_inc_unchecked(&vcc->stats->rx_drop);
79442 return NULL;
79443 }
79444 EXPORT_SYMBOL(atm_alloc_charge);
79445 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
79446
79447 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79448 {
79449 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79450 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79451 __SONET_ITEMS
79452 #undef __HANDLE_ITEM
79453 }
79454 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
79455
79456 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79457 {
79458 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79459 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79460 __SONET_ITEMS
79461 #undef __HANDLE_ITEM
79462 }
79463 diff --git a/net/atm/lec.h b/net/atm/lec.h
79464 index a86aff9..3a0d6f6 100644
79465 --- a/net/atm/lec.h
79466 +++ b/net/atm/lec.h
79467 @@ -48,7 +48,7 @@ struct lane2_ops {
79468 const u8 *tlvs, u32 sizeoftlvs);
79469 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79470 const u8 *tlvs, u32 sizeoftlvs);
79471 -};
79472 +} __no_const;
79473
79474 /*
79475 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79476 diff --git a/net/atm/proc.c b/net/atm/proc.c
79477 index 0d020de..011c7bb 100644
79478 --- a/net/atm/proc.c
79479 +++ b/net/atm/proc.c
79480 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79481 const struct k_atm_aal_stats *stats)
79482 {
79483 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79484 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
79485 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
79486 - atomic_read(&stats->rx_drop));
79487 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79488 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79489 + atomic_read_unchecked(&stats->rx_drop));
79490 }
79491
79492 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79493 diff --git a/net/atm/resources.c b/net/atm/resources.c
79494 index 0447d5d..3cf4728 100644
79495 --- a/net/atm/resources.c
79496 +++ b/net/atm/resources.c
79497 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
79498 static void copy_aal_stats(struct k_atm_aal_stats *from,
79499 struct atm_aal_stats *to)
79500 {
79501 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79502 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79503 __AAL_STAT_ITEMS
79504 #undef __HANDLE_ITEM
79505 }
79506 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79507 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79508 struct atm_aal_stats *to)
79509 {
79510 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79511 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79512 __AAL_STAT_ITEMS
79513 #undef __HANDLE_ITEM
79514 }
79515 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
79516 index 7d02ebd..4d4cc01 100644
79517 --- a/net/batman-adv/bat_iv_ogm.c
79518 +++ b/net/batman-adv/bat_iv_ogm.c
79519 @@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
79520
79521 /* randomize initial seqno to avoid collision */
79522 get_random_bytes(&random_seqno, sizeof(random_seqno));
79523 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79524 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79525
79526 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
79527 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
79528 @@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
79529 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
79530
79531 /* change sequence number to network order */
79532 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
79533 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
79534 batadv_ogm_packet->seqno = htonl(seqno);
79535 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
79536 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
79537
79538 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
79539 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
79540 @@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
79541 return;
79542
79543 /* could be changed by schedule_own_packet() */
79544 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
79545 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
79546
79547 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
79548 has_directlink_flag = 1;
79549 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
79550 index f1d37cd..4190879 100644
79551 --- a/net/batman-adv/hard-interface.c
79552 +++ b/net/batman-adv/hard-interface.c
79553 @@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
79554 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
79555 dev_add_pack(&hard_iface->batman_adv_ptype);
79556
79557 - atomic_set(&hard_iface->frag_seqno, 1);
79558 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
79559 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
79560 hard_iface->net_dev->name);
79561
79562 @@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
79563 /* This can't be called via a bat_priv callback because
79564 * we have no bat_priv yet.
79565 */
79566 - atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
79567 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
79568 hard_iface->bat_iv.ogm_buff = NULL;
79569
79570 return hard_iface;
79571 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
79572 index 6b548fd..fc32c8d 100644
79573 --- a/net/batman-adv/soft-interface.c
79574 +++ b/net/batman-adv/soft-interface.c
79575 @@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
79576 primary_if->net_dev->dev_addr, ETH_ALEN);
79577
79578 /* set broadcast sequence number */
79579 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
79580 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
79581 bcast_packet->seqno = htonl(seqno);
79582
79583 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
79584 @@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
79585 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
79586
79587 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
79588 - atomic_set(&bat_priv->bcast_seqno, 1);
79589 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
79590 atomic_set(&bat_priv->tt.vn, 0);
79591 atomic_set(&bat_priv->tt.local_changes, 0);
79592 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
79593 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
79594 index ae9ac9a..11e0fe7 100644
79595 --- a/net/batman-adv/types.h
79596 +++ b/net/batman-adv/types.h
79597 @@ -48,7 +48,7 @@
79598 struct batadv_hard_iface_bat_iv {
79599 unsigned char *ogm_buff;
79600 int ogm_buff_len;
79601 - atomic_t ogm_seqno;
79602 + atomic_unchecked_t ogm_seqno;
79603 };
79604
79605 struct batadv_hard_iface {
79606 @@ -56,7 +56,7 @@ struct batadv_hard_iface {
79607 int16_t if_num;
79608 char if_status;
79609 struct net_device *net_dev;
79610 - atomic_t frag_seqno;
79611 + atomic_unchecked_t frag_seqno;
79612 struct kobject *hardif_obj;
79613 atomic_t refcount;
79614 struct packet_type batman_adv_ptype;
79615 @@ -284,7 +284,7 @@ struct batadv_priv {
79616 atomic_t orig_interval; /* uint */
79617 atomic_t hop_penalty; /* uint */
79618 atomic_t log_level; /* uint */
79619 - atomic_t bcast_seqno;
79620 + atomic_unchecked_t bcast_seqno;
79621 atomic_t bcast_queue_left;
79622 atomic_t batman_queue_left;
79623 char num_ifaces;
79624 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
79625 index 10aff49..ea8e021 100644
79626 --- a/net/batman-adv/unicast.c
79627 +++ b/net/batman-adv/unicast.c
79628 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
79629 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
79630 frag2->flags = large_tail;
79631
79632 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
79633 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
79634 frag1->seqno = htons(seqno - 1);
79635 frag2->seqno = htons(seqno);
79636
79637 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
79638 index 07f0739..3c42e34 100644
79639 --- a/net/bluetooth/hci_sock.c
79640 +++ b/net/bluetooth/hci_sock.c
79641 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
79642 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
79643 }
79644
79645 - len = min_t(unsigned int, len, sizeof(uf));
79646 + len = min((size_t)len, sizeof(uf));
79647 if (copy_from_user(&uf, optval, len)) {
79648 err = -EFAULT;
79649 break;
79650 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
79651 index 22e6583..426e2f3 100644
79652 --- a/net/bluetooth/l2cap_core.c
79653 +++ b/net/bluetooth/l2cap_core.c
79654 @@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
79655 break;
79656
79657 case L2CAP_CONF_RFC:
79658 - if (olen == sizeof(rfc))
79659 - memcpy(&rfc, (void *)val, olen);
79660 + if (olen != sizeof(rfc))
79661 + break;
79662 +
79663 + memcpy(&rfc, (void *)val, olen);
79664
79665 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
79666 rfc.mode != chan->mode)
79667 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
79668 index 1bcfb84..dad9f98 100644
79669 --- a/net/bluetooth/l2cap_sock.c
79670 +++ b/net/bluetooth/l2cap_sock.c
79671 @@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
79672 struct sock *sk = sock->sk;
79673 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
79674 struct l2cap_options opts;
79675 - int len, err = 0;
79676 + int err = 0;
79677 + size_t len = optlen;
79678 u32 opt;
79679
79680 BT_DBG("sk %p", sk);
79681 @@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
79682 opts.max_tx = chan->max_tx;
79683 opts.txwin_size = chan->tx_win;
79684
79685 - len = min_t(unsigned int, sizeof(opts), optlen);
79686 + len = min(sizeof(opts), len);
79687 if (copy_from_user((char *) &opts, optval, len)) {
79688 err = -EFAULT;
79689 break;
79690 @@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79691 struct bt_security sec;
79692 struct bt_power pwr;
79693 struct l2cap_conn *conn;
79694 - int len, err = 0;
79695 + int err = 0;
79696 + size_t len = optlen;
79697 u32 opt;
79698
79699 BT_DBG("sk %p", sk);
79700 @@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79701
79702 sec.level = BT_SECURITY_LOW;
79703
79704 - len = min_t(unsigned int, sizeof(sec), optlen);
79705 + len = min(sizeof(sec), len);
79706 if (copy_from_user((char *) &sec, optval, len)) {
79707 err = -EFAULT;
79708 break;
79709 @@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
79710
79711 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
79712
79713 - len = min_t(unsigned int, sizeof(pwr), optlen);
79714 + len = min(sizeof(pwr), len);
79715 if (copy_from_user((char *) &pwr, optval, len)) {
79716 err = -EFAULT;
79717 break;
79718 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
79719 index ce3f665..2c7d08f 100644
79720 --- a/net/bluetooth/rfcomm/sock.c
79721 +++ b/net/bluetooth/rfcomm/sock.c
79722 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
79723 struct sock *sk = sock->sk;
79724 struct bt_security sec;
79725 int err = 0;
79726 - size_t len;
79727 + size_t len = optlen;
79728 u32 opt;
79729
79730 BT_DBG("sk %p", sk);
79731 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
79732
79733 sec.level = BT_SECURITY_LOW;
79734
79735 - len = min_t(unsigned int, sizeof(sec), optlen);
79736 + len = min(sizeof(sec), len);
79737 if (copy_from_user((char *) &sec, optval, len)) {
79738 err = -EFAULT;
79739 break;
79740 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
79741 index bd6fd0f..6492cba 100644
79742 --- a/net/bluetooth/rfcomm/tty.c
79743 +++ b/net/bluetooth/rfcomm/tty.c
79744 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
79745 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
79746
79747 spin_lock_irqsave(&dev->port.lock, flags);
79748 - if (dev->port.count > 0) {
79749 + if (atomic_read(&dev->port.count) > 0) {
79750 spin_unlock_irqrestore(&dev->port.lock, flags);
79751 return;
79752 }
79753 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
79754 return -ENODEV;
79755
79756 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
79757 - dev->channel, dev->port.count);
79758 + dev->channel, atomic_read(&dev->port.count));
79759
79760 spin_lock_irqsave(&dev->port.lock, flags);
79761 - if (++dev->port.count > 1) {
79762 + if (atomic_inc_return(&dev->port.count) > 1) {
79763 spin_unlock_irqrestore(&dev->port.lock, flags);
79764 return 0;
79765 }
79766 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
79767 return;
79768
79769 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
79770 - dev->port.count);
79771 + atomic_read(&dev->port.count));
79772
79773 spin_lock_irqsave(&dev->port.lock, flags);
79774 - if (!--dev->port.count) {
79775 + if (!atomic_dec_return(&dev->port.count)) {
79776 spin_unlock_irqrestore(&dev->port.lock, flags);
79777 if (dev->tty_dev->parent)
79778 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
79779 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
79780 index 5fe2ff3..121d696 100644
79781 --- a/net/bridge/netfilter/ebtables.c
79782 +++ b/net/bridge/netfilter/ebtables.c
79783 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79784 tmp.valid_hooks = t->table->valid_hooks;
79785 }
79786 mutex_unlock(&ebt_mutex);
79787 - if (copy_to_user(user, &tmp, *len) != 0){
79788 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
79789 BUGPRINT("c2u Didn't work\n");
79790 ret = -EFAULT;
79791 break;
79792 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79793 goto out;
79794 tmp.valid_hooks = t->valid_hooks;
79795
79796 - if (copy_to_user(user, &tmp, *len) != 0) {
79797 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79798 ret = -EFAULT;
79799 break;
79800 }
79801 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
79802 tmp.entries_size = t->table->entries_size;
79803 tmp.valid_hooks = t->table->valid_hooks;
79804
79805 - if (copy_to_user(user, &tmp, *len) != 0) {
79806 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
79807 ret = -EFAULT;
79808 break;
79809 }
79810 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
79811 index a376ec1..1fbd6be 100644
79812 --- a/net/caif/cfctrl.c
79813 +++ b/net/caif/cfctrl.c
79814 @@ -10,6 +10,7 @@
79815 #include <linux/spinlock.h>
79816 #include <linux/slab.h>
79817 #include <linux/pkt_sched.h>
79818 +#include <linux/sched.h>
79819 #include <net/caif/caif_layer.h>
79820 #include <net/caif/cfpkt.h>
79821 #include <net/caif/cfctrl.h>
79822 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
79823 memset(&dev_info, 0, sizeof(dev_info));
79824 dev_info.id = 0xff;
79825 cfsrvl_init(&this->serv, 0, &dev_info, false);
79826 - atomic_set(&this->req_seq_no, 1);
79827 - atomic_set(&this->rsp_seq_no, 1);
79828 + atomic_set_unchecked(&this->req_seq_no, 1);
79829 + atomic_set_unchecked(&this->rsp_seq_no, 1);
79830 this->serv.layer.receive = cfctrl_recv;
79831 sprintf(this->serv.layer.name, "ctrl");
79832 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
79833 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
79834 struct cfctrl_request_info *req)
79835 {
79836 spin_lock_bh(&ctrl->info_list_lock);
79837 - atomic_inc(&ctrl->req_seq_no);
79838 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
79839 + atomic_inc_unchecked(&ctrl->req_seq_no);
79840 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
79841 list_add_tail(&req->list, &ctrl->list);
79842 spin_unlock_bh(&ctrl->info_list_lock);
79843 }
79844 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
79845 if (p != first)
79846 pr_warn("Requests are not received in order\n");
79847
79848 - atomic_set(&ctrl->rsp_seq_no,
79849 + atomic_set_unchecked(&ctrl->rsp_seq_no,
79850 p->sequence_no);
79851 list_del(&p->list);
79852 goto out;
79853 diff --git a/net/can/af_can.c b/net/can/af_can.c
79854 index ddac1ee..3ee0a78 100644
79855 --- a/net/can/af_can.c
79856 +++ b/net/can/af_can.c
79857 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
79858 };
79859
79860 /* notifier block for netdevice event */
79861 -static struct notifier_block can_netdev_notifier __read_mostly = {
79862 +static struct notifier_block can_netdev_notifier = {
79863 .notifier_call = can_notifier,
79864 };
79865
79866 diff --git a/net/can/gw.c b/net/can/gw.c
79867 index 574dda78e..3d2b3da 100644
79868 --- a/net/can/gw.c
79869 +++ b/net/can/gw.c
79870 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
79871 MODULE_ALIAS("can-gw");
79872
79873 static HLIST_HEAD(cgw_list);
79874 -static struct notifier_block notifier;
79875
79876 static struct kmem_cache *cgw_cache __read_mostly;
79877
79878 @@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
79879 return err;
79880 }
79881
79882 +static struct notifier_block notifier = {
79883 + .notifier_call = cgw_notifier
79884 +};
79885 +
79886 static __init int cgw_module_init(void)
79887 {
79888 printk(banner);
79889 @@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
79890 return -ENOMEM;
79891
79892 /* set notifier */
79893 - notifier.notifier_call = cgw_notifier;
79894 register_netdevice_notifier(&notifier);
79895
79896 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
79897 diff --git a/net/compat.c b/net/compat.c
79898 index 79ae884..17c5c09 100644
79899 --- a/net/compat.c
79900 +++ b/net/compat.c
79901 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79902 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79903 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79904 return -EFAULT;
79905 - kmsg->msg_name = compat_ptr(tmp1);
79906 - kmsg->msg_iov = compat_ptr(tmp2);
79907 - kmsg->msg_control = compat_ptr(tmp3);
79908 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79909 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79910 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79911 return 0;
79912 }
79913
79914 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79915
79916 if (kern_msg->msg_namelen) {
79917 if (mode == VERIFY_READ) {
79918 - int err = move_addr_to_kernel(kern_msg->msg_name,
79919 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
79920 kern_msg->msg_namelen,
79921 kern_address);
79922 if (err < 0)
79923 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79924 kern_msg->msg_name = NULL;
79925
79926 tot_len = iov_from_user_compat_to_kern(kern_iov,
79927 - (struct compat_iovec __user *)kern_msg->msg_iov,
79928 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
79929 kern_msg->msg_iovlen);
79930 if (tot_len >= 0)
79931 kern_msg->msg_iov = kern_iov;
79932 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79933
79934 #define CMSG_COMPAT_FIRSTHDR(msg) \
79935 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79936 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79937 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79938 (struct compat_cmsghdr __user *)NULL)
79939
79940 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79941 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79942 (ucmlen) <= (unsigned long) \
79943 ((mhdr)->msg_controllen - \
79944 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79945 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79946
79947 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79948 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79949 {
79950 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79951 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79952 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79953 msg->msg_controllen)
79954 return NULL;
79955 return (struct compat_cmsghdr __user *)ptr;
79956 @@ -219,7 +219,7 @@ Efault:
79957
79958 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
79959 {
79960 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79961 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79962 struct compat_cmsghdr cmhdr;
79963 struct compat_timeval ctv;
79964 struct compat_timespec cts[3];
79965 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79966
79967 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79968 {
79969 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79970 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79971 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79972 int fdnum = scm->fp->count;
79973 struct file **fp = scm->fp->fp;
79974 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
79975 return -EFAULT;
79976 old_fs = get_fs();
79977 set_fs(KERNEL_DS);
79978 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
79979 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
79980 set_fs(old_fs);
79981
79982 return err;
79983 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79984 len = sizeof(ktime);
79985 old_fs = get_fs();
79986 set_fs(KERNEL_DS);
79987 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79988 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79989 set_fs(old_fs);
79990
79991 if (!err) {
79992 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79993 case MCAST_JOIN_GROUP:
79994 case MCAST_LEAVE_GROUP:
79995 {
79996 - struct compat_group_req __user *gr32 = (void *)optval;
79997 + struct compat_group_req __user *gr32 = (void __user *)optval;
79998 struct group_req __user *kgr =
79999 compat_alloc_user_space(sizeof(struct group_req));
80000 u32 interface;
80001 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80002 case MCAST_BLOCK_SOURCE:
80003 case MCAST_UNBLOCK_SOURCE:
80004 {
80005 - struct compat_group_source_req __user *gsr32 = (void *)optval;
80006 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80007 struct group_source_req __user *kgsr = compat_alloc_user_space(
80008 sizeof(struct group_source_req));
80009 u32 interface;
80010 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80011 }
80012 case MCAST_MSFILTER:
80013 {
80014 - struct compat_group_filter __user *gf32 = (void *)optval;
80015 + struct compat_group_filter __user *gf32 = (void __user *)optval;
80016 struct group_filter __user *kgf;
80017 u32 interface, fmode, numsrc;
80018
80019 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
80020 char __user *optval, int __user *optlen,
80021 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
80022 {
80023 - struct compat_group_filter __user *gf32 = (void *)optval;
80024 + struct compat_group_filter __user *gf32 = (void __user *)optval;
80025 struct group_filter __user *kgf;
80026 int __user *koptlen;
80027 u32 interface, fmode, numsrc;
80028 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
80029
80030 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
80031 return -EINVAL;
80032 - if (copy_from_user(a, args, nas[call]))
80033 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
80034 return -EFAULT;
80035 a0 = a[0];
80036 a1 = a[1];
80037 diff --git a/net/core/datagram.c b/net/core/datagram.c
80038 index 368f9c3..f82d4a3 100644
80039 --- a/net/core/datagram.c
80040 +++ b/net/core/datagram.c
80041 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
80042 }
80043
80044 kfree_skb(skb);
80045 - atomic_inc(&sk->sk_drops);
80046 + atomic_inc_unchecked(&sk->sk_drops);
80047 sk_mem_reclaim_partial(sk);
80048
80049 return err;
80050 diff --git a/net/core/dev.c b/net/core/dev.c
80051 index f64e439..8f959e6 100644
80052 --- a/net/core/dev.c
80053 +++ b/net/core/dev.c
80054 @@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
80055 if (no_module && capable(CAP_NET_ADMIN))
80056 no_module = request_module("netdev-%s", name);
80057 if (no_module && capable(CAP_SYS_MODULE)) {
80058 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
80059 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
80060 +#else
80061 if (!request_module("%s", name))
80062 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
80063 name);
80064 +#endif
80065 }
80066 }
80067 EXPORT_SYMBOL(dev_load);
80068 @@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80069 {
80070 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
80071 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
80072 - atomic_long_inc(&dev->rx_dropped);
80073 + atomic_long_inc_unchecked(&dev->rx_dropped);
80074 kfree_skb(skb);
80075 return NET_RX_DROP;
80076 }
80077 @@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80078 nf_reset(skb);
80079
80080 if (unlikely(!is_skb_forwardable(dev, skb))) {
80081 - atomic_long_inc(&dev->rx_dropped);
80082 + atomic_long_inc_unchecked(&dev->rx_dropped);
80083 kfree_skb(skb);
80084 return NET_RX_DROP;
80085 }
80086 @@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80087
80088 struct dev_gso_cb {
80089 void (*destructor)(struct sk_buff *skb);
80090 -};
80091 +} __no_const;
80092
80093 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80094
80095 @@ -3053,7 +3057,7 @@ enqueue:
80096
80097 local_irq_restore(flags);
80098
80099 - atomic_long_inc(&skb->dev->rx_dropped);
80100 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80101 kfree_skb(skb);
80102 return NET_RX_DROP;
80103 }
80104 @@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
80105 }
80106 EXPORT_SYMBOL(netif_rx_ni);
80107
80108 -static void net_tx_action(struct softirq_action *h)
80109 +static void net_tx_action(void)
80110 {
80111 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80112
80113 @@ -3456,7 +3460,7 @@ ncls:
80114 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
80115 } else {
80116 drop:
80117 - atomic_long_inc(&skb->dev->rx_dropped);
80118 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80119 kfree_skb(skb);
80120 /* Jamal, now you will not able to escape explaining
80121 * me how you were going to use this. :-)
80122 @@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
80123 }
80124 EXPORT_SYMBOL(netif_napi_del);
80125
80126 -static void net_rx_action(struct softirq_action *h)
80127 +static void net_rx_action(void)
80128 {
80129 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80130 unsigned long time_limit = jiffies + 2;
80131 @@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
80132 else
80133 seq_printf(seq, "%04x", ntohs(pt->type));
80134
80135 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80136 + seq_printf(seq, " %-8s %p\n",
80137 + pt->dev ? pt->dev->name : "", NULL);
80138 +#else
80139 seq_printf(seq, " %-8s %pF\n",
80140 pt->dev ? pt->dev->name : "", pt->func);
80141 +#endif
80142 }
80143
80144 return 0;
80145 @@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
80146 } else {
80147 netdev_stats_to_stats64(storage, &dev->stats);
80148 }
80149 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
80150 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
80151 return storage;
80152 }
80153 EXPORT_SYMBOL(dev_get_stats);
80154 diff --git a/net/core/flow.c b/net/core/flow.c
80155 index b0901ee..7d3c2ca 100644
80156 --- a/net/core/flow.c
80157 +++ b/net/core/flow.c
80158 @@ -61,7 +61,7 @@ struct flow_cache {
80159 struct timer_list rnd_timer;
80160 };
80161
80162 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
80163 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80164 EXPORT_SYMBOL(flow_cache_genid);
80165 static struct flow_cache flow_cache_global;
80166 static struct kmem_cache *flow_cachep __read_mostly;
80167 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
80168
80169 static int flow_entry_valid(struct flow_cache_entry *fle)
80170 {
80171 - if (atomic_read(&flow_cache_genid) != fle->genid)
80172 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
80173 return 0;
80174 if (fle->object && !fle->object->ops->check(fle->object))
80175 return 0;
80176 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
80177 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
80178 fcp->hash_count++;
80179 }
80180 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
80181 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
80182 flo = fle->object;
80183 if (!flo)
80184 goto ret_object;
80185 @@ -280,7 +280,7 @@ nocache:
80186 }
80187 flo = resolver(net, key, family, dir, flo, ctx);
80188 if (fle) {
80189 - fle->genid = atomic_read(&flow_cache_genid);
80190 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
80191 if (!IS_ERR(flo))
80192 fle->object = flo;
80193 else
80194 diff --git a/net/core/iovec.c b/net/core/iovec.c
80195 index 7e7aeb0..2a998cb 100644
80196 --- a/net/core/iovec.c
80197 +++ b/net/core/iovec.c
80198 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80199 if (m->msg_namelen) {
80200 if (mode == VERIFY_READ) {
80201 void __user *namep;
80202 - namep = (void __user __force *) m->msg_name;
80203 + namep = (void __force_user *) m->msg_name;
80204 err = move_addr_to_kernel(namep, m->msg_namelen,
80205 address);
80206 if (err < 0)
80207 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80208 }
80209
80210 size = m->msg_iovlen * sizeof(struct iovec);
80211 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
80212 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
80213 return -EFAULT;
80214
80215 m->msg_iov = iov;
80216 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80217 index 1868625..5f4de62 100644
80218 --- a/net/core/rtnetlink.c
80219 +++ b/net/core/rtnetlink.c
80220 @@ -58,7 +58,7 @@ struct rtnl_link {
80221 rtnl_doit_func doit;
80222 rtnl_dumpit_func dumpit;
80223 rtnl_calcit_func calcit;
80224 -};
80225 +} __no_const;
80226
80227 static DEFINE_MUTEX(rtnl_mutex);
80228
80229 diff --git a/net/core/scm.c b/net/core/scm.c
80230 index 905dcc6..14ee2d6 100644
80231 --- a/net/core/scm.c
80232 +++ b/net/core/scm.c
80233 @@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
80234 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80235 {
80236 struct cmsghdr __user *cm
80237 - = (__force struct cmsghdr __user *)msg->msg_control;
80238 + = (struct cmsghdr __force_user *)msg->msg_control;
80239 struct cmsghdr cmhdr;
80240 int cmlen = CMSG_LEN(len);
80241 int err;
80242 @@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80243 err = -EFAULT;
80244 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80245 goto out;
80246 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80247 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80248 goto out;
80249 cmlen = CMSG_SPACE(len);
80250 if (msg->msg_controllen < cmlen)
80251 @@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
80252 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80253 {
80254 struct cmsghdr __user *cm
80255 - = (__force struct cmsghdr __user*)msg->msg_control;
80256 + = (struct cmsghdr __force_user *)msg->msg_control;
80257
80258 int fdmax = 0;
80259 int fdnum = scm->fp->count;
80260 @@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80261 if (fdnum < fdmax)
80262 fdmax = fdnum;
80263
80264 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80265 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80266 i++, cmfptr++)
80267 {
80268 struct socket *sock;
80269 diff --git a/net/core/sock.c b/net/core/sock.c
80270 index bc131d4..029e378 100644
80271 --- a/net/core/sock.c
80272 +++ b/net/core/sock.c
80273 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80274 struct sk_buff_head *list = &sk->sk_receive_queue;
80275
80276 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
80277 - atomic_inc(&sk->sk_drops);
80278 + atomic_inc_unchecked(&sk->sk_drops);
80279 trace_sock_rcvqueue_full(sk, skb);
80280 return -ENOMEM;
80281 }
80282 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80283 return err;
80284
80285 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
80286 - atomic_inc(&sk->sk_drops);
80287 + atomic_inc_unchecked(&sk->sk_drops);
80288 return -ENOBUFS;
80289 }
80290
80291 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80292 skb_dst_force(skb);
80293
80294 spin_lock_irqsave(&list->lock, flags);
80295 - skb->dropcount = atomic_read(&sk->sk_drops);
80296 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80297 __skb_queue_tail(list, skb);
80298 spin_unlock_irqrestore(&list->lock, flags);
80299
80300 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80301 skb->dev = NULL;
80302
80303 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
80304 - atomic_inc(&sk->sk_drops);
80305 + atomic_inc_unchecked(&sk->sk_drops);
80306 goto discard_and_relse;
80307 }
80308 if (nested)
80309 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80310 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
80311 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
80312 bh_unlock_sock(sk);
80313 - atomic_inc(&sk->sk_drops);
80314 + atomic_inc_unchecked(&sk->sk_drops);
80315 goto discard_and_relse;
80316 }
80317
80318 @@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80319 struct timeval tm;
80320 } v;
80321
80322 - int lv = sizeof(int);
80323 - int len;
80324 + unsigned int lv = sizeof(int);
80325 + unsigned int len;
80326
80327 if (get_user(len, optlen))
80328 return -EFAULT;
80329 - if (len < 0)
80330 + if (len > INT_MAX)
80331 return -EINVAL;
80332
80333 memset(&v, 0, sizeof(v));
80334 @@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80335
80336 case SO_PEERNAME:
80337 {
80338 - char address[128];
80339 + char address[_K_SS_MAXSIZE];
80340
80341 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
80342 return -ENOTCONN;
80343 - if (lv < len)
80344 + if (lv < len || sizeof address < len)
80345 return -EINVAL;
80346 if (copy_to_user(optval, address, len))
80347 return -EFAULT;
80348 @@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80349
80350 if (len > lv)
80351 len = lv;
80352 - if (copy_to_user(optval, &v, len))
80353 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
80354 return -EFAULT;
80355 lenout:
80356 if (put_user(len, optlen))
80357 @@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80358 */
80359 smp_wmb();
80360 atomic_set(&sk->sk_refcnt, 1);
80361 - atomic_set(&sk->sk_drops, 0);
80362 + atomic_set_unchecked(&sk->sk_drops, 0);
80363 }
80364 EXPORT_SYMBOL(sock_init_data);
80365
80366 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
80367 index 602cd63..0a699b1 100644
80368 --- a/net/core/sock_diag.c
80369 +++ b/net/core/sock_diag.c
80370 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
80371
80372 int sock_diag_check_cookie(void *sk, __u32 *cookie)
80373 {
80374 +#ifndef CONFIG_GRKERNSEC_HIDESYM
80375 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
80376 cookie[1] != INET_DIAG_NOCOOKIE) &&
80377 ((u32)(unsigned long)sk != cookie[0] ||
80378 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
80379 return -ESTALE;
80380 else
80381 +#endif
80382 return 0;
80383 }
80384 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
80385
80386 void sock_diag_save_cookie(void *sk, __u32 *cookie)
80387 {
80388 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80389 + cookie[0] = 0;
80390 + cookie[1] = 0;
80391 +#else
80392 cookie[0] = (u32)(unsigned long)sk;
80393 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80394 +#endif
80395 }
80396 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
80397
80398 @@ -97,21 +104,6 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
80399 }
80400 EXPORT_SYMBOL_GPL(sock_diag_unregister);
80401
80402 -static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
80403 -{
80404 - if (sock_diag_handlers[family] == NULL)
80405 - request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80406 - NETLINK_SOCK_DIAG, family);
80407 -
80408 - mutex_lock(&sock_diag_table_mutex);
80409 - return sock_diag_handlers[family];
80410 -}
80411 -
80412 -static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
80413 -{
80414 - mutex_unlock(&sock_diag_table_mutex);
80415 -}
80416 -
80417 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80418 {
80419 int err;
80420 @@ -121,12 +113,20 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80421 if (nlmsg_len(nlh) < sizeof(*req))
80422 return -EINVAL;
80423
80424 - hndl = sock_diag_lock_handler(req->sdiag_family);
80425 + if (req->sdiag_family >= AF_MAX)
80426 + return -EINVAL;
80427 +
80428 + if (sock_diag_handlers[req->sdiag_family] == NULL)
80429 + request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80430 + NETLINK_SOCK_DIAG, req->sdiag_family);
80431 +
80432 + mutex_lock(&sock_diag_table_mutex);
80433 + hndl = sock_diag_handlers[req->sdiag_family];
80434 if (hndl == NULL)
80435 err = -ENOENT;
80436 else
80437 err = hndl->dump(skb, nlh);
80438 - sock_diag_unlock_handler(hndl);
80439 + mutex_unlock(&sock_diag_table_mutex);
80440
80441 return err;
80442 }
80443 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80444 index a55eecc..dd8428c 100644
80445 --- a/net/decnet/sysctl_net_decnet.c
80446 +++ b/net/decnet/sysctl_net_decnet.c
80447 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80448
80449 if (len > *lenp) len = *lenp;
80450
80451 - if (copy_to_user(buffer, addr, len))
80452 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
80453 return -EFAULT;
80454
80455 *lenp = len;
80456 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80457
80458 if (len > *lenp) len = *lenp;
80459
80460 - if (copy_to_user(buffer, devname, len))
80461 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
80462 return -EFAULT;
80463
80464 *lenp = len;
80465 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
80466 index a69b4e4..dbccba5 100644
80467 --- a/net/ipv4/ah4.c
80468 +++ b/net/ipv4/ah4.c
80469 @@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
80470 return;
80471
80472 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80473 - atomic_inc(&flow_cache_genid);
80474 + atomic_inc_unchecked(&flow_cache_genid);
80475 rt_genid_bump(net);
80476
80477 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
80478 diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
80479 index 3b4f0cd..8cb864c 100644
80480 --- a/net/ipv4/esp4.c
80481 +++ b/net/ipv4/esp4.c
80482 @@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
80483 return;
80484
80485 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80486 - atomic_inc(&flow_cache_genid);
80487 + atomic_inc_unchecked(&flow_cache_genid);
80488 rt_genid_bump(net);
80489
80490 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
80491 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
80492 index 5cd75e2..f57ef39 100644
80493 --- a/net/ipv4/fib_frontend.c
80494 +++ b/net/ipv4/fib_frontend.c
80495 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
80496 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80497 fib_sync_up(dev);
80498 #endif
80499 - atomic_inc(&net->ipv4.dev_addr_genid);
80500 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80501 rt_cache_flush(dev_net(dev));
80502 break;
80503 case NETDEV_DOWN:
80504 fib_del_ifaddr(ifa, NULL);
80505 - atomic_inc(&net->ipv4.dev_addr_genid);
80506 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80507 if (ifa->ifa_dev->ifa_list == NULL) {
80508 /* Last address was deleted from this interface.
80509 * Disable IP.
80510 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
80511 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80512 fib_sync_up(dev);
80513 #endif
80514 - atomic_inc(&net->ipv4.dev_addr_genid);
80515 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80516 rt_cache_flush(net);
80517 break;
80518 case NETDEV_DOWN:
80519 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
80520 index 4797a80..2bd54e9 100644
80521 --- a/net/ipv4/fib_semantics.c
80522 +++ b/net/ipv4/fib_semantics.c
80523 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
80524 nh->nh_saddr = inet_select_addr(nh->nh_dev,
80525 nh->nh_gw,
80526 nh->nh_parent->fib_scope);
80527 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
80528 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
80529
80530 return nh->nh_saddr;
80531 }
80532 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80533 index fa3ae81..0dbe6b8 100644
80534 --- a/net/ipv4/inet_hashtables.c
80535 +++ b/net/ipv4/inet_hashtables.c
80536 @@ -18,12 +18,15 @@
80537 #include <linux/sched.h>
80538 #include <linux/slab.h>
80539 #include <linux/wait.h>
80540 +#include <linux/security.h>
80541
80542 #include <net/inet_connection_sock.h>
80543 #include <net/inet_hashtables.h>
80544 #include <net/secure_seq.h>
80545 #include <net/ip.h>
80546
80547 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80548 +
80549 /*
80550 * Allocate and initialize a new local port bind bucket.
80551 * The bindhash mutex for snum's hash chain must be held here.
80552 @@ -540,6 +543,8 @@ ok:
80553 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
80554 spin_unlock(&head->lock);
80555
80556 + gr_update_task_in_ip_table(current, inet_sk(sk));
80557 +
80558 if (tw) {
80559 inet_twsk_deschedule(tw, death_row);
80560 while (twrefcnt) {
80561 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80562 index 000e3d2..5472da3 100644
80563 --- a/net/ipv4/inetpeer.c
80564 +++ b/net/ipv4/inetpeer.c
80565 @@ -503,8 +503,8 @@ relookup:
80566 if (p) {
80567 p->daddr = *daddr;
80568 atomic_set(&p->refcnt, 1);
80569 - atomic_set(&p->rid, 0);
80570 - atomic_set(&p->ip_id_count,
80571 + atomic_set_unchecked(&p->rid, 0);
80572 + atomic_set_unchecked(&p->ip_id_count,
80573 (daddr->family == AF_INET) ?
80574 secure_ip_id(daddr->addr.a4) :
80575 secure_ipv6_id(daddr->addr.a6));
80576 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
80577 index eb9d63a..50babc1 100644
80578 --- a/net/ipv4/ip_fragment.c
80579 +++ b/net/ipv4/ip_fragment.c
80580 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
80581 return 0;
80582
80583 start = qp->rid;
80584 - end = atomic_inc_return(&peer->rid);
80585 + end = atomic_inc_return_unchecked(&peer->rid);
80586 qp->rid = end;
80587
80588 rc = qp->q.fragments && (end - start) > max;
80589 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
80590 index d9c4f11..02b82db 100644
80591 --- a/net/ipv4/ip_sockglue.c
80592 +++ b/net/ipv4/ip_sockglue.c
80593 @@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80594 len = min_t(unsigned int, len, opt->optlen);
80595 if (put_user(len, optlen))
80596 return -EFAULT;
80597 - if (copy_to_user(optval, opt->__data, len))
80598 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
80599 + copy_to_user(optval, opt->__data, len))
80600 return -EFAULT;
80601 return 0;
80602 }
80603 @@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
80604 if (sk->sk_type != SOCK_STREAM)
80605 return -ENOPROTOOPT;
80606
80607 - msg.msg_control = optval;
80608 + msg.msg_control = (void __force_kernel *)optval;
80609 msg.msg_controllen = len;
80610 msg.msg_flags = flags;
80611
80612 diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
80613 index 9a46dae..5f793a0 100644
80614 --- a/net/ipv4/ipcomp.c
80615 +++ b/net/ipv4/ipcomp.c
80616 @@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
80617 return;
80618
80619 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80620 - atomic_inc(&flow_cache_genid);
80621 + atomic_inc_unchecked(&flow_cache_genid);
80622 rt_genid_bump(net);
80623
80624 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
80625 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
80626 index a2e50ae..e152b7c 100644
80627 --- a/net/ipv4/ipconfig.c
80628 +++ b/net/ipv4/ipconfig.c
80629 @@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
80630
80631 mm_segment_t oldfs = get_fs();
80632 set_fs(get_ds());
80633 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80634 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80635 set_fs(oldfs);
80636 return res;
80637 }
80638 @@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
80639
80640 mm_segment_t oldfs = get_fs();
80641 set_fs(get_ds());
80642 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
80643 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
80644 set_fs(oldfs);
80645 return res;
80646 }
80647 @@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
80648
80649 mm_segment_t oldfs = get_fs();
80650 set_fs(get_ds());
80651 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
80652 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
80653 set_fs(oldfs);
80654 return res;
80655 }
80656 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
80657 index 3ea4127..849297b 100644
80658 --- a/net/ipv4/netfilter/arp_tables.c
80659 +++ b/net/ipv4/netfilter/arp_tables.c
80660 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
80661 #endif
80662
80663 static int get_info(struct net *net, void __user *user,
80664 - const int *len, int compat)
80665 + int len, int compat)
80666 {
80667 char name[XT_TABLE_MAXNAMELEN];
80668 struct xt_table *t;
80669 int ret;
80670
80671 - if (*len != sizeof(struct arpt_getinfo)) {
80672 - duprintf("length %u != %Zu\n", *len,
80673 + if (len != sizeof(struct arpt_getinfo)) {
80674 + duprintf("length %u != %Zu\n", len,
80675 sizeof(struct arpt_getinfo));
80676 return -EINVAL;
80677 }
80678 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
80679 info.size = private->size;
80680 strcpy(info.name, name);
80681
80682 - if (copy_to_user(user, &info, *len) != 0)
80683 + if (copy_to_user(user, &info, len) != 0)
80684 ret = -EFAULT;
80685 else
80686 ret = 0;
80687 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
80688
80689 switch (cmd) {
80690 case ARPT_SO_GET_INFO:
80691 - ret = get_info(sock_net(sk), user, len, 1);
80692 + ret = get_info(sock_net(sk), user, *len, 1);
80693 break;
80694 case ARPT_SO_GET_ENTRIES:
80695 ret = compat_get_entries(sock_net(sk), user, len);
80696 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
80697
80698 switch (cmd) {
80699 case ARPT_SO_GET_INFO:
80700 - ret = get_info(sock_net(sk), user, len, 0);
80701 + ret = get_info(sock_net(sk), user, *len, 0);
80702 break;
80703
80704 case ARPT_SO_GET_ENTRIES:
80705 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
80706 index 17c5e06..1b91206 100644
80707 --- a/net/ipv4/netfilter/ip_tables.c
80708 +++ b/net/ipv4/netfilter/ip_tables.c
80709 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
80710 #endif
80711
80712 static int get_info(struct net *net, void __user *user,
80713 - const int *len, int compat)
80714 + int len, int compat)
80715 {
80716 char name[XT_TABLE_MAXNAMELEN];
80717 struct xt_table *t;
80718 int ret;
80719
80720 - if (*len != sizeof(struct ipt_getinfo)) {
80721 - duprintf("length %u != %zu\n", *len,
80722 + if (len != sizeof(struct ipt_getinfo)) {
80723 + duprintf("length %u != %zu\n", len,
80724 sizeof(struct ipt_getinfo));
80725 return -EINVAL;
80726 }
80727 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
80728 info.size = private->size;
80729 strcpy(info.name, name);
80730
80731 - if (copy_to_user(user, &info, *len) != 0)
80732 + if (copy_to_user(user, &info, len) != 0)
80733 ret = -EFAULT;
80734 else
80735 ret = 0;
80736 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80737
80738 switch (cmd) {
80739 case IPT_SO_GET_INFO:
80740 - ret = get_info(sock_net(sk), user, len, 1);
80741 + ret = get_info(sock_net(sk), user, *len, 1);
80742 break;
80743 case IPT_SO_GET_ENTRIES:
80744 ret = compat_get_entries(sock_net(sk), user, len);
80745 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80746
80747 switch (cmd) {
80748 case IPT_SO_GET_INFO:
80749 - ret = get_info(sock_net(sk), user, len, 0);
80750 + ret = get_info(sock_net(sk), user, *len, 0);
80751 break;
80752
80753 case IPT_SO_GET_ENTRIES:
80754 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
80755 index 6f9c072..38ea6c6 100644
80756 --- a/net/ipv4/ping.c
80757 +++ b/net/ipv4/ping.c
80758 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
80759 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80760 0, sock_i_ino(sp),
80761 atomic_read(&sp->sk_refcnt), sp,
80762 - atomic_read(&sp->sk_drops), len);
80763 + atomic_read_unchecked(&sp->sk_drops), len);
80764 }
80765
80766 static int ping_seq_show(struct seq_file *seq, void *v)
80767 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
80768 index 6f08991..55867ad 100644
80769 --- a/net/ipv4/raw.c
80770 +++ b/net/ipv4/raw.c
80771 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
80772 int raw_rcv(struct sock *sk, struct sk_buff *skb)
80773 {
80774 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
80775 - atomic_inc(&sk->sk_drops);
80776 + atomic_inc_unchecked(&sk->sk_drops);
80777 kfree_skb(skb);
80778 return NET_RX_DROP;
80779 }
80780 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
80781
80782 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
80783 {
80784 + struct icmp_filter filter;
80785 +
80786 if (optlen > sizeof(struct icmp_filter))
80787 optlen = sizeof(struct icmp_filter);
80788 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
80789 + if (copy_from_user(&filter, optval, optlen))
80790 return -EFAULT;
80791 + raw_sk(sk)->filter = filter;
80792 return 0;
80793 }
80794
80795 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
80796 {
80797 int len, ret = -EFAULT;
80798 + struct icmp_filter filter;
80799
80800 if (get_user(len, optlen))
80801 goto out;
80802 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
80803 if (len > sizeof(struct icmp_filter))
80804 len = sizeof(struct icmp_filter);
80805 ret = -EFAULT;
80806 - if (put_user(len, optlen) ||
80807 - copy_to_user(optval, &raw_sk(sk)->filter, len))
80808 + filter = raw_sk(sk)->filter;
80809 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
80810 goto out;
80811 ret = 0;
80812 out: return ret;
80813 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80814 0, 0L, 0,
80815 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80816 0, sock_i_ino(sp),
80817 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80818 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80819 }
80820
80821 static int raw_seq_show(struct seq_file *seq, void *v)
80822 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
80823 index a0fcc47..5949bba1 100644
80824 --- a/net/ipv4/route.c
80825 +++ b/net/ipv4/route.c
80826 @@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
80827
80828 static __net_init int rt_genid_init(struct net *net)
80829 {
80830 - atomic_set(&net->rt_genid, 0);
80831 + atomic_set_unchecked(&net->rt_genid, 0);
80832 get_random_bytes(&net->ipv4.dev_addr_genid,
80833 sizeof(net->ipv4.dev_addr_genid));
80834 return 0;
80835 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
80836 index ad70a96..50cb55b 100644
80837 --- a/net/ipv4/tcp_input.c
80838 +++ b/net/ipv4/tcp_input.c
80839 @@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
80840 * simplifies code)
80841 */
80842 static void
80843 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80844 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80845 struct sk_buff *head, struct sk_buff *tail,
80846 u32 start, u32 end)
80847 {
80848 @@ -5850,6 +5850,7 @@ discard:
80849 tcp_paws_reject(&tp->rx_opt, 0))
80850 goto discard_and_undo;
80851
80852 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
80853 if (th->syn) {
80854 /* We see SYN without ACK. It is attempt of
80855 * simultaneous connect with crossed SYNs.
80856 @@ -5900,6 +5901,7 @@ discard:
80857 goto discard;
80858 #endif
80859 }
80860 +#endif
80861 /* "fifth, if neither of the SYN or RST bits is set then
80862 * drop the segment and return."
80863 */
80864 @@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80865 goto discard;
80866
80867 if (th->syn) {
80868 - if (th->fin)
80869 + if (th->fin || th->urg || th->psh)
80870 goto discard;
80871 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
80872 return 1;
80873 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80874 index eadb693..e8f7251 100644
80875 --- a/net/ipv4/tcp_ipv4.c
80876 +++ b/net/ipv4/tcp_ipv4.c
80877 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
80878 EXPORT_SYMBOL(sysctl_tcp_low_latency);
80879
80880
80881 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80882 +extern int grsec_enable_blackhole;
80883 +#endif
80884 +
80885 #ifdef CONFIG_TCP_MD5SIG
80886 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
80887 __be32 daddr, __be32 saddr, const struct tcphdr *th);
80888 @@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80889 return 0;
80890
80891 reset:
80892 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80893 + if (!grsec_enable_blackhole)
80894 +#endif
80895 tcp_v4_send_reset(rsk, skb);
80896 discard:
80897 kfree_skb(skb);
80898 @@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
80899 TCP_SKB_CB(skb)->sacked = 0;
80900
80901 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80902 - if (!sk)
80903 + if (!sk) {
80904 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80905 + ret = 1;
80906 +#endif
80907 goto no_tcp_socket;
80908 -
80909 + }
80910 process:
80911 - if (sk->sk_state == TCP_TIME_WAIT)
80912 + if (sk->sk_state == TCP_TIME_WAIT) {
80913 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80914 + ret = 2;
80915 +#endif
80916 goto do_time_wait;
80917 + }
80918
80919 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
80920 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80921 @@ -2050,6 +2064,10 @@ no_tcp_socket:
80922 bad_packet:
80923 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80924 } else {
80925 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80926 + if (!grsec_enable_blackhole || (ret == 1 &&
80927 + (skb->dev->flags & IFF_LOOPBACK)))
80928 +#endif
80929 tcp_v4_send_reset(NULL, skb);
80930 }
80931
80932 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80933 index f35f2df..ccb5ca6 100644
80934 --- a/net/ipv4/tcp_minisocks.c
80935 +++ b/net/ipv4/tcp_minisocks.c
80936 @@ -27,6 +27,10 @@
80937 #include <net/inet_common.h>
80938 #include <net/xfrm.h>
80939
80940 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80941 +extern int grsec_enable_blackhole;
80942 +#endif
80943 +
80944 int sysctl_tcp_syncookies __read_mostly = 1;
80945 EXPORT_SYMBOL(sysctl_tcp_syncookies);
80946
80947 @@ -742,7 +746,10 @@ embryonic_reset:
80948 * avoid becoming vulnerable to outside attack aiming at
80949 * resetting legit local connections.
80950 */
80951 - req->rsk_ops->send_reset(sk, skb);
80952 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80953 + if (!grsec_enable_blackhole)
80954 +#endif
80955 + req->rsk_ops->send_reset(sk, skb);
80956 } else if (fastopen) { /* received a valid RST pkt */
80957 reqsk_fastopen_remove(sk, req, true);
80958 tcp_reset(sk);
80959 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80960 index 4526fe6..1a34e43 100644
80961 --- a/net/ipv4/tcp_probe.c
80962 +++ b/net/ipv4/tcp_probe.c
80963 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80964 if (cnt + width >= len)
80965 break;
80966
80967 - if (copy_to_user(buf + cnt, tbuf, width))
80968 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80969 return -EFAULT;
80970 cnt += width;
80971 }
80972 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80973 index b78aac3..e18230b 100644
80974 --- a/net/ipv4/tcp_timer.c
80975 +++ b/net/ipv4/tcp_timer.c
80976 @@ -22,6 +22,10 @@
80977 #include <linux/gfp.h>
80978 #include <net/tcp.h>
80979
80980 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80981 +extern int grsec_lastack_retries;
80982 +#endif
80983 +
80984 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80985 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80986 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80987 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
80988 }
80989 }
80990
80991 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80992 + if ((sk->sk_state == TCP_LAST_ACK) &&
80993 + (grsec_lastack_retries > 0) &&
80994 + (grsec_lastack_retries < retry_until))
80995 + retry_until = grsec_lastack_retries;
80996 +#endif
80997 +
80998 if (retransmits_timed_out(sk, retry_until,
80999 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
81000 /* Has it gone just too far? */
81001 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
81002 index 1f4d405..3524677 100644
81003 --- a/net/ipv4/udp.c
81004 +++ b/net/ipv4/udp.c
81005 @@ -87,6 +87,7 @@
81006 #include <linux/types.h>
81007 #include <linux/fcntl.h>
81008 #include <linux/module.h>
81009 +#include <linux/security.h>
81010 #include <linux/socket.h>
81011 #include <linux/sockios.h>
81012 #include <linux/igmp.h>
81013 @@ -111,6 +112,10 @@
81014 #include <trace/events/skb.h>
81015 #include "udp_impl.h"
81016
81017 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81018 +extern int grsec_enable_blackhole;
81019 +#endif
81020 +
81021 struct udp_table udp_table __read_mostly;
81022 EXPORT_SYMBOL(udp_table);
81023
81024 @@ -569,6 +574,9 @@ found:
81025 return s;
81026 }
81027
81028 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
81029 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
81030 +
81031 /*
81032 * This routine is called by the ICMP module when it gets some
81033 * sort of error condition. If err < 0 then the socket should
81034 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
81035 dport = usin->sin_port;
81036 if (dport == 0)
81037 return -EINVAL;
81038 +
81039 + err = gr_search_udp_sendmsg(sk, usin);
81040 + if (err)
81041 + return err;
81042 } else {
81043 if (sk->sk_state != TCP_ESTABLISHED)
81044 return -EDESTADDRREQ;
81045 +
81046 + err = gr_search_udp_sendmsg(sk, NULL);
81047 + if (err)
81048 + return err;
81049 +
81050 daddr = inet->inet_daddr;
81051 dport = inet->inet_dport;
81052 /* Open fast path for connected socket.
81053 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
81054 udp_lib_checksum_complete(skb)) {
81055 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81056 IS_UDPLITE(sk));
81057 - atomic_inc(&sk->sk_drops);
81058 + atomic_inc_unchecked(&sk->sk_drops);
81059 __skb_unlink(skb, rcvq);
81060 __skb_queue_tail(&list_kill, skb);
81061 }
81062 @@ -1194,6 +1211,10 @@ try_again:
81063 if (!skb)
81064 goto out;
81065
81066 + err = gr_search_udp_recvmsg(sk, skb);
81067 + if (err)
81068 + goto out_free;
81069 +
81070 ulen = skb->len - sizeof(struct udphdr);
81071 copied = len;
81072 if (copied > ulen)
81073 @@ -1227,7 +1248,7 @@ try_again:
81074 if (unlikely(err)) {
81075 trace_kfree_skb(skb, udp_recvmsg);
81076 if (!peeked) {
81077 - atomic_inc(&sk->sk_drops);
81078 + atomic_inc_unchecked(&sk->sk_drops);
81079 UDP_INC_STATS_USER(sock_net(sk),
81080 UDP_MIB_INERRORS, is_udplite);
81081 }
81082 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81083
81084 drop:
81085 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81086 - atomic_inc(&sk->sk_drops);
81087 + atomic_inc_unchecked(&sk->sk_drops);
81088 kfree_skb(skb);
81089 return -1;
81090 }
81091 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81092 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81093
81094 if (!skb1) {
81095 - atomic_inc(&sk->sk_drops);
81096 + atomic_inc_unchecked(&sk->sk_drops);
81097 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81098 IS_UDPLITE(sk));
81099 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81100 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81101 goto csum_error;
81102
81103 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81104 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81105 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81106 +#endif
81107 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
81108
81109 /*
81110 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
81111 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81112 0, sock_i_ino(sp),
81113 atomic_read(&sp->sk_refcnt), sp,
81114 - atomic_read(&sp->sk_drops), len);
81115 + atomic_read_unchecked(&sp->sk_drops), len);
81116 }
81117
81118 int udp4_seq_show(struct seq_file *seq, void *v)
81119 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81120 index 1b5d8cb..2e8c2d9 100644
81121 --- a/net/ipv6/addrconf.c
81122 +++ b/net/ipv6/addrconf.c
81123 @@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81124 p.iph.ihl = 5;
81125 p.iph.protocol = IPPROTO_IPV6;
81126 p.iph.ttl = 64;
81127 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81128 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81129
81130 if (ops->ndo_do_ioctl) {
81131 mm_segment_t oldfs = get_fs();
81132 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
81133 index 131dd09..7647ada 100644
81134 --- a/net/ipv6/ip6_gre.c
81135 +++ b/net/ipv6/ip6_gre.c
81136 @@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
81137 }
81138
81139
81140 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
81141 +static struct inet6_protocol ip6gre_protocol = {
81142 .handler = ip6gre_rcv,
81143 .err_handler = ip6gre_err,
81144 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
81145 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81146 index d1e2e8e..51c19ae 100644
81147 --- a/net/ipv6/ipv6_sockglue.c
81148 +++ b/net/ipv6/ipv6_sockglue.c
81149 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81150 if (sk->sk_type != SOCK_STREAM)
81151 return -ENOPROTOOPT;
81152
81153 - msg.msg_control = optval;
81154 + msg.msg_control = (void __force_kernel *)optval;
81155 msg.msg_controllen = len;
81156 msg.msg_flags = flags;
81157
81158 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81159 index 125a90d..2a11f36 100644
81160 --- a/net/ipv6/netfilter/ip6_tables.c
81161 +++ b/net/ipv6/netfilter/ip6_tables.c
81162 @@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
81163 #endif
81164
81165 static int get_info(struct net *net, void __user *user,
81166 - const int *len, int compat)
81167 + int len, int compat)
81168 {
81169 char name[XT_TABLE_MAXNAMELEN];
81170 struct xt_table *t;
81171 int ret;
81172
81173 - if (*len != sizeof(struct ip6t_getinfo)) {
81174 - duprintf("length %u != %zu\n", *len,
81175 + if (len != sizeof(struct ip6t_getinfo)) {
81176 + duprintf("length %u != %zu\n", len,
81177 sizeof(struct ip6t_getinfo));
81178 return -EINVAL;
81179 }
81180 @@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
81181 info.size = private->size;
81182 strcpy(info.name, name);
81183
81184 - if (copy_to_user(user, &info, *len) != 0)
81185 + if (copy_to_user(user, &info, len) != 0)
81186 ret = -EFAULT;
81187 else
81188 ret = 0;
81189 @@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81190
81191 switch (cmd) {
81192 case IP6T_SO_GET_INFO:
81193 - ret = get_info(sock_net(sk), user, len, 1);
81194 + ret = get_info(sock_net(sk), user, *len, 1);
81195 break;
81196 case IP6T_SO_GET_ENTRIES:
81197 ret = compat_get_entries(sock_net(sk), user, len);
81198 @@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81199
81200 switch (cmd) {
81201 case IP6T_SO_GET_INFO:
81202 - ret = get_info(sock_net(sk), user, len, 0);
81203 + ret = get_info(sock_net(sk), user, *len, 0);
81204 break;
81205
81206 case IP6T_SO_GET_ENTRIES:
81207 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81208 index 70fa814..d70c28c 100644
81209 --- a/net/ipv6/raw.c
81210 +++ b/net/ipv6/raw.c
81211 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
81212 {
81213 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
81214 skb_checksum_complete(skb)) {
81215 - atomic_inc(&sk->sk_drops);
81216 + atomic_inc_unchecked(&sk->sk_drops);
81217 kfree_skb(skb);
81218 return NET_RX_DROP;
81219 }
81220 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81221 struct raw6_sock *rp = raw6_sk(sk);
81222
81223 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81224 - atomic_inc(&sk->sk_drops);
81225 + atomic_inc_unchecked(&sk->sk_drops);
81226 kfree_skb(skb);
81227 return NET_RX_DROP;
81228 }
81229 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81230
81231 if (inet->hdrincl) {
81232 if (skb_checksum_complete(skb)) {
81233 - atomic_inc(&sk->sk_drops);
81234 + atomic_inc_unchecked(&sk->sk_drops);
81235 kfree_skb(skb);
81236 return NET_RX_DROP;
81237 }
81238 @@ -604,7 +604,7 @@ out:
81239 return err;
81240 }
81241
81242 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81243 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81244 struct flowi6 *fl6, struct dst_entry **dstp,
81245 unsigned int flags)
81246 {
81247 @@ -916,12 +916,15 @@ do_confirm:
81248 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81249 char __user *optval, int optlen)
81250 {
81251 + struct icmp6_filter filter;
81252 +
81253 switch (optname) {
81254 case ICMPV6_FILTER:
81255 if (optlen > sizeof(struct icmp6_filter))
81256 optlen = sizeof(struct icmp6_filter);
81257 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81258 + if (copy_from_user(&filter, optval, optlen))
81259 return -EFAULT;
81260 + raw6_sk(sk)->filter = filter;
81261 return 0;
81262 default:
81263 return -ENOPROTOOPT;
81264 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81265 char __user *optval, int __user *optlen)
81266 {
81267 int len;
81268 + struct icmp6_filter filter;
81269
81270 switch (optname) {
81271 case ICMPV6_FILTER:
81272 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81273 len = sizeof(struct icmp6_filter);
81274 if (put_user(len, optlen))
81275 return -EFAULT;
81276 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81277 + filter = raw6_sk(sk)->filter;
81278 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
81279 return -EFAULT;
81280 return 0;
81281 default:
81282 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81283 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81284 0,
81285 sock_i_ino(sp),
81286 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81287 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81288 }
81289
81290 static int raw6_seq_show(struct seq_file *seq, void *v)
81291 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81292 index 4f435371..5de9da7 100644
81293 --- a/net/ipv6/tcp_ipv6.c
81294 +++ b/net/ipv6/tcp_ipv6.c
81295 @@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
81296 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
81297 }
81298
81299 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81300 +extern int grsec_enable_blackhole;
81301 +#endif
81302 +
81303 static void tcp_v6_hash(struct sock *sk)
81304 {
81305 if (sk->sk_state != TCP_CLOSE) {
81306 @@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81307 return 0;
81308
81309 reset:
81310 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81311 + if (!grsec_enable_blackhole)
81312 +#endif
81313 tcp_v6_send_reset(sk, skb);
81314 discard:
81315 if (opt_skb)
81316 @@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81317 TCP_SKB_CB(skb)->sacked = 0;
81318
81319 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81320 - if (!sk)
81321 + if (!sk) {
81322 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81323 + ret = 1;
81324 +#endif
81325 goto no_tcp_socket;
81326 + }
81327
81328 process:
81329 - if (sk->sk_state == TCP_TIME_WAIT)
81330 + if (sk->sk_state == TCP_TIME_WAIT) {
81331 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81332 + ret = 2;
81333 +#endif
81334 goto do_time_wait;
81335 + }
81336
81337 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
81338 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81339 @@ -1568,6 +1583,10 @@ no_tcp_socket:
81340 bad_packet:
81341 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81342 } else {
81343 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81344 + if (!grsec_enable_blackhole || (ret == 1 &&
81345 + (skb->dev->flags & IFF_LOOPBACK)))
81346 +#endif
81347 tcp_v6_send_reset(NULL, skb);
81348 }
81349
81350 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81351 index fb08329..2d6919e 100644
81352 --- a/net/ipv6/udp.c
81353 +++ b/net/ipv6/udp.c
81354 @@ -51,6 +51,10 @@
81355 #include <trace/events/skb.h>
81356 #include "udp_impl.h"
81357
81358 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81359 +extern int grsec_enable_blackhole;
81360 +#endif
81361 +
81362 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81363 {
81364 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81365 @@ -395,7 +399,7 @@ try_again:
81366 if (unlikely(err)) {
81367 trace_kfree_skb(skb, udpv6_recvmsg);
81368 if (!peeked) {
81369 - atomic_inc(&sk->sk_drops);
81370 + atomic_inc_unchecked(&sk->sk_drops);
81371 if (is_udp4)
81372 UDP_INC_STATS_USER(sock_net(sk),
81373 UDP_MIB_INERRORS,
81374 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81375 return rc;
81376 drop:
81377 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81378 - atomic_inc(&sk->sk_drops);
81379 + atomic_inc_unchecked(&sk->sk_drops);
81380 kfree_skb(skb);
81381 return -1;
81382 }
81383 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81384 if (likely(skb1 == NULL))
81385 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81386 if (!skb1) {
81387 - atomic_inc(&sk->sk_drops);
81388 + atomic_inc_unchecked(&sk->sk_drops);
81389 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81390 IS_UDPLITE(sk));
81391 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81392 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81393 goto discard;
81394
81395 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81396 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81397 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81398 +#endif
81399 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
81400
81401 kfree_skb(skb);
81402 @@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81403 0,
81404 sock_i_ino(sp),
81405 atomic_read(&sp->sk_refcnt), sp,
81406 - atomic_read(&sp->sk_drops));
81407 + atomic_read_unchecked(&sp->sk_drops));
81408 }
81409
81410 int udp6_seq_show(struct seq_file *seq, void *v)
81411 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81412 index a68c88c..d55b0c5 100644
81413 --- a/net/irda/ircomm/ircomm_tty.c
81414 +++ b/net/irda/ircomm/ircomm_tty.c
81415 @@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81416 add_wait_queue(&port->open_wait, &wait);
81417
81418 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81419 - __FILE__, __LINE__, tty->driver->name, port->count);
81420 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81421
81422 spin_lock_irqsave(&port->lock, flags);
81423 if (!tty_hung_up_p(filp)) {
81424 extra_count = 1;
81425 - port->count--;
81426 + atomic_dec(&port->count);
81427 }
81428 spin_unlock_irqrestore(&port->lock, flags);
81429 port->blocked_open++;
81430 @@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81431 }
81432
81433 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81434 - __FILE__, __LINE__, tty->driver->name, port->count);
81435 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81436
81437 schedule();
81438 }
81439 @@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81440 if (extra_count) {
81441 /* ++ is not atomic, so this should be protected - Jean II */
81442 spin_lock_irqsave(&port->lock, flags);
81443 - port->count++;
81444 + atomic_inc(&port->count);
81445 spin_unlock_irqrestore(&port->lock, flags);
81446 }
81447 port->blocked_open--;
81448
81449 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81450 - __FILE__, __LINE__, tty->driver->name, port->count);
81451 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81452
81453 if (!retval)
81454 port->flags |= ASYNC_NORMAL_ACTIVE;
81455 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81456
81457 /* ++ is not atomic, so this should be protected - Jean II */
81458 spin_lock_irqsave(&self->port.lock, flags);
81459 - self->port.count++;
81460 + atomic_inc(&self->port.count);
81461 spin_unlock_irqrestore(&self->port.lock, flags);
81462 tty_port_tty_set(&self->port, tty);
81463
81464 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81465 - self->line, self->port.count);
81466 + self->line, atomic_read(&self->port.count));
81467
81468 /* Not really used by us, but lets do it anyway */
81469 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81470 @@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81471 tty_kref_put(port->tty);
81472 }
81473 port->tty = NULL;
81474 - port->count = 0;
81475 + atomic_set(&port->count, 0);
81476 spin_unlock_irqrestore(&port->lock, flags);
81477
81478 wake_up_interruptible(&port->open_wait);
81479 @@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81480 seq_putc(m, '\n');
81481
81482 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81483 - seq_printf(m, "Open count: %d\n", self->port.count);
81484 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
81485 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81486 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81487
81488 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81489 index cd6f7a9..e63fe89 100644
81490 --- a/net/iucv/af_iucv.c
81491 +++ b/net/iucv/af_iucv.c
81492 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
81493
81494 write_lock_bh(&iucv_sk_list.lock);
81495
81496 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81497 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81498 while (__iucv_get_sock_by_name(name)) {
81499 sprintf(name, "%08x",
81500 - atomic_inc_return(&iucv_sk_list.autobind_name));
81501 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81502 }
81503
81504 write_unlock_bh(&iucv_sk_list.lock);
81505 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
81506 index df08250..02021fe 100644
81507 --- a/net/iucv/iucv.c
81508 +++ b/net/iucv/iucv.c
81509 @@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
81510 return NOTIFY_OK;
81511 }
81512
81513 -static struct notifier_block __refdata iucv_cpu_notifier = {
81514 +static struct notifier_block iucv_cpu_notifier = {
81515 .notifier_call = iucv_cpu_notify,
81516 };
81517
81518 diff --git a/net/key/af_key.c b/net/key/af_key.c
81519 index 5b426a6..970032b 100644
81520 --- a/net/key/af_key.c
81521 +++ b/net/key/af_key.c
81522 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
81523 static u32 get_acqseq(void)
81524 {
81525 u32 res;
81526 - static atomic_t acqseq;
81527 + static atomic_unchecked_t acqseq;
81528
81529 do {
81530 - res = atomic_inc_return(&acqseq);
81531 + res = atomic_inc_return_unchecked(&acqseq);
81532 } while (!res);
81533 return res;
81534 }
81535 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81536 index 0479c64..d031db6 100644
81537 --- a/net/mac80211/cfg.c
81538 +++ b/net/mac80211/cfg.c
81539 @@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
81540 ret = ieee80211_vif_use_channel(sdata, chandef,
81541 IEEE80211_CHANCTX_EXCLUSIVE);
81542 }
81543 - } else if (local->open_count == local->monitors) {
81544 + } else if (local_read(&local->open_count) == local->monitors) {
81545 local->_oper_channel = chandef->chan;
81546 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
81547 ieee80211_hw_config(local, 0);
81548 @@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
81549 else
81550 local->probe_req_reg--;
81551
81552 - if (!local->open_count)
81553 + if (!local_read(&local->open_count))
81554 break;
81555
81556 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
81557 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81558 index 2ed065c..948177f 100644
81559 --- a/net/mac80211/ieee80211_i.h
81560 +++ b/net/mac80211/ieee80211_i.h
81561 @@ -28,6 +28,7 @@
81562 #include <net/ieee80211_radiotap.h>
81563 #include <net/cfg80211.h>
81564 #include <net/mac80211.h>
81565 +#include <asm/local.h>
81566 #include "key.h"
81567 #include "sta_info.h"
81568 #include "debug.h"
81569 @@ -909,7 +910,7 @@ struct ieee80211_local {
81570 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81571 spinlock_t queue_stop_reason_lock;
81572
81573 - int open_count;
81574 + local_t open_count;
81575 int monitors, cooked_mntrs;
81576 /* number of interfaces with corresponding FIF_ flags */
81577 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
81578 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
81579 index 8be854e..ad72a69 100644
81580 --- a/net/mac80211/iface.c
81581 +++ b/net/mac80211/iface.c
81582 @@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81583 break;
81584 }
81585
81586 - if (local->open_count == 0) {
81587 + if (local_read(&local->open_count) == 0) {
81588 res = drv_start(local);
81589 if (res)
81590 goto err_del_bss;
81591 @@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81592 break;
81593 }
81594
81595 - if (local->monitors == 0 && local->open_count == 0) {
81596 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
81597 res = ieee80211_add_virtual_monitor(local);
81598 if (res)
81599 goto err_stop;
81600 @@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81601 mutex_unlock(&local->mtx);
81602
81603 if (coming_up)
81604 - local->open_count++;
81605 + local_inc(&local->open_count);
81606
81607 if (hw_reconf_flags)
81608 ieee80211_hw_config(local, hw_reconf_flags);
81609 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
81610 err_del_interface:
81611 drv_remove_interface(local, sdata);
81612 err_stop:
81613 - if (!local->open_count)
81614 + if (!local_read(&local->open_count))
81615 drv_stop(local);
81616 err_del_bss:
81617 sdata->bss = NULL;
81618 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81619 }
81620
81621 if (going_down)
81622 - local->open_count--;
81623 + local_dec(&local->open_count);
81624
81625 switch (sdata->vif.type) {
81626 case NL80211_IFTYPE_AP_VLAN:
81627 @@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81628
81629 ieee80211_recalc_ps(local, -1);
81630
81631 - if (local->open_count == 0) {
81632 + if (local_read(&local->open_count) == 0) {
81633 if (local->ops->napi_poll)
81634 napi_disable(&local->napi);
81635 ieee80211_clear_tx_pending(local);
81636 @@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
81637 }
81638 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
81639
81640 - if (local->monitors == local->open_count && local->monitors > 0)
81641 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
81642 ieee80211_add_virtual_monitor(local);
81643 }
81644
81645 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
81646 index 1b087ff..bf600e9 100644
81647 --- a/net/mac80211/main.c
81648 +++ b/net/mac80211/main.c
81649 @@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
81650 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
81651 IEEE80211_CONF_CHANGE_POWER);
81652
81653 - if (changed && local->open_count) {
81654 + if (changed && local_read(&local->open_count)) {
81655 ret = drv_config(local, changed);
81656 /*
81657 * Goal:
81658 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
81659 index 79a48f3..5e185c9 100644
81660 --- a/net/mac80211/pm.c
81661 +++ b/net/mac80211/pm.c
81662 @@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81663 struct sta_info *sta;
81664 struct ieee80211_chanctx *ctx;
81665
81666 - if (!local->open_count)
81667 + if (!local_read(&local->open_count))
81668 goto suspend;
81669
81670 ieee80211_scan_cancel(local);
81671 @@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81672 cancel_work_sync(&local->dynamic_ps_enable_work);
81673 del_timer_sync(&local->dynamic_ps_timer);
81674
81675 - local->wowlan = wowlan && local->open_count;
81676 + local->wowlan = wowlan && local_read(&local->open_count);
81677 if (local->wowlan) {
81678 int err = drv_suspend(local, wowlan);
81679 if (err < 0) {
81680 @@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
81681 mutex_unlock(&local->chanctx_mtx);
81682
81683 /* stop hardware - this must stop RX */
81684 - if (local->open_count)
81685 + if (local_read(&local->open_count))
81686 ieee80211_stop_device(local);
81687
81688 suspend:
81689 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
81690 index dd88381..eef4dd6 100644
81691 --- a/net/mac80211/rate.c
81692 +++ b/net/mac80211/rate.c
81693 @@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
81694
81695 ASSERT_RTNL();
81696
81697 - if (local->open_count)
81698 + if (local_read(&local->open_count))
81699 return -EBUSY;
81700
81701 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
81702 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
81703 index c97a065..ff61928 100644
81704 --- a/net/mac80211/rc80211_pid_debugfs.c
81705 +++ b/net/mac80211/rc80211_pid_debugfs.c
81706 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
81707
81708 spin_unlock_irqrestore(&events->lock, status);
81709
81710 - if (copy_to_user(buf, pb, p))
81711 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
81712 return -EFAULT;
81713
81714 return p;
81715 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
81716 index f11e8c5..08d0013 100644
81717 --- a/net/mac80211/util.c
81718 +++ b/net/mac80211/util.c
81719 @@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
81720 }
81721 #endif
81722 /* everything else happens only if HW was up & running */
81723 - if (!local->open_count)
81724 + if (!local_read(&local->open_count))
81725 goto wake_up;
81726
81727 /*
81728 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
81729 index 49e96df..63a51c3 100644
81730 --- a/net/netfilter/Kconfig
81731 +++ b/net/netfilter/Kconfig
81732 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
81733
81734 To compile it as a module, choose M here. If unsure, say N.
81735
81736 +config NETFILTER_XT_MATCH_GRADM
81737 + tristate '"gradm" match support'
81738 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
81739 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
81740 + ---help---
81741 + The gradm match allows to match on grsecurity RBAC being enabled.
81742 + It is useful when iptables rules are applied early on bootup to
81743 + prevent connections to the machine (except from a trusted host)
81744 + while the RBAC system is disabled.
81745 +
81746 config NETFILTER_XT_MATCH_HASHLIMIT
81747 tristate '"hashlimit" match support'
81748 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
81749 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
81750 index 3259697..54d5393 100644
81751 --- a/net/netfilter/Makefile
81752 +++ b/net/netfilter/Makefile
81753 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
81754 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
81755 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
81756 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
81757 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
81758 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
81759 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
81760 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
81761 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
81762 index 30e764a..c3b6a9d 100644
81763 --- a/net/netfilter/ipvs/ip_vs_conn.c
81764 +++ b/net/netfilter/ipvs/ip_vs_conn.c
81765 @@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
81766 /* Increase the refcnt counter of the dest */
81767 atomic_inc(&dest->refcnt);
81768
81769 - conn_flags = atomic_read(&dest->conn_flags);
81770 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
81771 if (cp->protocol != IPPROTO_UDP)
81772 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
81773 flags = cp->flags;
81774 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
81775 atomic_set(&cp->refcnt, 1);
81776
81777 atomic_set(&cp->n_control, 0);
81778 - atomic_set(&cp->in_pkts, 0);
81779 + atomic_set_unchecked(&cp->in_pkts, 0);
81780
81781 atomic_inc(&ipvs->conn_count);
81782 if (flags & IP_VS_CONN_F_NO_CPORT)
81783 @@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
81784
81785 /* Don't drop the entry if its number of incoming packets is not
81786 located in [0, 8] */
81787 - i = atomic_read(&cp->in_pkts);
81788 + i = atomic_read_unchecked(&cp->in_pkts);
81789 if (i > 8 || i < 0) return 0;
81790
81791 if (!todrop_rate[i]) return 0;
81792 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
81793 index 47edf5a..235b07d 100644
81794 --- a/net/netfilter/ipvs/ip_vs_core.c
81795 +++ b/net/netfilter/ipvs/ip_vs_core.c
81796 @@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
81797 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
81798 /* do not touch skb anymore */
81799
81800 - atomic_inc(&cp->in_pkts);
81801 + atomic_inc_unchecked(&cp->in_pkts);
81802 ip_vs_conn_put(cp);
81803 return ret;
81804 }
81805 @@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
81806 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
81807 pkts = sysctl_sync_threshold(ipvs);
81808 else
81809 - pkts = atomic_add_return(1, &cp->in_pkts);
81810 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81811
81812 if (ipvs->sync_state & IP_VS_STATE_MASTER)
81813 ip_vs_sync_conn(net, cp, pkts);
81814 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
81815 index ec664cb..cd576ab 100644
81816 --- a/net/netfilter/ipvs/ip_vs_ctl.c
81817 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
81818 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
81819 ip_vs_rs_hash(ipvs, dest);
81820 write_unlock_bh(&ipvs->rs_lock);
81821 }
81822 - atomic_set(&dest->conn_flags, conn_flags);
81823 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
81824
81825 /* bind the service */
81826 if (!dest->svc) {
81827 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81828 " %-7s %-6d %-10d %-10d\n",
81829 &dest->addr.in6,
81830 ntohs(dest->port),
81831 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81832 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81833 atomic_read(&dest->weight),
81834 atomic_read(&dest->activeconns),
81835 atomic_read(&dest->inactconns));
81836 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81837 "%-7s %-6d %-10d %-10d\n",
81838 ntohl(dest->addr.ip),
81839 ntohs(dest->port),
81840 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81841 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81842 atomic_read(&dest->weight),
81843 atomic_read(&dest->activeconns),
81844 atomic_read(&dest->inactconns));
81845 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
81846
81847 entry.addr = dest->addr.ip;
81848 entry.port = dest->port;
81849 - entry.conn_flags = atomic_read(&dest->conn_flags);
81850 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81851 entry.weight = atomic_read(&dest->weight);
81852 entry.u_threshold = dest->u_threshold;
81853 entry.l_threshold = dest->l_threshold;
81854 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81855 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
81856 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
81857 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81858 - (atomic_read(&dest->conn_flags) &
81859 + (atomic_read_unchecked(&dest->conn_flags) &
81860 IP_VS_CONN_F_FWD_MASK)) ||
81861 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
81862 atomic_read(&dest->weight)) ||
81863 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81864 index 44fd10c..2a163b3 100644
81865 --- a/net/netfilter/ipvs/ip_vs_sync.c
81866 +++ b/net/netfilter/ipvs/ip_vs_sync.c
81867 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
81868 cp = cp->control;
81869 if (cp) {
81870 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81871 - pkts = atomic_add_return(1, &cp->in_pkts);
81872 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81873 else
81874 pkts = sysctl_sync_threshold(ipvs);
81875 ip_vs_sync_conn(net, cp->control, pkts);
81876 @@ -758,7 +758,7 @@ control:
81877 if (!cp)
81878 return;
81879 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81880 - pkts = atomic_add_return(1, &cp->in_pkts);
81881 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81882 else
81883 pkts = sysctl_sync_threshold(ipvs);
81884 goto sloop;
81885 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
81886
81887 if (opt)
81888 memcpy(&cp->in_seq, opt, sizeof(*opt));
81889 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81890 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81891 cp->state = state;
81892 cp->old_state = cp->state;
81893 /*
81894 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
81895 index ee6b7a9..f9a89f6 100644
81896 --- a/net/netfilter/ipvs/ip_vs_xmit.c
81897 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
81898 @@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
81899 else
81900 rc = NF_ACCEPT;
81901 /* do not touch skb anymore */
81902 - atomic_inc(&cp->in_pkts);
81903 + atomic_inc_unchecked(&cp->in_pkts);
81904 goto out;
81905 }
81906
81907 @@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
81908 else
81909 rc = NF_ACCEPT;
81910 /* do not touch skb anymore */
81911 - atomic_inc(&cp->in_pkts);
81912 + atomic_inc_unchecked(&cp->in_pkts);
81913 goto out;
81914 }
81915
81916 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
81917 index e4a0c4f..c263f28 100644
81918 --- a/net/netfilter/nf_conntrack_core.c
81919 +++ b/net/netfilter/nf_conntrack_core.c
81920 @@ -1529,6 +1529,10 @@ err_extend:
81921 #define DYING_NULLS_VAL ((1<<30)+1)
81922 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
81923
81924 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81925 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
81926 +#endif
81927 +
81928 static int nf_conntrack_init_net(struct net *net)
81929 {
81930 int ret;
81931 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
81932 goto err_stat;
81933 }
81934
81935 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81936 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
81937 +#else
81938 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
81939 +#endif
81940 if (!net->ct.slabname) {
81941 ret = -ENOMEM;
81942 goto err_slabname;
81943 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81944 index 92fd8ec..3f6ea4b 100644
81945 --- a/net/netfilter/nfnetlink_log.c
81946 +++ b/net/netfilter/nfnetlink_log.c
81947 @@ -72,7 +72,7 @@ struct nfulnl_instance {
81948 };
81949
81950 static DEFINE_SPINLOCK(instances_lock);
81951 -static atomic_t global_seq;
81952 +static atomic_unchecked_t global_seq;
81953
81954 #define INSTANCE_BUCKETS 16
81955 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81956 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81957 /* global sequence number */
81958 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
81959 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
81960 - htonl(atomic_inc_return(&global_seq))))
81961 + htonl(atomic_inc_return_unchecked(&global_seq))))
81962 goto nla_put_failure;
81963
81964 if (data_len) {
81965 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81966 new file mode 100644
81967 index 0000000..c566332
81968 --- /dev/null
81969 +++ b/net/netfilter/xt_gradm.c
81970 @@ -0,0 +1,51 @@
81971 +/*
81972 + * gradm match for netfilter
81973 + * Copyright © Zbigniew Krzystolik, 2010
81974 + *
81975 + * This program is free software; you can redistribute it and/or modify
81976 + * it under the terms of the GNU General Public License; either version
81977 + * 2 or 3 as published by the Free Software Foundation.
81978 + */
81979 +#include <linux/module.h>
81980 +#include <linux/moduleparam.h>
81981 +#include <linux/skbuff.h>
81982 +#include <linux/netfilter/x_tables.h>
81983 +#include <linux/grsecurity.h>
81984 +#include <linux/netfilter/xt_gradm.h>
81985 +
81986 +static bool
81987 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
81988 +{
81989 + const struct xt_gradm_mtinfo *info = par->matchinfo;
81990 + bool retval = false;
81991 + if (gr_acl_is_enabled())
81992 + retval = true;
81993 + return retval ^ info->invflags;
81994 +}
81995 +
81996 +static struct xt_match gradm_mt_reg __read_mostly = {
81997 + .name = "gradm",
81998 + .revision = 0,
81999 + .family = NFPROTO_UNSPEC,
82000 + .match = gradm_mt,
82001 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
82002 + .me = THIS_MODULE,
82003 +};
82004 +
82005 +static int __init gradm_mt_init(void)
82006 +{
82007 + return xt_register_match(&gradm_mt_reg);
82008 +}
82009 +
82010 +static void __exit gradm_mt_exit(void)
82011 +{
82012 + xt_unregister_match(&gradm_mt_reg);
82013 +}
82014 +
82015 +module_init(gradm_mt_init);
82016 +module_exit(gradm_mt_exit);
82017 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
82018 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
82019 +MODULE_LICENSE("GPL");
82020 +MODULE_ALIAS("ipt_gradm");
82021 +MODULE_ALIAS("ip6t_gradm");
82022 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
82023 index 4fe4fb4..87a89e5 100644
82024 --- a/net/netfilter/xt_statistic.c
82025 +++ b/net/netfilter/xt_statistic.c
82026 @@ -19,7 +19,7 @@
82027 #include <linux/module.h>
82028
82029 struct xt_statistic_priv {
82030 - atomic_t count;
82031 + atomic_unchecked_t count;
82032 } ____cacheline_aligned_in_smp;
82033
82034 MODULE_LICENSE("GPL");
82035 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
82036 break;
82037 case XT_STATISTIC_MODE_NTH:
82038 do {
82039 - oval = atomic_read(&info->master->count);
82040 + oval = atomic_read_unchecked(&info->master->count);
82041 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
82042 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
82043 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
82044 if (nval == 0)
82045 ret = !ret;
82046 break;
82047 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
82048 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
82049 if (info->master == NULL)
82050 return -ENOMEM;
82051 - atomic_set(&info->master->count, info->u.nth.count);
82052 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
82053
82054 return 0;
82055 }
82056 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
82057 index c0353d5..fcb0270 100644
82058 --- a/net/netlink/af_netlink.c
82059 +++ b/net/netlink/af_netlink.c
82060 @@ -785,7 +785,7 @@ static void netlink_overrun(struct sock *sk)
82061 sk->sk_error_report(sk);
82062 }
82063 }
82064 - atomic_inc(&sk->sk_drops);
82065 + atomic_inc_unchecked(&sk->sk_drops);
82066 }
82067
82068 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
82069 @@ -2071,7 +2071,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
82070 sk_wmem_alloc_get(s),
82071 nlk->cb,
82072 atomic_read(&s->sk_refcnt),
82073 - atomic_read(&s->sk_drops),
82074 + atomic_read_unchecked(&s->sk_drops),
82075 sock_i_ino(s)
82076 );
82077
82078 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
82079 index 7261eb8..44e8ac6 100644
82080 --- a/net/netrom/af_netrom.c
82081 +++ b/net/netrom/af_netrom.c
82082 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
82083 struct sock *sk = sock->sk;
82084 struct nr_sock *nr = nr_sk(sk);
82085
82086 + memset(sax, 0, sizeof(*sax));
82087 lock_sock(sk);
82088 if (peer != 0) {
82089 if (sk->sk_state != TCP_ESTABLISHED) {
82090 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
82091 *uaddr_len = sizeof(struct full_sockaddr_ax25);
82092 } else {
82093 sax->fsa_ax25.sax25_family = AF_NETROM;
82094 - sax->fsa_ax25.sax25_ndigis = 0;
82095 sax->fsa_ax25.sax25_call = nr->source_addr;
82096 *uaddr_len = sizeof(struct sockaddr_ax25);
82097 }
82098 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
82099 index c111bd0..7788ff7 100644
82100 --- a/net/packet/af_packet.c
82101 +++ b/net/packet/af_packet.c
82102 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
82103
82104 spin_lock(&sk->sk_receive_queue.lock);
82105 po->stats.tp_packets++;
82106 - skb->dropcount = atomic_read(&sk->sk_drops);
82107 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
82108 __skb_queue_tail(&sk->sk_receive_queue, skb);
82109 spin_unlock(&sk->sk_receive_queue.lock);
82110 sk->sk_data_ready(sk, skb->len);
82111 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
82112 drop_n_acct:
82113 spin_lock(&sk->sk_receive_queue.lock);
82114 po->stats.tp_drops++;
82115 - atomic_inc(&sk->sk_drops);
82116 + atomic_inc_unchecked(&sk->sk_drops);
82117 spin_unlock(&sk->sk_receive_queue.lock);
82118
82119 drop_n_restore:
82120 @@ -2565,6 +2565,7 @@ out:
82121
82122 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
82123 {
82124 + struct sock_extended_err ee;
82125 struct sock_exterr_skb *serr;
82126 struct sk_buff *skb, *skb2;
82127 int copied, err;
82128 @@ -2586,8 +2587,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
82129 sock_recv_timestamp(msg, sk, skb);
82130
82131 serr = SKB_EXT_ERR(skb);
82132 + ee = serr->ee;
82133 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
82134 - sizeof(serr->ee), &serr->ee);
82135 + sizeof ee, &ee);
82136
82137 msg->msg_flags |= MSG_ERRQUEUE;
82138 err = copied;
82139 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
82140 case PACKET_HDRLEN:
82141 if (len > sizeof(int))
82142 len = sizeof(int);
82143 - if (copy_from_user(&val, optval, len))
82144 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
82145 return -EFAULT;
82146 switch (val) {
82147 case TPACKET_V1:
82148 @@ -3254,7 +3256,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
82149 len = lv;
82150 if (put_user(len, optlen))
82151 return -EFAULT;
82152 - if (copy_to_user(optval, data, len))
82153 + if (len > sizeof(st) || copy_to_user(optval, data, len))
82154 return -EFAULT;
82155 return 0;
82156 }
82157 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
82158 index 5a940db..f0b9c12 100644
82159 --- a/net/phonet/af_phonet.c
82160 +++ b/net/phonet/af_phonet.c
82161 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
82162 {
82163 struct phonet_protocol *pp;
82164
82165 - if (protocol >= PHONET_NPROTO)
82166 + if (protocol < 0 || protocol >= PHONET_NPROTO)
82167 return NULL;
82168
82169 rcu_read_lock();
82170 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
82171 {
82172 int err = 0;
82173
82174 - if (protocol >= PHONET_NPROTO)
82175 + if (protocol < 0 || protocol >= PHONET_NPROTO)
82176 return -EINVAL;
82177
82178 err = proto_register(pp->prot, 1);
82179 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
82180 index 576f22c..bc7a71b 100644
82181 --- a/net/phonet/pep.c
82182 +++ b/net/phonet/pep.c
82183 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
82184
82185 case PNS_PEP_CTRL_REQ:
82186 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
82187 - atomic_inc(&sk->sk_drops);
82188 + atomic_inc_unchecked(&sk->sk_drops);
82189 break;
82190 }
82191 __skb_pull(skb, 4);
82192 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
82193 }
82194
82195 if (pn->rx_credits == 0) {
82196 - atomic_inc(&sk->sk_drops);
82197 + atomic_inc_unchecked(&sk->sk_drops);
82198 err = -ENOBUFS;
82199 break;
82200 }
82201 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
82202 }
82203
82204 if (pn->rx_credits == 0) {
82205 - atomic_inc(&sk->sk_drops);
82206 + atomic_inc_unchecked(&sk->sk_drops);
82207 err = NET_RX_DROP;
82208 break;
82209 }
82210 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
82211 index b7e9827..c264c85 100644
82212 --- a/net/phonet/socket.c
82213 +++ b/net/phonet/socket.c
82214 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
82215 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
82216 sock_i_ino(sk),
82217 atomic_read(&sk->sk_refcnt), sk,
82218 - atomic_read(&sk->sk_drops), &len);
82219 + atomic_read_unchecked(&sk->sk_drops), &len);
82220 }
82221 seq_printf(seq, "%*s\n", 127 - len, "");
82222 return 0;
82223 diff --git a/net/rds/cong.c b/net/rds/cong.c
82224 index e5b65ac..f3b6fb7 100644
82225 --- a/net/rds/cong.c
82226 +++ b/net/rds/cong.c
82227 @@ -78,7 +78,7 @@
82228 * finds that the saved generation number is smaller than the global generation
82229 * number, it wakes up the process.
82230 */
82231 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
82232 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
82233
82234 /*
82235 * Congestion monitoring
82236 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
82237 rdsdebug("waking map %p for %pI4\n",
82238 map, &map->m_addr);
82239 rds_stats_inc(s_cong_update_received);
82240 - atomic_inc(&rds_cong_generation);
82241 + atomic_inc_unchecked(&rds_cong_generation);
82242 if (waitqueue_active(&map->m_waitq))
82243 wake_up(&map->m_waitq);
82244 if (waitqueue_active(&rds_poll_waitq))
82245 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
82246
82247 int rds_cong_updated_since(unsigned long *recent)
82248 {
82249 - unsigned long gen = atomic_read(&rds_cong_generation);
82250 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
82251
82252 if (likely(*recent == gen))
82253 return 0;
82254 diff --git a/net/rds/ib.h b/net/rds/ib.h
82255 index 7280ab8..e04f4ea 100644
82256 --- a/net/rds/ib.h
82257 +++ b/net/rds/ib.h
82258 @@ -128,7 +128,7 @@ struct rds_ib_connection {
82259 /* sending acks */
82260 unsigned long i_ack_flags;
82261 #ifdef KERNEL_HAS_ATOMIC64
82262 - atomic64_t i_ack_next; /* next ACK to send */
82263 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
82264 #else
82265 spinlock_t i_ack_lock; /* protect i_ack_next */
82266 u64 i_ack_next; /* next ACK to send */
82267 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
82268 index 31b74f5..dc1fbfa 100644
82269 --- a/net/rds/ib_cm.c
82270 +++ b/net/rds/ib_cm.c
82271 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
82272 /* Clear the ACK state */
82273 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
82274 #ifdef KERNEL_HAS_ATOMIC64
82275 - atomic64_set(&ic->i_ack_next, 0);
82276 + atomic64_set_unchecked(&ic->i_ack_next, 0);
82277 #else
82278 ic->i_ack_next = 0;
82279 #endif
82280 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
82281 index 8eb9501..0c386ff 100644
82282 --- a/net/rds/ib_recv.c
82283 +++ b/net/rds/ib_recv.c
82284 @@ -597,7 +597,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
82285 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
82286 int ack_required)
82287 {
82288 - atomic64_set(&ic->i_ack_next, seq);
82289 + atomic64_set_unchecked(&ic->i_ack_next, seq);
82290 if (ack_required) {
82291 smp_mb__before_clear_bit();
82292 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82293 @@ -609,7 +609,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
82294 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82295 smp_mb__after_clear_bit();
82296
82297 - return atomic64_read(&ic->i_ack_next);
82298 + return atomic64_read_unchecked(&ic->i_ack_next);
82299 }
82300 #endif
82301
82302 diff --git a/net/rds/iw.h b/net/rds/iw.h
82303 index 04ce3b1..48119a6 100644
82304 --- a/net/rds/iw.h
82305 +++ b/net/rds/iw.h
82306 @@ -134,7 +134,7 @@ struct rds_iw_connection {
82307 /* sending acks */
82308 unsigned long i_ack_flags;
82309 #ifdef KERNEL_HAS_ATOMIC64
82310 - atomic64_t i_ack_next; /* next ACK to send */
82311 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
82312 #else
82313 spinlock_t i_ack_lock; /* protect i_ack_next */
82314 u64 i_ack_next; /* next ACK to send */
82315 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
82316 index a91e1db..cf3053f 100644
82317 --- a/net/rds/iw_cm.c
82318 +++ b/net/rds/iw_cm.c
82319 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
82320 /* Clear the ACK state */
82321 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
82322 #ifdef KERNEL_HAS_ATOMIC64
82323 - atomic64_set(&ic->i_ack_next, 0);
82324 + atomic64_set_unchecked(&ic->i_ack_next, 0);
82325 #else
82326 ic->i_ack_next = 0;
82327 #endif
82328 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
82329 index 4503335..db566b4 100644
82330 --- a/net/rds/iw_recv.c
82331 +++ b/net/rds/iw_recv.c
82332 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
82333 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
82334 int ack_required)
82335 {
82336 - atomic64_set(&ic->i_ack_next, seq);
82337 + atomic64_set_unchecked(&ic->i_ack_next, seq);
82338 if (ack_required) {
82339 smp_mb__before_clear_bit();
82340 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82341 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
82342 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82343 smp_mb__after_clear_bit();
82344
82345 - return atomic64_read(&ic->i_ack_next);
82346 + return atomic64_read_unchecked(&ic->i_ack_next);
82347 }
82348 #endif
82349
82350 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
82351 index edac9ef..16bcb98 100644
82352 --- a/net/rds/tcp.c
82353 +++ b/net/rds/tcp.c
82354 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
82355 int val = 1;
82356
82357 set_fs(KERNEL_DS);
82358 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
82359 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
82360 sizeof(val));
82361 set_fs(oldfs);
82362 }
82363 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
82364 index 81cf5a4..b5826ff 100644
82365 --- a/net/rds/tcp_send.c
82366 +++ b/net/rds/tcp_send.c
82367 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
82368
82369 oldfs = get_fs();
82370 set_fs(KERNEL_DS);
82371 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
82372 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
82373 sizeof(val));
82374 set_fs(oldfs);
82375 }
82376 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
82377 index 05996d0..5a1dfe0 100644
82378 --- a/net/rxrpc/af_rxrpc.c
82379 +++ b/net/rxrpc/af_rxrpc.c
82380 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
82381 __be32 rxrpc_epoch;
82382
82383 /* current debugging ID */
82384 -atomic_t rxrpc_debug_id;
82385 +atomic_unchecked_t rxrpc_debug_id;
82386
82387 /* count of skbs currently in use */
82388 atomic_t rxrpc_n_skbs;
82389 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
82390 index e4d9cbc..b229649 100644
82391 --- a/net/rxrpc/ar-ack.c
82392 +++ b/net/rxrpc/ar-ack.c
82393 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
82394
82395 _enter("{%d,%d,%d,%d},",
82396 call->acks_hard, call->acks_unacked,
82397 - atomic_read(&call->sequence),
82398 + atomic_read_unchecked(&call->sequence),
82399 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
82400
82401 stop = 0;
82402 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
82403
82404 /* each Tx packet has a new serial number */
82405 sp->hdr.serial =
82406 - htonl(atomic_inc_return(&call->conn->serial));
82407 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
82408
82409 hdr = (struct rxrpc_header *) txb->head;
82410 hdr->serial = sp->hdr.serial;
82411 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
82412 */
82413 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
82414 {
82415 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
82416 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
82417 }
82418
82419 /*
82420 @@ -629,7 +629,7 @@ process_further:
82421
82422 latest = ntohl(sp->hdr.serial);
82423 hard = ntohl(ack.firstPacket);
82424 - tx = atomic_read(&call->sequence);
82425 + tx = atomic_read_unchecked(&call->sequence);
82426
82427 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
82428 latest,
82429 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
82430 goto maybe_reschedule;
82431
82432 send_ACK_with_skew:
82433 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
82434 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
82435 ntohl(ack.serial));
82436 send_ACK:
82437 mtu = call->conn->trans->peer->if_mtu;
82438 @@ -1173,7 +1173,7 @@ send_ACK:
82439 ackinfo.rxMTU = htonl(5692);
82440 ackinfo.jumbo_max = htonl(4);
82441
82442 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
82443 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
82444 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
82445 ntohl(hdr.serial),
82446 ntohs(ack.maxSkew),
82447 @@ -1191,7 +1191,7 @@ send_ACK:
82448 send_message:
82449 _debug("send message");
82450
82451 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
82452 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
82453 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
82454 send_message_2:
82455
82456 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
82457 index a3bbb36..3341fb9 100644
82458 --- a/net/rxrpc/ar-call.c
82459 +++ b/net/rxrpc/ar-call.c
82460 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
82461 spin_lock_init(&call->lock);
82462 rwlock_init(&call->state_lock);
82463 atomic_set(&call->usage, 1);
82464 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
82465 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82466 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
82467
82468 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
82469 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
82470 index 4106ca9..a338d7a 100644
82471 --- a/net/rxrpc/ar-connection.c
82472 +++ b/net/rxrpc/ar-connection.c
82473 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
82474 rwlock_init(&conn->lock);
82475 spin_lock_init(&conn->state_lock);
82476 atomic_set(&conn->usage, 1);
82477 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
82478 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82479 conn->avail_calls = RXRPC_MAXCALLS;
82480 conn->size_align = 4;
82481 conn->header_size = sizeof(struct rxrpc_header);
82482 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
82483 index e7ed43a..6afa140 100644
82484 --- a/net/rxrpc/ar-connevent.c
82485 +++ b/net/rxrpc/ar-connevent.c
82486 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
82487
82488 len = iov[0].iov_len + iov[1].iov_len;
82489
82490 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
82491 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82492 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
82493
82494 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
82495 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
82496 index 529572f..c758ca7 100644
82497 --- a/net/rxrpc/ar-input.c
82498 +++ b/net/rxrpc/ar-input.c
82499 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
82500 /* track the latest serial number on this connection for ACK packet
82501 * information */
82502 serial = ntohl(sp->hdr.serial);
82503 - hi_serial = atomic_read(&call->conn->hi_serial);
82504 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
82505 while (serial > hi_serial)
82506 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
82507 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
82508 serial);
82509
82510 /* request ACK generation for any ACK or DATA packet that requests
82511 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
82512 index a693aca..81e7293 100644
82513 --- a/net/rxrpc/ar-internal.h
82514 +++ b/net/rxrpc/ar-internal.h
82515 @@ -272,8 +272,8 @@ struct rxrpc_connection {
82516 int error; /* error code for local abort */
82517 int debug_id; /* debug ID for printks */
82518 unsigned int call_counter; /* call ID counter */
82519 - atomic_t serial; /* packet serial number counter */
82520 - atomic_t hi_serial; /* highest serial number received */
82521 + atomic_unchecked_t serial; /* packet serial number counter */
82522 + atomic_unchecked_t hi_serial; /* highest serial number received */
82523 u8 avail_calls; /* number of calls available */
82524 u8 size_align; /* data size alignment (for security) */
82525 u8 header_size; /* rxrpc + security header size */
82526 @@ -346,7 +346,7 @@ struct rxrpc_call {
82527 spinlock_t lock;
82528 rwlock_t state_lock; /* lock for state transition */
82529 atomic_t usage;
82530 - atomic_t sequence; /* Tx data packet sequence counter */
82531 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
82532 u32 abort_code; /* local/remote abort code */
82533 enum { /* current state of call */
82534 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
82535 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
82536 */
82537 extern atomic_t rxrpc_n_skbs;
82538 extern __be32 rxrpc_epoch;
82539 -extern atomic_t rxrpc_debug_id;
82540 +extern atomic_unchecked_t rxrpc_debug_id;
82541 extern struct workqueue_struct *rxrpc_workqueue;
82542
82543 /*
82544 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
82545 index 87f7135..74d3703 100644
82546 --- a/net/rxrpc/ar-local.c
82547 +++ b/net/rxrpc/ar-local.c
82548 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
82549 spin_lock_init(&local->lock);
82550 rwlock_init(&local->services_lock);
82551 atomic_set(&local->usage, 1);
82552 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
82553 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82554 memcpy(&local->srx, srx, sizeof(*srx));
82555 }
82556
82557 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
82558 index e1ac183..b43e10e 100644
82559 --- a/net/rxrpc/ar-output.c
82560 +++ b/net/rxrpc/ar-output.c
82561 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
82562 sp->hdr.cid = call->cid;
82563 sp->hdr.callNumber = call->call_id;
82564 sp->hdr.seq =
82565 - htonl(atomic_inc_return(&call->sequence));
82566 + htonl(atomic_inc_return_unchecked(&call->sequence));
82567 sp->hdr.serial =
82568 - htonl(atomic_inc_return(&conn->serial));
82569 + htonl(atomic_inc_return_unchecked(&conn->serial));
82570 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
82571 sp->hdr.userStatus = 0;
82572 sp->hdr.securityIndex = conn->security_ix;
82573 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
82574 index bebaa43..2644591 100644
82575 --- a/net/rxrpc/ar-peer.c
82576 +++ b/net/rxrpc/ar-peer.c
82577 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
82578 INIT_LIST_HEAD(&peer->error_targets);
82579 spin_lock_init(&peer->lock);
82580 atomic_set(&peer->usage, 1);
82581 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
82582 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82583 memcpy(&peer->srx, srx, sizeof(*srx));
82584
82585 rxrpc_assess_MTU_size(peer);
82586 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
82587 index 38047f7..9f48511 100644
82588 --- a/net/rxrpc/ar-proc.c
82589 +++ b/net/rxrpc/ar-proc.c
82590 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
82591 atomic_read(&conn->usage),
82592 rxrpc_conn_states[conn->state],
82593 key_serial(conn->key),
82594 - atomic_read(&conn->serial),
82595 - atomic_read(&conn->hi_serial));
82596 + atomic_read_unchecked(&conn->serial),
82597 + atomic_read_unchecked(&conn->hi_serial));
82598
82599 return 0;
82600 }
82601 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
82602 index 92df566..87ec1bf 100644
82603 --- a/net/rxrpc/ar-transport.c
82604 +++ b/net/rxrpc/ar-transport.c
82605 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
82606 spin_lock_init(&trans->client_lock);
82607 rwlock_init(&trans->conn_lock);
82608 atomic_set(&trans->usage, 1);
82609 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
82610 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82611
82612 if (peer->srx.transport.family == AF_INET) {
82613 switch (peer->srx.transport_type) {
82614 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
82615 index f226709..0e735a8 100644
82616 --- a/net/rxrpc/rxkad.c
82617 +++ b/net/rxrpc/rxkad.c
82618 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
82619
82620 len = iov[0].iov_len + iov[1].iov_len;
82621
82622 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
82623 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82624 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
82625
82626 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
82627 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
82628
82629 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
82630
82631 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
82632 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82633 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
82634
82635 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
82636 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
82637 index 391a245..8f6a898 100644
82638 --- a/net/sctp/ipv6.c
82639 +++ b/net/sctp/ipv6.c
82640 @@ -1038,7 +1038,7 @@ void sctp_v6_pf_init(void)
82641
82642 void sctp_v6_pf_exit(void)
82643 {
82644 - list_del(&sctp_af_inet6.list);
82645 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
82646 }
82647
82648 /* Initialize IPv6 support and register with socket layer. */
82649 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
82650 index 8c19e97..16264b8 100644
82651 --- a/net/sctp/proc.c
82652 +++ b/net/sctp/proc.c
82653 @@ -338,7 +338,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
82654 seq_printf(seq,
82655 "%8pK %8pK %-3d %-3d %-2d %-4d "
82656 "%4d %8d %8d %7d %5lu %-5d %5d ",
82657 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
82658 + assoc, sk,
82659 + sctp_sk(sk)->type, sk->sk_state,
82660 assoc->state, hash,
82661 assoc->assoc_id,
82662 assoc->sndbuf_used,
82663 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
82664 index f898b1c..60bf8f2 100644
82665 --- a/net/sctp/protocol.c
82666 +++ b/net/sctp/protocol.c
82667 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
82668 return 0;
82669 }
82670
82671 - INIT_LIST_HEAD(&af->list);
82672 - list_add_tail(&af->list, &sctp_address_families);
82673 + pax_open_kernel();
82674 + INIT_LIST_HEAD((struct list_head *)&af->list);
82675 + pax_close_kernel();
82676 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
82677 return 1;
82678 }
82679
82680 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
82681
82682 static void sctp_v4_pf_exit(void)
82683 {
82684 - list_del(&sctp_af_inet.list);
82685 + pax_list_del((struct list_head *)&sctp_af_inet.list);
82686 }
82687
82688 static int sctp_v4_protosw_init(void)
82689 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
82690 index cedd9bf..b1fddeb 100644
82691 --- a/net/sctp/socket.c
82692 +++ b/net/sctp/socket.c
82693 @@ -4665,6 +4665,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
82694 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
82695 if (space_left < addrlen)
82696 return -ENOMEM;
82697 + if (addrlen > sizeof(temp) || addrlen < 0)
82698 + return -EFAULT;
82699 if (copy_to_user(to, &temp, addrlen))
82700 return -EFAULT;
82701 to += addrlen;
82702 diff --git a/net/socket.c b/net/socket.c
82703 index 2ca51c7..45d0b31 100644
82704 --- a/net/socket.c
82705 +++ b/net/socket.c
82706 @@ -89,6 +89,7 @@
82707 #include <linux/magic.h>
82708 #include <linux/slab.h>
82709 #include <linux/xattr.h>
82710 +#include <linux/in.h>
82711
82712 #include <asm/uaccess.h>
82713 #include <asm/unistd.h>
82714 @@ -106,6 +107,8 @@
82715 #include <linux/sockios.h>
82716 #include <linux/atalk.h>
82717
82718 +#include <linux/grsock.h>
82719 +
82720 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
82721 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
82722 unsigned long nr_segs, loff_t pos);
82723 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
82724 &sockfs_dentry_operations, SOCKFS_MAGIC);
82725 }
82726
82727 -static struct vfsmount *sock_mnt __read_mostly;
82728 +struct vfsmount *sock_mnt __read_mostly;
82729
82730 static struct file_system_type sock_fs_type = {
82731 .name = "sockfs",
82732 @@ -1270,6 +1273,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
82733 return -EAFNOSUPPORT;
82734 if (type < 0 || type >= SOCK_MAX)
82735 return -EINVAL;
82736 + if (protocol < 0)
82737 + return -EINVAL;
82738
82739 /* Compatibility.
82740
82741 @@ -1401,6 +1406,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
82742 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
82743 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
82744
82745 + if(!gr_search_socket(family, type, protocol)) {
82746 + retval = -EACCES;
82747 + goto out;
82748 + }
82749 +
82750 + if (gr_handle_sock_all(family, type, protocol)) {
82751 + retval = -EACCES;
82752 + goto out;
82753 + }
82754 +
82755 retval = sock_create(family, type, protocol, &sock);
82756 if (retval < 0)
82757 goto out;
82758 @@ -1528,6 +1543,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
82759 if (sock) {
82760 err = move_addr_to_kernel(umyaddr, addrlen, &address);
82761 if (err >= 0) {
82762 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
82763 + err = -EACCES;
82764 + goto error;
82765 + }
82766 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
82767 + if (err)
82768 + goto error;
82769 +
82770 err = security_socket_bind(sock,
82771 (struct sockaddr *)&address,
82772 addrlen);
82773 @@ -1536,6 +1559,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
82774 (struct sockaddr *)
82775 &address, addrlen);
82776 }
82777 +error:
82778 fput_light(sock->file, fput_needed);
82779 }
82780 return err;
82781 @@ -1559,10 +1583,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
82782 if ((unsigned int)backlog > somaxconn)
82783 backlog = somaxconn;
82784
82785 + if (gr_handle_sock_server_other(sock->sk)) {
82786 + err = -EPERM;
82787 + goto error;
82788 + }
82789 +
82790 + err = gr_search_listen(sock);
82791 + if (err)
82792 + goto error;
82793 +
82794 err = security_socket_listen(sock, backlog);
82795 if (!err)
82796 err = sock->ops->listen(sock, backlog);
82797
82798 +error:
82799 fput_light(sock->file, fput_needed);
82800 }
82801 return err;
82802 @@ -1606,6 +1640,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82803 newsock->type = sock->type;
82804 newsock->ops = sock->ops;
82805
82806 + if (gr_handle_sock_server_other(sock->sk)) {
82807 + err = -EPERM;
82808 + sock_release(newsock);
82809 + goto out_put;
82810 + }
82811 +
82812 + err = gr_search_accept(sock);
82813 + if (err) {
82814 + sock_release(newsock);
82815 + goto out_put;
82816 + }
82817 +
82818 /*
82819 * We don't need try_module_get here, as the listening socket (sock)
82820 * has the protocol module (sock->ops->owner) held.
82821 @@ -1651,6 +1697,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82822 fd_install(newfd, newfile);
82823 err = newfd;
82824
82825 + gr_attach_curr_ip(newsock->sk);
82826 +
82827 out_put:
82828 fput_light(sock->file, fput_needed);
82829 out:
82830 @@ -1683,6 +1731,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82831 int, addrlen)
82832 {
82833 struct socket *sock;
82834 + struct sockaddr *sck;
82835 struct sockaddr_storage address;
82836 int err, fput_needed;
82837
82838 @@ -1693,6 +1742,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82839 if (err < 0)
82840 goto out_put;
82841
82842 + sck = (struct sockaddr *)&address;
82843 +
82844 + if (gr_handle_sock_client(sck)) {
82845 + err = -EACCES;
82846 + goto out_put;
82847 + }
82848 +
82849 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
82850 + if (err)
82851 + goto out_put;
82852 +
82853 err =
82854 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
82855 if (err)
82856 @@ -2047,7 +2107,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
82857 * checking falls down on this.
82858 */
82859 if (copy_from_user(ctl_buf,
82860 - (void __user __force *)msg_sys->msg_control,
82861 + (void __force_user *)msg_sys->msg_control,
82862 ctl_len))
82863 goto out_freectl;
82864 msg_sys->msg_control = ctl_buf;
82865 @@ -2215,7 +2275,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
82866 * kernel msghdr to use the kernel address space)
82867 */
82868
82869 - uaddr = (__force void __user *)msg_sys->msg_name;
82870 + uaddr = (void __force_user *)msg_sys->msg_name;
82871 uaddr_len = COMPAT_NAMELEN(msg);
82872 if (MSG_CMSG_COMPAT & flags) {
82873 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
82874 @@ -2838,7 +2898,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82875 }
82876
82877 ifr = compat_alloc_user_space(buf_size);
82878 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
82879 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
82880
82881 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
82882 return -EFAULT;
82883 @@ -2862,12 +2922,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82884 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
82885
82886 if (copy_in_user(rxnfc, compat_rxnfc,
82887 - (void *)(&rxnfc->fs.m_ext + 1) -
82888 - (void *)rxnfc) ||
82889 + (void __user *)(&rxnfc->fs.m_ext + 1) -
82890 + (void __user *)rxnfc) ||
82891 copy_in_user(&rxnfc->fs.ring_cookie,
82892 &compat_rxnfc->fs.ring_cookie,
82893 - (void *)(&rxnfc->fs.location + 1) -
82894 - (void *)&rxnfc->fs.ring_cookie) ||
82895 + (void __user *)(&rxnfc->fs.location + 1) -
82896 + (void __user *)&rxnfc->fs.ring_cookie) ||
82897 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
82898 sizeof(rxnfc->rule_cnt)))
82899 return -EFAULT;
82900 @@ -2879,12 +2939,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82901
82902 if (convert_out) {
82903 if (copy_in_user(compat_rxnfc, rxnfc,
82904 - (const void *)(&rxnfc->fs.m_ext + 1) -
82905 - (const void *)rxnfc) ||
82906 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
82907 + (const void __user *)rxnfc) ||
82908 copy_in_user(&compat_rxnfc->fs.ring_cookie,
82909 &rxnfc->fs.ring_cookie,
82910 - (const void *)(&rxnfc->fs.location + 1) -
82911 - (const void *)&rxnfc->fs.ring_cookie) ||
82912 + (const void __user *)(&rxnfc->fs.location + 1) -
82913 + (const void __user *)&rxnfc->fs.ring_cookie) ||
82914 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
82915 sizeof(rxnfc->rule_cnt)))
82916 return -EFAULT;
82917 @@ -2954,7 +3014,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
82918 old_fs = get_fs();
82919 set_fs(KERNEL_DS);
82920 err = dev_ioctl(net, cmd,
82921 - (struct ifreq __user __force *) &kifr);
82922 + (struct ifreq __force_user *) &kifr);
82923 set_fs(old_fs);
82924
82925 return err;
82926 @@ -3063,7 +3123,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
82927
82928 old_fs = get_fs();
82929 set_fs(KERNEL_DS);
82930 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
82931 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
82932 set_fs(old_fs);
82933
82934 if (cmd == SIOCGIFMAP && !err) {
82935 @@ -3168,7 +3228,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
82936 ret |= __get_user(rtdev, &(ur4->rt_dev));
82937 if (rtdev) {
82938 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
82939 - r4.rt_dev = (char __user __force *)devname;
82940 + r4.rt_dev = (char __force_user *)devname;
82941 devname[15] = 0;
82942 } else
82943 r4.rt_dev = NULL;
82944 @@ -3394,8 +3454,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
82945 int __user *uoptlen;
82946 int err;
82947
82948 - uoptval = (char __user __force *) optval;
82949 - uoptlen = (int __user __force *) optlen;
82950 + uoptval = (char __force_user *) optval;
82951 + uoptlen = (int __force_user *) optlen;
82952
82953 set_fs(KERNEL_DS);
82954 if (level == SOL_SOCKET)
82955 @@ -3415,7 +3475,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
82956 char __user *uoptval;
82957 int err;
82958
82959 - uoptval = (char __user __force *) optval;
82960 + uoptval = (char __force_user *) optval;
82961
82962 set_fs(KERNEL_DS);
82963 if (level == SOL_SOCKET)
82964 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
82965 index fb20f25..e3ba316 100644
82966 --- a/net/sunrpc/sched.c
82967 +++ b/net/sunrpc/sched.c
82968 @@ -259,9 +259,9 @@ static int rpc_wait_bit_killable(void *word)
82969 #ifdef RPC_DEBUG
82970 static void rpc_task_set_debuginfo(struct rpc_task *task)
82971 {
82972 - static atomic_t rpc_pid;
82973 + static atomic_unchecked_t rpc_pid;
82974
82975 - task->tk_pid = atomic_inc_return(&rpc_pid);
82976 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
82977 }
82978 #else
82979 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
82980 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
82981 index 8343737..677025e 100644
82982 --- a/net/sunrpc/xprtrdma/svc_rdma.c
82983 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
82984 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
82985 static unsigned int min_max_inline = 4096;
82986 static unsigned int max_max_inline = 65536;
82987
82988 -atomic_t rdma_stat_recv;
82989 -atomic_t rdma_stat_read;
82990 -atomic_t rdma_stat_write;
82991 -atomic_t rdma_stat_sq_starve;
82992 -atomic_t rdma_stat_rq_starve;
82993 -atomic_t rdma_stat_rq_poll;
82994 -atomic_t rdma_stat_rq_prod;
82995 -atomic_t rdma_stat_sq_poll;
82996 -atomic_t rdma_stat_sq_prod;
82997 +atomic_unchecked_t rdma_stat_recv;
82998 +atomic_unchecked_t rdma_stat_read;
82999 +atomic_unchecked_t rdma_stat_write;
83000 +atomic_unchecked_t rdma_stat_sq_starve;
83001 +atomic_unchecked_t rdma_stat_rq_starve;
83002 +atomic_unchecked_t rdma_stat_rq_poll;
83003 +atomic_unchecked_t rdma_stat_rq_prod;
83004 +atomic_unchecked_t rdma_stat_sq_poll;
83005 +atomic_unchecked_t rdma_stat_sq_prod;
83006
83007 /* Temporary NFS request map and context caches */
83008 struct kmem_cache *svc_rdma_map_cachep;
83009 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
83010 len -= *ppos;
83011 if (len > *lenp)
83012 len = *lenp;
83013 - if (len && copy_to_user(buffer, str_buf, len))
83014 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
83015 return -EFAULT;
83016 *lenp = len;
83017 *ppos += len;
83018 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
83019 {
83020 .procname = "rdma_stat_read",
83021 .data = &rdma_stat_read,
83022 - .maxlen = sizeof(atomic_t),
83023 + .maxlen = sizeof(atomic_unchecked_t),
83024 .mode = 0644,
83025 .proc_handler = read_reset_stat,
83026 },
83027 {
83028 .procname = "rdma_stat_recv",
83029 .data = &rdma_stat_recv,
83030 - .maxlen = sizeof(atomic_t),
83031 + .maxlen = sizeof(atomic_unchecked_t),
83032 .mode = 0644,
83033 .proc_handler = read_reset_stat,
83034 },
83035 {
83036 .procname = "rdma_stat_write",
83037 .data = &rdma_stat_write,
83038 - .maxlen = sizeof(atomic_t),
83039 + .maxlen = sizeof(atomic_unchecked_t),
83040 .mode = 0644,
83041 .proc_handler = read_reset_stat,
83042 },
83043 {
83044 .procname = "rdma_stat_sq_starve",
83045 .data = &rdma_stat_sq_starve,
83046 - .maxlen = sizeof(atomic_t),
83047 + .maxlen = sizeof(atomic_unchecked_t),
83048 .mode = 0644,
83049 .proc_handler = read_reset_stat,
83050 },
83051 {
83052 .procname = "rdma_stat_rq_starve",
83053 .data = &rdma_stat_rq_starve,
83054 - .maxlen = sizeof(atomic_t),
83055 + .maxlen = sizeof(atomic_unchecked_t),
83056 .mode = 0644,
83057 .proc_handler = read_reset_stat,
83058 },
83059 {
83060 .procname = "rdma_stat_rq_poll",
83061 .data = &rdma_stat_rq_poll,
83062 - .maxlen = sizeof(atomic_t),
83063 + .maxlen = sizeof(atomic_unchecked_t),
83064 .mode = 0644,
83065 .proc_handler = read_reset_stat,
83066 },
83067 {
83068 .procname = "rdma_stat_rq_prod",
83069 .data = &rdma_stat_rq_prod,
83070 - .maxlen = sizeof(atomic_t),
83071 + .maxlen = sizeof(atomic_unchecked_t),
83072 .mode = 0644,
83073 .proc_handler = read_reset_stat,
83074 },
83075 {
83076 .procname = "rdma_stat_sq_poll",
83077 .data = &rdma_stat_sq_poll,
83078 - .maxlen = sizeof(atomic_t),
83079 + .maxlen = sizeof(atomic_unchecked_t),
83080 .mode = 0644,
83081 .proc_handler = read_reset_stat,
83082 },
83083 {
83084 .procname = "rdma_stat_sq_prod",
83085 .data = &rdma_stat_sq_prod,
83086 - .maxlen = sizeof(atomic_t),
83087 + .maxlen = sizeof(atomic_unchecked_t),
83088 .mode = 0644,
83089 .proc_handler = read_reset_stat,
83090 },
83091 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83092 index 0ce7552..d074459 100644
83093 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83094 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83095 @@ -501,7 +501,7 @@ next_sge:
83096 svc_rdma_put_context(ctxt, 0);
83097 goto out;
83098 }
83099 - atomic_inc(&rdma_stat_read);
83100 + atomic_inc_unchecked(&rdma_stat_read);
83101
83102 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
83103 chl_map->ch[ch_no].count -= read_wr.num_sge;
83104 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
83105 dto_q);
83106 list_del_init(&ctxt->dto_q);
83107 } else {
83108 - atomic_inc(&rdma_stat_rq_starve);
83109 + atomic_inc_unchecked(&rdma_stat_rq_starve);
83110 clear_bit(XPT_DATA, &xprt->xpt_flags);
83111 ctxt = NULL;
83112 }
83113 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
83114 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
83115 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
83116 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
83117 - atomic_inc(&rdma_stat_recv);
83118 + atomic_inc_unchecked(&rdma_stat_recv);
83119
83120 /* Build up the XDR from the receive buffers. */
83121 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
83122 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83123 index c1d124d..acfc59e 100644
83124 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83125 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83126 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
83127 write_wr.wr.rdma.remote_addr = to;
83128
83129 /* Post It */
83130 - atomic_inc(&rdma_stat_write);
83131 + atomic_inc_unchecked(&rdma_stat_write);
83132 if (svc_rdma_send(xprt, &write_wr))
83133 goto err;
83134 return 0;
83135 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
83136 index 62e4f9b..dd3f2d7 100644
83137 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
83138 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
83139 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
83140 return;
83141
83142 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
83143 - atomic_inc(&rdma_stat_rq_poll);
83144 + atomic_inc_unchecked(&rdma_stat_rq_poll);
83145
83146 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
83147 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
83148 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
83149 }
83150
83151 if (ctxt)
83152 - atomic_inc(&rdma_stat_rq_prod);
83153 + atomic_inc_unchecked(&rdma_stat_rq_prod);
83154
83155 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
83156 /*
83157 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
83158 return;
83159
83160 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
83161 - atomic_inc(&rdma_stat_sq_poll);
83162 + atomic_inc_unchecked(&rdma_stat_sq_poll);
83163 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
83164 if (wc.status != IB_WC_SUCCESS)
83165 /* Close the transport */
83166 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
83167 }
83168
83169 if (ctxt)
83170 - atomic_inc(&rdma_stat_sq_prod);
83171 + atomic_inc_unchecked(&rdma_stat_sq_prod);
83172 }
83173
83174 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
83175 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
83176 spin_lock_bh(&xprt->sc_lock);
83177 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
83178 spin_unlock_bh(&xprt->sc_lock);
83179 - atomic_inc(&rdma_stat_sq_starve);
83180 + atomic_inc_unchecked(&rdma_stat_sq_starve);
83181
83182 /* See if we can opportunistically reap SQ WR to make room */
83183 sq_cq_reap(xprt);
83184 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
83185 index 9bc6db0..47ac8c0 100644
83186 --- a/net/sysctl_net.c
83187 +++ b/net/sysctl_net.c
83188 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
83189 kgid_t root_gid = make_kgid(net->user_ns, 0);
83190
83191 /* Allow network administrator to have same access as root. */
83192 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
83193 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
83194 uid_eq(root_uid, current_uid())) {
83195 int mode = (table->mode >> 6) & 7;
83196 return (mode << 6) | (mode << 3) | mode;
83197 diff --git a/net/tipc/link.c b/net/tipc/link.c
83198 index daa6080..02d357f 100644
83199 --- a/net/tipc/link.c
83200 +++ b/net/tipc/link.c
83201 @@ -1201,7 +1201,7 @@ static int link_send_sections_long(struct tipc_port *sender,
83202 struct tipc_msg fragm_hdr;
83203 struct sk_buff *buf, *buf_chain, *prev;
83204 u32 fragm_crs, fragm_rest, hsz, sect_rest;
83205 - const unchar *sect_crs;
83206 + const unchar __user *sect_crs;
83207 int curr_sect;
83208 u32 fragm_no;
83209
83210 @@ -1242,7 +1242,7 @@ again:
83211
83212 if (!sect_rest) {
83213 sect_rest = msg_sect[++curr_sect].iov_len;
83214 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
83215 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
83216 }
83217
83218 if (sect_rest < fragm_rest)
83219 @@ -1261,7 +1261,7 @@ error:
83220 }
83221 } else
83222 skb_copy_to_linear_data_offset(buf, fragm_crs,
83223 - sect_crs, sz);
83224 + (const void __force_kernel *)sect_crs, sz);
83225 sect_crs += sz;
83226 sect_rest -= sz;
83227 fragm_crs += sz;
83228 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
83229 index f2db8a8..9245aa4 100644
83230 --- a/net/tipc/msg.c
83231 +++ b/net/tipc/msg.c
83232 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
83233 msg_sect[cnt].iov_len);
83234 else
83235 skb_copy_to_linear_data_offset(*buf, pos,
83236 - msg_sect[cnt].iov_base,
83237 + (const void __force_kernel *)msg_sect[cnt].iov_base,
83238 msg_sect[cnt].iov_len);
83239 pos += msg_sect[cnt].iov_len;
83240 }
83241 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
83242 index 6b42d47..2ac24d5 100644
83243 --- a/net/tipc/subscr.c
83244 +++ b/net/tipc/subscr.c
83245 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
83246 {
83247 struct iovec msg_sect;
83248
83249 - msg_sect.iov_base = (void *)&sub->evt;
83250 + msg_sect.iov_base = (void __force_user *)&sub->evt;
83251 msg_sect.iov_len = sizeof(struct tipc_event);
83252
83253 sub->evt.event = htohl(event, sub->swap);
83254 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
83255 index 5b5c876..3127bf7 100644
83256 --- a/net/unix/af_unix.c
83257 +++ b/net/unix/af_unix.c
83258 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
83259 err = -ECONNREFUSED;
83260 if (!S_ISSOCK(inode->i_mode))
83261 goto put_fail;
83262 +
83263 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
83264 + err = -EACCES;
83265 + goto put_fail;
83266 + }
83267 +
83268 u = unix_find_socket_byinode(inode);
83269 if (!u)
83270 goto put_fail;
83271 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
83272 if (u) {
83273 struct dentry *dentry;
83274 dentry = unix_sk(u)->path.dentry;
83275 +
83276 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
83277 + err = -EPERM;
83278 + sock_put(u);
83279 + goto fail;
83280 + }
83281 +
83282 if (dentry)
83283 touch_atime(&unix_sk(u)->path);
83284 } else
83285 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
83286 */
83287 err = security_path_mknod(&path, dentry, mode, 0);
83288 if (!err) {
83289 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
83290 + err = -EACCES;
83291 + goto out;
83292 + }
83293 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
83294 if (!err) {
83295 res->mnt = mntget(path.mnt);
83296 res->dentry = dget(dentry);
83297 + gr_handle_create(dentry, path.mnt);
83298 }
83299 }
83300 +out:
83301 done_path_create(&path, dentry);
83302 return err;
83303 }
83304 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
83305 index c8717c1..08539f5 100644
83306 --- a/net/wireless/wext-core.c
83307 +++ b/net/wireless/wext-core.c
83308 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
83309 */
83310
83311 /* Support for very large requests */
83312 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
83313 - (user_length > descr->max_tokens)) {
83314 + if (user_length > descr->max_tokens) {
83315 /* Allow userspace to GET more than max so
83316 * we can support any size GET requests.
83317 * There is still a limit : -ENOMEM.
83318 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
83319 }
83320 }
83321
83322 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
83323 - /*
83324 - * If this is a GET, but not NOMAX, it means that the extra
83325 - * data is not bounded by userspace, but by max_tokens. Thus
83326 - * set the length to max_tokens. This matches the extra data
83327 - * allocation.
83328 - * The driver should fill it with the number of tokens it
83329 - * provided, and it may check iwp->length rather than having
83330 - * knowledge of max_tokens. If the driver doesn't change the
83331 - * iwp->length, this ioctl just copies back max_token tokens
83332 - * filled with zeroes. Hopefully the driver isn't claiming
83333 - * them to be valid data.
83334 - */
83335 - iwp->length = descr->max_tokens;
83336 - }
83337 -
83338 err = handler(dev, info, (union iwreq_data *) iwp, extra);
83339
83340 iwp->length += essid_compat;
83341 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
83342 index 07c5857..edc6dc0 100644
83343 --- a/net/xfrm/xfrm_policy.c
83344 +++ b/net/xfrm/xfrm_policy.c
83345 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
83346 {
83347 policy->walk.dead = 1;
83348
83349 - atomic_inc(&policy->genid);
83350 + atomic_inc_unchecked(&policy->genid);
83351
83352 if (del_timer(&policy->timer))
83353 xfrm_pol_put(policy);
83354 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
83355 hlist_add_head(&policy->bydst, chain);
83356 xfrm_pol_hold(policy);
83357 net->xfrm.policy_count[dir]++;
83358 - atomic_inc(&flow_cache_genid);
83359 + atomic_inc_unchecked(&flow_cache_genid);
83360 rt_genid_bump(net);
83361 if (delpol)
83362 __xfrm_policy_unlink(delpol, dir);
83363 @@ -1550,7 +1550,7 @@ free_dst:
83364 goto out;
83365 }
83366
83367 -static int inline
83368 +static inline int
83369 xfrm_dst_alloc_copy(void **target, const void *src, int size)
83370 {
83371 if (!*target) {
83372 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
83373 return 0;
83374 }
83375
83376 -static int inline
83377 +static inline int
83378 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
83379 {
83380 #ifdef CONFIG_XFRM_SUB_POLICY
83381 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
83382 #endif
83383 }
83384
83385 -static int inline
83386 +static inline int
83387 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
83388 {
83389 #ifdef CONFIG_XFRM_SUB_POLICY
83390 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
83391
83392 xdst->num_pols = num_pols;
83393 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
83394 - xdst->policy_genid = atomic_read(&pols[0]->genid);
83395 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
83396
83397 return xdst;
83398 }
83399 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
83400 if (xdst->xfrm_genid != dst->xfrm->genid)
83401 return 0;
83402 if (xdst->num_pols > 0 &&
83403 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
83404 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
83405 return 0;
83406
83407 mtu = dst_mtu(dst->child);
83408 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
83409 sizeof(pol->xfrm_vec[i].saddr));
83410 pol->xfrm_vec[i].encap_family = mp->new_family;
83411 /* flush bundles */
83412 - atomic_inc(&pol->genid);
83413 + atomic_inc_unchecked(&pol->genid);
83414 }
83415 }
83416
83417 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
83418 index 3459692..eefb515 100644
83419 --- a/net/xfrm/xfrm_state.c
83420 +++ b/net/xfrm/xfrm_state.c
83421 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
83422 if (!try_module_get(afinfo->owner))
83423 goto out;
83424
83425 - mode->afinfo = afinfo;
83426 + pax_open_kernel();
83427 + *(void **)&mode->afinfo = afinfo;
83428 + pax_close_kernel();
83429 modemap[mode->encap] = mode;
83430 err = 0;
83431
83432 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
83433 index 0e801c3..5c8ad3b 100644
83434 --- a/scripts/Makefile.build
83435 +++ b/scripts/Makefile.build
83436 @@ -111,7 +111,7 @@ endif
83437 endif
83438
83439 # Do not include host rules unless needed
83440 -ifneq ($(hostprogs-y)$(hostprogs-m),)
83441 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
83442 include scripts/Makefile.host
83443 endif
83444
83445 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
83446 index 686cb0d..9d653bf 100644
83447 --- a/scripts/Makefile.clean
83448 +++ b/scripts/Makefile.clean
83449 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
83450 __clean-files := $(extra-y) $(always) \
83451 $(targets) $(clean-files) \
83452 $(host-progs) \
83453 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
83454 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
83455 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
83456
83457 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
83458
83459 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
83460 index 1ac414f..38575f7 100644
83461 --- a/scripts/Makefile.host
83462 +++ b/scripts/Makefile.host
83463 @@ -31,6 +31,8 @@
83464 # Note: Shared libraries consisting of C++ files are not supported
83465
83466 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
83467 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
83468 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
83469
83470 # C code
83471 # Executables compiled from a single .c file
83472 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
83473 # Shared libaries (only .c supported)
83474 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
83475 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
83476 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
83477 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
83478 # Remove .so files from "xxx-objs"
83479 host-cobjs := $(filter-out %.so,$(host-cobjs))
83480 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
83481
83482 -#Object (.o) files used by the shared libaries
83483 +# Object (.o) files used by the shared libaries
83484 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
83485 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
83486
83487 # output directory for programs/.o files
83488 # hostprogs-y := tools/build may have been specified. Retrieve directory
83489 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
83490 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
83491 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
83492 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
83493 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
83494 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
83495 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
83496 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
83497
83498 obj-dirs += $(host-objdirs)
83499 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
83500 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
83501 $(call if_changed_dep,host-cshobjs)
83502
83503 +# Compile .c file, create position independent .o file
83504 +# host-cxxshobjs -> .o
83505 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
83506 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
83507 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
83508 + $(call if_changed_dep,host-cxxshobjs)
83509 +
83510 # Link a shared library, based on position independent .o files
83511 # *.o -> .so shared library (host-cshlib)
83512 quiet_cmd_host-cshlib = HOSTLLD -shared $@
83513 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
83514 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
83515 $(call if_changed,host-cshlib)
83516
83517 +# Link a shared library, based on position independent .o files
83518 +# *.o -> .so shared library (host-cxxshlib)
83519 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
83520 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
83521 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
83522 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
83523 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
83524 + $(call if_changed,host-cxxshlib)
83525 +
83526 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
83527 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
83528 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
83529
83530 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
83531 index cb1f50c..cef2a7c 100644
83532 --- a/scripts/basic/fixdep.c
83533 +++ b/scripts/basic/fixdep.c
83534 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
83535 /*
83536 * Lookup a value in the configuration string.
83537 */
83538 -static int is_defined_config(const char *name, int len, unsigned int hash)
83539 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
83540 {
83541 struct item *aux;
83542
83543 @@ -211,10 +211,10 @@ static void clear_config(void)
83544 /*
83545 * Record the use of a CONFIG_* word.
83546 */
83547 -static void use_config(const char *m, int slen)
83548 +static void use_config(const char *m, unsigned int slen)
83549 {
83550 unsigned int hash = strhash(m, slen);
83551 - int c, i;
83552 + unsigned int c, i;
83553
83554 if (is_defined_config(m, slen, hash))
83555 return;
83556 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
83557
83558 static void parse_config_file(const char *map, size_t len)
83559 {
83560 - const int *end = (const int *) (map + len);
83561 + const unsigned int *end = (const unsigned int *) (map + len);
83562 /* start at +1, so that p can never be < map */
83563 - const int *m = (const int *) map + 1;
83564 + const unsigned int *m = (const unsigned int *) map + 1;
83565 const char *p, *q;
83566
83567 for (; m < end; m++) {
83568 @@ -406,7 +406,7 @@ static void print_deps(void)
83569 static void traps(void)
83570 {
83571 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
83572 - int *p = (int *)test;
83573 + unsigned int *p = (unsigned int *)test;
83574
83575 if (*p != INT_CONF) {
83576 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
83577 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
83578 new file mode 100644
83579 index 0000000..5e0222d
83580 --- /dev/null
83581 +++ b/scripts/gcc-plugin.sh
83582 @@ -0,0 +1,17 @@
83583 +#!/bin/bash
83584 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
83585 +#include "gcc-plugin.h"
83586 +#include "tree.h"
83587 +#include "tm.h"
83588 +#include "rtl.h"
83589 +#ifdef ENABLE_BUILD_WITH_CXX
83590 +#warning $2
83591 +#else
83592 +#warning $1
83593 +#endif
83594 +EOF`
83595 +if [ $? -eq 0 ]
83596 +then
83597 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
83598 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
83599 +fi
83600 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
83601 index b3d907e..a4782ab 100644
83602 --- a/scripts/link-vmlinux.sh
83603 +++ b/scripts/link-vmlinux.sh
83604 @@ -152,7 +152,7 @@ else
83605 fi;
83606
83607 # final build of init/
83608 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
83609 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
83610
83611 kallsymso=""
83612 kallsyms_vmlinux=""
83613 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
83614 index df4fc23..0ea719d 100644
83615 --- a/scripts/mod/file2alias.c
83616 +++ b/scripts/mod/file2alias.c
83617 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
83618 unsigned long size, unsigned long id_size,
83619 void *symval)
83620 {
83621 - int i;
83622 + unsigned int i;
83623
83624 if (size % id_size || size < id_size) {
83625 if (cross_build != 0)
83626 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
83627 /* USB is special because the bcdDevice can be matched against a numeric range */
83628 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
83629 static void do_usb_entry(struct usb_device_id *id,
83630 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
83631 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
83632 unsigned char range_lo, unsigned char range_hi,
83633 unsigned char max, struct module *mod)
83634 {
83635 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
83636 {
83637 unsigned int devlo, devhi;
83638 unsigned char chi, clo, max;
83639 - int ndigits;
83640 + unsigned int ndigits;
83641
83642 id->match_flags = TO_NATIVE(id->match_flags);
83643 id->idVendor = TO_NATIVE(id->idVendor);
83644 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
83645 for (i = 0; i < count; i++) {
83646 const char *id = (char *)devs[i].id;
83647 char acpi_id[sizeof(devs[0].id)];
83648 - int j;
83649 + unsigned int j;
83650
83651 buf_printf(&mod->dev_table_buf,
83652 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
83653 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
83654
83655 for (j = 0; j < PNP_MAX_DEVICES; j++) {
83656 const char *id = (char *)card->devs[j].id;
83657 - int i2, j2;
83658 + unsigned int i2, j2;
83659 int dup = 0;
83660
83661 if (!id[0])
83662 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
83663 /* add an individual alias for every device entry */
83664 if (!dup) {
83665 char acpi_id[sizeof(card->devs[0].id)];
83666 - int k;
83667 + unsigned int k;
83668
83669 buf_printf(&mod->dev_table_buf,
83670 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
83671 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
83672 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
83673 char *alias)
83674 {
83675 - int i, j;
83676 + unsigned int i, j;
83677
83678 sprintf(alias, "dmi*");
83679
83680 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
83681 index ff36c50..7ab4fa9 100644
83682 --- a/scripts/mod/modpost.c
83683 +++ b/scripts/mod/modpost.c
83684 @@ -929,6 +929,7 @@ enum mismatch {
83685 ANY_INIT_TO_ANY_EXIT,
83686 ANY_EXIT_TO_ANY_INIT,
83687 EXPORT_TO_INIT_EXIT,
83688 + DATA_TO_TEXT
83689 };
83690
83691 struct sectioncheck {
83692 @@ -1043,6 +1044,12 @@ const struct sectioncheck sectioncheck[] = {
83693 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
83694 .mismatch = EXPORT_TO_INIT_EXIT,
83695 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
83696 +},
83697 +/* Do not reference code from writable data */
83698 +{
83699 + .fromsec = { DATA_SECTIONS, NULL },
83700 + .tosec = { TEXT_SECTIONS, NULL },
83701 + .mismatch = DATA_TO_TEXT
83702 }
83703 };
83704
83705 @@ -1165,10 +1172,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
83706 continue;
83707 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
83708 continue;
83709 - if (sym->st_value == addr)
83710 - return sym;
83711 /* Find a symbol nearby - addr are maybe negative */
83712 d = sym->st_value - addr;
83713 + if (d == 0)
83714 + return sym;
83715 if (d < 0)
83716 d = addr - sym->st_value;
83717 if (d < distance) {
83718 @@ -1447,6 +1454,14 @@ static void report_sec_mismatch(const char *modname,
83719 tosym, prl_to, prl_to, tosym);
83720 free(prl_to);
83721 break;
83722 + case DATA_TO_TEXT:
83723 +#if 0
83724 + fprintf(stderr,
83725 + "The %s %s:%s references\n"
83726 + "the %s %s:%s%s\n",
83727 + from, fromsec, fromsym, to, tosec, tosym, to_p);
83728 +#endif
83729 + break;
83730 }
83731 fprintf(stderr, "\n");
83732 }
83733 @@ -1681,7 +1696,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
83734 static void check_sec_ref(struct module *mod, const char *modname,
83735 struct elf_info *elf)
83736 {
83737 - int i;
83738 + unsigned int i;
83739 Elf_Shdr *sechdrs = elf->sechdrs;
83740
83741 /* Walk through all sections */
83742 @@ -1779,7 +1794,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
83743 va_end(ap);
83744 }
83745
83746 -void buf_write(struct buffer *buf, const char *s, int len)
83747 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
83748 {
83749 if (buf->size - buf->pos < len) {
83750 buf->size += len + SZ;
83751 @@ -1997,7 +2012,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
83752 if (fstat(fileno(file), &st) < 0)
83753 goto close_write;
83754
83755 - if (st.st_size != b->pos)
83756 + if (st.st_size != (off_t)b->pos)
83757 goto close_write;
83758
83759 tmp = NOFAIL(malloc(b->pos));
83760 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
83761 index 51207e4..f7d603d 100644
83762 --- a/scripts/mod/modpost.h
83763 +++ b/scripts/mod/modpost.h
83764 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
83765
83766 struct buffer {
83767 char *p;
83768 - int pos;
83769 - int size;
83770 + unsigned int pos;
83771 + unsigned int size;
83772 };
83773
83774 void __attribute__((format(printf, 2, 3)))
83775 buf_printf(struct buffer *buf, const char *fmt, ...);
83776
83777 void
83778 -buf_write(struct buffer *buf, const char *s, int len);
83779 +buf_write(struct buffer *buf, const char *s, unsigned int len);
83780
83781 struct module {
83782 struct module *next;
83783 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
83784 index 9dfcd6d..099068e 100644
83785 --- a/scripts/mod/sumversion.c
83786 +++ b/scripts/mod/sumversion.c
83787 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
83788 goto out;
83789 }
83790
83791 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
83792 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
83793 warn("writing sum in %s failed: %s\n",
83794 filename, strerror(errno));
83795 goto out;
83796 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
83797 index 68bb4ef..2f419e1 100644
83798 --- a/scripts/pnmtologo.c
83799 +++ b/scripts/pnmtologo.c
83800 @@ -244,14 +244,14 @@ static void write_header(void)
83801 fprintf(out, " * Linux logo %s\n", logoname);
83802 fputs(" */\n\n", out);
83803 fputs("#include <linux/linux_logo.h>\n\n", out);
83804 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
83805 + fprintf(out, "static unsigned char %s_data[] = {\n",
83806 logoname);
83807 }
83808
83809 static void write_footer(void)
83810 {
83811 fputs("\n};\n\n", out);
83812 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
83813 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
83814 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
83815 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
83816 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
83817 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
83818 fputs("\n};\n\n", out);
83819
83820 /* write logo clut */
83821 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
83822 + fprintf(out, "static unsigned char %s_clut[] = {\n",
83823 logoname);
83824 write_hex_cnt = 0;
83825 for (i = 0; i < logo_clutsize; i++) {
83826 diff --git a/security/Kconfig b/security/Kconfig
83827 index e9c6ac7..ab9590d 100644
83828 --- a/security/Kconfig
83829 +++ b/security/Kconfig
83830 @@ -4,6 +4,902 @@
83831
83832 menu "Security options"
83833
83834 +menu "Grsecurity"
83835 +
83836 + config ARCH_TRACK_EXEC_LIMIT
83837 + bool
83838 +
83839 + config PAX_KERNEXEC_PLUGIN
83840 + bool
83841 +
83842 + config PAX_PER_CPU_PGD
83843 + bool
83844 +
83845 + config TASK_SIZE_MAX_SHIFT
83846 + int
83847 + depends on X86_64
83848 + default 47 if !PAX_PER_CPU_PGD
83849 + default 42 if PAX_PER_CPU_PGD
83850 +
83851 + config PAX_ENABLE_PAE
83852 + bool
83853 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
83854 +
83855 + config PAX_USERCOPY_SLABS
83856 + bool
83857 +
83858 +config GRKERNSEC
83859 + bool "Grsecurity"
83860 + select CRYPTO
83861 + select CRYPTO_SHA256
83862 + select PROC_FS
83863 + select STOP_MACHINE
83864 + help
83865 + If you say Y here, you will be able to configure many features
83866 + that will enhance the security of your system. It is highly
83867 + recommended that you say Y here and read through the help
83868 + for each option so that you fully understand the features and
83869 + can evaluate their usefulness for your machine.
83870 +
83871 +choice
83872 + prompt "Configuration Method"
83873 + depends on GRKERNSEC
83874 + default GRKERNSEC_CONFIG_CUSTOM
83875 + help
83876 +
83877 +config GRKERNSEC_CONFIG_AUTO
83878 + bool "Automatic"
83879 + help
83880 + If you choose this configuration method, you'll be able to answer a small
83881 + number of simple questions about how you plan to use this kernel.
83882 + The settings of grsecurity and PaX will be automatically configured for
83883 + the highest commonly-used settings within the provided constraints.
83884 +
83885 + If you require additional configuration, custom changes can still be made
83886 + from the "custom configuration" menu.
83887 +
83888 +config GRKERNSEC_CONFIG_CUSTOM
83889 + bool "Custom"
83890 + help
83891 + If you choose this configuration method, you'll be able to configure all
83892 + grsecurity and PaX settings manually. Via this method, no options are
83893 + automatically enabled.
83894 +
83895 +endchoice
83896 +
83897 +choice
83898 + prompt "Usage Type"
83899 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83900 + default GRKERNSEC_CONFIG_SERVER
83901 + help
83902 +
83903 +config GRKERNSEC_CONFIG_SERVER
83904 + bool "Server"
83905 + help
83906 + Choose this option if you plan to use this kernel on a server.
83907 +
83908 +config GRKERNSEC_CONFIG_DESKTOP
83909 + bool "Desktop"
83910 + help
83911 + Choose this option if you plan to use this kernel on a desktop.
83912 +
83913 +endchoice
83914 +
83915 +choice
83916 + prompt "Virtualization Type"
83917 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
83918 + default GRKERNSEC_CONFIG_VIRT_NONE
83919 + help
83920 +
83921 +config GRKERNSEC_CONFIG_VIRT_NONE
83922 + bool "None"
83923 + help
83924 + Choose this option if this kernel will be run on bare metal.
83925 +
83926 +config GRKERNSEC_CONFIG_VIRT_GUEST
83927 + bool "Guest"
83928 + help
83929 + Choose this option if this kernel will be run as a VM guest.
83930 +
83931 +config GRKERNSEC_CONFIG_VIRT_HOST
83932 + bool "Host"
83933 + help
83934 + Choose this option if this kernel will be run as a VM host.
83935 +
83936 +endchoice
83937 +
83938 +choice
83939 + prompt "Virtualization Hardware"
83940 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
83941 + help
83942 +
83943 +config GRKERNSEC_CONFIG_VIRT_EPT
83944 + bool "EPT/RVI Processor Support"
83945 + depends on X86
83946 + help
83947 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
83948 + hardware virtualization. This allows for additional kernel hardening protections
83949 + to operate without additional performance impact.
83950 +
83951 + To see if your Intel processor supports EPT, see:
83952 + http://ark.intel.com/Products/VirtualizationTechnology
83953 + (Most Core i3/5/7 support EPT)
83954 +
83955 + To see if your AMD processor supports RVI, see:
83956 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
83957 +
83958 +config GRKERNSEC_CONFIG_VIRT_SOFT
83959 + bool "First-gen/No Hardware Virtualization"
83960 + help
83961 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
83962 + support hardware virtualization or doesn't support the EPT/RVI extensions.
83963 +
83964 +endchoice
83965 +
83966 +choice
83967 + prompt "Virtualization Software"
83968 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
83969 + help
83970 +
83971 +config GRKERNSEC_CONFIG_VIRT_XEN
83972 + bool "Xen"
83973 + help
83974 + Choose this option if this kernel is running as a Xen guest or host.
83975 +
83976 +config GRKERNSEC_CONFIG_VIRT_VMWARE
83977 + bool "VMWare"
83978 + help
83979 + Choose this option if this kernel is running as a VMWare guest or host.
83980 +
83981 +config GRKERNSEC_CONFIG_VIRT_KVM
83982 + bool "KVM"
83983 + help
83984 + Choose this option if this kernel is running as a KVM guest or host.
83985 +
83986 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
83987 + bool "VirtualBox"
83988 + help
83989 + Choose this option if this kernel is running as a VirtualBox guest or host.
83990 +
83991 +endchoice
83992 +
83993 +choice
83994 + prompt "Required Priorities"
83995 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83996 + default GRKERNSEC_CONFIG_PRIORITY_PERF
83997 + help
83998 +
83999 +config GRKERNSEC_CONFIG_PRIORITY_PERF
84000 + bool "Performance"
84001 + help
84002 + Choose this option if performance is of highest priority for this deployment
84003 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
84004 + and freed memory sanitizing will be disabled.
84005 +
84006 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
84007 + bool "Security"
84008 + help
84009 + Choose this option if security is of highest priority for this deployment of
84010 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
84011 + be enabled for this kernel. In a worst-case scenario, these features can
84012 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
84013 +
84014 +endchoice
84015 +
84016 +menu "Default Special Groups"
84017 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
84018 +
84019 +config GRKERNSEC_PROC_GID
84020 + int "GID exempted from /proc restrictions"
84021 + default 1001
84022 + help
84023 + Setting this GID determines which group will be exempted from
84024 + grsecurity's /proc restrictions, allowing users of the specified
84025 + group to view network statistics and the existence of other users'
84026 + processes on the system. This GID may also be chosen at boot time
84027 + via "grsec_proc_gid=" on the kernel commandline.
84028 +
84029 +config GRKERNSEC_TPE_UNTRUSTED_GID
84030 + int "GID for TPE-untrusted users"
84031 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
84032 + default 1005
84033 + help
84034 + Setting this GID determines which group untrusted users should
84035 + be added to. These users will be placed under grsecurity's Trusted Path
84036 + Execution mechanism, preventing them from executing their own binaries.
84037 + The users will only be able to execute binaries in directories owned and
84038 + writable only by the root user. If the sysctl option is enabled, a sysctl
84039 + option with name "tpe_gid" is created.
84040 +
84041 +config GRKERNSEC_TPE_TRUSTED_GID
84042 + int "GID for TPE-trusted users"
84043 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
84044 + default 1005
84045 + help
84046 + Setting this GID determines what group TPE restrictions will be
84047 + *disabled* for. If the sysctl option is enabled, a sysctl option
84048 + with name "tpe_gid" is created.
84049 +
84050 +config GRKERNSEC_SYMLINKOWN_GID
84051 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
84052 + depends on GRKERNSEC_CONFIG_SERVER
84053 + default 1006
84054 + help
84055 + Setting this GID determines what group kernel-enforced
84056 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
84057 + is enabled, a sysctl option with name "symlinkown_gid" is created.
84058 +
84059 +
84060 +endmenu
84061 +
84062 +menu "Customize Configuration"
84063 +depends on GRKERNSEC
84064 +
84065 +menu "PaX"
84066 +
84067 +config PAX
84068 + bool "Enable various PaX features"
84069 + default y if GRKERNSEC_CONFIG_AUTO
84070 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
84071 + help
84072 + This allows you to enable various PaX features. PaX adds
84073 + intrusion prevention mechanisms to the kernel that reduce
84074 + the risks posed by exploitable memory corruption bugs.
84075 +
84076 +menu "PaX Control"
84077 + depends on PAX
84078 +
84079 +config PAX_SOFTMODE
84080 + bool 'Support soft mode'
84081 + help
84082 + Enabling this option will allow you to run PaX in soft mode, that
84083 + is, PaX features will not be enforced by default, only on executables
84084 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
84085 + support as they are the only way to mark executables for soft mode use.
84086 +
84087 + Soft mode can be activated by using the "pax_softmode=1" kernel command
84088 + line option on boot. Furthermore you can control various PaX features
84089 + at runtime via the entries in /proc/sys/kernel/pax.
84090 +
84091 +config PAX_EI_PAX
84092 + bool 'Use legacy ELF header marking'
84093 + default y if GRKERNSEC_CONFIG_AUTO
84094 + help
84095 + Enabling this option will allow you to control PaX features on
84096 + a per executable basis via the 'chpax' utility available at
84097 + http://pax.grsecurity.net/. The control flags will be read from
84098 + an otherwise reserved part of the ELF header. This marking has
84099 + numerous drawbacks (no support for soft-mode, toolchain does not
84100 + know about the non-standard use of the ELF header) therefore it
84101 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
84102 + support.
84103 +
84104 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
84105 + support as well, they will override the legacy EI_PAX marks.
84106 +
84107 + If you enable none of the marking options then all applications
84108 + will run with PaX enabled on them by default.
84109 +
84110 +config PAX_PT_PAX_FLAGS
84111 + bool 'Use ELF program header marking'
84112 + default y if GRKERNSEC_CONFIG_AUTO
84113 + help
84114 + Enabling this option will allow you to control PaX features on
84115 + a per executable basis via the 'paxctl' utility available at
84116 + http://pax.grsecurity.net/. The control flags will be read from
84117 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
84118 + has the benefits of supporting both soft mode and being fully
84119 + integrated into the toolchain (the binutils patch is available
84120 + from http://pax.grsecurity.net).
84121 +
84122 + Note that if you enable the legacy EI_PAX marking support as well,
84123 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
84124 +
84125 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
84126 + must make sure that the marks are the same if a binary has both marks.
84127 +
84128 + If you enable none of the marking options then all applications
84129 + will run with PaX enabled on them by default.
84130 +
84131 +config PAX_XATTR_PAX_FLAGS
84132 + bool 'Use filesystem extended attributes marking'
84133 + default y if GRKERNSEC_CONFIG_AUTO
84134 + select CIFS_XATTR if CIFS
84135 + select EXT2_FS_XATTR if EXT2_FS
84136 + select EXT3_FS_XATTR if EXT3_FS
84137 + select EXT4_FS_XATTR if EXT4_FS
84138 + select JFFS2_FS_XATTR if JFFS2_FS
84139 + select REISERFS_FS_XATTR if REISERFS_FS
84140 + select SQUASHFS_XATTR if SQUASHFS
84141 + select TMPFS_XATTR if TMPFS
84142 + select UBIFS_FS_XATTR if UBIFS_FS
84143 + help
84144 + Enabling this option will allow you to control PaX features on
84145 + a per executable basis via the 'setfattr' utility. The control
84146 + flags will be read from the user.pax.flags extended attribute of
84147 + the file. This marking has the benefit of supporting binary-only
84148 + applications that self-check themselves (e.g., skype) and would
84149 + not tolerate chpax/paxctl changes. The main drawback is that
84150 + extended attributes are not supported by some filesystems (e.g.,
84151 + isofs, udf, vfat) so copying files through such filesystems will
84152 + lose the extended attributes and these PaX markings.
84153 +
84154 + Note that if you enable the legacy EI_PAX marking support as well,
84155 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
84156 +
84157 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
84158 + must make sure that the marks are the same if a binary has both marks.
84159 +
84160 + If you enable none of the marking options then all applications
84161 + will run with PaX enabled on them by default.
84162 +
84163 +choice
84164 + prompt 'MAC system integration'
84165 + default PAX_HAVE_ACL_FLAGS
84166 + help
84167 + Mandatory Access Control systems have the option of controlling
84168 + PaX flags on a per executable basis, choose the method supported
84169 + by your particular system.
84170 +
84171 + - "none": if your MAC system does not interact with PaX,
84172 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
84173 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
84174 +
84175 + NOTE: this option is for developers/integrators only.
84176 +
84177 + config PAX_NO_ACL_FLAGS
84178 + bool 'none'
84179 +
84180 + config PAX_HAVE_ACL_FLAGS
84181 + bool 'direct'
84182 +
84183 + config PAX_HOOK_ACL_FLAGS
84184 + bool 'hook'
84185 +endchoice
84186 +
84187 +endmenu
84188 +
84189 +menu "Non-executable pages"
84190 + depends on PAX
84191 +
84192 +config PAX_NOEXEC
84193 + bool "Enforce non-executable pages"
84194 + default y if GRKERNSEC_CONFIG_AUTO
84195 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
84196 + help
84197 + By design some architectures do not allow for protecting memory
84198 + pages against execution or even if they do, Linux does not make
84199 + use of this feature. In practice this means that if a page is
84200 + readable (such as the stack or heap) it is also executable.
84201 +
84202 + There is a well known exploit technique that makes use of this
84203 + fact and a common programming mistake where an attacker can
84204 + introduce code of his choice somewhere in the attacked program's
84205 + memory (typically the stack or the heap) and then execute it.
84206 +
84207 + If the attacked program was running with different (typically
84208 + higher) privileges than that of the attacker, then he can elevate
84209 + his own privilege level (e.g. get a root shell, write to files for
84210 + which he does not have write access to, etc).
84211 +
84212 + Enabling this option will let you choose from various features
84213 + that prevent the injection and execution of 'foreign' code in
84214 + a program.
84215 +
84216 + This will also break programs that rely on the old behaviour and
84217 + expect that dynamically allocated memory via the malloc() family
84218 + of functions is executable (which it is not). Notable examples
84219 + are the XFree86 4.x server, the java runtime and wine.
84220 +
84221 +config PAX_PAGEEXEC
84222 + bool "Paging based non-executable pages"
84223 + default y if GRKERNSEC_CONFIG_AUTO
84224 + 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)
84225 + select S390_SWITCH_AMODE if S390
84226 + select S390_EXEC_PROTECT if S390
84227 + select ARCH_TRACK_EXEC_LIMIT if X86_32
84228 + help
84229 + This implementation is based on the paging feature of the CPU.
84230 + On i386 without hardware non-executable bit support there is a
84231 + variable but usually low performance impact, however on Intel's
84232 + P4 core based CPUs it is very high so you should not enable this
84233 + for kernels meant to be used on such CPUs.
84234 +
84235 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
84236 + with hardware non-executable bit support there is no performance
84237 + impact, on ppc the impact is negligible.
84238 +
84239 + Note that several architectures require various emulations due to
84240 + badly designed userland ABIs, this will cause a performance impact
84241 + but will disappear as soon as userland is fixed. For example, ppc
84242 + userland MUST have been built with secure-plt by a recent toolchain.
84243 +
84244 +config PAX_SEGMEXEC
84245 + bool "Segmentation based non-executable pages"
84246 + default y if GRKERNSEC_CONFIG_AUTO
84247 + depends on PAX_NOEXEC && X86_32
84248 + help
84249 + This implementation is based on the segmentation feature of the
84250 + CPU and has a very small performance impact, however applications
84251 + will be limited to a 1.5 GB address space instead of the normal
84252 + 3 GB.
84253 +
84254 +config PAX_EMUTRAMP
84255 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
84256 + default y if PARISC
84257 + help
84258 + There are some programs and libraries that for one reason or
84259 + another attempt to execute special small code snippets from
84260 + non-executable memory pages. Most notable examples are the
84261 + signal handler return code generated by the kernel itself and
84262 + the GCC trampolines.
84263 +
84264 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
84265 + such programs will no longer work under your kernel.
84266 +
84267 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
84268 + utilities to enable trampoline emulation for the affected programs
84269 + yet still have the protection provided by the non-executable pages.
84270 +
84271 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
84272 + your system will not even boot.
84273 +
84274 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
84275 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
84276 + for the affected files.
84277 +
84278 + NOTE: enabling this feature *may* open up a loophole in the
84279 + protection provided by non-executable pages that an attacker
84280 + could abuse. Therefore the best solution is to not have any
84281 + files on your system that would require this option. This can
84282 + be achieved by not using libc5 (which relies on the kernel
84283 + signal handler return code) and not using or rewriting programs
84284 + that make use of the nested function implementation of GCC.
84285 + Skilled users can just fix GCC itself so that it implements
84286 + nested function calls in a way that does not interfere with PaX.
84287 +
84288 +config PAX_EMUSIGRT
84289 + bool "Automatically emulate sigreturn trampolines"
84290 + depends on PAX_EMUTRAMP && PARISC
84291 + default y
84292 + help
84293 + Enabling this option will have the kernel automatically detect
84294 + and emulate signal return trampolines executing on the stack
84295 + that would otherwise lead to task termination.
84296 +
84297 + This solution is intended as a temporary one for users with
84298 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
84299 + Modula-3 runtime, etc) or executables linked to such, basically
84300 + everything that does not specify its own SA_RESTORER function in
84301 + normal executable memory like glibc 2.1+ does.
84302 +
84303 + On parisc you MUST enable this option, otherwise your system will
84304 + not even boot.
84305 +
84306 + NOTE: this feature cannot be disabled on a per executable basis
84307 + and since it *does* open up a loophole in the protection provided
84308 + by non-executable pages, the best solution is to not have any
84309 + files on your system that would require this option.
84310 +
84311 +config PAX_MPROTECT
84312 + bool "Restrict mprotect()"
84313 + default y if GRKERNSEC_CONFIG_AUTO
84314 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
84315 + help
84316 + Enabling this option will prevent programs from
84317 + - changing the executable status of memory pages that were
84318 + not originally created as executable,
84319 + - making read-only executable pages writable again,
84320 + - creating executable pages from anonymous memory,
84321 + - making read-only-after-relocations (RELRO) data pages writable again.
84322 +
84323 + You should say Y here to complete the protection provided by
84324 + the enforcement of non-executable pages.
84325 +
84326 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
84327 + this feature on a per file basis.
84328 +
84329 +config PAX_MPROTECT_COMPAT
84330 + bool "Use legacy/compat protection demoting (read help)"
84331 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
84332 + depends on PAX_MPROTECT
84333 + help
84334 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
84335 + by sending the proper error code to the application. For some broken
84336 + userland, this can cause problems with Python or other applications. The
84337 + current implementation however allows for applications like clamav to
84338 + detect if JIT compilation/execution is allowed and to fall back gracefully
84339 + to an interpreter-based mode if it does not. While we encourage everyone
84340 + to use the current implementation as-is and push upstream to fix broken
84341 + userland (note that the RWX logging option can assist with this), in some
84342 + environments this may not be possible. Having to disable MPROTECT
84343 + completely on certain binaries reduces the security benefit of PaX,
84344 + so this option is provided for those environments to revert to the old
84345 + behavior.
84346 +
84347 +config PAX_ELFRELOCS
84348 + bool "Allow ELF text relocations (read help)"
84349 + depends on PAX_MPROTECT
84350 + default n
84351 + help
84352 + Non-executable pages and mprotect() restrictions are effective
84353 + in preventing the introduction of new executable code into an
84354 + attacked task's address space. There remain only two venues
84355 + for this kind of attack: if the attacker can execute already
84356 + existing code in the attacked task then he can either have it
84357 + create and mmap() a file containing his code or have it mmap()
84358 + an already existing ELF library that does not have position
84359 + independent code in it and use mprotect() on it to make it
84360 + writable and copy his code there. While protecting against
84361 + the former approach is beyond PaX, the latter can be prevented
84362 + by having only PIC ELF libraries on one's system (which do not
84363 + need to relocate their code). If you are sure this is your case,
84364 + as is the case with all modern Linux distributions, then leave
84365 + this option disabled. You should say 'n' here.
84366 +
84367 +config PAX_ETEXECRELOCS
84368 + bool "Allow ELF ET_EXEC text relocations"
84369 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
84370 + select PAX_ELFRELOCS
84371 + default y
84372 + help
84373 + On some architectures there are incorrectly created applications
84374 + that require text relocations and would not work without enabling
84375 + this option. If you are an alpha, ia64 or parisc user, you should
84376 + enable this option and disable it once you have made sure that
84377 + none of your applications need it.
84378 +
84379 +config PAX_EMUPLT
84380 + bool "Automatically emulate ELF PLT"
84381 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
84382 + default y
84383 + help
84384 + Enabling this option will have the kernel automatically detect
84385 + and emulate the Procedure Linkage Table entries in ELF files.
84386 + On some architectures such entries are in writable memory, and
84387 + become non-executable leading to task termination. Therefore
84388 + it is mandatory that you enable this option on alpha, parisc,
84389 + sparc and sparc64, otherwise your system would not even boot.
84390 +
84391 + NOTE: this feature *does* open up a loophole in the protection
84392 + provided by the non-executable pages, therefore the proper
84393 + solution is to modify the toolchain to produce a PLT that does
84394 + not need to be writable.
84395 +
84396 +config PAX_DLRESOLVE
84397 + bool 'Emulate old glibc resolver stub'
84398 + depends on PAX_EMUPLT && SPARC
84399 + default n
84400 + help
84401 + This option is needed if userland has an old glibc (before 2.4)
84402 + that puts a 'save' instruction into the runtime generated resolver
84403 + stub that needs special emulation.
84404 +
84405 +config PAX_KERNEXEC
84406 + bool "Enforce non-executable kernel pages"
84407 + 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))
84408 + depends on ((X86 && (!X86_32 || X86_WP_WORKS_OK)) || (ARM && (CPU_V6 || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
84409 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
84410 + select PAX_KERNEXEC_PLUGIN if X86_64
84411 + help
84412 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
84413 + that is, enabling this option will make it harder to inject
84414 + and execute 'foreign' code in kernel memory itself.
84415 +
84416 +choice
84417 + prompt "Return Address Instrumentation Method"
84418 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
84419 + depends on PAX_KERNEXEC_PLUGIN
84420 + help
84421 + Select the method used to instrument function pointer dereferences.
84422 + Note that binary modules cannot be instrumented by this approach.
84423 +
84424 + Note that the implementation requires a gcc with plugin support,
84425 + i.e., gcc 4.5 or newer. You may need to install the supporting
84426 + headers explicitly in addition to the normal gcc package.
84427 +
84428 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
84429 + bool "bts"
84430 + help
84431 + This method is compatible with binary only modules but has
84432 + a higher runtime overhead.
84433 +
84434 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
84435 + bool "or"
84436 + depends on !PARAVIRT
84437 + help
84438 + This method is incompatible with binary only modules but has
84439 + a lower runtime overhead.
84440 +endchoice
84441 +
84442 +config PAX_KERNEXEC_PLUGIN_METHOD
84443 + string
84444 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
84445 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
84446 + default ""
84447 +
84448 +config PAX_KERNEXEC_MODULE_TEXT
84449 + int "Minimum amount of memory reserved for module code"
84450 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
84451 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
84452 + depends on PAX_KERNEXEC && X86_32 && MODULES
84453 + help
84454 + Due to implementation details the kernel must reserve a fixed
84455 + amount of memory for module code at compile time that cannot be
84456 + changed at runtime. Here you can specify the minimum amount
84457 + in MB that will be reserved. Due to the same implementation
84458 + details this size will always be rounded up to the next 2/4 MB
84459 + boundary (depends on PAE) so the actually available memory for
84460 + module code will usually be more than this minimum.
84461 +
84462 + The default 4 MB should be enough for most users but if you have
84463 + an excessive number of modules (e.g., most distribution configs
84464 + compile many drivers as modules) or use huge modules such as
84465 + nvidia's kernel driver, you will need to adjust this amount.
84466 + A good rule of thumb is to look at your currently loaded kernel
84467 + modules and add up their sizes.
84468 +
84469 +endmenu
84470 +
84471 +menu "Address Space Layout Randomization"
84472 + depends on PAX
84473 +
84474 +config PAX_ASLR
84475 + bool "Address Space Layout Randomization"
84476 + default y if GRKERNSEC_CONFIG_AUTO
84477 + help
84478 + Many if not most exploit techniques rely on the knowledge of
84479 + certain addresses in the attacked program. The following options
84480 + will allow the kernel to apply a certain amount of randomization
84481 + to specific parts of the program thereby forcing an attacker to
84482 + guess them in most cases. Any failed guess will most likely crash
84483 + the attacked program which allows the kernel to detect such attempts
84484 + and react on them. PaX itself provides no reaction mechanisms,
84485 + instead it is strongly encouraged that you make use of Nergal's
84486 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
84487 + (http://www.grsecurity.net/) built-in crash detection features or
84488 + develop one yourself.
84489 +
84490 + By saying Y here you can choose to randomize the following areas:
84491 + - top of the task's kernel stack
84492 + - top of the task's userland stack
84493 + - base address for mmap() requests that do not specify one
84494 + (this includes all libraries)
84495 + - base address of the main executable
84496 +
84497 + It is strongly recommended to say Y here as address space layout
84498 + randomization has negligible impact on performance yet it provides
84499 + a very effective protection.
84500 +
84501 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
84502 + this feature on a per file basis.
84503 +
84504 +config PAX_RANDKSTACK
84505 + bool "Randomize kernel stack base"
84506 + default y if GRKERNSEC_CONFIG_AUTO
84507 + depends on X86_TSC && X86
84508 + help
84509 + By saying Y here the kernel will randomize every task's kernel
84510 + stack on every system call. This will not only force an attacker
84511 + to guess it but also prevent him from making use of possible
84512 + leaked information about it.
84513 +
84514 + Since the kernel stack is a rather scarce resource, randomization
84515 + may cause unexpected stack overflows, therefore you should very
84516 + carefully test your system. Note that once enabled in the kernel
84517 + configuration, this feature cannot be disabled on a per file basis.
84518 +
84519 +config PAX_RANDUSTACK
84520 + bool "Randomize user stack base"
84521 + default y if GRKERNSEC_CONFIG_AUTO
84522 + depends on PAX_ASLR
84523 + help
84524 + By saying Y here the kernel will randomize every task's userland
84525 + stack. The randomization is done in two steps where the second
84526 + one may apply a big amount of shift to the top of the stack and
84527 + cause problems for programs that want to use lots of memory (more
84528 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
84529 + For this reason the second step can be controlled by 'chpax' or
84530 + 'paxctl' on a per file basis.
84531 +
84532 +config PAX_RANDMMAP
84533 + bool "Randomize mmap() base"
84534 + default y if GRKERNSEC_CONFIG_AUTO
84535 + depends on PAX_ASLR
84536 + help
84537 + By saying Y here the kernel will use a randomized base address for
84538 + mmap() requests that do not specify one themselves. As a result
84539 + all dynamically loaded libraries will appear at random addresses
84540 + and therefore be harder to exploit by a technique where an attacker
84541 + attempts to execute library code for his purposes (e.g. spawn a
84542 + shell from an exploited program that is running at an elevated
84543 + privilege level).
84544 +
84545 + Furthermore, if a program is relinked as a dynamic ELF file, its
84546 + base address will be randomized as well, completing the full
84547 + randomization of the address space layout. Attacking such programs
84548 + becomes a guess game. You can find an example of doing this at
84549 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
84550 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
84551 +
84552 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
84553 + feature on a per file basis.
84554 +
84555 +endmenu
84556 +
84557 +menu "Miscellaneous hardening features"
84558 +
84559 +config PAX_MEMORY_SANITIZE
84560 + bool "Sanitize all freed memory"
84561 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
84562 + depends on !HIBERNATION
84563 + help
84564 + By saying Y here the kernel will erase memory pages as soon as they
84565 + are freed. This in turn reduces the lifetime of data stored in the
84566 + pages, making it less likely that sensitive information such as
84567 + passwords, cryptographic secrets, etc stay in memory for too long.
84568 +
84569 + This is especially useful for programs whose runtime is short, long
84570 + lived processes and the kernel itself benefit from this as long as
84571 + they operate on whole memory pages and ensure timely freeing of pages
84572 + that may hold sensitive information.
84573 +
84574 + The tradeoff is performance impact, on a single CPU system kernel
84575 + compilation sees a 3% slowdown, other systems and workloads may vary
84576 + and you are advised to test this feature on your expected workload
84577 + before deploying it.
84578 +
84579 + Note that this feature does not protect data stored in live pages,
84580 + e.g., process memory swapped to disk may stay there for a long time.
84581 +
84582 +config PAX_MEMORY_STACKLEAK
84583 + bool "Sanitize kernel stack"
84584 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
84585 + depends on X86
84586 + help
84587 + By saying Y here the kernel will erase the kernel stack before it
84588 + returns from a system call. This in turn reduces the information
84589 + that a kernel stack leak bug can reveal.
84590 +
84591 + Note that such a bug can still leak information that was put on
84592 + the stack by the current system call (the one eventually triggering
84593 + the bug) but traces of earlier system calls on the kernel stack
84594 + cannot leak anymore.
84595 +
84596 + The tradeoff is performance impact: on a single CPU system kernel
84597 + compilation sees a 1% slowdown, other systems and workloads may vary
84598 + and you are advised to test this feature on your expected workload
84599 + before deploying it.
84600 +
84601 + Note that the full feature requires a gcc with plugin support,
84602 + i.e., gcc 4.5 or newer. You may need to install the supporting
84603 + headers explicitly in addition to the normal gcc package. Using
84604 + older gcc versions means that functions with large enough stack
84605 + frames may leave uninitialized memory behind that may be exposed
84606 + to a later syscall leaking the stack.
84607 +
84608 +config PAX_MEMORY_UDEREF
84609 + bool "Prevent invalid userland pointer dereference"
84610 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
84611 + depends on (X86 || (ARM && (CPU_V6 || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
84612 + select PAX_PER_CPU_PGD if X86_64
84613 + help
84614 + By saying Y here the kernel will be prevented from dereferencing
84615 + userland pointers in contexts where the kernel expects only kernel
84616 + pointers. This is both a useful runtime debugging feature and a
84617 + security measure that prevents exploiting a class of kernel bugs.
84618 +
84619 + The tradeoff is that some virtualization solutions may experience
84620 + a huge slowdown and therefore you should not enable this feature
84621 + for kernels meant to run in such environments. Whether a given VM
84622 + solution is affected or not is best determined by simply trying it
84623 + out, the performance impact will be obvious right on boot as this
84624 + mechanism engages from very early on. A good rule of thumb is that
84625 + VMs running on CPUs without hardware virtualization support (i.e.,
84626 + the majority of IA-32 CPUs) will likely experience the slowdown.
84627 +
84628 +config PAX_REFCOUNT
84629 + bool "Prevent various kernel object reference counter overflows"
84630 + default y if GRKERNSEC_CONFIG_AUTO
84631 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
84632 + help
84633 + By saying Y here the kernel will detect and prevent overflowing
84634 + various (but not all) kinds of object reference counters. Such
84635 + overflows can normally occur due to bugs only and are often, if
84636 + not always, exploitable.
84637 +
84638 + The tradeoff is that data structures protected by an overflowed
84639 + refcount will never be freed and therefore will leak memory. Note
84640 + that this leak also happens even without this protection but in
84641 + that case the overflow can eventually trigger the freeing of the
84642 + data structure while it is still being used elsewhere, resulting
84643 + in the exploitable situation that this feature prevents.
84644 +
84645 + Since this has a negligible performance impact, you should enable
84646 + this feature.
84647 +
84648 +config PAX_USERCOPY
84649 + bool "Harden heap object copies between kernel and userland"
84650 + default y if GRKERNSEC_CONFIG_AUTO
84651 + depends on ARM || IA64 || PPC || SPARC || X86
84652 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
84653 + select PAX_USERCOPY_SLABS
84654 + help
84655 + By saying Y here the kernel will enforce the size of heap objects
84656 + when they are copied in either direction between the kernel and
84657 + userland, even if only a part of the heap object is copied.
84658 +
84659 + Specifically, this checking prevents information leaking from the
84660 + kernel heap during kernel to userland copies (if the kernel heap
84661 + object is otherwise fully initialized) and prevents kernel heap
84662 + overflows during userland to kernel copies.
84663 +
84664 + Note that the current implementation provides the strictest bounds
84665 + checks for the SLUB allocator.
84666 +
84667 + Enabling this option also enables per-slab cache protection against
84668 + data in a given cache being copied into/out of via userland
84669 + accessors. Though the whitelist of regions will be reduced over
84670 + time, it notably protects important data structures like task structs.
84671 +
84672 + If frame pointers are enabled on x86, this option will also restrict
84673 + copies into and out of the kernel stack to local variables within a
84674 + single frame.
84675 +
84676 + Since this has a negligible performance impact, you should enable
84677 + this feature.
84678 +
84679 +
84680 +config PAX_USERCOPY_DEBUG
84681 + bool
84682 + depends on X86 && PAX_USERCOPY
84683 + default n
84684 +
84685 +config PAX_SIZE_OVERFLOW
84686 + bool "Prevent various integer overflows in function size parameters"
84687 + default y if GRKERNSEC_CONFIG_AUTO
84688 + depends on X86
84689 + help
84690 + By saying Y here the kernel recomputes expressions of function
84691 + arguments marked by a size_overflow attribute with double integer
84692 + precision (DImode/TImode for 32/64 bit integer types).
84693 +
84694 + The recomputed argument is checked against TYPE_MAX and an event
84695 + is logged on overflow and the triggering process is killed.
84696 +
84697 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
84698 +
84699 + Note that the implementation requires a gcc with plugin support,
84700 + i.e., gcc 4.5 or newer. You may need to install the supporting
84701 + headers explicitly in addition to the normal gcc package.
84702 +
84703 +config PAX_LATENT_ENTROPY
84704 + bool "Generate some entropy during boot"
84705 + default y if GRKERNSEC_CONFIG_AUTO
84706 + help
84707 + By saying Y here the kernel will instrument early boot code to
84708 + extract some entropy from both original and artificially created
84709 + program state. This will help especially embedded systems where
84710 + there is little 'natural' source of entropy normally. The cost
84711 + is some slowdown of the boot process.
84712 +
84713 + Note that the implementation requires a gcc with plugin support,
84714 + i.e., gcc 4.5 or newer. You may need to install the supporting
84715 + headers explicitly in addition to the normal gcc package.
84716 +
84717 + Note that entropy extracted this way is not cryptographically
84718 + secure!
84719 +
84720 +endmenu
84721 +
84722 +endmenu
84723 +
84724 +source grsecurity/Kconfig
84725 +
84726 +endmenu
84727 +
84728 +endmenu
84729 +
84730 source security/keys/Kconfig
84731
84732 config SECURITY_DMESG_RESTRICT
84733 @@ -103,7 +999,7 @@ config INTEL_TXT
84734 config LSM_MMAP_MIN_ADDR
84735 int "Low address space for LSM to protect from user allocation"
84736 depends on SECURITY && SECURITY_SELINUX
84737 - default 32768 if ARM
84738 + default 32768 if ALPHA || ARM || PARISC || SPARC32
84739 default 65536
84740 help
84741 This is the portion of low virtual memory which should be protected
84742 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
84743 index 8c2a7f6..b133ac9 100644
84744 --- a/security/apparmor/lsm.c
84745 +++ b/security/apparmor/lsm.c
84746 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
84747 return error;
84748 }
84749
84750 -static struct security_operations apparmor_ops = {
84751 +static struct security_operations apparmor_ops __read_only = {
84752 .name = "apparmor",
84753
84754 .ptrace_access_check = apparmor_ptrace_access_check,
84755 diff --git a/security/commoncap.c b/security/commoncap.c
84756 index 7ee08c7..8d1a9d6 100644
84757 --- a/security/commoncap.c
84758 +++ b/security/commoncap.c
84759 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
84760 return 0;
84761 }
84762
84763 +/* returns:
84764 + 1 for suid privilege
84765 + 2 for sgid privilege
84766 + 3 for fscap privilege
84767 +*/
84768 +int is_privileged_binary(const struct dentry *dentry)
84769 +{
84770 + struct cpu_vfs_cap_data capdata;
84771 + struct inode *inode = dentry->d_inode;
84772 +
84773 + if (!inode || S_ISDIR(inode->i_mode))
84774 + return 0;
84775 +
84776 + if (inode->i_mode & S_ISUID)
84777 + return 1;
84778 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
84779 + return 2;
84780 +
84781 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
84782 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
84783 + return 3;
84784 + }
84785 +
84786 + return 0;
84787 +}
84788 +
84789 /*
84790 * Attempt to get the on-exec apply capability sets for an executable file from
84791 * its xattrs and, if present, apply them to the proposed credentials being
84792 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
84793 const struct cred *cred = current_cred();
84794 kuid_t root_uid = make_kuid(cred->user_ns, 0);
84795
84796 + if (gr_acl_enable_at_secure())
84797 + return 1;
84798 +
84799 if (!uid_eq(cred->uid, root_uid)) {
84800 if (bprm->cap_effective)
84801 return 1;
84802 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
84803 index 079a85d..12e93f8 100644
84804 --- a/security/integrity/ima/ima.h
84805 +++ b/security/integrity/ima/ima.h
84806 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84807 extern spinlock_t ima_queue_lock;
84808
84809 struct ima_h_table {
84810 - atomic_long_t len; /* number of stored measurements in the list */
84811 - atomic_long_t violations;
84812 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
84813 + atomic_long_unchecked_t violations;
84814 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
84815 };
84816 extern struct ima_h_table ima_htable;
84817 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
84818 index 0cea3db..2f0ef77 100644
84819 --- a/security/integrity/ima/ima_api.c
84820 +++ b/security/integrity/ima/ima_api.c
84821 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84822 int result;
84823
84824 /* can overflow, only indicator */
84825 - atomic_long_inc(&ima_htable.violations);
84826 + atomic_long_inc_unchecked(&ima_htable.violations);
84827
84828 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
84829 if (!entry) {
84830 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
84831 index 38477c9..87a60c7 100644
84832 --- a/security/integrity/ima/ima_fs.c
84833 +++ b/security/integrity/ima/ima_fs.c
84834 @@ -28,12 +28,12 @@
84835 static int valid_policy = 1;
84836 #define TMPBUFLEN 12
84837 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
84838 - loff_t *ppos, atomic_long_t *val)
84839 + loff_t *ppos, atomic_long_unchecked_t *val)
84840 {
84841 char tmpbuf[TMPBUFLEN];
84842 ssize_t len;
84843
84844 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
84845 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
84846 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
84847 }
84848
84849 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
84850 index 55a6271..ad829c3 100644
84851 --- a/security/integrity/ima/ima_queue.c
84852 +++ b/security/integrity/ima/ima_queue.c
84853 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
84854 INIT_LIST_HEAD(&qe->later);
84855 list_add_tail_rcu(&qe->later, &ima_measurements);
84856
84857 - atomic_long_inc(&ima_htable.len);
84858 + atomic_long_inc_unchecked(&ima_htable.len);
84859 key = ima_hash_key(entry->digest);
84860 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
84861 return 0;
84862 diff --git a/security/keys/compat.c b/security/keys/compat.c
84863 index 1c26176..64a1ba2 100644
84864 --- a/security/keys/compat.c
84865 +++ b/security/keys/compat.c
84866 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
84867 if (ret == 0)
84868 goto no_payload_free;
84869
84870 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
84871 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
84872
84873 if (iov != iovstack)
84874 kfree(iov);
84875 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
84876 index 4b5c948..2054dc1 100644
84877 --- a/security/keys/keyctl.c
84878 +++ b/security/keys/keyctl.c
84879 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
84880 /*
84881 * Copy the iovec data from userspace
84882 */
84883 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
84884 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
84885 unsigned ioc)
84886 {
84887 for (; ioc > 0; ioc--) {
84888 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
84889 * If successful, 0 will be returned.
84890 */
84891 long keyctl_instantiate_key_common(key_serial_t id,
84892 - const struct iovec *payload_iov,
84893 + const struct iovec __user *payload_iov,
84894 unsigned ioc,
84895 size_t plen,
84896 key_serial_t ringid)
84897 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
84898 [0].iov_len = plen
84899 };
84900
84901 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
84902 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
84903 }
84904
84905 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
84906 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
84907 if (ret == 0)
84908 goto no_payload_free;
84909
84910 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
84911 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
84912 err:
84913 if (iov != iovstack)
84914 kfree(iov);
84915 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
84916 index 6ece7f2..ecdb55c 100644
84917 --- a/security/keys/keyring.c
84918 +++ b/security/keys/keyring.c
84919 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
84920 ret = -EFAULT;
84921
84922 for (loop = 0; loop < klist->nkeys; loop++) {
84923 + key_serial_t serial;
84924 key = rcu_deref_link_locked(klist, loop,
84925 keyring);
84926 + serial = key->serial;
84927
84928 tmp = sizeof(key_serial_t);
84929 if (tmp > buflen)
84930 tmp = buflen;
84931
84932 - if (copy_to_user(buffer,
84933 - &key->serial,
84934 - tmp) != 0)
84935 + if (copy_to_user(buffer, &serial, tmp))
84936 goto error;
84937
84938 buflen -= tmp;
84939 diff --git a/security/min_addr.c b/security/min_addr.c
84940 index f728728..6457a0c 100644
84941 --- a/security/min_addr.c
84942 +++ b/security/min_addr.c
84943 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
84944 */
84945 static void update_mmap_min_addr(void)
84946 {
84947 +#ifndef SPARC
84948 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
84949 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
84950 mmap_min_addr = dac_mmap_min_addr;
84951 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
84952 #else
84953 mmap_min_addr = dac_mmap_min_addr;
84954 #endif
84955 +#endif
84956 }
84957
84958 /*
84959 diff --git a/security/security.c b/security/security.c
84960 index 7b88c6a..1e3ea8f 100644
84961 --- a/security/security.c
84962 +++ b/security/security.c
84963 @@ -20,6 +20,7 @@
84964 #include <linux/ima.h>
84965 #include <linux/evm.h>
84966 #include <linux/fsnotify.h>
84967 +#include <linux/mm.h>
84968 #include <linux/mman.h>
84969 #include <linux/mount.h>
84970 #include <linux/personality.h>
84971 @@ -32,8 +33,8 @@
84972 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
84973 CONFIG_DEFAULT_SECURITY;
84974
84975 -static struct security_operations *security_ops;
84976 -static struct security_operations default_security_ops = {
84977 +static struct security_operations *security_ops __read_only;
84978 +static struct security_operations default_security_ops __read_only = {
84979 .name = "default",
84980 };
84981
84982 @@ -74,7 +75,9 @@ int __init security_init(void)
84983
84984 void reset_security_ops(void)
84985 {
84986 + pax_open_kernel();
84987 security_ops = &default_security_ops;
84988 + pax_close_kernel();
84989 }
84990
84991 /* Save user chosen LSM */
84992 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
84993 index ef26e96..642fb78 100644
84994 --- a/security/selinux/hooks.c
84995 +++ b/security/selinux/hooks.c
84996 @@ -95,8 +95,6 @@
84997
84998 #define NUM_SEL_MNT_OPTS 5
84999
85000 -extern struct security_operations *security_ops;
85001 -
85002 /* SECMARK reference count */
85003 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
85004
85005 @@ -5501,7 +5499,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
85006
85007 #endif
85008
85009 -static struct security_operations selinux_ops = {
85010 +static struct security_operations selinux_ops __read_only = {
85011 .name = "selinux",
85012
85013 .ptrace_access_check = selinux_ptrace_access_check,
85014 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
85015 index 65f67cb..3f141ef 100644
85016 --- a/security/selinux/include/xfrm.h
85017 +++ b/security/selinux/include/xfrm.h
85018 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
85019
85020 static inline void selinux_xfrm_notify_policyload(void)
85021 {
85022 - atomic_inc(&flow_cache_genid);
85023 + atomic_inc_unchecked(&flow_cache_genid);
85024 rt_genid_bump(&init_net);
85025 }
85026 #else
85027 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
85028 index 38be92c..21f49ee 100644
85029 --- a/security/smack/smack_lsm.c
85030 +++ b/security/smack/smack_lsm.c
85031 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
85032 return 0;
85033 }
85034
85035 -struct security_operations smack_ops = {
85036 +struct security_operations smack_ops __read_only = {
85037 .name = "smack",
85038
85039 .ptrace_access_check = smack_ptrace_access_check,
85040 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
85041 index a2ee362..5754f34 100644
85042 --- a/security/tomoyo/tomoyo.c
85043 +++ b/security/tomoyo/tomoyo.c
85044 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
85045 * tomoyo_security_ops is a "struct security_operations" which is used for
85046 * registering TOMOYO.
85047 */
85048 -static struct security_operations tomoyo_security_ops = {
85049 +static struct security_operations tomoyo_security_ops __read_only = {
85050 .name = "tomoyo",
85051 .cred_alloc_blank = tomoyo_cred_alloc_blank,
85052 .cred_prepare = tomoyo_cred_prepare,
85053 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
85054 index 20ef514..4182bed 100644
85055 --- a/security/yama/Kconfig
85056 +++ b/security/yama/Kconfig
85057 @@ -1,6 +1,6 @@
85058 config SECURITY_YAMA
85059 bool "Yama support"
85060 - depends on SECURITY
85061 + depends on SECURITY && !GRKERNSEC
85062 select SECURITYFS
85063 select SECURITY_PATH
85064 default n
85065 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
85066 index 4cedc69..e59d8a3 100644
85067 --- a/sound/aoa/codecs/onyx.c
85068 +++ b/sound/aoa/codecs/onyx.c
85069 @@ -54,7 +54,7 @@ struct onyx {
85070 spdif_locked:1,
85071 analog_locked:1,
85072 original_mute:2;
85073 - int open_count;
85074 + local_t open_count;
85075 struct codec_info *codec_info;
85076
85077 /* mutex serializes concurrent access to the device
85078 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
85079 struct onyx *onyx = cii->codec_data;
85080
85081 mutex_lock(&onyx->mutex);
85082 - onyx->open_count++;
85083 + local_inc(&onyx->open_count);
85084 mutex_unlock(&onyx->mutex);
85085
85086 return 0;
85087 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
85088 struct onyx *onyx = cii->codec_data;
85089
85090 mutex_lock(&onyx->mutex);
85091 - onyx->open_count--;
85092 - if (!onyx->open_count)
85093 + if (local_dec_and_test(&onyx->open_count))
85094 onyx->spdif_locked = onyx->analog_locked = 0;
85095 mutex_unlock(&onyx->mutex);
85096
85097 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
85098 index ffd2025..df062c9 100644
85099 --- a/sound/aoa/codecs/onyx.h
85100 +++ b/sound/aoa/codecs/onyx.h
85101 @@ -11,6 +11,7 @@
85102 #include <linux/i2c.h>
85103 #include <asm/pmac_low_i2c.h>
85104 #include <asm/prom.h>
85105 +#include <asm/local.h>
85106
85107 /* PCM3052 register definitions */
85108
85109 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
85110 index 4c1cc51..16040040 100644
85111 --- a/sound/core/oss/pcm_oss.c
85112 +++ b/sound/core/oss/pcm_oss.c
85113 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
85114 if (in_kernel) {
85115 mm_segment_t fs;
85116 fs = snd_enter_user();
85117 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
85118 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
85119 snd_leave_user(fs);
85120 } else {
85121 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
85122 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
85123 }
85124 if (ret != -EPIPE && ret != -ESTRPIPE)
85125 break;
85126 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
85127 if (in_kernel) {
85128 mm_segment_t fs;
85129 fs = snd_enter_user();
85130 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
85131 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
85132 snd_leave_user(fs);
85133 } else {
85134 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
85135 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
85136 }
85137 if (ret == -EPIPE) {
85138 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
85139 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
85140 struct snd_pcm_plugin_channel *channels;
85141 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
85142 if (!in_kernel) {
85143 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
85144 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
85145 return -EFAULT;
85146 buf = runtime->oss.buffer;
85147 }
85148 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
85149 }
85150 } else {
85151 tmp = snd_pcm_oss_write2(substream,
85152 - (const char __force *)buf,
85153 + (const char __force_kernel *)buf,
85154 runtime->oss.period_bytes, 0);
85155 if (tmp <= 0)
85156 goto err;
85157 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
85158 struct snd_pcm_runtime *runtime = substream->runtime;
85159 snd_pcm_sframes_t frames, frames1;
85160 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
85161 - char __user *final_dst = (char __force __user *)buf;
85162 + char __user *final_dst = (char __force_user *)buf;
85163 if (runtime->oss.plugin_first) {
85164 struct snd_pcm_plugin_channel *channels;
85165 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
85166 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
85167 xfer += tmp;
85168 runtime->oss.buffer_used -= tmp;
85169 } else {
85170 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
85171 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
85172 runtime->oss.period_bytes, 0);
85173 if (tmp <= 0)
85174 goto err;
85175 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
85176 size1);
85177 size1 /= runtime->channels; /* frames */
85178 fs = snd_enter_user();
85179 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
85180 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
85181 snd_leave_user(fs);
85182 }
85183 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
85184 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
85185 index af49721..e85058e 100644
85186 --- a/sound/core/pcm_compat.c
85187 +++ b/sound/core/pcm_compat.c
85188 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
85189 int err;
85190
85191 fs = snd_enter_user();
85192 - err = snd_pcm_delay(substream, &delay);
85193 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
85194 snd_leave_user(fs);
85195 if (err < 0)
85196 return err;
85197 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
85198 index 09b4286..8620fac 100644
85199 --- a/sound/core/pcm_native.c
85200 +++ b/sound/core/pcm_native.c
85201 @@ -2806,11 +2806,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
85202 switch (substream->stream) {
85203 case SNDRV_PCM_STREAM_PLAYBACK:
85204 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
85205 - (void __user *)arg);
85206 + (void __force_user *)arg);
85207 break;
85208 case SNDRV_PCM_STREAM_CAPTURE:
85209 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
85210 - (void __user *)arg);
85211 + (void __force_user *)arg);
85212 break;
85213 default:
85214 result = -EINVAL;
85215 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
85216 index 040c60e..989a19a 100644
85217 --- a/sound/core/seq/seq_device.c
85218 +++ b/sound/core/seq/seq_device.c
85219 @@ -64,7 +64,7 @@ struct ops_list {
85220 int argsize; /* argument size */
85221
85222 /* operators */
85223 - struct snd_seq_dev_ops ops;
85224 + struct snd_seq_dev_ops *ops;
85225
85226 /* registered devices */
85227 struct list_head dev_list; /* list of devices */
85228 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
85229
85230 mutex_lock(&ops->reg_mutex);
85231 /* copy driver operators */
85232 - ops->ops = *entry;
85233 + ops->ops = entry;
85234 ops->driver |= DRIVER_LOADED;
85235 ops->argsize = argsize;
85236
85237 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
85238 dev->name, ops->id, ops->argsize, dev->argsize);
85239 return -EINVAL;
85240 }
85241 - if (ops->ops.init_device(dev) >= 0) {
85242 + if (ops->ops->init_device(dev) >= 0) {
85243 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
85244 ops->num_init_devices++;
85245 } else {
85246 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
85247 dev->name, ops->id, ops->argsize, dev->argsize);
85248 return -EINVAL;
85249 }
85250 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
85251 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
85252 dev->status = SNDRV_SEQ_DEVICE_FREE;
85253 dev->driver_data = NULL;
85254 ops->num_init_devices--;
85255 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
85256 index 4e0dd22..7a1f32c 100644
85257 --- a/sound/drivers/mts64.c
85258 +++ b/sound/drivers/mts64.c
85259 @@ -29,6 +29,7 @@
85260 #include <sound/initval.h>
85261 #include <sound/rawmidi.h>
85262 #include <sound/control.h>
85263 +#include <asm/local.h>
85264
85265 #define CARD_NAME "Miditerminal 4140"
85266 #define DRIVER_NAME "MTS64"
85267 @@ -67,7 +68,7 @@ struct mts64 {
85268 struct pardevice *pardev;
85269 int pardev_claimed;
85270
85271 - int open_count;
85272 + local_t open_count;
85273 int current_midi_output_port;
85274 int current_midi_input_port;
85275 u8 mode[MTS64_NUM_INPUT_PORTS];
85276 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
85277 {
85278 struct mts64 *mts = substream->rmidi->private_data;
85279
85280 - if (mts->open_count == 0) {
85281 + if (local_read(&mts->open_count) == 0) {
85282 /* We don't need a spinlock here, because this is just called
85283 if the device has not been opened before.
85284 So there aren't any IRQs from the device */
85285 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
85286
85287 msleep(50);
85288 }
85289 - ++(mts->open_count);
85290 + local_inc(&mts->open_count);
85291
85292 return 0;
85293 }
85294 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
85295 struct mts64 *mts = substream->rmidi->private_data;
85296 unsigned long flags;
85297
85298 - --(mts->open_count);
85299 - if (mts->open_count == 0) {
85300 + if (local_dec_return(&mts->open_count) == 0) {
85301 /* We need the spinlock_irqsave here because we can still
85302 have IRQs at this point */
85303 spin_lock_irqsave(&mts->lock, flags);
85304 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
85305
85306 msleep(500);
85307
85308 - } else if (mts->open_count < 0)
85309 - mts->open_count = 0;
85310 + } else if (local_read(&mts->open_count) < 0)
85311 + local_set(&mts->open_count, 0);
85312
85313 return 0;
85314 }
85315 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
85316 index b953fb4..1999c01 100644
85317 --- a/sound/drivers/opl4/opl4_lib.c
85318 +++ b/sound/drivers/opl4/opl4_lib.c
85319 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
85320 MODULE_DESCRIPTION("OPL4 driver");
85321 MODULE_LICENSE("GPL");
85322
85323 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
85324 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
85325 {
85326 int timeout = 10;
85327 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
85328 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
85329 index 991018d..8984740 100644
85330 --- a/sound/drivers/portman2x4.c
85331 +++ b/sound/drivers/portman2x4.c
85332 @@ -48,6 +48,7 @@
85333 #include <sound/initval.h>
85334 #include <sound/rawmidi.h>
85335 #include <sound/control.h>
85336 +#include <asm/local.h>
85337
85338 #define CARD_NAME "Portman 2x4"
85339 #define DRIVER_NAME "portman"
85340 @@ -85,7 +86,7 @@ struct portman {
85341 struct pardevice *pardev;
85342 int pardev_claimed;
85343
85344 - int open_count;
85345 + local_t open_count;
85346 int mode[PORTMAN_NUM_INPUT_PORTS];
85347 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
85348 };
85349 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
85350 index ea995af..f1bfa37 100644
85351 --- a/sound/firewire/amdtp.c
85352 +++ b/sound/firewire/amdtp.c
85353 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
85354 ptr = s->pcm_buffer_pointer + data_blocks;
85355 if (ptr >= pcm->runtime->buffer_size)
85356 ptr -= pcm->runtime->buffer_size;
85357 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
85358 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
85359
85360 s->pcm_period_pointer += data_blocks;
85361 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
85362 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
85363 */
85364 void amdtp_out_stream_update(struct amdtp_out_stream *s)
85365 {
85366 - ACCESS_ONCE(s->source_node_id_field) =
85367 + ACCESS_ONCE_RW(s->source_node_id_field) =
85368 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
85369 }
85370 EXPORT_SYMBOL(amdtp_out_stream_update);
85371 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
85372 index b680c5e..061b7a0 100644
85373 --- a/sound/firewire/amdtp.h
85374 +++ b/sound/firewire/amdtp.h
85375 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
85376 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
85377 struct snd_pcm_substream *pcm)
85378 {
85379 - ACCESS_ONCE(s->pcm) = pcm;
85380 + ACCESS_ONCE_RW(s->pcm) = pcm;
85381 }
85382
85383 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
85384 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
85385 index d428ffe..751ef78 100644
85386 --- a/sound/firewire/isight.c
85387 +++ b/sound/firewire/isight.c
85388 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
85389 ptr += count;
85390 if (ptr >= runtime->buffer_size)
85391 ptr -= runtime->buffer_size;
85392 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
85393 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
85394
85395 isight->period_counter += count;
85396 if (isight->period_counter >= runtime->period_size) {
85397 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
85398 if (err < 0)
85399 return err;
85400
85401 - ACCESS_ONCE(isight->pcm_active) = true;
85402 + ACCESS_ONCE_RW(isight->pcm_active) = true;
85403
85404 return 0;
85405 }
85406 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
85407 {
85408 struct isight *isight = substream->private_data;
85409
85410 - ACCESS_ONCE(isight->pcm_active) = false;
85411 + ACCESS_ONCE_RW(isight->pcm_active) = false;
85412
85413 mutex_lock(&isight->mutex);
85414 isight_stop_streaming(isight);
85415 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
85416
85417 switch (cmd) {
85418 case SNDRV_PCM_TRIGGER_START:
85419 - ACCESS_ONCE(isight->pcm_running) = true;
85420 + ACCESS_ONCE_RW(isight->pcm_running) = true;
85421 break;
85422 case SNDRV_PCM_TRIGGER_STOP:
85423 - ACCESS_ONCE(isight->pcm_running) = false;
85424 + ACCESS_ONCE_RW(isight->pcm_running) = false;
85425 break;
85426 default:
85427 return -EINVAL;
85428 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
85429 index 844a555..985ab83 100644
85430 --- a/sound/firewire/scs1x.c
85431 +++ b/sound/firewire/scs1x.c
85432 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
85433 {
85434 struct scs *scs = stream->rmidi->private_data;
85435
85436 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
85437 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
85438 if (up) {
85439 scs->output_idle = false;
85440 tasklet_schedule(&scs->tasklet);
85441 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
85442 {
85443 struct scs *scs = stream->rmidi->private_data;
85444
85445 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
85446 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
85447 }
85448
85449 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
85450 @@ -457,8 +457,8 @@ static int scs_remove(struct device *dev)
85451
85452 snd_card_disconnect(scs->card);
85453
85454 - ACCESS_ONCE(scs->output) = NULL;
85455 - ACCESS_ONCE(scs->input) = NULL;
85456 + ACCESS_ONCE_RW(scs->output) = NULL;
85457 + ACCESS_ONCE_RW(scs->input) = NULL;
85458
85459 wait_event(scs->idle_wait, scs->output_idle);
85460
85461 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
85462 index 048439a..3be9f6f 100644
85463 --- a/sound/oss/sb_audio.c
85464 +++ b/sound/oss/sb_audio.c
85465 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
85466 buf16 = (signed short *)(localbuf + localoffs);
85467 while (c)
85468 {
85469 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
85470 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
85471 if (copy_from_user(lbuf8,
85472 userbuf+useroffs + p,
85473 locallen))
85474 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
85475 index 7d8803a..559f8d0 100644
85476 --- a/sound/oss/swarm_cs4297a.c
85477 +++ b/sound/oss/swarm_cs4297a.c
85478 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
85479 {
85480 struct cs4297a_state *s;
85481 u32 pwr, id;
85482 - mm_segment_t fs;
85483 int rval;
85484 #ifndef CONFIG_BCM_CS4297A_CSWARM
85485 u64 cfg;
85486 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
85487 if (!rval) {
85488 char *sb1250_duart_present;
85489
85490 +#if 0
85491 + mm_segment_t fs;
85492 fs = get_fs();
85493 set_fs(KERNEL_DS);
85494 -#if 0
85495 val = SOUND_MASK_LINE;
85496 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
85497 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
85498 val = initvol[i].vol;
85499 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
85500 }
85501 + set_fs(fs);
85502 // cs4297a_write_ac97(s, 0x18, 0x0808);
85503 #else
85504 // cs4297a_write_ac97(s, 0x5e, 0x180);
85505 cs4297a_write_ac97(s, 0x02, 0x0808);
85506 cs4297a_write_ac97(s, 0x18, 0x0808);
85507 #endif
85508 - set_fs(fs);
85509
85510 list_add(&s->list, &cs4297a_devs);
85511
85512 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
85513 index 4631a23..001ae57 100644
85514 --- a/sound/pci/ymfpci/ymfpci.h
85515 +++ b/sound/pci/ymfpci/ymfpci.h
85516 @@ -358,7 +358,7 @@ struct snd_ymfpci {
85517 spinlock_t reg_lock;
85518 spinlock_t voice_lock;
85519 wait_queue_head_t interrupt_sleep;
85520 - atomic_t interrupt_sleep_count;
85521 + atomic_unchecked_t interrupt_sleep_count;
85522 struct snd_info_entry *proc_entry;
85523 const struct firmware *dsp_microcode;
85524 const struct firmware *controller_microcode;
85525 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
85526 index 22056c5..25d3244 100644
85527 --- a/sound/pci/ymfpci/ymfpci_main.c
85528 +++ b/sound/pci/ymfpci/ymfpci_main.c
85529 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
85530 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
85531 break;
85532 }
85533 - if (atomic_read(&chip->interrupt_sleep_count)) {
85534 - atomic_set(&chip->interrupt_sleep_count, 0);
85535 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
85536 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85537 wake_up(&chip->interrupt_sleep);
85538 }
85539 __end:
85540 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
85541 continue;
85542 init_waitqueue_entry(&wait, current);
85543 add_wait_queue(&chip->interrupt_sleep, &wait);
85544 - atomic_inc(&chip->interrupt_sleep_count);
85545 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
85546 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
85547 remove_wait_queue(&chip->interrupt_sleep, &wait);
85548 }
85549 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
85550 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
85551 spin_unlock(&chip->reg_lock);
85552
85553 - if (atomic_read(&chip->interrupt_sleep_count)) {
85554 - atomic_set(&chip->interrupt_sleep_count, 0);
85555 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
85556 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85557 wake_up(&chip->interrupt_sleep);
85558 }
85559 }
85560 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
85561 spin_lock_init(&chip->reg_lock);
85562 spin_lock_init(&chip->voice_lock);
85563 init_waitqueue_head(&chip->interrupt_sleep);
85564 - atomic_set(&chip->interrupt_sleep_count, 0);
85565 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85566 chip->card = card;
85567 chip->pci = pci;
85568 chip->irq = -1;
85569 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
85570 new file mode 100644
85571 index 0000000..50f2f2f
85572 --- /dev/null
85573 +++ b/tools/gcc/.gitignore
85574 @@ -0,0 +1 @@
85575 +size_overflow_hash.h
85576 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
85577 new file mode 100644
85578 index 0000000..1d09b7e
85579 --- /dev/null
85580 +++ b/tools/gcc/Makefile
85581 @@ -0,0 +1,43 @@
85582 +#CC := gcc
85583 +#PLUGIN_SOURCE_FILES := pax_plugin.c
85584 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
85585 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
85586 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
85587 +
85588 +ifeq ($(PLUGINCC),$(HOSTCC))
85589 +HOSTLIBS := hostlibs
85590 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
85591 +else
85592 +HOSTLIBS := hostcxxlibs
85593 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
85594 +endif
85595 +
85596 +$(HOSTLIBS)-y := constify_plugin.so
85597 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
85598 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
85599 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
85600 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
85601 +$(HOSTLIBS)-y += colorize_plugin.so
85602 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
85603 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
85604 +
85605 +always := $($(HOSTLIBS)-y)
85606 +
85607 +constify_plugin-objs := constify_plugin.o
85608 +stackleak_plugin-objs := stackleak_plugin.o
85609 +kallocstat_plugin-objs := kallocstat_plugin.o
85610 +kernexec_plugin-objs := kernexec_plugin.o
85611 +checker_plugin-objs := checker_plugin.o
85612 +colorize_plugin-objs := colorize_plugin.o
85613 +size_overflow_plugin-objs := size_overflow_plugin.o
85614 +latent_entropy_plugin-objs := latent_entropy_plugin.o
85615 +
85616 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
85617 +
85618 +quiet_cmd_build_size_overflow_hash = GENHASH $@
85619 + cmd_build_size_overflow_hash = \
85620 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
85621 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
85622 + $(call if_changed,build_size_overflow_hash)
85623 +
85624 +targets += size_overflow_hash.h
85625 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
85626 new file mode 100644
85627 index 0000000..d41b5af
85628 --- /dev/null
85629 +++ b/tools/gcc/checker_plugin.c
85630 @@ -0,0 +1,171 @@
85631 +/*
85632 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85633 + * Licensed under the GPL v2
85634 + *
85635 + * Note: the choice of the license means that the compilation process is
85636 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85637 + * but for the kernel it doesn't matter since it doesn't link against
85638 + * any of the gcc libraries
85639 + *
85640 + * gcc plugin to implement various sparse (source code checker) features
85641 + *
85642 + * TODO:
85643 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
85644 + *
85645 + * BUGS:
85646 + * - none known
85647 + */
85648 +#include "gcc-plugin.h"
85649 +#include "config.h"
85650 +#include "system.h"
85651 +#include "coretypes.h"
85652 +#include "tree.h"
85653 +#include "tree-pass.h"
85654 +#include "flags.h"
85655 +#include "intl.h"
85656 +#include "toplev.h"
85657 +#include "plugin.h"
85658 +//#include "expr.h" where are you...
85659 +#include "diagnostic.h"
85660 +#include "plugin-version.h"
85661 +#include "tm.h"
85662 +#include "function.h"
85663 +#include "basic-block.h"
85664 +#include "gimple.h"
85665 +#include "rtl.h"
85666 +#include "emit-rtl.h"
85667 +#include "tree-flow.h"
85668 +#include "target.h"
85669 +
85670 +extern void c_register_addr_space (const char *str, addr_space_t as);
85671 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
85672 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
85673 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
85674 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
85675 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
85676 +
85677 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85678 +extern rtx emit_move_insn(rtx x, rtx y);
85679 +
85680 +int plugin_is_GPL_compatible;
85681 +
85682 +static struct plugin_info checker_plugin_info = {
85683 + .version = "201111150100",
85684 +};
85685 +
85686 +#define ADDR_SPACE_KERNEL 0
85687 +#define ADDR_SPACE_FORCE_KERNEL 1
85688 +#define ADDR_SPACE_USER 2
85689 +#define ADDR_SPACE_FORCE_USER 3
85690 +#define ADDR_SPACE_IOMEM 0
85691 +#define ADDR_SPACE_FORCE_IOMEM 0
85692 +#define ADDR_SPACE_PERCPU 0
85693 +#define ADDR_SPACE_FORCE_PERCPU 0
85694 +#define ADDR_SPACE_RCU 0
85695 +#define ADDR_SPACE_FORCE_RCU 0
85696 +
85697 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
85698 +{
85699 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
85700 +}
85701 +
85702 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
85703 +{
85704 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
85705 +}
85706 +
85707 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
85708 +{
85709 + return default_addr_space_valid_pointer_mode(mode, as);
85710 +}
85711 +
85712 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
85713 +{
85714 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
85715 +}
85716 +
85717 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
85718 +{
85719 + return default_addr_space_legitimize_address(x, oldx, mode, as);
85720 +}
85721 +
85722 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
85723 +{
85724 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
85725 + return true;
85726 +
85727 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
85728 + return true;
85729 +
85730 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
85731 + return true;
85732 +
85733 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
85734 + return true;
85735 +
85736 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
85737 + return true;
85738 +
85739 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
85740 + return true;
85741 +
85742 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
85743 + return true;
85744 +
85745 + return subset == superset;
85746 +}
85747 +
85748 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
85749 +{
85750 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
85751 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
85752 +
85753 + return op;
85754 +}
85755 +
85756 +static void register_checker_address_spaces(void *event_data, void *data)
85757 +{
85758 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
85759 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
85760 + c_register_addr_space("__user", ADDR_SPACE_USER);
85761 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
85762 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
85763 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
85764 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
85765 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
85766 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
85767 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
85768 +
85769 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
85770 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
85771 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
85772 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
85773 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
85774 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
85775 + targetm.addr_space.convert = checker_addr_space_convert;
85776 +}
85777 +
85778 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85779 +{
85780 + const char * const plugin_name = plugin_info->base_name;
85781 + const int argc = plugin_info->argc;
85782 + const struct plugin_argument * const argv = plugin_info->argv;
85783 + int i;
85784 +
85785 + if (!plugin_default_version_check(version, &gcc_version)) {
85786 + error(G_("incompatible gcc/plugin versions"));
85787 + return 1;
85788 + }
85789 +
85790 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
85791 +
85792 + for (i = 0; i < argc; ++i)
85793 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85794 +
85795 + if (TARGET_64BIT == 0)
85796 + return 0;
85797 +
85798 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
85799 +
85800 + return 0;
85801 +}
85802 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
85803 new file mode 100644
85804 index 0000000..414fe5e
85805 --- /dev/null
85806 +++ b/tools/gcc/colorize_plugin.c
85807 @@ -0,0 +1,151 @@
85808 +/*
85809 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
85810 + * Licensed under the GPL v2
85811 + *
85812 + * Note: the choice of the license means that the compilation process is
85813 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85814 + * but for the kernel it doesn't matter since it doesn't link against
85815 + * any of the gcc libraries
85816 + *
85817 + * gcc plugin to colorize diagnostic output
85818 + *
85819 + */
85820 +
85821 +#include "gcc-plugin.h"
85822 +#include "config.h"
85823 +#include "system.h"
85824 +#include "coretypes.h"
85825 +#include "tree.h"
85826 +#include "tree-pass.h"
85827 +#include "flags.h"
85828 +#include "intl.h"
85829 +#include "toplev.h"
85830 +#include "plugin.h"
85831 +#include "diagnostic.h"
85832 +#include "plugin-version.h"
85833 +#include "tm.h"
85834 +
85835 +int plugin_is_GPL_compatible;
85836 +
85837 +static struct plugin_info colorize_plugin_info = {
85838 + .version = "201302112000",
85839 + .help = NULL,
85840 +};
85841 +
85842 +#define GREEN "\033[32m\033[2m"
85843 +#define LIGHTGREEN "\033[32m\033[1m"
85844 +#define YELLOW "\033[33m\033[2m"
85845 +#define LIGHTYELLOW "\033[33m\033[1m"
85846 +#define RED "\033[31m\033[2m"
85847 +#define LIGHTRED "\033[31m\033[1m"
85848 +#define BLUE "\033[34m\033[2m"
85849 +#define LIGHTBLUE "\033[34m\033[1m"
85850 +#define BRIGHT "\033[m\033[1m"
85851 +#define NORMAL "\033[m"
85852 +
85853 +static diagnostic_starter_fn old_starter;
85854 +static diagnostic_finalizer_fn old_finalizer;
85855 +
85856 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
85857 +{
85858 + const char *color;
85859 + char *newprefix;
85860 +
85861 + switch (diagnostic->kind) {
85862 + case DK_NOTE:
85863 + color = LIGHTBLUE;
85864 + break;
85865 +
85866 + case DK_PEDWARN:
85867 + case DK_WARNING:
85868 + color = LIGHTYELLOW;
85869 + break;
85870 +
85871 + case DK_ERROR:
85872 + case DK_FATAL:
85873 + case DK_ICE:
85874 + case DK_PERMERROR:
85875 + case DK_SORRY:
85876 + color = LIGHTRED;
85877 + break;
85878 +
85879 + default:
85880 + color = NORMAL;
85881 + }
85882 +
85883 + old_starter(context, diagnostic);
85884 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
85885 + return;
85886 + pp_destroy_prefix(context->printer);
85887 + pp_set_prefix(context->printer, newprefix);
85888 +}
85889 +
85890 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
85891 +{
85892 + old_finalizer(context, diagnostic);
85893 +}
85894 +
85895 +static void colorize_arm(void)
85896 +{
85897 + old_starter = diagnostic_starter(global_dc);
85898 + old_finalizer = diagnostic_finalizer(global_dc);
85899 +
85900 + diagnostic_starter(global_dc) = start_colorize;
85901 + diagnostic_finalizer(global_dc) = finalize_colorize;
85902 +}
85903 +
85904 +static unsigned int execute_colorize_rearm(void)
85905 +{
85906 + if (diagnostic_starter(global_dc) == start_colorize)
85907 + return 0;
85908 +
85909 + colorize_arm();
85910 + return 0;
85911 +}
85912 +
85913 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
85914 + .pass = {
85915 + .type = SIMPLE_IPA_PASS,
85916 + .name = "colorize_rearm",
85917 +#if BUILDING_GCC_VERSION >= 4008
85918 + .optinfo_flags = OPTGROUP_NONE,
85919 +#endif
85920 + .gate = NULL,
85921 + .execute = execute_colorize_rearm,
85922 + .sub = NULL,
85923 + .next = NULL,
85924 + .static_pass_number = 0,
85925 + .tv_id = TV_NONE,
85926 + .properties_required = 0,
85927 + .properties_provided = 0,
85928 + .properties_destroyed = 0,
85929 + .todo_flags_start = 0,
85930 + .todo_flags_finish = 0
85931 + }
85932 +};
85933 +
85934 +static void colorize_start_unit(void *gcc_data, void *user_data)
85935 +{
85936 + colorize_arm();
85937 +}
85938 +
85939 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85940 +{
85941 + const char * const plugin_name = plugin_info->base_name;
85942 + struct register_pass_info colorize_rearm_pass_info = {
85943 + .pass = &pass_ipa_colorize_rearm.pass,
85944 + .reference_pass_name = "*free_lang_data",
85945 + .ref_pass_instance_number = 1,
85946 + .pos_op = PASS_POS_INSERT_AFTER
85947 + };
85948 +
85949 + if (!plugin_default_version_check(version, &gcc_version)) {
85950 + error(G_("incompatible gcc/plugin versions"));
85951 + return 1;
85952 + }
85953 +
85954 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
85955 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
85956 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
85957 + return 0;
85958 +}
85959 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
85960 new file mode 100644
85961 index 0000000..8bd6f995
85962 --- /dev/null
85963 +++ b/tools/gcc/constify_plugin.c
85964 @@ -0,0 +1,359 @@
85965 +/*
85966 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
85967 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
85968 + * Licensed under the GPL v2, or (at your option) v3
85969 + *
85970 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
85971 + *
85972 + * Homepage:
85973 + * http://www.grsecurity.net/~ephox/const_plugin/
85974 + *
85975 + * Usage:
85976 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
85977 + * $ gcc -fplugin=constify_plugin.so test.c -O2
85978 + */
85979 +
85980 +#include "gcc-plugin.h"
85981 +#include "config.h"
85982 +#include "system.h"
85983 +#include "coretypes.h"
85984 +#include "tree.h"
85985 +#include "tree-pass.h"
85986 +#include "flags.h"
85987 +#include "intl.h"
85988 +#include "toplev.h"
85989 +#include "plugin.h"
85990 +#include "diagnostic.h"
85991 +#include "plugin-version.h"
85992 +#include "tm.h"
85993 +#include "function.h"
85994 +#include "basic-block.h"
85995 +#include "gimple.h"
85996 +#include "rtl.h"
85997 +#include "emit-rtl.h"
85998 +#include "tree-flow.h"
85999 +
86000 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
86001 +
86002 +int plugin_is_GPL_compatible;
86003 +
86004 +static struct plugin_info const_plugin_info = {
86005 + .version = "201302112000",
86006 + .help = "no-constify\tturn off constification\n",
86007 +};
86008 +
86009 +static tree get_field_type(tree field)
86010 +{
86011 + return strip_array_types(TREE_TYPE(field));
86012 +}
86013 +
86014 +static bool walk_struct(tree node, bool all);
86015 +static void deconstify_tree(tree node);
86016 +
86017 +static void deconstify_type(tree type)
86018 +{
86019 + tree field;
86020 +
86021 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
86022 + tree fieldtype = get_field_type(field);
86023 +
86024 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
86025 + continue;
86026 + if (!TYPE_READONLY(fieldtype))
86027 + continue;
86028 + if (!walk_struct(fieldtype, true))
86029 + continue;
86030 +
86031 + deconstify_tree(field);
86032 + TREE_READONLY(field) = 0;
86033 + }
86034 + TYPE_READONLY(type) = 0;
86035 + C_TYPE_FIELDS_READONLY(type) = 0;
86036 +}
86037 +
86038 +static void deconstify_tree(tree node)
86039 +{
86040 + tree old_type, new_type, field;
86041 +
86042 +// TREE_READONLY(node) = 0;
86043 + old_type = TREE_TYPE(node);
86044 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
86045 + node = old_type;
86046 + old_type = TREE_TYPE(old_type);
86047 + }
86048 +
86049 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
86050 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
86051 +
86052 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
86053 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
86054 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
86055 + DECL_FIELD_CONTEXT(field) = new_type;
86056 +
86057 + deconstify_type(new_type);
86058 +
86059 + TREE_TYPE(node) = new_type;
86060 +}
86061 +
86062 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86063 +{
86064 + tree type;
86065 +
86066 + *no_add_attrs = true;
86067 + if (TREE_CODE(*node) == FUNCTION_DECL) {
86068 + error("%qE attribute does not apply to functions", name);
86069 + return NULL_TREE;
86070 + }
86071 +
86072 + if (TREE_CODE(*node) == VAR_DECL) {
86073 + error("%qE attribute does not apply to variables", name);
86074 + return NULL_TREE;
86075 + }
86076 +
86077 + if (TYPE_P(*node)) {
86078 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
86079 + *no_add_attrs = false;
86080 + else
86081 + error("%qE attribute applies to struct and union types only", name);
86082 + return NULL_TREE;
86083 + }
86084 +
86085 + type = TREE_TYPE(*node);
86086 +
86087 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
86088 + error("%qE attribute applies to struct and union types only", name);
86089 + return NULL_TREE;
86090 + }
86091 +
86092 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
86093 + error("%qE attribute is already applied to the type", name);
86094 + return NULL_TREE;
86095 + }
86096 +
86097 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
86098 + error("%qE attribute used on type that is not constified", name);
86099 + return NULL_TREE;
86100 + }
86101 +
86102 + if (TREE_CODE(*node) == TYPE_DECL) {
86103 + deconstify_tree(*node);
86104 + return NULL_TREE;
86105 + }
86106 +
86107 + return NULL_TREE;
86108 +}
86109 +
86110 +static void constify_type(tree type)
86111 +{
86112 + TYPE_READONLY(type) = 1;
86113 + C_TYPE_FIELDS_READONLY(type) = 1;
86114 +}
86115 +
86116 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86117 +{
86118 + *no_add_attrs = true;
86119 + if (!TYPE_P(*node)) {
86120 + error("%qE attribute applies to types only", name);
86121 + return NULL_TREE;
86122 + }
86123 +
86124 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
86125 + error("%qE attribute applies to struct and union types only", name);
86126 + return NULL_TREE;
86127 + }
86128 +
86129 + *no_add_attrs = false;
86130 + constify_type(*node);
86131 + return NULL_TREE;
86132 +}
86133 +
86134 +static struct attribute_spec no_const_attr = {
86135 + .name = "no_const",
86136 + .min_length = 0,
86137 + .max_length = 0,
86138 + .decl_required = false,
86139 + .type_required = false,
86140 + .function_type_required = false,
86141 + .handler = handle_no_const_attribute,
86142 +#if BUILDING_GCC_VERSION >= 4007
86143 + .affects_type_identity = true
86144 +#endif
86145 +};
86146 +
86147 +static struct attribute_spec do_const_attr = {
86148 + .name = "do_const",
86149 + .min_length = 0,
86150 + .max_length = 0,
86151 + .decl_required = false,
86152 + .type_required = false,
86153 + .function_type_required = false,
86154 + .handler = handle_do_const_attribute,
86155 +#if BUILDING_GCC_VERSION >= 4007
86156 + .affects_type_identity = true
86157 +#endif
86158 +};
86159 +
86160 +static void register_attributes(void *event_data, void *data)
86161 +{
86162 + register_attribute(&no_const_attr);
86163 + register_attribute(&do_const_attr);
86164 +}
86165 +
86166 +static bool is_fptr(tree field)
86167 +{
86168 + tree ptr = get_field_type(field);
86169 +
86170 + if (TREE_CODE(ptr) != POINTER_TYPE)
86171 + return false;
86172 +
86173 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
86174 +}
86175 +
86176 +static bool walk_struct(tree node, bool all)
86177 +{
86178 + tree field;
86179 +
86180 + if (TYPE_FIELDS(node) == NULL_TREE)
86181 + return false;
86182 +
86183 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
86184 + return true;
86185 +
86186 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
86187 + gcc_assert(!TYPE_READONLY(node));
86188 + deconstify_type(node);
86189 + return false;
86190 + }
86191 +
86192 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
86193 + tree type = get_field_type(field);
86194 + enum tree_code code = TREE_CODE(type);
86195 +
86196 + if (node == type)
86197 + return false;
86198 + if (code == RECORD_TYPE || code == UNION_TYPE) {
86199 + if (!(walk_struct(type, all)))
86200 + return false;
86201 + } else if (!is_fptr(field) && (!all || !TREE_READONLY(field)))
86202 + return false;
86203 + }
86204 + return true;
86205 +}
86206 +
86207 +static void finish_type(void *event_data, void *data)
86208 +{
86209 + tree type = (tree)event_data;
86210 +
86211 + if (type == NULL_TREE || type == error_mark_node)
86212 + return;
86213 +
86214 + if (TYPE_READONLY(type))
86215 + return;
86216 +
86217 + if (walk_struct(type, true))
86218 + constify_type(type);
86219 + else
86220 + deconstify_type(type);
86221 +}
86222 +
86223 +static unsigned int check_local_variables(void)
86224 +{
86225 + unsigned int ret = 0;
86226 + tree var;
86227 +
86228 +#if BUILDING_GCC_VERSION == 4005
86229 + tree vars;
86230 +#else
86231 + unsigned int i;
86232 +#endif
86233 +
86234 +#if BUILDING_GCC_VERSION == 4005
86235 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
86236 + var = TREE_VALUE(vars);
86237 +#else
86238 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
86239 +#endif
86240 + tree type = TREE_TYPE(var);
86241 +
86242 + gcc_assert(DECL_P(var));
86243 + if (is_global_var(var))
86244 + continue;
86245 +
86246 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
86247 + continue;
86248 +
86249 + if (!TYPE_READONLY(type))
86250 + continue;
86251 +
86252 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
86253 +// continue;
86254 +
86255 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
86256 + continue;
86257 +
86258 + if (walk_struct(type, false)) {
86259 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
86260 + ret = 1;
86261 + }
86262 + }
86263 + return ret;
86264 +}
86265 +
86266 +struct gimple_opt_pass pass_local_variable = {
86267 + {
86268 + .type = GIMPLE_PASS,
86269 + .name = "check_local_variables",
86270 +#if BUILDING_GCC_VERSION >= 4008
86271 + .optinfo_flags = OPTGROUP_NONE,
86272 +#endif
86273 + .gate = NULL,
86274 + .execute = check_local_variables,
86275 + .sub = NULL,
86276 + .next = NULL,
86277 + .static_pass_number = 0,
86278 + .tv_id = TV_NONE,
86279 + .properties_required = 0,
86280 + .properties_provided = 0,
86281 + .properties_destroyed = 0,
86282 + .todo_flags_start = 0,
86283 + .todo_flags_finish = 0
86284 + }
86285 +};
86286 +
86287 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86288 +{
86289 + const char * const plugin_name = plugin_info->base_name;
86290 + const int argc = plugin_info->argc;
86291 + const struct plugin_argument * const argv = plugin_info->argv;
86292 + int i;
86293 + bool constify = true;
86294 +
86295 + struct register_pass_info local_variable_pass_info = {
86296 + .pass = &pass_local_variable.pass,
86297 + .reference_pass_name = "ssa",
86298 + .ref_pass_instance_number = 1,
86299 + .pos_op = PASS_POS_INSERT_BEFORE
86300 + };
86301 +
86302 + if (!plugin_default_version_check(version, &gcc_version)) {
86303 + error(G_("incompatible gcc/plugin versions"));
86304 + return 1;
86305 + }
86306 +
86307 + for (i = 0; i < argc; ++i) {
86308 + if (!(strcmp(argv[i].key, "no-constify"))) {
86309 + constify = false;
86310 + continue;
86311 + }
86312 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86313 + }
86314 +
86315 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
86316 + if (constify) {
86317 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
86318 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
86319 + }
86320 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86321 +
86322 + return 0;
86323 +}
86324 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
86325 new file mode 100644
86326 index 0000000..e518932
86327 --- /dev/null
86328 +++ b/tools/gcc/generate_size_overflow_hash.sh
86329 @@ -0,0 +1,94 @@
86330 +#!/bin/bash
86331 +
86332 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
86333 +
86334 +header1="size_overflow_hash.h"
86335 +database="size_overflow_hash.data"
86336 +n=65536
86337 +
86338 +usage() {
86339 +cat <<EOF
86340 +usage: $0 options
86341 +OPTIONS:
86342 + -h|--help help
86343 + -o header file
86344 + -d database file
86345 + -n hash array size
86346 +EOF
86347 + return 0
86348 +}
86349 +
86350 +while true
86351 +do
86352 + case "$1" in
86353 + -h|--help) usage && exit 0;;
86354 + -n) n=$2; shift 2;;
86355 + -o) header1="$2"; shift 2;;
86356 + -d) database="$2"; shift 2;;
86357 + --) shift 1; break ;;
86358 + *) break ;;
86359 + esac
86360 +done
86361 +
86362 +create_defines() {
86363 + for i in `seq 0 31`
86364 + do
86365 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
86366 + done
86367 + echo >> "$header1"
86368 +}
86369 +
86370 +create_structs() {
86371 + rm -f "$header1"
86372 +
86373 + create_defines
86374 +
86375 + cat "$database" | while read data
86376 + do
86377 + data_array=($data)
86378 + struct_hash_name="${data_array[0]}"
86379 + funcn="${data_array[1]}"
86380 + params="${data_array[2]}"
86381 + next="${data_array[4]}"
86382 +
86383 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
86384 +
86385 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
86386 + echo -en "\t.param\t= " >> "$header1"
86387 + line=
86388 + for param_num in ${params//-/ };
86389 + do
86390 + line="${line}PARAM"$param_num"|"
86391 + done
86392 +
86393 + echo -e "${line%?},\n};\n" >> "$header1"
86394 + done
86395 +}
86396 +
86397 +create_headers() {
86398 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
86399 +}
86400 +
86401 +create_array_elements() {
86402 + index=0
86403 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
86404 + do
86405 + data_array=($data)
86406 + i="${data_array[3]}"
86407 + hash="${data_array[0]}"
86408 + while [[ $index -lt $i ]]
86409 + do
86410 + echo -e "\t["$index"]\t= NULL," >> "$header1"
86411 + index=$(($index + 1))
86412 + done
86413 + index=$(($index + 1))
86414 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
86415 + done
86416 + echo '};' >> $header1
86417 +}
86418 +
86419 +create_structs
86420 +create_headers
86421 +create_array_elements
86422 +
86423 +exit 0
86424 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
86425 new file mode 100644
86426 index 0000000..568b360
86427 --- /dev/null
86428 +++ b/tools/gcc/kallocstat_plugin.c
86429 @@ -0,0 +1,170 @@
86430 +/*
86431 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
86432 + * Licensed under the GPL v2
86433 + *
86434 + * Note: the choice of the license means that the compilation process is
86435 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86436 + * but for the kernel it doesn't matter since it doesn't link against
86437 + * any of the gcc libraries
86438 + *
86439 + * gcc plugin to find the distribution of k*alloc sizes
86440 + *
86441 + * TODO:
86442 + *
86443 + * BUGS:
86444 + * - none known
86445 + */
86446 +#include "gcc-plugin.h"
86447 +#include "config.h"
86448 +#include "system.h"
86449 +#include "coretypes.h"
86450 +#include "tree.h"
86451 +#include "tree-pass.h"
86452 +#include "flags.h"
86453 +#include "intl.h"
86454 +#include "toplev.h"
86455 +#include "plugin.h"
86456 +//#include "expr.h" where are you...
86457 +#include "diagnostic.h"
86458 +#include "plugin-version.h"
86459 +#include "tm.h"
86460 +#include "function.h"
86461 +#include "basic-block.h"
86462 +#include "gimple.h"
86463 +#include "rtl.h"
86464 +#include "emit-rtl.h"
86465 +
86466 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86467 +
86468 +int plugin_is_GPL_compatible;
86469 +
86470 +static const char * const kalloc_functions[] = {
86471 + "__kmalloc",
86472 + "kmalloc",
86473 + "kmalloc_large",
86474 + "kmalloc_node",
86475 + "kmalloc_order",
86476 + "kmalloc_order_trace",
86477 + "kmalloc_slab",
86478 + "kzalloc",
86479 + "kzalloc_node",
86480 +};
86481 +
86482 +static struct plugin_info kallocstat_plugin_info = {
86483 + .version = "201302112000",
86484 +};
86485 +
86486 +static unsigned int execute_kallocstat(void);
86487 +
86488 +static struct gimple_opt_pass kallocstat_pass = {
86489 + .pass = {
86490 + .type = GIMPLE_PASS,
86491 + .name = "kallocstat",
86492 +#if BUILDING_GCC_VERSION >= 4008
86493 + .optinfo_flags = OPTGROUP_NONE,
86494 +#endif
86495 + .gate = NULL,
86496 + .execute = execute_kallocstat,
86497 + .sub = NULL,
86498 + .next = NULL,
86499 + .static_pass_number = 0,
86500 + .tv_id = TV_NONE,
86501 + .properties_required = 0,
86502 + .properties_provided = 0,
86503 + .properties_destroyed = 0,
86504 + .todo_flags_start = 0,
86505 + .todo_flags_finish = 0
86506 + }
86507 +};
86508 +
86509 +static bool is_kalloc(const char *fnname)
86510 +{
86511 + size_t i;
86512 +
86513 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
86514 + if (!strcmp(fnname, kalloc_functions[i]))
86515 + return true;
86516 + return false;
86517 +}
86518 +
86519 +static unsigned int execute_kallocstat(void)
86520 +{
86521 + basic_block bb;
86522 +
86523 + // 1. loop through BBs and GIMPLE statements
86524 + FOR_EACH_BB(bb) {
86525 + gimple_stmt_iterator gsi;
86526 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86527 + // gimple match:
86528 + tree fndecl, size;
86529 + gimple call_stmt;
86530 + const char *fnname;
86531 +
86532 + // is it a call
86533 + call_stmt = gsi_stmt(gsi);
86534 + if (!is_gimple_call(call_stmt))
86535 + continue;
86536 + fndecl = gimple_call_fndecl(call_stmt);
86537 + if (fndecl == NULL_TREE)
86538 + continue;
86539 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
86540 + continue;
86541 +
86542 + // is it a call to k*alloc
86543 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
86544 + if (!is_kalloc(fnname))
86545 + continue;
86546 +
86547 + // is the size arg the result of a simple const assignment
86548 + size = gimple_call_arg(call_stmt, 0);
86549 + while (true) {
86550 + gimple def_stmt;
86551 + expanded_location xloc;
86552 + size_t size_val;
86553 +
86554 + if (TREE_CODE(size) != SSA_NAME)
86555 + break;
86556 + def_stmt = SSA_NAME_DEF_STMT(size);
86557 + if (!def_stmt || !is_gimple_assign(def_stmt))
86558 + break;
86559 + if (gimple_num_ops(def_stmt) != 2)
86560 + break;
86561 + size = gimple_assign_rhs1(def_stmt);
86562 + if (!TREE_CONSTANT(size))
86563 + continue;
86564 + xloc = expand_location(gimple_location(def_stmt));
86565 + if (!xloc.file)
86566 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
86567 + size_val = TREE_INT_CST_LOW(size);
86568 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
86569 + break;
86570 + }
86571 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
86572 +//debug_tree(gimple_call_fn(call_stmt));
86573 +//print_node(stderr, "pax", fndecl, 4);
86574 + }
86575 + }
86576 +
86577 + return 0;
86578 +}
86579 +
86580 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86581 +{
86582 + const char * const plugin_name = plugin_info->base_name;
86583 + struct register_pass_info kallocstat_pass_info = {
86584 + .pass = &kallocstat_pass.pass,
86585 + .reference_pass_name = "ssa",
86586 + .ref_pass_instance_number = 1,
86587 + .pos_op = PASS_POS_INSERT_AFTER
86588 + };
86589 +
86590 + if (!plugin_default_version_check(version, &gcc_version)) {
86591 + error(G_("incompatible gcc/plugin versions"));
86592 + return 1;
86593 + }
86594 +
86595 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
86596 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
86597 +
86598 + return 0;
86599 +}
86600 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
86601 new file mode 100644
86602 index 0000000..0408e06
86603 --- /dev/null
86604 +++ b/tools/gcc/kernexec_plugin.c
86605 @@ -0,0 +1,465 @@
86606 +/*
86607 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
86608 + * Licensed under the GPL v2
86609 + *
86610 + * Note: the choice of the license means that the compilation process is
86611 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86612 + * but for the kernel it doesn't matter since it doesn't link against
86613 + * any of the gcc libraries
86614 + *
86615 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
86616 + *
86617 + * TODO:
86618 + *
86619 + * BUGS:
86620 + * - none known
86621 + */
86622 +#include "gcc-plugin.h"
86623 +#include "config.h"
86624 +#include "system.h"
86625 +#include "coretypes.h"
86626 +#include "tree.h"
86627 +#include "tree-pass.h"
86628 +#include "flags.h"
86629 +#include "intl.h"
86630 +#include "toplev.h"
86631 +#include "plugin.h"
86632 +//#include "expr.h" where are you...
86633 +#include "diagnostic.h"
86634 +#include "plugin-version.h"
86635 +#include "tm.h"
86636 +#include "function.h"
86637 +#include "basic-block.h"
86638 +#include "gimple.h"
86639 +#include "rtl.h"
86640 +#include "emit-rtl.h"
86641 +#include "tree-flow.h"
86642 +
86643 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86644 +extern rtx emit_move_insn(rtx x, rtx y);
86645 +
86646 +#if BUILDING_GCC_VERSION <= 4006
86647 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
86648 +#endif
86649 +
86650 +#if BUILDING_GCC_VERSION >= 4008
86651 +#define TODO_dump_func 0
86652 +#endif
86653 +
86654 +int plugin_is_GPL_compatible;
86655 +
86656 +static struct plugin_info kernexec_plugin_info = {
86657 + .version = "201302112000",
86658 + .help = "method=[bts|or]\tinstrumentation method\n"
86659 +};
86660 +
86661 +static unsigned int execute_kernexec_reload(void);
86662 +static unsigned int execute_kernexec_fptr(void);
86663 +static unsigned int execute_kernexec_retaddr(void);
86664 +static bool kernexec_cmodel_check(void);
86665 +
86666 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
86667 +static void (*kernexec_instrument_retaddr)(rtx);
86668 +
86669 +static struct gimple_opt_pass kernexec_reload_pass = {
86670 + .pass = {
86671 + .type = GIMPLE_PASS,
86672 + .name = "kernexec_reload",
86673 +#if BUILDING_GCC_VERSION >= 4008
86674 + .optinfo_flags = OPTGROUP_NONE,
86675 +#endif
86676 + .gate = kernexec_cmodel_check,
86677 + .execute = execute_kernexec_reload,
86678 + .sub = NULL,
86679 + .next = NULL,
86680 + .static_pass_number = 0,
86681 + .tv_id = TV_NONE,
86682 + .properties_required = 0,
86683 + .properties_provided = 0,
86684 + .properties_destroyed = 0,
86685 + .todo_flags_start = 0,
86686 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
86687 + }
86688 +};
86689 +
86690 +static struct gimple_opt_pass kernexec_fptr_pass = {
86691 + .pass = {
86692 + .type = GIMPLE_PASS,
86693 + .name = "kernexec_fptr",
86694 +#if BUILDING_GCC_VERSION >= 4008
86695 + .optinfo_flags = OPTGROUP_NONE,
86696 +#endif
86697 + .gate = kernexec_cmodel_check,
86698 + .execute = execute_kernexec_fptr,
86699 + .sub = NULL,
86700 + .next = NULL,
86701 + .static_pass_number = 0,
86702 + .tv_id = TV_NONE,
86703 + .properties_required = 0,
86704 + .properties_provided = 0,
86705 + .properties_destroyed = 0,
86706 + .todo_flags_start = 0,
86707 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
86708 + }
86709 +};
86710 +
86711 +static struct rtl_opt_pass kernexec_retaddr_pass = {
86712 + .pass = {
86713 + .type = RTL_PASS,
86714 + .name = "kernexec_retaddr",
86715 +#if BUILDING_GCC_VERSION >= 4008
86716 + .optinfo_flags = OPTGROUP_NONE,
86717 +#endif
86718 + .gate = kernexec_cmodel_check,
86719 + .execute = execute_kernexec_retaddr,
86720 + .sub = NULL,
86721 + .next = NULL,
86722 + .static_pass_number = 0,
86723 + .tv_id = TV_NONE,
86724 + .properties_required = 0,
86725 + .properties_provided = 0,
86726 + .properties_destroyed = 0,
86727 + .todo_flags_start = 0,
86728 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
86729 + }
86730 +};
86731 +
86732 +static bool kernexec_cmodel_check(void)
86733 +{
86734 + tree section;
86735 +
86736 + if (ix86_cmodel != CM_KERNEL)
86737 + return false;
86738 +
86739 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
86740 + if (!section || !TREE_VALUE(section))
86741 + return true;
86742 +
86743 + section = TREE_VALUE(TREE_VALUE(section));
86744 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
86745 + return true;
86746 +
86747 + return false;
86748 +}
86749 +
86750 +/*
86751 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
86752 + */
86753 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
86754 +{
86755 + gimple asm_movabs_stmt;
86756 +
86757 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
86758 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
86759 + gimple_asm_set_volatile(asm_movabs_stmt, true);
86760 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
86761 + update_stmt(asm_movabs_stmt);
86762 +}
86763 +
86764 +/*
86765 + * find all asm() stmts that clobber r10 and add a reload of r10
86766 + */
86767 +static unsigned int execute_kernexec_reload(void)
86768 +{
86769 + basic_block bb;
86770 +
86771 + // 1. loop through BBs and GIMPLE statements
86772 + FOR_EACH_BB(bb) {
86773 + gimple_stmt_iterator gsi;
86774 +
86775 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86776 + // gimple match: __asm__ ("" : : : "r10");
86777 + gimple asm_stmt;
86778 + size_t nclobbers;
86779 +
86780 + // is it an asm ...
86781 + asm_stmt = gsi_stmt(gsi);
86782 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
86783 + continue;
86784 +
86785 + // ... clobbering r10
86786 + nclobbers = gimple_asm_nclobbers(asm_stmt);
86787 + while (nclobbers--) {
86788 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
86789 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
86790 + continue;
86791 + kernexec_reload_fptr_mask(&gsi);
86792 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
86793 + break;
86794 + }
86795 + }
86796 + }
86797 +
86798 + return 0;
86799 +}
86800 +
86801 +/*
86802 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
86803 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
86804 + */
86805 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
86806 +{
86807 + gimple assign_intptr, assign_new_fptr, call_stmt;
86808 + tree intptr, old_fptr, new_fptr, kernexec_mask;
86809 +
86810 + call_stmt = gsi_stmt(*gsi);
86811 + old_fptr = gimple_call_fn(call_stmt);
86812 +
86813 + // create temporary unsigned long variable used for bitops and cast fptr to it
86814 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
86815 +#if BUILDING_GCC_VERSION <= 4007
86816 + add_referenced_var(intptr);
86817 + mark_sym_for_renaming(intptr);
86818 +#endif
86819 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
86820 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
86821 + update_stmt(assign_intptr);
86822 +
86823 + // apply logical or to temporary unsigned long and bitmask
86824 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
86825 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
86826 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
86827 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
86828 + update_stmt(assign_intptr);
86829 +
86830 + // cast temporary unsigned long back to a temporary fptr variable
86831 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
86832 +#if BUILDING_GCC_VERSION <= 4007
86833 + add_referenced_var(new_fptr);
86834 + mark_sym_for_renaming(new_fptr);
86835 +#endif
86836 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
86837 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
86838 + update_stmt(assign_new_fptr);
86839 +
86840 + // replace call stmt fn with the new fptr
86841 + gimple_call_set_fn(call_stmt, new_fptr);
86842 + update_stmt(call_stmt);
86843 +}
86844 +
86845 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
86846 +{
86847 + gimple asm_or_stmt, call_stmt;
86848 + tree old_fptr, new_fptr, input, output;
86849 +#if BUILDING_GCC_VERSION <= 4007
86850 + VEC(tree, gc) *inputs = NULL;
86851 + VEC(tree, gc) *outputs = NULL;
86852 +#else
86853 + vec<tree, va_gc> *inputs = NULL;
86854 + vec<tree, va_gc> *outputs = NULL;
86855 +#endif
86856 +
86857 + call_stmt = gsi_stmt(*gsi);
86858 + old_fptr = gimple_call_fn(call_stmt);
86859 +
86860 + // create temporary fptr variable
86861 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
86862 +#if BUILDING_GCC_VERSION <= 4007
86863 + add_referenced_var(new_fptr);
86864 + mark_sym_for_renaming(new_fptr);
86865 +#endif
86866 +
86867 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
86868 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
86869 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
86870 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
86871 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
86872 +#if BUILDING_GCC_VERSION <= 4007
86873 + VEC_safe_push(tree, gc, inputs, input);
86874 + VEC_safe_push(tree, gc, outputs, output);
86875 +#else
86876 + vec_safe_push(inputs, input);
86877 + vec_safe_push(outputs, output);
86878 +#endif
86879 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
86880 + gimple_asm_set_volatile(asm_or_stmt, true);
86881 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
86882 + update_stmt(asm_or_stmt);
86883 +
86884 + // replace call stmt fn with the new fptr
86885 + gimple_call_set_fn(call_stmt, new_fptr);
86886 + update_stmt(call_stmt);
86887 +}
86888 +
86889 +/*
86890 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
86891 + */
86892 +static unsigned int execute_kernexec_fptr(void)
86893 +{
86894 + basic_block bb;
86895 +
86896 + // 1. loop through BBs and GIMPLE statements
86897 + FOR_EACH_BB(bb) {
86898 + gimple_stmt_iterator gsi;
86899 +
86900 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86901 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
86902 + tree fn;
86903 + gimple call_stmt;
86904 +
86905 + // is it a call ...
86906 + call_stmt = gsi_stmt(gsi);
86907 + if (!is_gimple_call(call_stmt))
86908 + continue;
86909 + fn = gimple_call_fn(call_stmt);
86910 + if (TREE_CODE(fn) == ADDR_EXPR)
86911 + continue;
86912 + if (TREE_CODE(fn) != SSA_NAME)
86913 + gcc_unreachable();
86914 +
86915 + // ... through a function pointer
86916 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
86917 + fn = SSA_NAME_VAR(fn);
86918 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
86919 + debug_tree(fn);
86920 + gcc_unreachable();
86921 + }
86922 + }
86923 + fn = TREE_TYPE(fn);
86924 + if (TREE_CODE(fn) != POINTER_TYPE)
86925 + continue;
86926 + fn = TREE_TYPE(fn);
86927 + if (TREE_CODE(fn) != FUNCTION_TYPE)
86928 + continue;
86929 +
86930 + kernexec_instrument_fptr(&gsi);
86931 +
86932 +//debug_tree(gimple_call_fn(call_stmt));
86933 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
86934 + }
86935 + }
86936 +
86937 + return 0;
86938 +}
86939 +
86940 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
86941 +static void kernexec_instrument_retaddr_bts(rtx insn)
86942 +{
86943 + rtx btsq;
86944 + rtvec argvec, constraintvec, labelvec;
86945 + int line;
86946 +
86947 + // create asm volatile("btsq $63,(%%rsp)":::)
86948 + argvec = rtvec_alloc(0);
86949 + constraintvec = rtvec_alloc(0);
86950 + labelvec = rtvec_alloc(0);
86951 + line = expand_location(RTL_LOCATION(insn)).line;
86952 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
86953 + MEM_VOLATILE_P(btsq) = 1;
86954 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
86955 + emit_insn_before(btsq, insn);
86956 +}
86957 +
86958 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
86959 +static void kernexec_instrument_retaddr_or(rtx insn)
86960 +{
86961 + rtx orq;
86962 + rtvec argvec, constraintvec, labelvec;
86963 + int line;
86964 +
86965 + // create asm volatile("orq %%r10,(%%rsp)":::)
86966 + argvec = rtvec_alloc(0);
86967 + constraintvec = rtvec_alloc(0);
86968 + labelvec = rtvec_alloc(0);
86969 + line = expand_location(RTL_LOCATION(insn)).line;
86970 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
86971 + MEM_VOLATILE_P(orq) = 1;
86972 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
86973 + emit_insn_before(orq, insn);
86974 +}
86975 +
86976 +/*
86977 + * find all asm level function returns and forcibly set the highest bit of the return address
86978 + */
86979 +static unsigned int execute_kernexec_retaddr(void)
86980 +{
86981 + rtx insn;
86982 +
86983 + // 1. find function returns
86984 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86985 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
86986 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
86987 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
86988 + rtx body;
86989 +
86990 + // is it a retn
86991 + if (!JUMP_P(insn))
86992 + continue;
86993 + body = PATTERN(insn);
86994 + if (GET_CODE(body) == PARALLEL)
86995 + body = XVECEXP(body, 0, 0);
86996 + if (!ANY_RETURN_P(body))
86997 + continue;
86998 + kernexec_instrument_retaddr(insn);
86999 + }
87000 +
87001 +// print_simple_rtl(stderr, get_insns());
87002 +// print_rtl(stderr, get_insns());
87003 +
87004 + return 0;
87005 +}
87006 +
87007 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87008 +{
87009 + const char * const plugin_name = plugin_info->base_name;
87010 + const int argc = plugin_info->argc;
87011 + const struct plugin_argument * const argv = plugin_info->argv;
87012 + int i;
87013 + struct register_pass_info kernexec_reload_pass_info = {
87014 + .pass = &kernexec_reload_pass.pass,
87015 + .reference_pass_name = "ssa",
87016 + .ref_pass_instance_number = 1,
87017 + .pos_op = PASS_POS_INSERT_AFTER
87018 + };
87019 + struct register_pass_info kernexec_fptr_pass_info = {
87020 + .pass = &kernexec_fptr_pass.pass,
87021 + .reference_pass_name = "ssa",
87022 + .ref_pass_instance_number = 1,
87023 + .pos_op = PASS_POS_INSERT_AFTER
87024 + };
87025 + struct register_pass_info kernexec_retaddr_pass_info = {
87026 + .pass = &kernexec_retaddr_pass.pass,
87027 + .reference_pass_name = "pro_and_epilogue",
87028 + .ref_pass_instance_number = 1,
87029 + .pos_op = PASS_POS_INSERT_AFTER
87030 + };
87031 +
87032 + if (!plugin_default_version_check(version, &gcc_version)) {
87033 + error(G_("incompatible gcc/plugin versions"));
87034 + return 1;
87035 + }
87036 +
87037 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
87038 +
87039 + if (TARGET_64BIT == 0)
87040 + return 0;
87041 +
87042 + for (i = 0; i < argc; ++i) {
87043 + if (!strcmp(argv[i].key, "method")) {
87044 + if (!argv[i].value) {
87045 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87046 + continue;
87047 + }
87048 + if (!strcmp(argv[i].value, "bts")) {
87049 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
87050 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
87051 + } else if (!strcmp(argv[i].value, "or")) {
87052 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
87053 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
87054 + fix_register("r10", 1, 1);
87055 + } else
87056 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
87057 + continue;
87058 + }
87059 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87060 + }
87061 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
87062 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
87063 +
87064 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
87065 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
87066 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
87067 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
87068 +
87069 + return 0;
87070 +}
87071 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
87072 new file mode 100644
87073 index 0000000..1276616
87074 --- /dev/null
87075 +++ b/tools/gcc/latent_entropy_plugin.c
87076 @@ -0,0 +1,321 @@
87077 +/*
87078 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
87079 + * Licensed under the GPL v2
87080 + *
87081 + * Note: the choice of the license means that the compilation process is
87082 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
87083 + * but for the kernel it doesn't matter since it doesn't link against
87084 + * any of the gcc libraries
87085 + *
87086 + * gcc plugin to help generate a little bit of entropy from program state,
87087 + * used during boot in the kernel
87088 + *
87089 + * TODO:
87090 + * - add ipa pass to identify not explicitly marked candidate functions
87091 + * - mix in more program state (function arguments/return values, loop variables, etc)
87092 + * - more instrumentation control via attribute parameters
87093 + *
87094 + * BUGS:
87095 + * - LTO needs -flto-partition=none for now
87096 + */
87097 +#include "gcc-plugin.h"
87098 +#include "config.h"
87099 +#include "system.h"
87100 +#include "coretypes.h"
87101 +#include "tree.h"
87102 +#include "tree-pass.h"
87103 +#include "flags.h"
87104 +#include "intl.h"
87105 +#include "toplev.h"
87106 +#include "plugin.h"
87107 +//#include "expr.h" where are you...
87108 +#include "diagnostic.h"
87109 +#include "plugin-version.h"
87110 +#include "tm.h"
87111 +#include "function.h"
87112 +#include "basic-block.h"
87113 +#include "gimple.h"
87114 +#include "rtl.h"
87115 +#include "emit-rtl.h"
87116 +#include "tree-flow.h"
87117 +
87118 +#if BUILDING_GCC_VERSION >= 4008
87119 +#define TODO_dump_func 0
87120 +#endif
87121 +
87122 +int plugin_is_GPL_compatible;
87123 +
87124 +static tree latent_entropy_decl;
87125 +
87126 +static struct plugin_info latent_entropy_plugin_info = {
87127 + .version = "201302112000",
87128 + .help = NULL
87129 +};
87130 +
87131 +static unsigned int execute_latent_entropy(void);
87132 +static bool gate_latent_entropy(void);
87133 +
87134 +static struct gimple_opt_pass latent_entropy_pass = {
87135 + .pass = {
87136 + .type = GIMPLE_PASS,
87137 + .name = "latent_entropy",
87138 +#if BUILDING_GCC_VERSION >= 4008
87139 + .optinfo_flags = OPTGROUP_NONE,
87140 +#endif
87141 + .gate = gate_latent_entropy,
87142 + .execute = execute_latent_entropy,
87143 + .sub = NULL,
87144 + .next = NULL,
87145 + .static_pass_number = 0,
87146 + .tv_id = TV_NONE,
87147 + .properties_required = PROP_gimple_leh | PROP_cfg,
87148 + .properties_provided = 0,
87149 + .properties_destroyed = 0,
87150 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
87151 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
87152 + }
87153 +};
87154 +
87155 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
87156 +{
87157 + if (TREE_CODE(*node) != FUNCTION_DECL) {
87158 + *no_add_attrs = true;
87159 + error("%qE attribute only applies to functions", name);
87160 + }
87161 + return NULL_TREE;
87162 +}
87163 +
87164 +static struct attribute_spec latent_entropy_attr = {
87165 + .name = "latent_entropy",
87166 + .min_length = 0,
87167 + .max_length = 0,
87168 + .decl_required = true,
87169 + .type_required = false,
87170 + .function_type_required = false,
87171 + .handler = handle_latent_entropy_attribute,
87172 +#if BUILDING_GCC_VERSION >= 4007
87173 + .affects_type_identity = false
87174 +#endif
87175 +};
87176 +
87177 +static void register_attributes(void *event_data, void *data)
87178 +{
87179 + register_attribute(&latent_entropy_attr);
87180 +}
87181 +
87182 +static bool gate_latent_entropy(void)
87183 +{
87184 + tree latent_entropy_attr;
87185 +
87186 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
87187 + return latent_entropy_attr != NULL_TREE;
87188 +}
87189 +
87190 +static unsigned HOST_WIDE_INT seed;
87191 +static unsigned HOST_WIDE_INT get_random_const(void)
87192 +{
87193 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
87194 + return seed;
87195 +}
87196 +
87197 +static enum tree_code get_op(tree *rhs)
87198 +{
87199 + static enum tree_code op;
87200 + unsigned HOST_WIDE_INT random_const;
87201 +
87202 + random_const = get_random_const();
87203 +
87204 + switch (op) {
87205 + case BIT_XOR_EXPR:
87206 + op = PLUS_EXPR;
87207 + break;
87208 +
87209 + case PLUS_EXPR:
87210 + if (rhs) {
87211 + op = LROTATE_EXPR;
87212 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
87213 + break;
87214 + }
87215 +
87216 + case LROTATE_EXPR:
87217 + default:
87218 + op = BIT_XOR_EXPR;
87219 + break;
87220 + }
87221 + if (rhs)
87222 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
87223 + return op;
87224 +}
87225 +
87226 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
87227 +{
87228 + gimple_stmt_iterator gsi;
87229 + gimple assign;
87230 + tree addxorrol, rhs;
87231 + enum tree_code op;
87232 +
87233 + op = get_op(&rhs);
87234 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
87235 + assign = gimple_build_assign(local_entropy, addxorrol);
87236 +#if BUILDING_GCC_VERSION <= 4007
87237 + find_referenced_vars_in(assign);
87238 +#endif
87239 +//debug_bb(bb);
87240 + gsi = gsi_after_labels(bb);
87241 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
87242 + update_stmt(assign);
87243 +}
87244 +
87245 +static void perturb_latent_entropy(basic_block bb, tree rhs)
87246 +{
87247 + gimple_stmt_iterator gsi;
87248 + gimple assign;
87249 + tree addxorrol, temp;
87250 +
87251 + // 1. create temporary copy of latent_entropy
87252 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
87253 +#if BUILDING_GCC_VERSION <= 4007
87254 + add_referenced_var(temp);
87255 + mark_sym_for_renaming(temp);
87256 +#endif
87257 +
87258 + // 2. read...
87259 + assign = gimple_build_assign(temp, latent_entropy_decl);
87260 +#if BUILDING_GCC_VERSION <= 4007
87261 + find_referenced_vars_in(assign);
87262 +#endif
87263 + gsi = gsi_after_labels(bb);
87264 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87265 + update_stmt(assign);
87266 +
87267 + // 3. ...modify...
87268 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
87269 + assign = gimple_build_assign(temp, addxorrol);
87270 +#if BUILDING_GCC_VERSION <= 4007
87271 + find_referenced_vars_in(assign);
87272 +#endif
87273 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87274 + update_stmt(assign);
87275 +
87276 + // 4. ...write latent_entropy
87277 + assign = gimple_build_assign(latent_entropy_decl, temp);
87278 +#if BUILDING_GCC_VERSION <= 4007
87279 + find_referenced_vars_in(assign);
87280 +#endif
87281 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87282 + update_stmt(assign);
87283 +}
87284 +
87285 +static unsigned int execute_latent_entropy(void)
87286 +{
87287 + basic_block bb;
87288 + gimple assign;
87289 + gimple_stmt_iterator gsi;
87290 + tree local_entropy;
87291 +
87292 + if (!latent_entropy_decl) {
87293 + struct varpool_node *node;
87294 +
87295 +#if BUILDING_GCC_VERSION <= 4007
87296 + for (node = varpool_nodes; node; node = node->next) {
87297 + tree var = node->decl;
87298 +#else
87299 + FOR_EACH_VARIABLE(node) {
87300 + tree var = node->symbol.decl;
87301 +#endif
87302 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
87303 + continue;
87304 + latent_entropy_decl = var;
87305 +// debug_tree(var);
87306 + break;
87307 + }
87308 + if (!latent_entropy_decl) {
87309 +// debug_tree(current_function_decl);
87310 + return 0;
87311 + }
87312 + }
87313 +
87314 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
87315 +
87316 + // 1. create local entropy variable
87317 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
87318 +#if BUILDING_GCC_VERSION <= 4007
87319 + add_referenced_var(local_entropy);
87320 + mark_sym_for_renaming(local_entropy);
87321 +#endif
87322 +
87323 + // 2. initialize local entropy variable
87324 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87325 + if (dom_info_available_p(CDI_DOMINATORS))
87326 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
87327 + gsi = gsi_start_bb(bb);
87328 +
87329 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
87330 +// gimple_set_location(assign, loc);
87331 +#if BUILDING_GCC_VERSION <= 4007
87332 + find_referenced_vars_in(assign);
87333 +#endif
87334 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87335 + update_stmt(assign);
87336 + bb = bb->next_bb;
87337 +
87338 + // 3. instrument each BB with an operation on the local entropy variable
87339 + while (bb != EXIT_BLOCK_PTR) {
87340 + perturb_local_entropy(bb, local_entropy);
87341 + bb = bb->next_bb;
87342 + };
87343 +
87344 + // 4. mix local entropy into the global entropy variable
87345 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
87346 + return 0;
87347 +}
87348 +
87349 +static void start_unit_callback(void *gcc_data, void *user_data)
87350 +{
87351 +#if BUILDING_GCC_VERSION >= 4007
87352 + seed = get_random_seed(false);
87353 +#else
87354 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
87355 + seed *= seed;
87356 +#endif
87357 +
87358 + if (in_lto_p)
87359 + return;
87360 +
87361 + // extern u64 latent_entropy
87362 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
87363 +
87364 + TREE_STATIC(latent_entropy_decl) = 1;
87365 + TREE_PUBLIC(latent_entropy_decl) = 1;
87366 + TREE_USED(latent_entropy_decl) = 1;
87367 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
87368 + DECL_EXTERNAL(latent_entropy_decl) = 1;
87369 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
87370 + DECL_INITIAL(latent_entropy_decl) = NULL;
87371 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
87372 +// varpool_finalize_decl(latent_entropy_decl);
87373 +// varpool_mark_needed_node(latent_entropy_decl);
87374 +}
87375 +
87376 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87377 +{
87378 + const char * const plugin_name = plugin_info->base_name;
87379 + struct register_pass_info latent_entropy_pass_info = {
87380 + .pass = &latent_entropy_pass.pass,
87381 + .reference_pass_name = "optimized",
87382 + .ref_pass_instance_number = 1,
87383 + .pos_op = PASS_POS_INSERT_BEFORE
87384 + };
87385 +
87386 + if (!plugin_default_version_check(version, &gcc_version)) {
87387 + error(G_("incompatible gcc/plugin versions"));
87388 + return 1;
87389 + }
87390 +
87391 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
87392 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
87393 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
87394 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
87395 +
87396 + return 0;
87397 +}
87398 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
87399 new file mode 100644
87400 index 0000000..5921fd7
87401 --- /dev/null
87402 +++ b/tools/gcc/size_overflow_hash.data
87403 @@ -0,0 +1,3713 @@
87404 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
87405 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
87406 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
87407 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
87408 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
87409 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
87410 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
87411 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
87412 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
87413 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
87414 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
87415 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
87416 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
87417 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
87418 +create_log_8225 create_log 2 8225 NULL
87419 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
87420 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
87421 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
87422 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
87423 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
87424 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
87425 +padzero_55 padzero 1 55 &sel_read_policyvers_55
87426 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
87427 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
87428 +read_file_blob_57406 read_file_blob 3 57406 NULL
87429 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
87430 +enclosure_register_57412 enclosure_register 3 57412 NULL
87431 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
87432 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
87433 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
87434 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
87435 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
87436 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
87437 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
87438 +init_cdev_8274 init_cdev 1 8274 NULL
87439 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
87440 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
87441 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
87442 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
87443 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
87444 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
87445 +load_msg_95 load_msg 2 95 NULL
87446 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
87447 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
87448 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
87449 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
87450 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
87451 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
87452 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
87453 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
87454 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
87455 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
87456 +send_midi_async_57463 send_midi_async 3 57463 NULL
87457 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
87458 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
87459 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
87460 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
87461 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
87462 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
87463 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
87464 +init_q_132 init_q 4 132 NULL
87465 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
87466 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
87467 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
87468 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
87469 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
87470 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
87471 +uio_read_49300 uio_read 3 49300 NULL
87472 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
87473 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
87474 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
87475 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
87476 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
87477 +play_iframe_8219 play_iframe 3 8219 NULL
87478 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
87479 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
87480 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
87481 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
87482 +init_tag_map_57515 init_tag_map 3 57515 NULL
87483 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
87484 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
87485 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
87486 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
87487 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
87488 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
87489 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
87490 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
87491 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
87492 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
87493 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
87494 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
87495 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
87496 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
87497 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
87498 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
87499 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
87500 +cache_read_24790 cache_read 3 24790 NULL
87501 +px_raw_event_49371 px_raw_event 4 49371 NULL
87502 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
87503 +compat_filldir_32999 compat_filldir 3 32999 NULL
87504 +hci_si_event_1404 hci_si_event 3 1404 NULL
87505 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
87506 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
87507 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
87508 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
87509 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
87510 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
87511 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
87512 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
87513 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
87514 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
87515 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
87516 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
87517 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
87518 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
87519 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
87520 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
87521 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
87522 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
87523 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
87524 +mem_read_57631 mem_read 3 57631 NULL
87525 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
87526 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
87527 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
87528 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
87529 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
87530 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
87531 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
87532 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
87533 +queues_read_24877 queues_read 3 24877 NULL
87534 +__fprog_create_41263 __fprog_create 2 41263 NULL
87535 +syslog_print_307 syslog_print 2 307 NULL
87536 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
87537 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
87538 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
87539 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
87540 +r3964_write_57662 r3964_write 4 57662 NULL
87541 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
87542 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
87543 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
87544 +alloc_context_41283 alloc_context 1 41283 NULL
87545 +__lgwrite_57669 __lgwrite 4 57669 NULL
87546 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
87547 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
87548 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
87549 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
87550 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
87551 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
87552 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
87553 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
87554 +write_node_33121 write_node 4 33121 NULL
87555 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
87556 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
87557 +profile_remove_8556 profile_remove 3 8556 NULL
87558 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
87559 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
87560 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
87561 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
87562 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
87563 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
87564 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
87565 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
87566 +tower_write_8580 tower_write 3 8580 NULL
87567 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
87568 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
87569 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
87570 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
87571 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
87572 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
87573 +smk_write_access_49561 smk_write_access 3 49561 NULL
87574 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
87575 +kmp_init_41373 kmp_init 2 41373 NULL
87576 +context_alloc_24645 context_alloc 3 24645 NULL
87577 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
87578 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
87579 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
87580 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
87581 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
87582 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
87583 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
87584 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
87585 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
87586 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
87587 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
87588 +pp_read_33210 pp_read 3 33210 NULL
87589 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
87590 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
87591 +ivtv_read_57796 ivtv_read 3 57796 NULL
87592 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
87593 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
87594 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
87595 +heap_init_49617 heap_init 2 49617 NULL
87596 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
87597 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
87598 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
87599 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
87600 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
87601 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
87602 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
87603 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
87604 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
87605 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
87606 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
87607 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
87608 +st_write_16874 st_write 3 16874 NULL
87609 +copy_to_user_57835 copy_to_user 3 57835 NULL
87610 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
87611 +pidlist_resize_496 pidlist_resize 2 496 NULL
87612 +flash_read_57843 flash_read 3 57843 NULL
87613 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
87614 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
87615 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
87616 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
87617 +arcfb_write_8702 arcfb_write 3 8702 NULL
87618 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
87619 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
87620 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
87621 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
87622 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
87623 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
87624 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
87625 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
87626 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
87627 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
87628 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
87629 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
87630 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
87631 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
87632 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
87633 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
87634 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
87635 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
87636 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
87637 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
87638 +devres_alloc_551 devres_alloc 2 551 NULL
87639 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
87640 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
87641 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
87642 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
87643 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
87644 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
87645 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
87646 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
87647 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
87648 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
87649 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
87650 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
87651 +sys_prctl_8766 sys_prctl 4 8766 NULL
87652 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
87653 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
87654 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
87655 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
87656 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
87657 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
87658 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
87659 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
87660 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
87661 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
87662 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
87663 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
87664 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
87665 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
87666 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
87667 +gserial_setup_41558 gserial_setup 2 41558 NULL
87668 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
87669 +rx_57944 rx 4 57944 NULL
87670 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
87671 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
87672 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
87673 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
87674 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
87675 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
87676 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
87677 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
87678 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
87679 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
87680 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
87681 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
87682 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
87683 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
87684 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
87685 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
87686 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
87687 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
87688 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
87689 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
87690 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
87691 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
87692 +a2mp_send_41615 a2mp_send 4 41615 NULL
87693 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
87694 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
87695 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
87696 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
87697 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
87698 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
87699 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
87700 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
87701 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
87702 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
87703 +add_uuid_49831 add_uuid 4 49831 NULL
87704 +send_pages_8872 send_pages 3 8872 NULL
87705 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
87706 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
87707 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
87708 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
87709 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
87710 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
87711 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
87712 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
87713 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
87714 +vfs_writev_25278 vfs_writev 3 25278 NULL
87715 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
87716 +alloc_async_14208 alloc_async 1 14208 NULL
87717 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
87718 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
87719 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
87720 +create_entry_33479 create_entry 2 33479 NULL
87721 +mce_async_out_58056 mce_async_out 3 58056 NULL
87722 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
87723 +sys_preadv_17100 sys_preadv 3 17100 NULL
87724 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
87725 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
87726 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
87727 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
87728 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
87729 +res_counter_read_33499 res_counter_read 4 33499 NULL
87730 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
87731 +cm4040_write_58079 cm4040_write 3 58079 NULL
87732 +fb_read_33506 fb_read 3 33506 NULL
87733 +help_25316 help 5 25316 NULL nohasharray
87734 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
87735 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
87736 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
87737 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
87738 +ddp_set_map_751 ddp_set_map 4 751 NULL
87739 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
87740 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
87741 +dvb_video_write_754 dvb_video_write 3 754 NULL
87742 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
87743 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
87744 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
87745 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
87746 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
87747 +udi_log_event_58105 udi_log_event 3 58105 NULL
87748 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
87749 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
87750 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
87751 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
87752 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
87753 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
87754 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
87755 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
87756 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
87757 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
87758 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
87759 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
87760 +sep_read_17161 sep_read 3 17161 NULL
87761 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
87762 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
87763 +dup_array_33551 dup_array 3 33551 NULL
87764 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
87765 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
87766 +fillonedir_41746 fillonedir 3 41746 NULL
87767 +init_bch_64130 init_bch 1-2 64130 NULL
87768 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
87769 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
87770 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
87771 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
87772 +savemem_58129 savemem 3 58129 NULL
87773 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
87774 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
87775 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
87776 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
87777 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
87778 +if_writecmd_815 if_writecmd 2 815 NULL
87779 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
87780 +read_fifo_826 read_fifo 3 826 NULL
87781 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
87782 +scsi_execute_33596 scsi_execute 5 33596 NULL
87783 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
87784 +ms_rw_17220 ms_rw 3-4 17220 NULL
87785 +read_tree_block_841 read_tree_block 3 841 NULL
87786 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
87787 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
87788 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
87789 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
87790 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
87791 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
87792 +um_idi_read_850 um_idi_read 3 850 NULL
87793 +__module_alloc_50004 __module_alloc 1 50004 NULL
87794 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
87795 +ts_read_44687 ts_read 3 44687 NULL
87796 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
87797 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
87798 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
87799 +provide_user_output_41105 provide_user_output 3 41105 NULL
87800 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
87801 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
87802 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
87803 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
87804 +alloc_ep_17269 alloc_ep 1 17269 NULL
87805 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
87806 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
87807 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
87808 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
87809 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
87810 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
87811 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
87812 +create_queues_9088 create_queues 2-3 9088 NULL
87813 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
87814 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
87815 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
87816 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
87817 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
87818 +read_file_debug_58256 read_file_debug 3 58256 NULL
87819 +skb_pad_17302 skb_pad 2 17302 NULL
87820 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
87821 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
87822 +profile_load_58267 profile_load 3 58267 NULL
87823 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
87824 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
87825 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
87826 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
87827 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
87828 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
87829 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
87830 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
87831 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
87832 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
87833 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
87834 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
87835 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
87836 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
87837 +get_packet_41914 get_packet 3 41914 NULL
87838 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
87839 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
87840 +read_file_slot_50111 read_file_slot 3 50111 NULL
87841 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
87842 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
87843 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
87844 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
87845 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
87846 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
87847 +copy_items_50140 copy_items 6 50140 NULL
87848 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
87849 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
87850 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
87851 +map_addr_56144 map_addr 7 56144 NULL
87852 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
87853 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
87854 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
87855 +portnames_read_41958 portnames_read 3 41958 NULL
87856 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
87857 +hashtab_create_33769 hashtab_create 3 33769 NULL
87858 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
87859 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
87860 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
87861 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
87862 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
87863 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
87864 +odev_update_50169 odev_update 2 50169 NULL
87865 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
87866 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
87867 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
87868 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
87869 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
87870 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
87871 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
87872 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
87873 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
87874 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
87875 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
87876 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
87877 +lguest_map_42008 lguest_map 1-2 42008 NULL
87878 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
87879 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
87880 +pool_allocate_42012 pool_allocate 3 42012 NULL
87881 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
87882 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
87883 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
87884 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
87885 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
87886 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
87887 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
87888 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
87889 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
87890 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
87891 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
87892 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
87893 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
87894 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
87895 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
87896 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
87897 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
87898 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
87899 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
87900 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
87901 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
87902 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
87903 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
87904 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
87905 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
87906 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
87907 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
87908 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
87909 +config_proc_write_33878 config_proc_write 3 33878 NULL
87910 +capabilities_read_58457 capabilities_read 3 58457 NULL
87911 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
87912 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
87913 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
87914 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
87915 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
87916 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
87917 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
87918 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
87919 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
87920 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
87921 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
87922 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
87923 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
87924 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
87925 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
87926 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
87927 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
87928 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
87929 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
87930 +vme_user_write_15587 vme_user_write 3 15587 NULL
87931 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
87932 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
87933 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
87934 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
87935 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
87936 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
87937 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
87938 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
87939 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
87940 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
87941 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
87942 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
87943 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
87944 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
87945 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
87946 +read_9397 read 3 9397 NULL
87947 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
87948 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
87949 +printer_write_60276 printer_write 3 60276 NULL
87950 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
87951 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
87952 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
87953 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
87954 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
87955 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
87956 +osst_execute_17607 osst_execute 7-6 17607 NULL
87957 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
87958 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
87959 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
87960 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
87961 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
87962 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
87963 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
87964 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
87965 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
87966 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
87967 +xip_file_read_58592 xip_file_read 3 58592 NULL
87968 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
87969 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
87970 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
87971 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
87972 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
87973 +ppp_write_34034 ppp_write 3 34034 NULL
87974 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
87975 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
87976 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
87977 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
87978 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
87979 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
87980 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
87981 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
87982 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
87983 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
87984 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
87985 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
87986 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
87987 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
87988 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
87989 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
87990 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
87991 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
87992 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
87993 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
87994 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
87995 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
87996 +lp_write_9511 lp_write 3 9511 NULL
87997 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
87998 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
87999 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
88000 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
88001 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
88002 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
88003 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
88004 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
88005 +read_file_dma_9530 read_file_dma 3 9530 NULL
88006 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
88007 +rcname_read_25919 rcname_read 3 25919 NULL
88008 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
88009 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
88010 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
88011 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
88012 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
88013 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
88014 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
88015 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
88016 +key_flags_read_25931 key_flags_read 3 25931 NULL
88017 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
88018 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
88019 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
88020 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
88021 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
88022 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
88023 +fw_node_create_9559 fw_node_create 2 9559 NULL
88024 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
88025 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
88026 +kobj_map_9566 kobj_map 2-3 9566 NULL
88027 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
88028 +acpi_map_58725 acpi_map 1-2 58725 NULL
88029 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
88030 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
88031 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
88032 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
88033 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
88034 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
88035 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
88036 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
88037 +file_read_actor_1401 file_read_actor 4 1401 NULL
88038 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
88039 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
88040 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
88041 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
88042 +do_sync_9604 do_sync 1 9604 NULL
88043 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
88044 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
88045 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
88046 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
88047 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
88048 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
88049 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
88050 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
88051 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
88052 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
88053 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
88054 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
88055 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
88056 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
88057 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
88058 +sge_rx_50594 sge_rx 3 50594 NULL
88059 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
88060 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
88061 +skb_padto_50759 skb_padto 2 50759 NULL
88062 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
88063 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
88064 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
88065 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
88066 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
88067 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
88068 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
88069 +ep_read_58813 ep_read 3 58813 NULL
88070 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
88071 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
88072 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
88073 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
88074 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
88075 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
88076 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
88077 +dns_query_9676 dns_query 3 9676 NULL
88078 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
88079 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
88080 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
88081 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
88082 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
88083 +command_write_58841 command_write 3 58841 NULL
88084 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
88085 +dev_config_8506 dev_config 3 8506 NULL
88086 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
88087 +sys_readv_50664 sys_readv 3 50664 NULL
88088 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
88089 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
88090 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
88091 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
88092 +recover_head_17904 recover_head 3 17904 NULL
88093 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
88094 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
88095 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
88096 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
88097 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
88098 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
88099 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
88100 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
88101 +skb_cow_26138 skb_cow 2 26138 NULL
88102 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
88103 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
88104 +do_sigpending_9766 do_sigpending 2 9766 NULL
88105 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
88106 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
88107 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
88108 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
88109 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
88110 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
88111 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
88112 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
88113 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
88114 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
88115 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
88116 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
88117 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
88118 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
88119 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
88120 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
88121 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
88122 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
88123 +get_registers_26187 get_registers 3 26187 NULL
88124 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
88125 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
88126 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
88127 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
88128 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
88129 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
88130 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
88131 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
88132 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
88133 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
88134 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
88135 +mce_write_26201 mce_write 3 26201 NULL
88136 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
88137 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
88138 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
88139 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
88140 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
88141 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
88142 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
88143 +tpm_write_50798 tpm_write 3 50798 NULL
88144 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
88145 +tun_do_read_50800 tun_do_read 4 50800 NULL
88146 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
88147 +write_flush_50803 write_flush 3 50803 NULL
88148 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
88149 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
88150 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
88151 +dvb_play_50814 dvb_play 3 50814 NULL
88152 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
88153 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
88154 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
88155 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
88156 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
88157 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
88158 +dma_attach_50831 dma_attach 6-7 50831 NULL
88159 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
88160 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
88161 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
88162 +packet_came_18072 packet_came 3 18072 NULL
88163 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
88164 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
88165 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
88166 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
88167 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
88168 +get_vm_area_18080 get_vm_area 1 18080 NULL
88169 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
88170 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
88171 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
88172 +self_check_write_50856 self_check_write 5 50856 NULL
88173 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
88174 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
88175 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
88176 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
88177 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
88178 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
88179 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
88180 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
88181 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
88182 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
88183 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
88184 +vb2_read_42703 vb2_read 3 42703 NULL
88185 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
88186 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
88187 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
88188 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
88189 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
88190 +read_file_misc_9948 read_file_misc 3 9948 NULL
88191 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
88192 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
88193 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
88194 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
88195 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
88196 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
88197 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
88198 +cosa_write_1774 cosa_write 3 1774 NULL
88199 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
88200 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
88201 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
88202 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
88203 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
88204 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
88205 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
88206 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
88207 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
88208 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
88209 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
88210 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
88211 +mld_newpack_50950 mld_newpack 2 50950 NULL
88212 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
88213 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
88214 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
88215 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
88216 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
88217 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
88218 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
88219 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
88220 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
88221 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
88222 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
88223 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
88224 +handle_request_10024 handle_request 9 10024 NULL
88225 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
88226 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
88227 +timeout_write_50991 timeout_write 3 50991 NULL
88228 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
88229 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
88230 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
88231 +proc_write_51003 proc_write 3 51003 NULL
88232 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
88233 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
88234 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
88235 +set_arg_42824 set_arg 3 42824 NULL
88236 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
88237 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
88238 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
88239 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
88240 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
88241 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
88242 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
88243 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
88244 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
88245 +dt3155_read_59226 dt3155_read 3 59226 NULL
88246 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
88247 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
88248 +dump_midi_51040 dump_midi 3 51040 NULL
88249 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
88250 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
88251 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
88252 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
88253 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
88254 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
88255 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
88256 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
88257 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
88258 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
88259 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
88260 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
88261 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
88262 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
88263 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
88264 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
88265 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
88266 +read_vmcore_26501 read_vmcore 3 26501 NULL
88267 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
88268 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
88269 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
88270 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
88271 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
88272 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
88273 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
88274 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
88275 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
88276 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
88277 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
88278 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
88279 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
88280 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
88281 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
88282 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
88283 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
88284 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
88285 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
88286 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
88287 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
88288 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
88289 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
88290 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
88291 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
88292 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
88293 +fd_copyout_59323 fd_copyout 3 59323 NULL
88294 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
88295 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
88296 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
88297 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
88298 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
88299 +solos_param_store_34755 solos_param_store 4 34755 NULL
88300 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
88301 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
88302 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
88303 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
88304 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
88305 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
88306 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
88307 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
88308 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
88309 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
88310 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
88311 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
88312 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
88313 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
88314 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
88315 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
88316 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
88317 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
88318 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
88319 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
88320 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
88321 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
88322 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
88323 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
88324 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
88325 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
88326 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
88327 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
88328 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
88329 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
88330 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
88331 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
88332 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
88333 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
88334 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
88335 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
88336 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
88337 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
88338 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
88339 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
88340 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
88341 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
88342 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
88343 +tipc_send_51238 tipc_send 4 51238 NULL
88344 +drm_property_create_51239 drm_property_create 4 51239 NULL
88345 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
88346 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
88347 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
88348 +audit_expand_2098 audit_expand 2 2098 NULL
88349 +st_read_51251 st_read 3 51251 NULL
88350 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
88351 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
88352 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
88353 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
88354 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
88355 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
88356 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
88357 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
88358 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
88359 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
88360 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
88361 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
88362 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
88363 +c4_add_card_54968 c4_add_card 3 54968 NULL
88364 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
88365 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
88366 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
88367 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
88368 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
88369 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
88370 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
88371 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
88372 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
88373 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
88374 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
88375 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
88376 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
88377 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
88378 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
88379 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
88380 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
88381 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
88382 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
88383 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
88384 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
88385 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
88386 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
88387 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
88388 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
88389 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
88390 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
88391 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
88392 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
88393 +debug_output_18575 debug_output 3 18575 NULL
88394 +Realloc_34961 Realloc 2 34961 NULL
88395 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
88396 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
88397 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
88398 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
88399 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
88400 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
88401 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
88402 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
88403 +vhci_write_2224 vhci_write 3 2224 NULL
88404 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
88405 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
88406 +rb_alloc_3102 rb_alloc 1 3102 NULL
88407 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
88408 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
88409 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
88410 +write_pbl_59583 write_pbl 4 59583 NULL
88411 +from_buffer_18625 from_buffer 3 18625 NULL
88412 +uio_write_43202 uio_write 3 43202 NULL
88413 +memdup_user_59590 memdup_user 2 59590 NULL
88414 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
88415 +iso_callback_43208 iso_callback 3 43208 NULL
88416 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
88417 +smk_write_load_26829 smk_write_load 3 26829 NULL
88418 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
88419 +do_update_counters_2259 do_update_counters 4 2259 NULL
88420 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
88421 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
88422 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
88423 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
88424 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
88425 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
88426 +mtrr_write_59622 mtrr_write 3 59622 NULL
88427 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
88428 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
88429 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
88430 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
88431 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
88432 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
88433 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
88434 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
88435 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
88436 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
88437 +fixup_leb_43256 fixup_leb 3 43256 NULL
88438 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
88439 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
88440 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
88441 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
88442 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
88443 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
88444 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
88445 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
88446 +evtchn_write_43278 evtchn_write 3 43278 NULL
88447 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
88448 +store_ifalias_35088 store_ifalias 4 35088 NULL
88449 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
88450 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
88451 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
88452 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
88453 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
88454 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
88455 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
88456 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
88457 +capi_write_35104 capi_write 3 35104 NULL nohasharray
88458 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
88459 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
88460 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
88461 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
88462 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
88463 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
88464 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
88465 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
88466 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
88467 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
88468 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
88469 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
88470 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
88471 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
88472 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
88473 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
88474 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
88475 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
88476 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
88477 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
88478 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
88479 +do_trimming_26952 do_trimming 3 26952 NULL
88480 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
88481 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
88482 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
88483 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
88484 +alloc_buf_34532 alloc_buf 1 34532 NULL
88485 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
88486 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
88487 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
88488 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
88489 +otp_read_10594 otp_read 2-4-5 10594 NULL
88490 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
88491 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
88492 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
88493 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
88494 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
88495 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
88496 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
88497 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
88498 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
88499 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
88500 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
88501 +venus_remove_59781 venus_remove 4 59781 NULL
88502 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
88503 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
88504 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
88505 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
88506 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
88507 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
88508 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
88509 +xenfb_write_43412 xenfb_write 3 43412 NULL
88510 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
88511 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
88512 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
88513 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
88514 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
88515 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
88516 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
88517 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
88518 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
88519 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
88520 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
88521 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
88522 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
88523 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
88524 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
88525 +cmd_complete_51629 cmd_complete 6 51629 NULL
88526 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
88527 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
88528 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
88529 +set_fd_set_35249 set_fd_set 1 35249 NULL
88530 +wiphy_new_2482 wiphy_new 2 2482 NULL
88531 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
88532 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
88533 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
88534 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
88535 +tcp_push_10680 tcp_push 3 10680 NULL
88536 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
88537 +c101_run_37279 c101_run 2 37279 NULL
88538 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
88539 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
88540 +tun_put_user_59849 tun_put_user 4 59849 NULL
88541 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
88542 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
88543 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
88544 +dm_write_2513 dm_write 3 2513 NULL
88545 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
88546 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
88547 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
88548 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
88549 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
88550 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
88551 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
88552 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
88553 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
88554 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
88555 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
88556 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
88557 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
88558 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
88559 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
88560 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
88561 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
88562 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
88563 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
88564 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
88565 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
88566 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
88567 +sel_write_access_51704 sel_write_access 3 51704 NULL
88568 +sys_syslog_10746 sys_syslog 3 10746 NULL
88569 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
88570 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
88571 +do_readlink_43518 do_readlink 2 43518 NULL
88572 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
88573 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
88574 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
88575 +read_file_reset_52310 read_file_reset 3 52310 NULL
88576 +pms_capture_27142 pms_capture 4 27142 NULL
88577 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
88578 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
88579 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
88580 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
88581 +msg_set_51725 msg_set 3 51725 NULL
88582 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
88583 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
88584 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
88585 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
88586 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
88587 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
88588 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
88589 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
88590 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
88591 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
88592 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
88593 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
88594 +sys_bind_10799 sys_bind 3 10799 NULL
88595 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
88596 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
88597 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
88598 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
88599 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
88600 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
88601 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
88602 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
88603 +send_command_10832 send_command 4 10832 NULL
88604 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
88605 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
88606 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
88607 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
88608 +proc_read_43614 proc_read 3 43614 NULL
88609 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
88610 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
88611 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
88612 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
88613 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
88614 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
88615 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
88616 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
88617 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
88618 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
88619 +vmalloc_15464 vmalloc 1 15464 NULL
88620 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
88621 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
88622 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
88623 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
88624 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
88625 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
88626 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
88627 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
88628 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
88629 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
88630 +adu_write_30487 adu_write 3 30487 NULL
88631 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
88632 +get_scq_10897 get_scq 2 10897 NULL
88633 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
88634 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
88635 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
88636 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
88637 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
88638 +load_module_60056 load_module 2 60056 NULL nohasharray
88639 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
88640 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
88641 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
88642 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
88643 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
88644 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
88645 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
88646 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
88647 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
88648 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
88649 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
88650 +user_read_51881 user_read 3 51881 NULL
88651 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
88652 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
88653 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
88654 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
88655 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
88656 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
88657 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
88658 +async_setkey_35521 async_setkey 3 35521 NULL
88659 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
88660 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
88661 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
88662 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
88663 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
88664 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
88665 +add_tty_40055 add_tty 1 40055 NULL nohasharray
88666 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
88667 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
88668 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
88669 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
88670 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
88671 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
88672 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
88673 +alloc_context_3194 alloc_context 1 3194 NULL
88674 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
88675 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
88676 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
88677 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
88678 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
88679 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
88680 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
88681 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
88682 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
88683 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
88684 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
88685 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
88686 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
88687 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
88688 +init_state_60165 init_state 2 60165 NULL
88689 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
88690 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
88691 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
88692 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
88693 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
88694 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
88695 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
88696 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
88697 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
88698 +calc_hmac_32010 calc_hmac 3 32010 NULL
88699 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
88700 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
88701 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
88702 +kernel_readv_35617 kernel_readv 3 35617 NULL
88703 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
88704 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
88705 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
88706 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
88707 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
88708 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
88709 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
88710 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
88711 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
88712 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
88713 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
88714 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
88715 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
88716 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
88717 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
88718 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
88719 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
88720 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
88721 +store_debug_level_35652 store_debug_level 3 35652 NULL
88722 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
88723 +read_flush_43851 read_flush 3 43851 NULL
88724 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
88725 +cmm_write_2896 cmm_write 3 2896 NULL
88726 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
88727 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
88728 +tunables_write_59563 tunables_write 3 59563 NULL
88729 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
88730 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
88731 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
88732 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
88733 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
88734 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
88735 +dm_table_create_35687 dm_table_create 3 35687 NULL
88736 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
88737 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
88738 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
88739 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
88740 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
88741 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
88742 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
88743 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
88744 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
88745 +debug_read_19322 debug_read 3 19322 NULL
88746 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
88747 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
88748 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
88749 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
88750 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
88751 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
88752 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
88753 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
88754 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
88755 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
88756 +doc_probe_23285 doc_probe 1 23285 NULL
88757 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
88758 +SendString_43928 SendString 3 43928 NULL
88759 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
88760 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
88761 +retry_count_read_52129 retry_count_read 3 52129 NULL
88762 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
88763 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
88764 +read_zero_19366 read_zero 3 19366 NULL
88765 +bch_alloc_4593 bch_alloc 1 4593 NULL
88766 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
88767 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
88768 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
88769 +raid5_resize_63306 raid5_resize 2 63306 NULL
88770 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
88771 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
88772 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
88773 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
88774 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
88775 +depth_write_3021 depth_write 3 3021 NULL
88776 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
88777 +read_file_stations_35795 read_file_stations 3 35795 NULL
88778 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
88779 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
88780 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
88781 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
88782 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
88783 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
88784 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
88785 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
88786 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
88787 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
88788 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
88789 +driver_names_read_60399 driver_names_read 3 60399 NULL
88790 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
88791 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
88792 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
88793 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
88794 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
88795 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
88796 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
88797 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
88798 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
88799 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
88800 +rx_data_60442 rx_data 4 60442 NULL
88801 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
88802 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
88803 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
88804 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
88805 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
88806 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
88807 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
88808 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
88809 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
88810 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
88811 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
88812 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
88813 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
88814 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
88815 +construct_key_11329 construct_key 3 11329 NULL
88816 +evm_write_key_27715 evm_write_key 3 27715 NULL
88817 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
88818 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
88819 +filldir_55137 filldir 3 55137 NULL
88820 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
88821 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
88822 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
88823 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
88824 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
88825 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
88826 +sel_write_create_11353 sel_write_create 3 11353 NULL
88827 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
88828 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
88829 +hwflags_read_52318 hwflags_read 3 52318 NULL
88830 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
88831 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
88832 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
88833 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
88834 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
88835 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
88836 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
88837 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
88838 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
88839 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
88840 +nfsd_read_19568 nfsd_read 5 19568 NULL
88841 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
88842 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
88843 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
88844 +kcalloc_27770 kcalloc 1-2 27770 NULL
88845 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
88846 +bm_status_read_19583 bm_status_read 3 19583 NULL
88847 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
88848 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
88849 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
88850 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
88851 +acl_alloc_35979 acl_alloc 1 35979 NULL
88852 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
88853 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
88854 +str_to_user_11411 str_to_user 2 11411 NULL
88855 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
88856 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
88857 +trace_options_read_11419 trace_options_read 3 11419 NULL
88858 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
88859 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
88860 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
88861 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
88862 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
88863 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
88864 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
88865 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
88866 +console_store_36007 console_store 4 36007 NULL
88867 +bttv_read_11432 bttv_read 3 11432 NULL
88868 +key_key_read_3241 key_key_read 3 3241 NULL
88869 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
88870 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
88871 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
88872 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
88873 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
88874 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
88875 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
88876 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
88877 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
88878 +um_idi_write_18293 um_idi_write 3 18293 NULL
88879 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
88880 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
88881 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
88882 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
88883 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
88884 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
88885 +sys_init_module_36047 sys_init_module 2 36047 NULL
88886 +read_profile_27859 read_profile 3 27859 NULL
88887 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
88888 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
88889 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
88890 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
88891 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
88892 +refill_pool_19477 refill_pool 2 19477 NULL
88893 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
88894 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
88895 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
88896 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
88897 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
88898 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
88899 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
88900 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
88901 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
88902 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
88903 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
88904 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
88905 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
88906 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
88907 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
88908 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
88909 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
88910 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
88911 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
88912 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
88913 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
88914 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
88915 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
88916 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
88917 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
88918 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
88919 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
88920 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
88921 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
88922 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
88923 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
88924 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
88925 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
88926 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
88927 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
88928 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
88929 +init_data_container_60709 init_data_container 1 60709 NULL
88930 +p9_client_read_19750 p9_client_read 5 19750 NULL
88931 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
88932 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
88933 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
88934 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
88935 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
88936 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
88937 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
88938 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
88939 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
88940 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
88941 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
88942 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
88943 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
88944 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
88945 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
88946 +send_stream_3397 send_stream 4 3397 NULL
88947 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
88948 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
88949 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
88950 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
88951 +msix_map_region_3411 msix_map_region 3 3411 NULL
88952 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
88953 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
88954 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
88955 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
88956 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
88957 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
88958 +opticon_write_60775 opticon_write 4 60775 NULL
88959 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
88960 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
88961 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
88962 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
88963 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
88964 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
88965 +vip_read_19832 vip_read 3 19832 NULL
88966 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
88967 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
88968 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
88969 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
88970 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
88971 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
88972 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
88973 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
88974 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
88975 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
88976 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
88977 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
88978 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
88979 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
88980 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
88981 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
88982 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
88983 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
88984 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
88985 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
88986 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
88987 +split_11691 split 2 11691 NULL
88988 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
88989 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
88990 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
88991 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
88992 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
88993 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
88994 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
88995 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
88996 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
88997 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
88998 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
88999 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
89000 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
89001 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
89002 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
89003 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
89004 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
89005 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
89006 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
89007 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
89008 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
89009 +spidev_write_44510 spidev_write 3 44510 NULL
89010 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
89011 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
89012 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
89013 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
89014 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
89015 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
89016 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
89017 +kone_receive_4690 kone_receive 4 4690 NULL
89018 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
89019 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
89020 +evtchn_read_3569 evtchn_read 3 3569 NULL
89021 +video_read_28148 video_read 3 28148 NULL
89022 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
89023 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
89024 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
89025 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
89026 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
89027 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
89028 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
89029 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
89030 +vc_resize_3585 vc_resize 2-3 3585 NULL
89031 +gluebi_write_27905 gluebi_write 3 27905 NULL
89032 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
89033 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
89034 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
89035 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
89036 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
89037 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
89038 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
89039 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
89040 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
89041 +pti_char_write_60960 pti_char_write 3 60960 NULL
89042 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
89043 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
89044 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
89045 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
89046 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
89047 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
89048 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
89049 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
89050 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
89051 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
89052 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
89053 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
89054 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
89055 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
89056 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
89057 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
89058 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
89059 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
89060 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
89061 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
89062 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
89063 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
89064 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
89065 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
89066 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
89067 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
89068 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
89069 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
89070 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
89071 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
89072 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
89073 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
89074 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
89075 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
89076 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
89077 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
89078 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
89079 +symtab_init_61050 symtab_init 2 61050 NULL
89080 +team_options_register_20091 team_options_register 3 20091 NULL
89081 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
89082 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
89083 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
89084 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
89085 +mpi_resize_44674 mpi_resize 2 44674 NULL
89086 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
89087 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
89088 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
89089 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
89090 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
89091 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
89092 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
89093 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
89094 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
89095 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
89096 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
89097 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
89098 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
89099 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
89100 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
89101 +pms_read_53873 pms_read 3 53873 NULL
89102 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
89103 +get_derived_key_61100 get_derived_key 4 61100 NULL
89104 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
89105 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
89106 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
89107 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
89108 +dm_read_15674 dm_read 3 15674 NULL
89109 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
89110 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
89111 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
89112 +kone_send_63435 kone_send 4 63435 NULL
89113 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
89114 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
89115 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
89116 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
89117 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
89118 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
89119 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
89120 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
89121 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
89122 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
89123 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
89124 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
89125 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
89126 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
89127 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
89128 +send_packet_52960 send_packet 4 52960 NULL
89129 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
89130 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
89131 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
89132 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
89133 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
89134 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
89135 +put_cmsg_36589 put_cmsg 4 36589 NULL
89136 +__vmalloc_61168 __vmalloc 1 61168 NULL
89137 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
89138 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
89139 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
89140 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
89141 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
89142 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
89143 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
89144 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
89145 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
89146 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
89147 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
89148 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
89149 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
89150 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
89151 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
89152 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
89153 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
89154 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
89155 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
89156 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
89157 +get_fd_set_3866 get_fd_set 1 3866 NULL
89158 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
89159 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
89160 +unlink_queued_645 unlink_queued 3-4 645 NULL
89161 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
89162 +sisusb_write_44834 sisusb_write 3 44834 NULL
89163 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
89164 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
89165 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
89166 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
89167 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
89168 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
89169 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
89170 +nvram_write_3894 nvram_write 3 3894 NULL
89171 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
89172 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
89173 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
89174 +vcs_write_3910 vcs_write 3 3910 NULL
89175 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
89176 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
89177 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
89178 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
89179 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
89180 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
89181 +do_tty_write_44896 do_tty_write 5 44896 NULL
89182 +set_powered_12129 set_powered 4 12129 NULL
89183 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
89184 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
89185 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
89186 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
89187 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
89188 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
89189 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
89190 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
89191 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
89192 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
89193 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
89194 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
89195 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
89196 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
89197 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
89198 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
89199 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
89200 +gather_array_56641 gather_array 3 56641 NULL
89201 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
89202 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
89203 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
89204 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
89205 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
89206 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
89207 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
89208 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
89209 +do_add_counters_3992 do_add_counters 3 3992 NULL
89210 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
89211 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
89212 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
89213 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
89214 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
89215 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
89216 +mei_write_4005 mei_write 3 4005 NULL
89217 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
89218 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
89219 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
89220 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
89221 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
89222 +receive_copy_12216 receive_copy 3 12216 NULL
89223 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
89224 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
89225 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
89226 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
89227 +change_xattr_61390 change_xattr 5 61390 NULL
89228 +find_skb_20431 find_skb 2 20431 NULL
89229 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
89230 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
89231 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
89232 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
89233 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
89234 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
89235 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
89236 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
89237 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
89238 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
89239 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
89240 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
89241 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
89242 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
89243 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
89244 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
89245 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
89246 +read_buf_20469 read_buf 2 20469 NULL
89247 +cm_write_36858 cm_write 3 36858 NULL
89248 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
89249 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
89250 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
89251 +sel_write_user_45060 sel_write_user 3 45060 NULL
89252 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
89253 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
89254 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
89255 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
89256 +fast_user_write_20494 fast_user_write 5 20494 NULL
89257 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
89258 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
89259 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
89260 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
89261 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
89262 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
89263 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
89264 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
89265 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
89266 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
89267 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
89268 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
89269 +osst_read_40237 osst_read 3 40237 NULL
89270 +tm6000_read_4151 tm6000_read 3 4151 NULL
89271 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
89272 +usbdev_read_45114 usbdev_read 3 45114 NULL
89273 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
89274 +spi_execute_28736 spi_execute 5 28736 NULL
89275 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
89276 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
89277 +get_alua_req_4166 get_alua_req 3 4166 NULL
89278 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
89279 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
89280 +venus_create_20555 venus_create 4 20555 NULL
89281 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
89282 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
89283 +receive_packet_12367 receive_packet 2 12367 NULL
89284 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
89285 +mem_write_22232 mem_write 3 22232 NULL
89286 +read_file_bool_4180 read_file_bool 3 4180 NULL
89287 +send_to_tty_45141 send_to_tty 3 45141 NULL
89288 +fops_read_40672 fops_read 3 40672 NULL
89289 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
89290 +write_leb_36957 write_leb 5 36957 NULL
89291 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
89292 +device_write_45156 device_write 3 45156 NULL
89293 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
89294 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
89295 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
89296 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
89297 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
89298 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
89299 +isp1760_register_628 isp1760_register 1-2 628 NULL
89300 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
89301 +lirc_write_20604 lirc_write 3 20604 NULL
89302 +sel_write_member_28800 sel_write_member 3 28800 NULL
89303 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
89304 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
89305 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
89306 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
89307 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
89308 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
89309 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
89310 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
89311 +setxattr_37006 setxattr 4 37006 NULL
89312 +add_child_45201 add_child 4 45201 NULL
89313 +seq_open_private_61589 seq_open_private 3 61589 NULL
89314 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
89315 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
89316 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
89317 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
89318 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
89319 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
89320 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
89321 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
89322 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
89323 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
89324 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
89325 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
89326 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
89327 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
89328 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
89329 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
89330 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
89331 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
89332 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
89333 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
89334 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
89335 +resize_stripes_61650 resize_stripes 2 61650 NULL
89336 +n2_run_53459 n2_run 3 53459 NULL
89337 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
89338 +parse_command_37079 parse_command 2 37079 NULL
89339 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
89340 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
89341 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
89342 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
89343 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
89344 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
89345 +insert_one_name_61668 insert_one_name 7 61668 NULL
89346 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
89347 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
89348 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
89349 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
89350 +lock_loop_61681 lock_loop 1 61681 NULL
89351 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
89352 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
89353 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
89354 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
89355 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
89356 +push_rx_28939 push_rx 3 28939 NULL
89357 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
89358 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
89359 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
89360 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
89361 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
89362 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
89363 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
89364 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
89365 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
89366 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
89367 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
89368 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
89369 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
89370 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
89371 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
89372 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
89373 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
89374 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
89375 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
89376 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
89377 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
89378 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
89379 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
89380 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
89381 +bin_uuid_28999 bin_uuid 3 28999 NULL
89382 +sys_sendto_20809 sys_sendto 6 20809 NULL
89383 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
89384 +set_registers_53582 set_registers 3 53582 NULL
89385 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
89386 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
89387 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
89388 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
89389 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
89390 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
89391 +keymap_store_45406 keymap_store 4 45406 NULL
89392 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
89393 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
89394 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
89395 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
89396 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
89397 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
89398 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
89399 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
89400 +__do_replace_37227 __do_replace 5 37227 NULL
89401 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
89402 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
89403 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
89404 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
89405 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
89406 +tso_fragment_29050 tso_fragment 3 29050 NULL
89407 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
89408 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
89409 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
89410 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
89411 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
89412 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
89413 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
89414 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
89415 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
89416 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
89417 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
89418 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
89419 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
89420 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
89421 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
89422 +set_link_security_4502 set_link_security 4 4502 NULL
89423 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
89424 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
89425 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
89426 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
89427 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
89428 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
89429 +mmio_read_40348 mmio_read 4 40348 NULL
89430 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
89431 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
89432 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
89433 +ivtv_write_12721 ivtv_write 3 12721 NULL
89434 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
89435 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
89436 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
89437 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
89438 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
89439 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
89440 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
89441 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
89442 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
89443 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
89444 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
89445 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
89446 +send_msg_37323 send_msg 4 37323 NULL
89447 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
89448 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
89449 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
89450 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
89451 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
89452 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
89453 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
89454 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
89455 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
89456 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
89457 +reshape_ring_29147 reshape_ring 2 29147 NULL
89458 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
89459 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
89460 +copy_macs_45534 copy_macs 4 45534 NULL
89461 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
89462 +listxattr_12769 listxattr 3 12769 NULL
89463 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
89464 +wdm_write_53735 wdm_write 3 53735 NULL
89465 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
89466 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
89467 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
89468 +mempool_create_29437 mempool_create 1 29437 NULL
89469 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
89470 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
89471 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
89472 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
89473 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
89474 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
89475 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
89476 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
89477 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
89478 +mgmt_event_12810 mgmt_event 4 12810 NULL
89479 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
89480 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
89481 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
89482 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
89483 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
89484 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
89485 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
89486 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
89487 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
89488 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
89489 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
89490 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
89491 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
89492 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
89493 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
89494 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
89495 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
89496 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
89497 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
89498 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
89499 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
89500 +recover_peb_29238 recover_peb 6-7 29238 NULL
89501 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
89502 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
89503 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
89504 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
89505 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
89506 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
89507 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
89508 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
89509 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
89510 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
89511 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
89512 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
89513 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
89514 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
89515 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
89516 +do_pselect_62061 do_pselect 1 62061 NULL
89517 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
89518 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
89519 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
89520 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
89521 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
89522 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
89523 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
89524 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
89525 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
89526 +sg_read_25799 sg_read 3 25799 NULL
89527 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
89528 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
89529 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
89530 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
89531 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
89532 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
89533 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
89534 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
89535 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
89536 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
89537 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
89538 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
89539 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
89540 +new_skb_21148 new_skb 1 21148 NULL
89541 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
89542 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
89543 +bm_status_write_12964 bm_status_write 3 12964 NULL
89544 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
89545 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
89546 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
89547 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
89548 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
89549 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
89550 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
89551 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
89552 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
89553 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
89554 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
89555 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
89556 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
89557 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
89558 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
89559 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
89560 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
89561 +video_usercopy_62151 video_usercopy 2 62151 NULL
89562 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
89563 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
89564 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
89565 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
89566 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
89567 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
89568 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
89569 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
89570 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
89571 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
89572 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
89573 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
89574 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
89575 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
89576 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
89577 +input_ff_create_21240 input_ff_create 2 21240 NULL
89578 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
89579 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
89580 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
89581 +amthi_read_45831 amthi_read 4 45831 NULL
89582 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
89583 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
89584 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
89585 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
89586 +sys_ipc_4889 sys_ipc 3 4889 NULL
89587 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
89588 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
89589 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
89590 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
89591 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
89592 +do_register_entry_29478 do_register_entry 4 29478 NULL
89593 +isdn_write_45863 isdn_write 3 45863 NULL
89594 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
89595 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
89596 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
89597 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
89598 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
89599 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
89600 +_malloc_54077 _malloc 1 54077 NULL
89601 +add_res_range_21310 add_res_range 4 21310 NULL
89602 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
89603 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
89604 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
89605 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
89606 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
89607 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
89608 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
89609 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
89610 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
89611 +create_xattr_54106 create_xattr 5 54106 NULL
89612 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
89613 +ep_write_59008 ep_write 3 59008 NULL
89614 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
89615 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
89616 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
89617 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
89618 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
89619 +alloc_mr_45935 alloc_mr 1 45935 NULL
89620 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
89621 +isku_receive_54130 isku_receive 4 54130 NULL
89622 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
89623 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
89624 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
89625 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
89626 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
89627 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
89628 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
89629 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
89630 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
89631 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
89632 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
89633 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
89634 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
89635 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
89636 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
89637 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
89638 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
89639 +comedi_read_13199 comedi_read 3 13199 NULL
89640 +flash_write_62354 flash_write 3 62354 NULL
89641 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
89642 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
89643 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
89644 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
89645 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
89646 +proc_file_read_53905 proc_file_read 3 53905 NULL
89647 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
89648 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
89649 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
89650 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
89651 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
89652 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
89653 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
89654 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
89655 +cru_detect_11272 cru_detect 1 11272 NULL
89656 +altera_irscan_62396 altera_irscan 2 62396 NULL
89657 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
89658 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
89659 +fw_download_code_13249 fw_download_code 3 13249 NULL
89660 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
89661 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
89662 +set_ssp_62411 set_ssp 4 62411 NULL
89663 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
89664 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
89665 +get_free_entries_46030 get_free_entries 1 46030 NULL
89666 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
89667 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
89668 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
89669 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
89670 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
89671 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
89672 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
89673 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
89674 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
89675 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
89676 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
89677 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
89678 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
89679 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
89680 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
89681 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
89682 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
89683 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
89684 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
89685 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
89686 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
89687 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
89688 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
89689 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
89690 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
89691 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
89692 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
89693 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
89694 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
89695 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
89696 +probes_write_29711 probes_write 3 29711 NULL
89697 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
89698 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
89699 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
89700 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
89701 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
89702 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
89703 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
89704 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
89705 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
89706 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
89707 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
89708 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
89709 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
89710 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
89711 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
89712 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
89713 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
89714 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
89715 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
89716 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
89717 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
89718 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
89719 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
89720 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
89721 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
89722 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
89723 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
89724 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
89725 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
89726 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
89727 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
89728 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
89729 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
89730 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
89731 +isdn_read_50021 isdn_read 3 50021 NULL
89732 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
89733 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
89734 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
89735 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
89736 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
89737 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
89738 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
89739 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
89740 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
89741 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
89742 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
89743 +get_subdir_62581 get_subdir 3 62581 NULL
89744 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
89745 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
89746 +vfs_readv_38011 vfs_readv 3 38011 NULL
89747 +keyring_read_13438 keyring_read 3 13438 NULL
89748 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
89749 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
89750 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
89751 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
89752 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
89753 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
89754 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
89755 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
89756 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
89757 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
89758 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
89759 +ftrace_write_29551 ftrace_write 3 29551 NULL
89760 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
89761 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
89762 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
89763 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
89764 +dev_write_7708 dev_write 3 7708 NULL
89765 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
89766 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
89767 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
89768 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
89769 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
89770 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
89771 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
89772 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
89773 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
89774 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
89775 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
89776 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
89777 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
89778 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
89779 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
89780 +bm_init_13529 bm_init 2 13529 NULL
89781 +check586_29914 check586 2 29914 NULL
89782 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
89783 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
89784 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
89785 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
89786 +pg_read_17276 pg_read 3 17276 NULL
89787 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
89788 +ep0_read_38095 ep0_read 3 38095 NULL
89789 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
89790 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
89791 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
89792 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
89793 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
89794 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
89795 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
89796 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
89797 +l2down_create_21755 l2down_create 4 21755 NULL
89798 +alloc_tio_13564 alloc_tio 3 13564 NULL
89799 +viacam_read_54526 viacam_read 3 54526 NULL
89800 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
89801 +tunables_read_36385 tunables_read 3 36385 NULL
89802 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
89803 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
89804 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
89805 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
89806 +setsockopt_54539 setsockopt 5 54539 NULL
89807 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
89808 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
89809 +tty_register_device_4544 tty_register_device 2 4544 NULL
89810 +cache_write_13589 cache_write 3 13589 NULL
89811 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
89812 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
89813 +key_replays_read_62746 key_replays_read 3 62746 NULL
89814 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
89815 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
89816 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
89817 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
89818 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
89819 +cdev_add_38176 cdev_add 2-3 38176 NULL
89820 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
89821 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
89822 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
89823 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
89824 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
89825 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
89826 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
89827 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
89828 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
89829 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
89830 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
89831 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
89832 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
89833 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
89834 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
89835 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
89836 +packet_snd_13634 packet_snd 3 13634 NULL
89837 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
89838 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
89839 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
89840 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
89841 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
89842 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
89843 +drp_wmove_30043 drp_wmove 4 30043 NULL
89844 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
89845 +cache_downcall_13666 cache_downcall 3 13666 NULL
89846 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
89847 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
89848 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
89849 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
89850 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
89851 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
89852 +tty_write_5494 tty_write 3 5494 NULL
89853 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
89854 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
89855 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
89856 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
89857 +teiup_create_43201 teiup_create 3 43201 NULL
89858 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
89859 +filldir64_46469 filldir64 3 46469 NULL
89860 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
89861 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
89862 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
89863 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
89864 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
89865 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
89866 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
89867 +spidev_message_5518 spidev_message 3 5518 NULL
89868 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
89869 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
89870 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
89871 +evm_read_key_54674 evm_read_key 3 54674 NULL
89872 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
89873 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
89874 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
89875 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
89876 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
89877 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
89878 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
89879 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
89880 +u32_array_read_2219 u32_array_read 3 2219 NULL
89881 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
89882 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
89883 +sys_add_key_61288 sys_add_key 4 61288 NULL
89884 +kmsg_read_46514 kmsg_read 3 46514 NULL
89885 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
89886 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
89887 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
89888 +recv_stream_30138 recv_stream 4 30138 NULL
89889 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
89890 +getdqbuf_62908 getdqbuf 1 62908 NULL
89891 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
89892 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
89893 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
89894 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
89895 +fir16_create_5574 fir16_create 3 5574 NULL
89896 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
89897 +pt_write_40159 pt_write 3 40159 NULL
89898 +bioset_create_5580 bioset_create 1 5580 NULL
89899 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
89900 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
89901 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
89902 +kzalloc_54740 kzalloc 1 54740 NULL
89903 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
89904 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
89905 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
89906 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
89907 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
89908 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
89909 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
89910 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
89911 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
89912 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
89913 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
89914 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
89915 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
89916 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
89917 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
89918 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
89919 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
89920 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
89921 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
89922 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
89923 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
89924 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
89925 +ti_recv_22027 ti_recv 4 22027 NULL
89926 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
89927 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
89928 +nfsd_write_54809 nfsd_write 6 54809 NULL
89929 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
89930 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
89931 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
89932 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
89933 +get_skb_63008 get_skb 2 63008 NULL
89934 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
89935 +netlink_send_38434 netlink_send 5 38434 NULL
89936 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
89937 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
89938 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
89939 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
89940 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
89941 +write_rio_54837 write_rio 3 54837 NULL
89942 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
89943 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
89944 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
89945 +get_arg_5694 get_arg 3 5694 NULL
89946 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
89947 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
89948 +compat_readv_30273 compat_readv 3 30273 NULL
89949 +printer_read_54851 printer_read 3 54851 NULL
89950 +mem_rw_22085 mem_rw 3 22085 NULL
89951 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
89952 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
89953 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
89954 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
89955 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
89956 +unlink1_63059 unlink1 3 63059 NULL
89957 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
89958 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
89959 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
89960 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
89961 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
89962 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
89963 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
89964 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
89965 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
89966 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
89967 +dev_names_read_38509 dev_names_read 3 38509 NULL
89968 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
89969 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
89970 +get_packet_5747 get_packet 3 5747 NULL
89971 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
89972 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
89973 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
89974 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
89975 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
89976 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
89977 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
89978 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
89979 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
89980 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
89981 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
89982 +resource_from_user_30341 resource_from_user 3 30341 NULL
89983 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
89984 +sound_write_5102 sound_write 3 5102 NULL
89985 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
89986 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
89987 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
89988 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
89989 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
89990 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
89991 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
89992 +com90xx_found_13974 com90xx_found 3 13974 NULL
89993 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
89994 +qcam_read_13977 qcam_read 3 13977 NULL
89995 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
89996 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
89997 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
89998 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
89999 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
90000 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
90001 +generic_readlink_32654 generic_readlink 3 32654 NULL
90002 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
90003 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
90004 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
90005 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
90006 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
90007 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
90008 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
90009 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
90010 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
90011 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
90012 +concat_writev_21451 concat_writev 3 21451 NULL
90013 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
90014 +_queue_data_54983 _queue_data 4 54983 NULL
90015 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
90016 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
90017 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
90018 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
90019 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
90020 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
90021 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
90022 +setup_req_5848 setup_req 3 5848 NULL
90023 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
90024 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
90025 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
90026 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
90027 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
90028 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
90029 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
90030 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
90031 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
90032 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
90033 +cma_create_area_38642 cma_create_area 2 38642 NULL
90034 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
90035 +sriov_enable_59689 sriov_enable 2 59689 NULL
90036 +enable_write_30456 enable_write 3 30456 NULL
90037 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
90038 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
90039 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
90040 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
90041 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
90042 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
90043 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
90044 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
90045 +port_show_regs_5904 port_show_regs 3 5904 NULL
90046 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
90047 +ptp_read_63251 ptp_read 4 63251 NULL
90048 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
90049 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
90050 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
90051 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
90052 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
90053 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
90054 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
90055 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
90056 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
90057 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
90058 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
90059 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
90060 +read_dma_55086 read_dma 3 55086 NULL
90061 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
90062 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
90063 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
90064 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
90065 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
90066 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
90067 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
90068 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
90069 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
90070 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
90071 +em_canid_change_14150 em_canid_change 3 14150 NULL
90072 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
90073 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
90074 +fb_write_46924 fb_write 3 46924 NULL
90075 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
90076 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
90077 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
90078 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
90079 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
90080 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
90081 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
90082 +udf_readpages_38761 udf_readpages 4 38761 NULL
90083 +reada_add_block_54247 reada_add_block 2 54247 NULL
90084 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
90085 +proc_info_read_63344 proc_info_read 3 63344 NULL
90086 +pep_indicate_38611 pep_indicate 5 38611 NULL
90087 +set_le_30581 set_le 4 30581 NULL
90088 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
90089 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
90090 +alloc_private_22399 alloc_private 2 22399 NULL
90091 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
90092 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
90093 +zoran_write_22404 zoran_write 3 22404 NULL
90094 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
90095 +idmouse_read_63374 idmouse_read 3 63374 NULL
90096 +queue_reply_22416 queue_reply 3 22416 NULL
90097 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
90098 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
90099 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
90100 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
90101 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
90102 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
90103 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
90104 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
90105 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
90106 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
90107 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
90108 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
90109 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
90110 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
90111 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
90112 +sys_select_38827 sys_select 1 38827 NULL
90113 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
90114 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
90115 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
90116 +direct_entry_38836 direct_entry 3 38836 NULL
90117 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
90118 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
90119 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
90120 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
90121 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
90122 +write_head_30481 write_head 4 30481 NULL
90123 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
90124 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
90125 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
90126 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
90127 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
90128 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
90129 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
90130 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
90131 +agp_remap_30665 agp_remap 2 30665 NULL
90132 +interfaces_38859 interfaces 2 38859 NULL
90133 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
90134 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
90135 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
90136 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
90137 +qc_capture_19298 qc_capture 3 19298 NULL
90138 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
90139 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
90140 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
90141 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
90142 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
90143 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
90144 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
90145 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
90146 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
90147 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
90148 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
90149 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
90150 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
90151 +read_kcore_63488 read_kcore 3 63488 NULL
90152 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
90153 +__skb_cow_39254 __skb_cow 2 39254 NULL
90154 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
90155 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
90156 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
90157 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
90158 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
90159 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
90160 +mousedev_read_47123 mousedev_read 3 47123 NULL
90161 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
90162 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
90163 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
90164 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
90165 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
90166 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
90167 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
90168 +vme_user_read_55338 vme_user_read 3 55338 NULL
90169 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
90170 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
90171 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
90172 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
90173 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
90174 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
90175 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
90176 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
90177 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
90178 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
90179 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
90180 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
90181 +snapshot_read_22601 snapshot_read 3 22601 NULL
90182 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
90183 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
90184 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
90185 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
90186 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
90187 +__send_to_port_55383 __send_to_port 3 55383 NULL
90188 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
90189 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
90190 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
90191 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
90192 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
90193 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
90194 +get_nodes_39012 get_nodes 3 39012 NULL
90195 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
90196 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
90197 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
90198 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
90199 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
90200 +create_subvol_30836 create_subvol 4 30836 NULL
90201 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
90202 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
90203 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
90204 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
90205 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
90206 +read_oldmem_55658 read_oldmem 3 55658 NULL
90207 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
90208 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
90209 +options_write_47243 options_write 3 47243 NULL
90210 +module_alloc_63630 module_alloc 1 63630 NULL
90211 +alloc_skb_55439 alloc_skb 1 55439 NULL
90212 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
90213 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
90214 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
90215 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
90216 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
90217 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
90218 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
90219 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
90220 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
90221 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
90222 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
90223 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
90224 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
90225 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
90226 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
90227 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
90228 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
90229 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
90230 +vbi_read_63673 vbi_read 3 63673 NULL
90231 +tun_get_user_39099 tun_get_user 4 39099 NULL
90232 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
90233 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
90234 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
90235 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
90236 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
90237 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
90238 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
90239 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
90240 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
90241 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
90242 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
90243 +ax25_output_22736 ax25_output 2 22736 NULL
90244 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
90245 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
90246 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
90247 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
90248 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
90249 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
90250 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
90251 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
90252 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
90253 +hid_input_report_32458 hid_input_report 4 32458 NULL
90254 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
90255 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
90256 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
90257 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
90258 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
90259 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
90260 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
90261 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
90262 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
90263 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
90264 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
90265 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
90266 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
90267 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
90268 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
90269 +get_info_55681 get_info 3 55681 NULL
90270 +setkey_14987 setkey 3 14987 NULL
90271 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
90272 +init_list_set_39188 init_list_set 2-3 39188 NULL
90273 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
90274 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
90275 +l2up_create_6430 l2up_create 3 6430 NULL
90276 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
90277 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
90278 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
90279 +add_partition_55588 add_partition 2 55588 NULL
90280 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
90281 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
90282 +depth_read_31112 depth_read 3 31112 NULL
90283 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
90284 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
90285 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
90286 +profile_replace_14652 profile_replace 3 14652 NULL
90287 +vzalloc_47421 vzalloc 1 47421 NULL
90288 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
90289 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
90290 +sys_writev_28384 sys_writev 3 28384 NULL
90291 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
90292 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
90293 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
90294 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
90295 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
90296 +create_attr_set_22861 create_attr_set 1 22861 NULL
90297 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
90298 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
90299 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
90300 +sel_write_load_63830 sel_write_load 3 63830 NULL
90301 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
90302 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
90303 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
90304 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
90305 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
90306 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
90307 +probe_bios_17467 probe_bios 1 17467 NULL
90308 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
90309 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
90310 +mei_read_6507 mei_read 3 6507 NULL
90311 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
90312 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
90313 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
90314 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
90315 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
90316 +SetArea_50835 SetArea 4 50835 NULL
90317 +tpm_read_50344 tpm_read 3 50344 NULL
90318 +newpart_47485 newpart 6 47485 NULL
90319 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
90320 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
90321 +core_sys_select_47494 core_sys_select 1 47494 NULL
90322 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
90323 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
90324 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
90325 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
90326 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
90327 +unlink_simple_47506 unlink_simple 3 47506 NULL
90328 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
90329 +wdm_read_6549 wdm_read 3 6549 NULL
90330 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
90331 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
90332 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
90333 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
90334 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
90335 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
90336 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
90337 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
90338 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
90339 +filter_read_61692 filter_read 3 61692 NULL
90340 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
90341 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
90342 +debugfs_read_62535 debugfs_read 3 62535 NULL
90343 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
90344 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
90345 +divas_write_63901 divas_write 3 63901 NULL
90346 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
90347 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
90348 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
90349 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
90350 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
90351 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
90352 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
90353 +ipw_write_59807 ipw_write 3 59807 NULL
90354 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
90355 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
90356 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
90357 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
90358 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
90359 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
90360 +cycx_setup_47562 cycx_setup 4 47562 NULL
90361 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
90362 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
90363 +set_local_name_55757 set_local_name 4 55757 NULL
90364 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
90365 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
90366 +read_ldt_47570 read_ldt 2 47570 NULL
90367 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
90368 +pci_iomap_47575 pci_iomap 3 47575 NULL
90369 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
90370 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
90371 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
90372 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
90373 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
90374 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
90375 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
90376 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
90377 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
90378 +conf_read_55786 conf_read 3 55786 NULL
90379 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
90380 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
90381 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
90382 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
90383 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
90384 +user_power_read_39414 user_power_read 3 39414 NULL
90385 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
90386 +uea_request_47613 uea_request 4 47613 NULL
90387 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
90388 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
90389 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
90390 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
90391 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
90392 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
90393 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
90394 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
90395 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
90396 +kmemdup_64015 kmemdup 2 64015 NULL
90397 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
90398 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
90399 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
90400 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
90401 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
90402 +oz_events_read_47535 oz_events_read 3 47535 NULL
90403 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
90404 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
90405 +sys_semop_39457 sys_semop 3 39457 NULL
90406 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
90407 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
90408 +update_pmkid_2481 update_pmkid 4 2481 NULL
90409 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
90410 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
90411 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
90412 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
90413 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
90414 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
90415 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
90416 +mpeg_read_6708 mpeg_read 3 6708 NULL
90417 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
90418 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
90419 +sky2_receive_13407 sky2_receive 2 13407 NULL
90420 +krealloc_14908 krealloc 2 14908 NULL
90421 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
90422 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
90423 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
90424 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
90425 +video_proc_write_6724 video_proc_write 3 6724 NULL
90426 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
90427 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
90428 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
90429 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
90430 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
90431 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
90432 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
90433 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
90434 +command_file_write_31318 command_file_write 3 31318 NULL
90435 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
90436 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
90437 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
90438 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
90439 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
90440 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
90441 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
90442 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
90443 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
90444 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
90445 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
90446 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
90447 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
90448 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
90449 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
90450 +int_proc_write_39542 int_proc_write 3 39542 NULL
90451 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
90452 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
90453 +read_file_ani_23161 read_file_ani 3 23161 NULL
90454 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
90455 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
90456 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
90457 +pp_write_39554 pp_write 3 39554 NULL
90458 +ioremap_23172 ioremap 1-2 23172 NULL
90459 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
90460 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
90461 +usblp_write_23178 usblp_write 3 23178 NULL
90462 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
90463 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
90464 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
90465 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
90466 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
90467 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
90468 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
90469 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
90470 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
90471 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
90472 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
90473 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
90474 +__team_options_register_63941 __team_options_register 3 63941 NULL
90475 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
90476 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
90477 +rvmalloc_46873 rvmalloc 1 46873 NULL
90478 +vmap_15025 vmap 2 15025 NULL
90479 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
90480 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
90481 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
90482 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
90483 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
90484 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
90485 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
90486 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
90487 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
90488 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
90489 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
90490 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
90491 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
90492 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
90493 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
90494 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
90495 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
90496 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
90497 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
90498 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
90499 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
90500 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
90501 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
90502 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
90503 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
90504 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
90505 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
90506 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
90507 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
90508 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
90509 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
90510 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
90511 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
90512 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
90513 +alg_setkey_31485 alg_setkey 3 31485 NULL
90514 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
90515 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
90516 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
90517 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
90518 +vhci_read_47878 vhci_read 3 47878 NULL
90519 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
90520 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
90521 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
90522 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
90523 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
90524 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
90525 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
90526 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
90527 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
90528 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
90529 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
90530 +timeout_read_47915 timeout_read 3 47915 NULL
90531 +hidraw_write_31536 hidraw_write 3 31536 NULL
90532 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
90533 +page_readlink_23346 page_readlink 3 23346 NULL
90534 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
90535 +comedi_write_47926 comedi_write 3 47926 NULL
90536 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
90537 +dsp_write_46218 dsp_write 2 46218 NULL
90538 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
90539 +usbvision_read_31555 usbvision_read 3 31555 NULL
90540 +pd_video_read_24510 pd_video_read 3 24510 NULL
90541 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
90542 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
90543 +request_key_async_6990 request_key_async 4 6990 NULL
90544 +ts_write_64336 ts_write 3 64336 NULL
90545 +handle_response_55951 handle_response 5 55951 NULL
90546 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
90547 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
90548 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
90549 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
90550 +osst_write_31581 osst_write 3 31581 NULL
90551 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
90552 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
90553 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
90554 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
90555 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
90556 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
90557 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
90558 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
90559 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
90560 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
90561 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
90562 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
90563 +ilo_write_64378 ilo_write 3 64378 NULL
90564 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
90565 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
90566 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
90567 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
90568 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
90569 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
90570 +copy_from_user_17559 copy_from_user 3 17559 NULL
90571 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
90572 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
90573 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
90574 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
90575 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
90576 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
90577 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
90578 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
90579 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
90580 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
90581 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
90582 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
90583 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
90584 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
90585 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
90586 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
90587 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
90588 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
90589 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
90590 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
90591 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
90592 +__lgread_31668 __lgread 4 31668 NULL
90593 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
90594 +fd_copyin_56247 fd_copyin 3 56247 NULL
90595 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
90596 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
90597 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
90598 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
90599 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
90600 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
90601 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
90602 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
90603 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
90604 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
90605 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
90606 +event_filter_read_23494 event_filter_read 3 23494 NULL
90607 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
90608 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
90609 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
90610 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
90611 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
90612 +pkt_add_39897 pkt_add 3 39897 NULL
90613 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
90614 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
90615 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
90616 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
90617 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
90618 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
90619 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
90620 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
90621 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
90622 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
90623 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
90624 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
90625 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
90626 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
90627 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
90628 +remove_uuid_64505 remove_uuid 4 64505 NULL
90629 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
90630 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
90631 +create_table_16213 create_table 2 16213 NULL
90632 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
90633 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
90634 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
90635 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
90636 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
90637 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
90638 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
90639 +set_discoverable_48141 set_discoverable 4 48141 NULL
90640 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
90641 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
90642 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
90643 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
90644 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
90645 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
90646 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
90647 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
90648 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
90649 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
90650 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
90651 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
90652 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
90653 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
90654 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
90655 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
90656 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
90657 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
90658 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
90659 +dev_read_56369 dev_read 3 56369 NULL
90660 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
90661 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
90662 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
90663 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
90664 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
90665 +init_ipath_48187 init_ipath 1 48187 NULL
90666 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
90667 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
90668 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
90669 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
90670 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
90671 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
90672 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
90673 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
90674 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
90675 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
90676 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
90677 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
90678 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
90679 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
90680 +use_pool_64607 use_pool 2 64607 NULL
90681 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
90682 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
90683 +store_msg_56417 store_msg 3 56417 NULL
90684 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
90685 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
90686 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
90687 +read_file_recv_48232 read_file_recv 3 48232 NULL
90688 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
90689 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
90690 +fanotify_write_64623 fanotify_write 3 64623 NULL
90691 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
90692 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
90693 +fl_create_56435 fl_create 5 56435 NULL
90694 +gnttab_map_56439 gnttab_map 2 56439 NULL
90695 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
90696 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
90697 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
90698 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
90699 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
90700 +set_connectable_56458 set_connectable 4 56458 NULL
90701 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
90702 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
90703 +add_port_54941 add_port 2 54941 NULL
90704 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
90705 +cx18_read_23699 cx18_read 3 23699 NULL
90706 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
90707 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
90708 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
90709 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
90710 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
90711 +send_set_info_48288 send_set_info 7 48288 NULL
90712 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
90713 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
90714 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
90715 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
90716 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
90717 +new_dir_31919 new_dir 3 31919 NULL
90718 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
90719 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
90720 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
90721 +mgmt_control_7349 mgmt_control 3 7349 NULL
90722 +hash_setkey_48310 hash_setkey 3 48310 NULL
90723 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
90724 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
90725 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
90726 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
90727 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
90728 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
90729 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
90730 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
90731 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
90732 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
90733 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
90734 +vb2_write_31948 vb2_write 3 31948 NULL
90735 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
90736 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
90737 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
90738 +ip_options_get_56538 ip_options_get 4 56538 NULL
90739 +write_62671 write 3 62671 NULL
90740 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
90741 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
90742 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
90743 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
90744 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
90745 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
90746 +skb_add_data_48363 skb_add_data 3 48363 NULL
90747 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
90748 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
90749 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
90750 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
90751 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
90752 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
90753 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
90754 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
90755 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
90756 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
90757 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
90758 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
90759 +system_enable_read_25815 system_enable_read 3 25815 NULL
90760 +allocate_probes_40204 allocate_probes 1 40204 NULL
90761 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
90762 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
90763 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
90764 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
90765 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
90766 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
90767 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
90768 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
90769 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
90770 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
90771 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
90772 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
90773 +fs_path_add_15648 fs_path_add 3 15648 NULL
90774 +event_filter_write_56609 event_filter_write 3 56609 NULL
90775 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
90776 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
90777 +xsd_read_15653 xsd_read 3 15653 NULL
90778 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
90779 +p54_init_common_23850 p54_init_common 1 23850 NULL
90780 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
90781 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
90782 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
90783 +garp_request_join_7471 garp_request_join 4 7471 NULL
90784 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
90785 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
90786 +unifi_read_14899 unifi_read 3 14899 NULL
90787 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
90788 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
90789 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
90790 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
90791 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
90792 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
90793 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
90794 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
90795 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
90796 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
90797 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
90798 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
90799 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
90800 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
90801 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
90802 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
90803 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
90804 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
90805 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
90806 +bio_alloc_32095 bio_alloc 2 32095 NULL
90807 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
90808 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
90809 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
90810 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
90811 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
90812 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
90813 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
90814 +send_control_msg_48498 send_control_msg 6 48498 NULL
90815 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
90816 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
90817 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
90818 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
90819 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
90820 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
90821 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
90822 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
90823 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
90824 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
90825 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
90826 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
90827 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
90828 +alloc_tx_32143 alloc_tx 2 32143 NULL
90829 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
90830 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
90831 +hsc_write_55875 hsc_write 3 55875 NULL
90832 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
90833 +do_test_15766 do_test 1 15766 NULL
90834 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
90835 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
90836 +named_distribute_48544 named_distribute 4 48544 NULL
90837 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
90838 +venus_link_32165 venus_link 5 32165 NULL
90839 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
90840 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
90841 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
90842 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
90843 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
90844 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
90845 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
90846 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
90847 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
90848 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
90849 +groups_alloc_7614 groups_alloc 1 7614 NULL
90850 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
90851 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
90852 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
90853 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
90854 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
90855 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
90856 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
90857 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
90858 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
90859 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
90860 +snapshot_write_28351 snapshot_write 3 28351 NULL
90861 +event_enable_read_7074 event_enable_read 3 7074 NULL
90862 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
90863 +do_syslog_56807 do_syslog 3 56807 NULL
90864 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
90865 +pskb_pull_65005 pskb_pull 2 65005 NULL
90866 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
90867 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
90868 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
90869 +unifi_write_65012 unifi_write 3 65012 NULL
90870 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
90871 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
90872 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
90873 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
90874 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
90875 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
90876 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
90877 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
90878 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
90879 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
90880 +if_write_51756 if_write 3 51756 NULL
90881 +insert_dent_65034 insert_dent 7 65034 NULL
90882 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
90883 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
90884 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
90885 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
90886 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
90887 +lc_create_48662 lc_create 3 48662 NULL
90888 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
90889 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
90890 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
90891 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
90892 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
90893 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
90894 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
90895 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
90896 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
90897 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
90898 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
90899 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
90900 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
90901 +altera_drscan_48698 altera_drscan 2 48698 NULL
90902 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
90903 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
90904 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
90905 +power_read_15939 power_read 3 15939 NULL
90906 +recv_msg_48709 recv_msg 4 48709 NULL
90907 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
90908 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
90909 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
90910 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
90911 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
90912 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
90913 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
90914 +revalidate_19043 revalidate 2 19043 NULL
90915 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
90916 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
90917 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
90918 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
90919 +check_header_56930 check_header 2 56930 NULL
90920 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
90921 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
90922 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
90923 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
90924 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
90925 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
90926 +frame_alloc_15981 frame_alloc 4 15981 NULL
90927 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
90928 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
90929 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
90930 +adu_read_24177 adu_read 3 24177 NULL
90931 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
90932 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
90933 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
90934 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
90935 +vfd_write_14717 vfd_write 3 14717 NULL
90936 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
90937 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
90938 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
90939 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
90940 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
90941 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
90942 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
90943 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
90944 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
90945 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
90946 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
90947 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
90948 +register_device_60015 register_device 2-3 60015 NULL
90949 +got_frame_16028 got_frame 2 16028 NULL
90950 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
90951 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
90952 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
90953 +scsi_register_49094 scsi_register 2 49094 NULL
90954 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
90955 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
90956 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
90957 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
90958 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
90959 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
90960 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
90961 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
90962 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
90963 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
90964 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
90965 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
90966 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
90967 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
90968 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
90969 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
90970 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
90971 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
90972 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
90973 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
90974 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
90975 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
90976 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
90977 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
90978 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
90979 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
90980 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
90981 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
90982 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
90983 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
90984 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
90985 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
90986 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
90987 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
90988 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
90989 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
90990 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
90991 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
90992 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
90993 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
90994 +fsm_init_16134 fsm_init 2 16134 NULL
90995 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
90996 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
90997 +disconnect_32521 disconnect 4 32521 NULL
90998 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
90999 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
91000 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
91001 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
91002 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
91003 +ilo_read_32531 ilo_read 3 32531 NULL
91004 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
91005 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
91006 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
91007 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
91008 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
91009 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
91010 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
91011 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
91012 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
91013 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
91014 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
91015 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
91016 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
91017 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
91018 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
91019 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
91020 +card_send_command_40757 card_send_command 3 40757 NULL
91021 +sys_mbind_7990 sys_mbind 5 7990 NULL
91022 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
91023 +pg_write_40766 pg_write 3 40766 NULL
91024 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
91025 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
91026 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
91027 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
91028 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
91029 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
91030 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
91031 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
91032 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
91033 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
91034 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
91035 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
91036 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
91037 +vcs_read_8017 vcs_read 3 8017 NULL
91038 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
91039 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
91040 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
91041 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
91042 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
91043 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
91044 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
91045 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
91046 +copy_and_check_19089 copy_and_check 3 19089 NULL
91047 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
91048 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
91049 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
91050 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
91051 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
91052 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
91053 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
91054 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
91055 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
91056 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
91057 +smk_user_access_24440 smk_user_access 3 24440 NULL
91058 +xd_rw_49020 xd_rw 3-4 49020 NULL
91059 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
91060 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
91061 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
91062 +kvmalloc_32646 kvmalloc 1 32646 NULL
91063 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
91064 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
91065 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
91066 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
91067 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
91068 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
91069 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
91070 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
91071 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
91072 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
91073 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
91074 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
91075 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
91076 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
91077 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
91078 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
91079 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
91080 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
91081 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
91082 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
91083 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
91084 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
91085 +venus_lookup_8121 venus_lookup 4 8121 NULL
91086 +compat_writev_60063 compat_writev 3 60063 NULL
91087 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
91088 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
91089 +read_file_queue_40895 read_file_queue 3 40895 NULL
91090 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
91091 +waiters_read_40902 waiters_read 3 40902 NULL
91092 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
91093 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
91094 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
91095 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
91096 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
91097 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
91098 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
91099 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
91100 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
91101 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
91102 +alloc_dr_65495 alloc_dr 2 65495 NULL
91103 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
91104 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
91105 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
91106 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
91107 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
91108 +rbd_add_16366 rbd_add 3 16366 NULL
91109 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
91110 +pt_read_49136 pt_read 3 49136 NULL
91111 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
91112 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
91113 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
91114 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
91115 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
91116 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
91117 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
91118 new file mode 100644
91119 index 0000000..d52f2ee
91120 --- /dev/null
91121 +++ b/tools/gcc/size_overflow_plugin.c
91122 @@ -0,0 +1,1941 @@
91123 +/*
91124 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
91125 + * Licensed under the GPL v2, or (at your option) v3
91126 + *
91127 + * Homepage:
91128 + * http://www.grsecurity.net/~ephox/overflow_plugin/
91129 + *
91130 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
91131 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
91132 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
91133 + *
91134 + * Usage:
91135 + * $ 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
91136 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
91137 + */
91138 +
91139 +#include "gcc-plugin.h"
91140 +#include "config.h"
91141 +#include "system.h"
91142 +#include "coretypes.h"
91143 +#include "tree.h"
91144 +#include "tree-pass.h"
91145 +#include "intl.h"
91146 +#include "plugin-version.h"
91147 +#include "tm.h"
91148 +#include "toplev.h"
91149 +#include "function.h"
91150 +#include "tree-flow.h"
91151 +#include "plugin.h"
91152 +#include "gimple.h"
91153 +#include "c-common.h"
91154 +#include "diagnostic.h"
91155 +#include "cfgloop.h"
91156 +
91157 +#if BUILDING_GCC_VERSION >= 4007
91158 +#include "c-tree.h"
91159 +#else
91160 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
91161 +#endif
91162 +
91163 +#if BUILDING_GCC_VERSION >= 4008
91164 +#define TODO_dump_func 0
91165 +#endif
91166 +
91167 +struct size_overflow_hash {
91168 + const struct size_overflow_hash * const next;
91169 + const char * const name;
91170 + const unsigned int param;
91171 +};
91172 +
91173 +#include "size_overflow_hash.h"
91174 +
91175 +enum marked {
91176 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
91177 +};
91178 +
91179 +static unsigned int call_count = 0;
91180 +
91181 +#define __unused __attribute__((__unused__))
91182 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
91183 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
91184 +#define BEFORE_STMT true
91185 +#define AFTER_STMT false
91186 +#define CREATE_NEW_VAR NULL_TREE
91187 +#define CODES_LIMIT 32
91188 +#define MAX_PARAM 32
91189 +#define MY_STMT GF_PLF_1
91190 +#define NO_CAST_CHECK GF_PLF_2
91191 +
91192 +#if BUILDING_GCC_VERSION == 4005
91193 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
91194 +#endif
91195 +
91196 +int plugin_is_GPL_compatible;
91197 +void debug_gimple_stmt(gimple gs);
91198 +
91199 +static tree expand(struct pointer_set_t *visited, tree lhs);
91200 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
91201 +static tree report_size_overflow_decl;
91202 +static const_tree const_char_ptr_type_node;
91203 +static unsigned int handle_function(void);
91204 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
91205 +static tree get_size_overflow_type(gimple stmt, const_tree node);
91206 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
91207 +
91208 +static struct plugin_info size_overflow_plugin_info = {
91209 + .version = "20130109beta",
91210 + .help = "no-size-overflow\tturn off size overflow checking\n",
91211 +};
91212 +
91213 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
91214 +{
91215 + unsigned int arg_count;
91216 + enum tree_code code = TREE_CODE(*node);
91217 +
91218 + switch (code) {
91219 + case FUNCTION_DECL:
91220 + arg_count = type_num_arguments(TREE_TYPE(*node));
91221 + break;
91222 + case FUNCTION_TYPE:
91223 + case METHOD_TYPE:
91224 + arg_count = type_num_arguments(*node);
91225 + break;
91226 + default:
91227 + *no_add_attrs = true;
91228 + error("%s: %qE attribute only applies to functions", __func__, name);
91229 + return NULL_TREE;
91230 + }
91231 +
91232 + for (; args; args = TREE_CHAIN(args)) {
91233 + tree position = TREE_VALUE(args);
91234 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
91235 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
91236 + *no_add_attrs = true;
91237 + }
91238 + }
91239 + return NULL_TREE;
91240 +}
91241 +
91242 +static const char* get_asm_name(tree node)
91243 +{
91244 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
91245 +}
91246 +
91247 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
91248 +{
91249 + unsigned int arg_count, arg_num;
91250 + enum tree_code code = TREE_CODE(*node);
91251 +
91252 + switch (code) {
91253 + case FUNCTION_DECL:
91254 + arg_count = type_num_arguments(TREE_TYPE(*node));
91255 + break;
91256 + case FUNCTION_TYPE:
91257 + case METHOD_TYPE:
91258 + arg_count = type_num_arguments(*node);
91259 + break;
91260 + case FIELD_DECL:
91261 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
91262 + if (arg_num != 0) {
91263 + *no_add_attrs = true;
91264 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
91265 + }
91266 + return NULL_TREE;
91267 + default:
91268 + *no_add_attrs = true;
91269 + error("%qE attribute only applies to functions", name);
91270 + return NULL_TREE;
91271 + }
91272 +
91273 + for (; args; args = TREE_CHAIN(args)) {
91274 + tree position = TREE_VALUE(args);
91275 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
91276 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
91277 + *no_add_attrs = true;
91278 + }
91279 + }
91280 + return NULL_TREE;
91281 +}
91282 +
91283 +static struct attribute_spec size_overflow_attr = {
91284 + .name = "size_overflow",
91285 + .min_length = 1,
91286 + .max_length = -1,
91287 + .decl_required = true,
91288 + .type_required = false,
91289 + .function_type_required = false,
91290 + .handler = handle_size_overflow_attribute,
91291 +#if BUILDING_GCC_VERSION >= 4007
91292 + .affects_type_identity = false
91293 +#endif
91294 +};
91295 +
91296 +static struct attribute_spec intentional_overflow_attr = {
91297 + .name = "intentional_overflow",
91298 + .min_length = 1,
91299 + .max_length = -1,
91300 + .decl_required = true,
91301 + .type_required = false,
91302 + .function_type_required = false,
91303 + .handler = handle_intentional_overflow_attribute,
91304 +#if BUILDING_GCC_VERSION >= 4007
91305 + .affects_type_identity = false
91306 +#endif
91307 +};
91308 +
91309 +static void register_attributes(void __unused *event_data, void __unused *data)
91310 +{
91311 + register_attribute(&size_overflow_attr);
91312 + register_attribute(&intentional_overflow_attr);
91313 +}
91314 +
91315 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
91316 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
91317 +{
91318 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
91319 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
91320 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
91321 +
91322 + unsigned int m = 0x57559429;
91323 + unsigned int n = 0x5052acdb;
91324 + const unsigned int *key4 = (const unsigned int *)key;
91325 + unsigned int h = len;
91326 + unsigned int k = len + seed + n;
91327 + unsigned long long p;
91328 +
91329 + while (len >= 8) {
91330 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
91331 + len -= 8;
91332 + }
91333 + if (len >= 4) {
91334 + cwmixb(key4[0]) key4 += 1;
91335 + len -= 4;
91336 + }
91337 + if (len)
91338 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
91339 + cwmixb(h ^ (k + n));
91340 + return k ^ h;
91341 +
91342 +#undef cwfold
91343 +#undef cwmixa
91344 +#undef cwmixb
91345 +}
91346 +
91347 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
91348 +{
91349 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
91350 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
91351 + return fn ^ codes;
91352 +}
91353 +
91354 +static inline tree get_original_function_decl(tree fndecl)
91355 +{
91356 + if (DECL_ABSTRACT_ORIGIN(fndecl))
91357 + return DECL_ABSTRACT_ORIGIN(fndecl);
91358 + return fndecl;
91359 +}
91360 +
91361 +static inline gimple get_def_stmt(const_tree node)
91362 +{
91363 + gcc_assert(node != NULL_TREE);
91364 + gcc_assert(TREE_CODE(node) == SSA_NAME);
91365 + return SSA_NAME_DEF_STMT(node);
91366 +}
91367 +
91368 +static unsigned char get_tree_code(const_tree type)
91369 +{
91370 + switch (TREE_CODE(type)) {
91371 + case ARRAY_TYPE:
91372 + return 0;
91373 + case BOOLEAN_TYPE:
91374 + return 1;
91375 + case ENUMERAL_TYPE:
91376 + return 2;
91377 + case FUNCTION_TYPE:
91378 + return 3;
91379 + case INTEGER_TYPE:
91380 + return 4;
91381 + case POINTER_TYPE:
91382 + return 5;
91383 + case RECORD_TYPE:
91384 + return 6;
91385 + case UNION_TYPE:
91386 + return 7;
91387 + case VOID_TYPE:
91388 + return 8;
91389 + case REAL_TYPE:
91390 + return 9;
91391 + case VECTOR_TYPE:
91392 + return 10;
91393 + case REFERENCE_TYPE:
91394 + return 11;
91395 + case OFFSET_TYPE:
91396 + return 12;
91397 + case COMPLEX_TYPE:
91398 + return 13;
91399 + default:
91400 + debug_tree((tree)type);
91401 + gcc_unreachable();
91402 + }
91403 +}
91404 +
91405 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
91406 +{
91407 + gcc_assert(type != NULL_TREE);
91408 +
91409 + while (type && len < CODES_LIMIT) {
91410 + tree_codes[len] = get_tree_code(type);
91411 + len++;
91412 + type = TREE_TYPE(type);
91413 + }
91414 + return len;
91415 +}
91416 +
91417 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
91418 +{
91419 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
91420 + enum tree_code code = TREE_CODE(type);
91421 + size_t len = 0;
91422 +
91423 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
91424 +
91425 + arg = TYPE_ARG_TYPES(type);
91426 + // skip builtins __builtin_constant_p
91427 + if (!arg && DECL_BUILT_IN(fndecl))
91428 + return 0;
91429 +
91430 + if (TREE_CODE_CLASS(code) == tcc_type)
91431 + result = type;
91432 + else
91433 + result = DECL_RESULT(fndecl);
91434 +
91435 + gcc_assert(result != NULL_TREE);
91436 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
91437 +
91438 + if (arg == NULL_TREE) {
91439 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
91440 + arg_field = DECL_ARGUMENT_FLD(fndecl);
91441 + if (arg_field == NULL_TREE)
91442 + return 0;
91443 + arg = TREE_TYPE(arg_field);
91444 + len = add_type_codes(arg, tree_codes, len);
91445 + gcc_assert(len != 0);
91446 + return len;
91447 + }
91448 +
91449 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
91450 + while (arg && len < CODES_LIMIT) {
91451 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
91452 + arg = TREE_CHAIN(arg);
91453 + }
91454 +
91455 + gcc_assert(len != 0);
91456 + return len;
91457 +}
91458 +
91459 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
91460 +{
91461 + unsigned int hash;
91462 + const struct size_overflow_hash *entry;
91463 + unsigned char tree_codes[CODES_LIMIT];
91464 + size_t len;
91465 + const char *func_name = get_asm_name(fndecl);
91466 +
91467 + len = get_function_decl(fndecl, tree_codes);
91468 + if (len == 0)
91469 + return NULL;
91470 +
91471 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
91472 +
91473 + entry = size_overflow_hash[hash];
91474 + while (entry) {
91475 + if (!strcmp(entry->name, func_name))
91476 + return entry;
91477 + entry = entry->next;
91478 + }
91479 +
91480 + return NULL;
91481 +}
91482 +
91483 +static void check_arg_type(const_tree arg)
91484 +{
91485 + const_tree type = TREE_TYPE(arg);
91486 + enum tree_code code = TREE_CODE(type);
91487 +
91488 + if (code == BOOLEAN_TYPE)
91489 + return;
91490 +
91491 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
91492 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
91493 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
91494 +}
91495 +
91496 +static unsigned int find_arg_number(const_tree arg, tree func)
91497 +{
91498 + tree var;
91499 + unsigned int argnum = 1;
91500 +
91501 + if (TREE_CODE(arg) == SSA_NAME)
91502 + arg = SSA_NAME_VAR(arg);
91503 +
91504 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
91505 + if (strcmp(NAME(arg), NAME(var))) {
91506 + argnum++;
91507 + continue;
91508 + }
91509 + check_arg_type(var);
91510 + return argnum;
91511 + }
91512 + gcc_unreachable();
91513 +}
91514 +
91515 +static tree create_new_var(tree type)
91516 +{
91517 + tree new_var = create_tmp_var(type, "cicus");
91518 +
91519 +#if BUILDING_GCC_VERSION <= 4007
91520 + add_referenced_var(new_var);
91521 + mark_sym_for_renaming(new_var);
91522 +#endif
91523 + return new_var;
91524 +}
91525 +
91526 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
91527 +{
91528 + gimple assign;
91529 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91530 + tree type = TREE_TYPE(rhs1);
91531 + tree lhs = create_new_var(type);
91532 +
91533 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
91534 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
91535 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
91536 +
91537 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
91538 + update_stmt(assign);
91539 + gimple_set_plf(assign, MY_STMT, true);
91540 + return assign;
91541 +}
91542 +
91543 +static bool is_bool(const_tree node)
91544 +{
91545 + const_tree type;
91546 +
91547 + if (node == NULL_TREE)
91548 + return false;
91549 +
91550 + type = TREE_TYPE(node);
91551 + if (!INTEGRAL_TYPE_P(type))
91552 + return false;
91553 + if (TREE_CODE(type) == BOOLEAN_TYPE)
91554 + return true;
91555 + if (TYPE_PRECISION(type) == 1)
91556 + return true;
91557 + return false;
91558 +}
91559 +
91560 +static tree cast_a_tree(tree type, tree var)
91561 +{
91562 + gcc_assert(type != NULL_TREE);
91563 + gcc_assert(var != NULL_TREE);
91564 + gcc_assert(fold_convertible_p(type, var));
91565 +
91566 + return fold_convert(type, var);
91567 +}
91568 +
91569 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
91570 +{
91571 + gimple assign;
91572 +
91573 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
91574 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
91575 + gcc_unreachable();
91576 +
91577 + if (lhs == CREATE_NEW_VAR)
91578 + lhs = create_new_var(dst_type);
91579 +
91580 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
91581 +
91582 + if (!gsi_end_p(*gsi)) {
91583 + location_t loc = gimple_location(gsi_stmt(*gsi));
91584 + gimple_set_location(assign, loc);
91585 + }
91586 +
91587 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
91588 +
91589 + if (before)
91590 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
91591 + else
91592 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
91593 + update_stmt(assign);
91594 + gimple_set_plf(assign, MY_STMT, true);
91595 +
91596 + return assign;
91597 +}
91598 +
91599 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
91600 +{
91601 + gimple assign;
91602 + gimple_stmt_iterator gsi;
91603 +
91604 + if (rhs == NULL_TREE)
91605 + return NULL_TREE;
91606 +
91607 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
91608 + return rhs;
91609 +
91610 + gsi = gsi_for_stmt(stmt);
91611 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
91612 + gimple_set_plf(assign, MY_STMT, true);
91613 + return gimple_get_lhs(assign);
91614 +}
91615 +
91616 +static tree cast_to_TI_type(gimple stmt, tree node)
91617 +{
91618 + gimple_stmt_iterator gsi;
91619 + gimple cast_stmt;
91620 + tree type = TREE_TYPE(node);
91621 +
91622 + if (types_compatible_p(type, intTI_type_node))
91623 + return node;
91624 +
91625 + gsi = gsi_for_stmt(stmt);
91626 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91627 + gimple_set_plf(cast_stmt, MY_STMT, true);
91628 + return gimple_get_lhs(cast_stmt);
91629 +}
91630 +
91631 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
91632 +{
91633 + tree lhs;
91634 + gimple_stmt_iterator gsi;
91635 +
91636 + if (rhs1 == NULL_TREE) {
91637 + debug_gimple_stmt(oldstmt);
91638 + error("%s: rhs1 is NULL_TREE", __func__);
91639 + gcc_unreachable();
91640 + }
91641 +
91642 + switch (gimple_code(oldstmt)) {
91643 + case GIMPLE_ASM:
91644 + lhs = rhs1;
91645 + break;
91646 + case GIMPLE_CALL:
91647 + lhs = gimple_call_lhs(oldstmt);
91648 + break;
91649 + case GIMPLE_ASSIGN:
91650 + lhs = gimple_get_lhs(oldstmt);
91651 + break;
91652 + default:
91653 + debug_gimple_stmt(oldstmt);
91654 + gcc_unreachable();
91655 + }
91656 +
91657 + gsi = gsi_for_stmt(oldstmt);
91658 + pointer_set_insert(visited, oldstmt);
91659 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
91660 + basic_block next_bb, cur_bb;
91661 + const_edge e;
91662 +
91663 + gcc_assert(before == false);
91664 + gcc_assert(stmt_can_throw_internal(oldstmt));
91665 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
91666 + gcc_assert(!gsi_end_p(gsi));
91667 +
91668 + cur_bb = gimple_bb(oldstmt);
91669 + next_bb = cur_bb->next_bb;
91670 + e = find_edge(cur_bb, next_bb);
91671 + gcc_assert(e != NULL);
91672 + gcc_assert(e->flags & EDGE_FALLTHRU);
91673 +
91674 + gsi = gsi_after_labels(next_bb);
91675 + gcc_assert(!gsi_end_p(gsi));
91676 +
91677 + before = true;
91678 + oldstmt = gsi_stmt(gsi);
91679 + }
91680 +
91681 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
91682 +}
91683 +
91684 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
91685 +{
91686 + gimple stmt;
91687 + gimple_stmt_iterator gsi;
91688 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
91689 +
91690 + if (gimple_plf(oldstmt, MY_STMT))
91691 + return lhs;
91692 +
91693 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
91694 + rhs1 = gimple_assign_rhs1(oldstmt);
91695 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
91696 + }
91697 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
91698 + rhs2 = gimple_assign_rhs2(oldstmt);
91699 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
91700 + }
91701 +
91702 + stmt = gimple_copy(oldstmt);
91703 + gimple_set_location(stmt, gimple_location(oldstmt));
91704 + gimple_set_plf(stmt, MY_STMT, true);
91705 +
91706 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
91707 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
91708 +
91709 + size_overflow_type = get_size_overflow_type(oldstmt, node);
91710 +
91711 + if (is_bool(lhs))
91712 + new_var = SSA_NAME_VAR(lhs);
91713 + else
91714 + new_var = create_new_var(size_overflow_type);
91715 + new_var = make_ssa_name(new_var, stmt);
91716 + gimple_set_lhs(stmt, new_var);
91717 +
91718 + if (rhs1 != NULL_TREE)
91719 + gimple_assign_set_rhs1(stmt, rhs1);
91720 +
91721 + if (rhs2 != NULL_TREE)
91722 + gimple_assign_set_rhs2(stmt, rhs2);
91723 +#if BUILDING_GCC_VERSION >= 4007
91724 + if (rhs3 != NULL_TREE)
91725 + gimple_assign_set_rhs3(stmt, rhs3);
91726 +#endif
91727 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
91728 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
91729 +
91730 + gsi = gsi_for_stmt(oldstmt);
91731 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
91732 + update_stmt(stmt);
91733 + pointer_set_insert(visited, oldstmt);
91734 + return gimple_get_lhs(stmt);
91735 +}
91736 +
91737 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
91738 +{
91739 + basic_block bb;
91740 + gimple phi;
91741 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
91742 + gimple_seq seq;
91743 +
91744 + bb = gsi_bb(gsi);
91745 +
91746 + phi = create_phi_node(result, bb);
91747 + seq = phi_nodes(bb);
91748 + gsi = gsi_last(seq);
91749 + gsi_remove(&gsi, false);
91750 +
91751 + gsi = gsi_for_stmt(oldstmt);
91752 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
91753 + gimple_set_bb(phi, bb);
91754 + gimple_set_plf(phi, MY_STMT, true);
91755 + return phi;
91756 +}
91757 +
91758 +static basic_block create_a_first_bb(void)
91759 +{
91760 + basic_block first_bb;
91761 +
91762 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
91763 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
91764 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
91765 + return first_bb;
91766 +}
91767 +
91768 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
91769 +{
91770 + basic_block bb;
91771 + const_gimple newstmt;
91772 + gimple_stmt_iterator gsi;
91773 + bool before = BEFORE_STMT;
91774 +
91775 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
91776 + gsi = gsi_for_stmt(get_def_stmt(arg));
91777 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
91778 + return gimple_get_lhs(newstmt);
91779 + }
91780 +
91781 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
91782 + gsi = gsi_after_labels(bb);
91783 + if (bb->index == 0) {
91784 + bb = create_a_first_bb();
91785 + gsi = gsi_start_bb(bb);
91786 + }
91787 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
91788 + return gimple_get_lhs(newstmt);
91789 +}
91790 +
91791 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
91792 +{
91793 + gimple newstmt;
91794 + gimple_stmt_iterator gsi;
91795 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
91796 + gimple def_newstmt = get_def_stmt(new_rhs);
91797 +
91798 + gsi_insert = gsi_insert_after;
91799 + gsi = gsi_for_stmt(def_newstmt);
91800 +
91801 + switch (gimple_code(get_def_stmt(arg))) {
91802 + case GIMPLE_PHI:
91803 + newstmt = gimple_build_assign(new_var, new_rhs);
91804 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
91805 + gsi_insert = gsi_insert_before;
91806 + break;
91807 + case GIMPLE_ASM:
91808 + case GIMPLE_CALL:
91809 + newstmt = gimple_build_assign(new_var, new_rhs);
91810 + break;
91811 + case GIMPLE_ASSIGN:
91812 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
91813 + break;
91814 + default:
91815 + /* unknown gimple_code (handle_build_new_phi_arg) */
91816 + gcc_unreachable();
91817 + }
91818 +
91819 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
91820 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
91821 + gimple_set_plf(newstmt, MY_STMT, true);
91822 + update_stmt(newstmt);
91823 + return newstmt;
91824 +}
91825 +
91826 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
91827 +{
91828 + const_gimple newstmt;
91829 + gimple def_stmt;
91830 + tree new_rhs;
91831 +
91832 + new_rhs = expand(visited, arg);
91833 + if (new_rhs == NULL_TREE)
91834 + return NULL_TREE;
91835 +
91836 + def_stmt = get_def_stmt(new_rhs);
91837 + if (gimple_code(def_stmt) == GIMPLE_NOP)
91838 + return NULL_TREE;
91839 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
91840 +
91841 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
91842 + return gimple_get_lhs(newstmt);
91843 +}
91844 +
91845 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
91846 +{
91847 + gimple phi, oldstmt = get_def_stmt(orig_result);
91848 + tree new_result, size_overflow_type;
91849 + unsigned int i;
91850 + unsigned int n = gimple_phi_num_args(oldstmt);
91851 +
91852 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
91853 +
91854 + new_result = create_new_var(size_overflow_type);
91855 +
91856 + pointer_set_insert(visited, oldstmt);
91857 + phi = overflow_create_phi_node(oldstmt, new_result);
91858 + for (i = 0; i < n; i++) {
91859 + tree arg, lhs;
91860 +
91861 + arg = gimple_phi_arg_def(oldstmt, i);
91862 + if (is_gimple_constant(arg))
91863 + arg = cast_a_tree(size_overflow_type, arg);
91864 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
91865 + if (lhs == NULL_TREE)
91866 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
91867 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
91868 + }
91869 +
91870 + update_stmt(phi);
91871 + return gimple_phi_result(phi);
91872 +}
91873 +
91874 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
91875 +{
91876 + const_gimple assign;
91877 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91878 + tree origtype = TREE_TYPE(orig_rhs);
91879 +
91880 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
91881 +
91882 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91883 + return gimple_get_lhs(assign);
91884 +}
91885 +
91886 +static void change_rhs1(gimple stmt, tree new_rhs1)
91887 +{
91888 + tree assign_rhs;
91889 + const_tree rhs = gimple_assign_rhs1(stmt);
91890 +
91891 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
91892 + gimple_assign_set_rhs1(stmt, assign_rhs);
91893 + update_stmt(stmt);
91894 +}
91895 +
91896 +static bool check_mode_type(const_gimple stmt)
91897 +{
91898 + const_tree lhs = gimple_get_lhs(stmt);
91899 + const_tree lhs_type = TREE_TYPE(lhs);
91900 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
91901 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
91902 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
91903 +
91904 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
91905 + return false;
91906 +
91907 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
91908 + return false;
91909 +
91910 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
91911 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
91912 + return false;
91913 +
91914 + return true;
91915 +}
91916 +
91917 +static bool check_undefined_integer_operation(const_gimple stmt)
91918 +{
91919 + const_gimple def_stmt;
91920 + const_tree lhs = gimple_get_lhs(stmt);
91921 + const_tree rhs1 = gimple_assign_rhs1(stmt);
91922 + const_tree rhs1_type = TREE_TYPE(rhs1);
91923 + const_tree lhs_type = TREE_TYPE(lhs);
91924 +
91925 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
91926 + return false;
91927 +
91928 + def_stmt = get_def_stmt(rhs1);
91929 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
91930 + return false;
91931 +
91932 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
91933 + return false;
91934 + return true;
91935 +}
91936 +
91937 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
91938 +{
91939 + const_tree rhs1, lhs, rhs1_type, lhs_type;
91940 + enum machine_mode lhs_mode, rhs_mode;
91941 + gimple def_stmt = get_def_stmt(no_const_rhs);
91942 +
91943 + if (!gimple_assign_cast_p(def_stmt))
91944 + return false;
91945 +
91946 + rhs1 = gimple_assign_rhs1(def_stmt);
91947 + lhs = gimple_get_lhs(def_stmt);
91948 + rhs1_type = TREE_TYPE(rhs1);
91949 + lhs_type = TREE_TYPE(lhs);
91950 + rhs_mode = TYPE_MODE(rhs1_type);
91951 + lhs_mode = TYPE_MODE(lhs_type);
91952 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
91953 + return false;
91954 +
91955 + return true;
91956 +}
91957 +
91958 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
91959 +{
91960 + tree rhs1 = gimple_assign_rhs1(stmt);
91961 + tree lhs = gimple_get_lhs(stmt);
91962 + const_tree rhs1_type = TREE_TYPE(rhs1);
91963 + const_tree lhs_type = TREE_TYPE(lhs);
91964 +
91965 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
91966 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91967 +
91968 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
91969 +}
91970 +
91971 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
91972 +{
91973 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
91974 + tree new_rhs1 = NULL_TREE;
91975 + tree rhs1 = gimple_assign_rhs1(stmt);
91976 + const_tree rhs1_type = TREE_TYPE(rhs1);
91977 + const_tree lhs_type = TREE_TYPE(lhs);
91978 +
91979 + if (gimple_plf(stmt, MY_STMT))
91980 + return lhs;
91981 +
91982 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
91983 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91984 +
91985 + new_rhs1 = expand(visited, rhs1);
91986 +
91987 + if (new_rhs1 == NULL_TREE)
91988 + return create_cast_assign(visited, stmt);
91989 +
91990 + if (gimple_plf(stmt, NO_CAST_CHECK))
91991 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
91992 +
91993 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
91994 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
91995 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
91996 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
91997 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91998 + }
91999 +
92000 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
92001 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
92002 +
92003 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
92004 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
92005 +
92006 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
92007 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
92008 +
92009 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
92010 +
92011 + change_rhs1(stmt, new_rhs1);
92012 +
92013 + if (!check_mode_type(stmt))
92014 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92015 +
92016 + size_overflow_type = get_size_overflow_type(stmt, lhs);
92017 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
92018 +
92019 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
92020 +
92021 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92022 +}
92023 +
92024 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
92025 +{
92026 + tree rhs1, lhs = gimple_get_lhs(stmt);
92027 + gimple def_stmt = get_def_stmt(lhs);
92028 +
92029 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
92030 + rhs1 = gimple_assign_rhs1(def_stmt);
92031 +
92032 + if (is_gimple_constant(rhs1))
92033 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92034 +
92035 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
92036 + switch (TREE_CODE(rhs1)) {
92037 + case SSA_NAME:
92038 + return handle_unary_rhs(visited, def_stmt);
92039 + case ARRAY_REF:
92040 + case BIT_FIELD_REF:
92041 + case ADDR_EXPR:
92042 + case COMPONENT_REF:
92043 + case INDIRECT_REF:
92044 +#if BUILDING_GCC_VERSION >= 4006
92045 + case MEM_REF:
92046 +#endif
92047 + case TARGET_MEM_REF:
92048 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92049 + case PARM_DECL:
92050 + case VAR_DECL:
92051 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92052 +
92053 + default:
92054 + debug_gimple_stmt(def_stmt);
92055 + debug_tree(rhs1);
92056 + gcc_unreachable();
92057 + }
92058 +}
92059 +
92060 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
92061 +{
92062 + gimple cond_stmt;
92063 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
92064 +
92065 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
92066 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
92067 + update_stmt(cond_stmt);
92068 +}
92069 +
92070 +static tree create_string_param(tree string)
92071 +{
92072 + tree i_type, a_type;
92073 + const int length = TREE_STRING_LENGTH(string);
92074 +
92075 + gcc_assert(length > 0);
92076 +
92077 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
92078 + a_type = build_array_type(char_type_node, i_type);
92079 +
92080 + TREE_TYPE(string) = a_type;
92081 + TREE_CONSTANT(string) = 1;
92082 + TREE_READONLY(string) = 1;
92083 +
92084 + return build1(ADDR_EXPR, ptr_type_node, string);
92085 +}
92086 +
92087 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
92088 +{
92089 + gimple func_stmt;
92090 + const_gimple def_stmt;
92091 + const_tree loc_line;
92092 + tree loc_file, ssa_name, current_func;
92093 + expanded_location xloc;
92094 + char *ssa_name_buf;
92095 + int len;
92096 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
92097 +
92098 + def_stmt = get_def_stmt(arg);
92099 + xloc = expand_location(gimple_location(def_stmt));
92100 +
92101 + if (!gimple_has_location(def_stmt)) {
92102 + xloc = expand_location(gimple_location(stmt));
92103 + if (!gimple_has_location(stmt))
92104 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
92105 + }
92106 +
92107 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
92108 +
92109 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
92110 + loc_file = create_string_param(loc_file);
92111 +
92112 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
92113 + current_func = create_string_param(current_func);
92114 +
92115 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
92116 + call_count++;
92117 + 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);
92118 + gcc_assert(len > 0);
92119 + ssa_name = build_string(len + 1, ssa_name_buf);
92120 + free(ssa_name_buf);
92121 + ssa_name = create_string_param(ssa_name);
92122 +
92123 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
92124 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
92125 +
92126 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
92127 +}
92128 +
92129 +static void __unused print_the_code_insertions(const_gimple stmt)
92130 +{
92131 + location_t loc = gimple_location(stmt);
92132 +
92133 + inform(loc, "Integer size_overflow check applied here.");
92134 +}
92135 +
92136 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
92137 +{
92138 + basic_block cond_bb, join_bb, bb_true;
92139 + edge e;
92140 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
92141 +
92142 + cond_bb = gimple_bb(stmt);
92143 + if (before)
92144 + gsi_prev(&gsi);
92145 + if (gsi_end_p(gsi))
92146 + e = split_block_after_labels(cond_bb);
92147 + else
92148 + e = split_block(cond_bb, gsi_stmt(gsi));
92149 + cond_bb = e->src;
92150 + join_bb = e->dest;
92151 + e->flags = EDGE_FALSE_VALUE;
92152 + e->probability = REG_BR_PROB_BASE;
92153 +
92154 + bb_true = create_empty_bb(cond_bb);
92155 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
92156 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
92157 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
92158 +
92159 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
92160 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
92161 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
92162 +
92163 + if (current_loops != NULL) {
92164 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
92165 + add_bb_to_loop(bb_true, cond_bb->loop_father);
92166 + }
92167 +
92168 + insert_cond(cond_bb, arg, cond_code, type_value);
92169 + insert_cond_result(bb_true, stmt, arg, min);
92170 +
92171 +// print_the_code_insertions(stmt);
92172 +}
92173 +
92174 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
92175 +{
92176 + const_tree rhs_type = TREE_TYPE(rhs);
92177 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
92178 +
92179 + gcc_assert(rhs_type != NULL_TREE);
92180 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
92181 + return;
92182 +
92183 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
92184 +
92185 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
92186 + // typemax (-1) < typemin (0)
92187 + if (TREE_OVERFLOW(type_max))
92188 + return;
92189 +
92190 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
92191 +
92192 + cast_rhs_type = TREE_TYPE(cast_rhs);
92193 + type_max_type = TREE_TYPE(type_max);
92194 + type_min_type = TREE_TYPE(type_min);
92195 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
92196 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
92197 +
92198 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
92199 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
92200 +}
92201 +
92202 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
92203 +{
92204 + gimple change_rhs_def_stmt;
92205 + tree lhs = gimple_get_lhs(def_stmt);
92206 + tree lhs_type = TREE_TYPE(lhs);
92207 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
92208 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
92209 +
92210 + if (change_rhs == NULL_TREE)
92211 + return get_size_overflow_type(def_stmt, lhs);
92212 +
92213 + change_rhs_def_stmt = get_def_stmt(change_rhs);
92214 +
92215 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
92216 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92217 +
92218 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
92219 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92220 +
92221 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
92222 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92223 +
92224 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
92225 + debug_gimple_stmt(def_stmt);
92226 + gcc_unreachable();
92227 + }
92228 +
92229 + return get_size_overflow_type(def_stmt, lhs);
92230 +}
92231 +
92232 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
92233 +{
92234 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
92235 + return false;
92236 + if (!is_gimple_constant(rhs))
92237 + return false;
92238 + return true;
92239 +}
92240 +
92241 +static bool is_subtraction_special(const_gimple stmt)
92242 +{
92243 + gimple rhs1_def_stmt, rhs2_def_stmt;
92244 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
92245 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
92246 + const_tree rhs1 = gimple_assign_rhs1(stmt);
92247 + const_tree rhs2 = gimple_assign_rhs2(stmt);
92248 +
92249 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
92250 + return false;
92251 +
92252 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
92253 +
92254 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
92255 + return false;
92256 +
92257 + rhs1_def_stmt = get_def_stmt(rhs1);
92258 + rhs2_def_stmt = get_def_stmt(rhs2);
92259 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
92260 + return false;
92261 +
92262 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
92263 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
92264 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
92265 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
92266 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
92267 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
92268 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
92269 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
92270 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
92271 + return false;
92272 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
92273 + return false;
92274 +
92275 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
92276 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
92277 + return true;
92278 +}
92279 +
92280 +static tree get_def_stmt_rhs(const_tree var)
92281 +{
92282 + tree rhs1, def_stmt_rhs1;
92283 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
92284 +
92285 + def_stmt = get_def_stmt(var);
92286 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
92287 +
92288 + rhs1 = gimple_assign_rhs1(def_stmt);
92289 + rhs1_def_stmt = get_def_stmt(rhs1);
92290 + if (!gimple_assign_cast_p(rhs1_def_stmt))
92291 + return rhs1;
92292 +
92293 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
92294 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
92295 +
92296 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
92297 + case GIMPLE_CALL:
92298 + case GIMPLE_NOP:
92299 + case GIMPLE_ASM:
92300 + return def_stmt_rhs1;
92301 + case GIMPLE_ASSIGN:
92302 + return rhs1;
92303 + default:
92304 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
92305 + gcc_unreachable();
92306 + }
92307 +}
92308 +
92309 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
92310 +{
92311 + tree new_rhs1, new_rhs2;
92312 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
92313 + gimple assign, stmt = get_def_stmt(lhs);
92314 + tree rhs1 = gimple_assign_rhs1(stmt);
92315 + tree rhs2 = gimple_assign_rhs2(stmt);
92316 +
92317 + if (!is_subtraction_special(stmt))
92318 + return NULL_TREE;
92319 +
92320 + new_rhs1 = expand(visited, rhs1);
92321 + new_rhs2 = expand(visited, rhs2);
92322 +
92323 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
92324 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
92325 +
92326 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
92327 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
92328 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
92329 + }
92330 +
92331 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
92332 + new_lhs = gimple_get_lhs(assign);
92333 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
92334 +
92335 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
92336 +}
92337 +
92338 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
92339 +{
92340 + const_gimple def_stmt;
92341 +
92342 + if (TREE_CODE(rhs) != SSA_NAME)
92343 + return false;
92344 +
92345 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
92346 + return false;
92347 +
92348 + def_stmt = get_def_stmt(rhs);
92349 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
92350 + return false;
92351 +
92352 + return true;
92353 +}
92354 +
92355 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
92356 +{
92357 + tree new_rhs, size_overflow_type, orig_rhs;
92358 + void (*gimple_assign_set_rhs)(gimple, tree);
92359 + tree rhs1 = gimple_assign_rhs1(stmt);
92360 + tree rhs2 = gimple_assign_rhs2(stmt);
92361 + tree lhs = gimple_get_lhs(stmt);
92362 +
92363 + if (change_rhs == NULL_TREE)
92364 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92365 +
92366 + if (new_rhs2 == NULL_TREE) {
92367 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
92368 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
92369 + orig_rhs = rhs1;
92370 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
92371 + } else {
92372 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
92373 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
92374 + orig_rhs = rhs2;
92375 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
92376 + }
92377 +
92378 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
92379 +
92380 + if (check_overflow)
92381 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
92382 +
92383 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
92384 + gimple_assign_set_rhs(stmt, new_rhs);
92385 + update_stmt(stmt);
92386 +
92387 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92388 +}
92389 +
92390 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
92391 +{
92392 + tree rhs1, rhs2, new_lhs;
92393 + gimple def_stmt = get_def_stmt(lhs);
92394 + tree new_rhs1 = NULL_TREE;
92395 + tree new_rhs2 = NULL_TREE;
92396 +
92397 + rhs1 = gimple_assign_rhs1(def_stmt);
92398 + rhs2 = gimple_assign_rhs2(def_stmt);
92399 +
92400 + /* no DImode/TImode division in the 32/64 bit kernel */
92401 + switch (gimple_assign_rhs_code(def_stmt)) {
92402 + case RDIV_EXPR:
92403 + case TRUNC_DIV_EXPR:
92404 + case CEIL_DIV_EXPR:
92405 + case FLOOR_DIV_EXPR:
92406 + case ROUND_DIV_EXPR:
92407 + case TRUNC_MOD_EXPR:
92408 + case CEIL_MOD_EXPR:
92409 + case FLOOR_MOD_EXPR:
92410 + case ROUND_MOD_EXPR:
92411 + case EXACT_DIV_EXPR:
92412 + case POINTER_PLUS_EXPR:
92413 + case BIT_AND_EXPR:
92414 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92415 + default:
92416 + break;
92417 + }
92418 +
92419 + new_lhs = handle_integer_truncation(visited, lhs);
92420 + if (new_lhs != NULL_TREE)
92421 + return new_lhs;
92422 +
92423 + if (TREE_CODE(rhs1) == SSA_NAME)
92424 + new_rhs1 = expand(visited, rhs1);
92425 + if (TREE_CODE(rhs2) == SSA_NAME)
92426 + new_rhs2 = expand(visited, rhs2);
92427 +
92428 + if (is_a_neg_overflow(def_stmt, rhs2))
92429 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
92430 + if (is_a_neg_overflow(def_stmt, rhs1))
92431 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
92432 +
92433 + if (is_a_constant_overflow(def_stmt, rhs2))
92434 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
92435 + if (is_a_constant_overflow(def_stmt, rhs1))
92436 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
92437 +
92438 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
92439 +}
92440 +
92441 +#if BUILDING_GCC_VERSION >= 4007
92442 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
92443 +{
92444 + if (is_gimple_constant(rhs))
92445 + return cast_a_tree(size_overflow_type, rhs);
92446 + if (TREE_CODE(rhs) != SSA_NAME)
92447 + return NULL_TREE;
92448 + return expand(visited, rhs);
92449 +}
92450 +
92451 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
92452 +{
92453 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
92454 + gimple def_stmt = get_def_stmt(lhs);
92455 +
92456 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
92457 +
92458 + rhs1 = gimple_assign_rhs1(def_stmt);
92459 + rhs2 = gimple_assign_rhs2(def_stmt);
92460 + rhs3 = gimple_assign_rhs3(def_stmt);
92461 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
92462 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
92463 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
92464 +
92465 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
92466 +}
92467 +#endif
92468 +
92469 +static tree get_size_overflow_type(gimple stmt, const_tree node)
92470 +{
92471 + const_tree type;
92472 + tree new_type;
92473 +
92474 + gcc_assert(node != NULL_TREE);
92475 +
92476 + type = TREE_TYPE(node);
92477 +
92478 + if (gimple_plf(stmt, MY_STMT))
92479 + return TREE_TYPE(node);
92480 +
92481 + switch (TYPE_MODE(type)) {
92482 + case QImode:
92483 + new_type = intHI_type_node;
92484 + break;
92485 + case HImode:
92486 + new_type = intSI_type_node;
92487 + break;
92488 + case SImode:
92489 + new_type = intDI_type_node;
92490 + break;
92491 + case DImode:
92492 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
92493 + new_type = intDI_type_node;
92494 + else
92495 + new_type = intTI_type_node;
92496 + break;
92497 + default:
92498 + debug_tree((tree)node);
92499 + error("%s: unsupported gcc configuration.", __func__);
92500 + gcc_unreachable();
92501 + }
92502 +
92503 + if (TYPE_QUALS(type) != 0)
92504 + return build_qualified_type(new_type, TYPE_QUALS(type));
92505 + return new_type;
92506 +}
92507 +
92508 +static tree expand_visited(gimple def_stmt)
92509 +{
92510 + const_gimple next_stmt;
92511 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
92512 +
92513 + gsi_next(&gsi);
92514 + next_stmt = gsi_stmt(gsi);
92515 +
92516 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
92517 +
92518 + switch (gimple_code(next_stmt)) {
92519 + case GIMPLE_ASSIGN:
92520 + return gimple_get_lhs(next_stmt);
92521 + case GIMPLE_PHI:
92522 + return gimple_phi_result(next_stmt);
92523 + case GIMPLE_CALL:
92524 + return gimple_call_lhs(next_stmt);
92525 + default:
92526 + return NULL_TREE;
92527 + }
92528 +}
92529 +
92530 +static tree expand(struct pointer_set_t *visited, tree lhs)
92531 +{
92532 + gimple def_stmt;
92533 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
92534 +
92535 + if (is_gimple_constant(lhs))
92536 + return NULL_TREE;
92537 +
92538 + if (TREE_CODE(lhs) == ADDR_EXPR)
92539 + return NULL_TREE;
92540 +
92541 + if (code == REAL_TYPE)
92542 + return NULL_TREE;
92543 +
92544 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
92545 +
92546 + def_stmt = get_def_stmt(lhs);
92547 +
92548 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
92549 + return NULL_TREE;
92550 +
92551 + if (gimple_plf(def_stmt, MY_STMT))
92552 + return lhs;
92553 +
92554 + if (pointer_set_contains(visited, def_stmt))
92555 + return expand_visited(def_stmt);
92556 +
92557 + switch (gimple_code(def_stmt)) {
92558 + case GIMPLE_PHI:
92559 + return build_new_phi(visited, lhs);
92560 + case GIMPLE_CALL:
92561 + case GIMPLE_ASM:
92562 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92563 + case GIMPLE_ASSIGN:
92564 + switch (gimple_num_ops(def_stmt)) {
92565 + case 2:
92566 + return handle_unary_ops(visited, def_stmt);
92567 + case 3:
92568 + return handle_binary_ops(visited, lhs);
92569 +#if BUILDING_GCC_VERSION >= 4007
92570 + case 4:
92571 + return handle_ternary_ops(visited, lhs);
92572 +#endif
92573 + }
92574 + default:
92575 + debug_gimple_stmt(def_stmt);
92576 + error("%s: unknown gimple code", __func__);
92577 + gcc_unreachable();
92578 + }
92579 +}
92580 +
92581 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
92582 +{
92583 + const_gimple assign;
92584 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
92585 + tree origtype = TREE_TYPE(origarg);
92586 +
92587 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
92588 +
92589 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
92590 +
92591 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
92592 + update_stmt(stmt);
92593 +}
92594 +
92595 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
92596 +{
92597 + const char *origid;
92598 + tree arg;
92599 + const_tree origarg;
92600 +
92601 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
92602 + return true;
92603 +
92604 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
92605 + while (origarg && *argnum) {
92606 + (*argnum)--;
92607 + origarg = TREE_CHAIN(origarg);
92608 + }
92609 +
92610 + gcc_assert(*argnum == 0);
92611 +
92612 + gcc_assert(origarg != NULL_TREE);
92613 + origid = NAME(origarg);
92614 + *argnum = 0;
92615 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
92616 + if (!strcmp(origid, NAME(arg)))
92617 + return true;
92618 + (*argnum)++;
92619 + }
92620 + return false;
92621 +}
92622 +
92623 +static bool skip_types(const_tree var)
92624 +{
92625 + const_tree type;
92626 +
92627 + switch (TREE_CODE(var)) {
92628 + case ADDR_EXPR:
92629 +#if BUILDING_GCC_VERSION >= 4006
92630 + case MEM_REF:
92631 +#endif
92632 + case ARRAY_REF:
92633 + case BIT_FIELD_REF:
92634 + case INDIRECT_REF:
92635 + case TARGET_MEM_REF:
92636 + case VAR_DECL:
92637 + return true;
92638 + default:
92639 + break;
92640 + }
92641 +
92642 + type = TREE_TYPE(TREE_TYPE(var));
92643 + if (!type)
92644 + return false;
92645 + switch (TREE_CODE(type)) {
92646 + case RECORD_TYPE:
92647 + return true;
92648 + default:
92649 + break;
92650 + }
92651 +
92652 + return false;
92653 +}
92654 +
92655 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
92656 +{
92657 + gimple phi = get_def_stmt(result);
92658 + unsigned int i, n = gimple_phi_num_args(phi);
92659 +
92660 + if (!phi)
92661 + return false;
92662 +
92663 + pointer_set_insert(visited, phi);
92664 + for (i = 0; i < n; i++) {
92665 + const_tree arg = gimple_phi_arg_def(phi, i);
92666 + if (pre_expand(visited, arg))
92667 + return true;
92668 + }
92669 + return false;
92670 +}
92671 +
92672 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
92673 +{
92674 + gimple def_stmt = get_def_stmt(lhs);
92675 + const_tree rhs;
92676 +
92677 + if (!def_stmt)
92678 + return false;
92679 +
92680 + rhs = gimple_assign_rhs1(def_stmt);
92681 + if (pre_expand(visited, rhs))
92682 + return true;
92683 + return false;
92684 +}
92685 +
92686 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
92687 +{
92688 + bool rhs1_found, rhs2_found;
92689 + gimple def_stmt = get_def_stmt(lhs);
92690 + const_tree rhs1, rhs2;
92691 +
92692 + if (!def_stmt)
92693 + return false;
92694 +
92695 + rhs1 = gimple_assign_rhs1(def_stmt);
92696 + rhs2 = gimple_assign_rhs2(def_stmt);
92697 + rhs1_found = pre_expand(visited, rhs1);
92698 + rhs2_found = pre_expand(visited, rhs2);
92699 +
92700 + return rhs1_found || rhs2_found;
92701 +}
92702 +
92703 +static const_tree search_field_decl(const_tree comp_ref)
92704 +{
92705 + const_tree field = NULL_TREE;
92706 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
92707 +
92708 + for (i = 0; i < len; i++) {
92709 + field = TREE_OPERAND(comp_ref, i);
92710 + if (TREE_CODE(field) == FIELD_DECL)
92711 + break;
92712 + }
92713 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
92714 + return field;
92715 +}
92716 +
92717 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
92718 +{
92719 + const_tree attr, p;
92720 +
92721 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
92722 + if (!attr || !TREE_VALUE(attr))
92723 + return MARKED_NO;
92724 +
92725 + p = TREE_VALUE(attr);
92726 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
92727 + return MARKED_NOT_INTENTIONAL;
92728 +
92729 + do {
92730 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
92731 + return MARKED_YES;
92732 + p = TREE_CHAIN(p);
92733 + } while (p);
92734 +
92735 + return MARKED_NO;
92736 +}
92737 +
92738 +static void print_missing_msg(tree func, unsigned int argnum)
92739 +{
92740 + unsigned int new_hash;
92741 + size_t len;
92742 + unsigned char tree_codes[CODES_LIMIT];
92743 + location_t loc = DECL_SOURCE_LOCATION(func);
92744 + const char *curfunc = get_asm_name(func);
92745 +
92746 + len = get_function_decl(func, tree_codes);
92747 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
92748 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
92749 +}
92750 +
92751 +static unsigned int search_missing_attribute(const_tree arg)
92752 +{
92753 + const_tree type = TREE_TYPE(arg);
92754 + tree func = get_original_function_decl(current_function_decl);
92755 + unsigned int argnum;
92756 + const struct size_overflow_hash *hash;
92757 +
92758 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
92759 +
92760 + if (TREE_CODE(type) == POINTER_TYPE)
92761 + return 0;
92762 +
92763 + argnum = find_arg_number(arg, func);
92764 + if (argnum == 0)
92765 + return 0;
92766 +
92767 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
92768 + return argnum;
92769 +
92770 + hash = get_function_hash(func);
92771 + if (!hash || !(hash->param & (1U << argnum))) {
92772 + print_missing_msg(func, argnum);
92773 + return 0;
92774 + }
92775 + return argnum;
92776 +}
92777 +
92778 +static bool is_already_marked(const_tree lhs)
92779 +{
92780 + unsigned int argnum;
92781 + const_tree fndecl;
92782 +
92783 + argnum = search_missing_attribute(lhs);
92784 + fndecl = get_original_function_decl(current_function_decl);
92785 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
92786 + return true;
92787 + return false;
92788 +}
92789 +
92790 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
92791 +{
92792 + const_gimple def_stmt;
92793 +
92794 + if (is_gimple_constant(lhs))
92795 + return false;
92796 +
92797 + if (skip_types(lhs))
92798 + return false;
92799 +
92800 + // skip char type (FIXME: only kernel)
92801 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
92802 + return false;
92803 +
92804 + if (TREE_CODE(lhs) == PARM_DECL)
92805 + return is_already_marked(lhs);
92806 +
92807 + if (TREE_CODE(lhs) == COMPONENT_REF) {
92808 + const_tree field, attr;
92809 +
92810 + field = search_field_decl(lhs);
92811 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
92812 + if (!attr || !TREE_VALUE(attr))
92813 + return false;
92814 + return true;
92815 + }
92816 +
92817 + def_stmt = get_def_stmt(lhs);
92818 +
92819 + if (!def_stmt)
92820 + return false;
92821 +
92822 + if (pointer_set_contains(visited, def_stmt))
92823 + return false;
92824 +
92825 + switch (gimple_code(def_stmt)) {
92826 + case GIMPLE_NOP:
92827 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
92828 + return is_already_marked(lhs);
92829 + return false;
92830 + case GIMPLE_PHI:
92831 + return walk_phi(visited, lhs);
92832 + case GIMPLE_CALL:
92833 + case GIMPLE_ASM:
92834 + return false;
92835 + case GIMPLE_ASSIGN:
92836 + switch (gimple_num_ops(def_stmt)) {
92837 + case 2:
92838 + return walk_unary_ops(visited, lhs);
92839 + case 3:
92840 + return walk_binary_ops(visited, lhs);
92841 + }
92842 + default:
92843 + debug_gimple_stmt((gimple)def_stmt);
92844 + error("%s: unknown gimple code", __func__);
92845 + gcc_unreachable();
92846 + }
92847 +}
92848 +
92849 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
92850 +{
92851 + struct pointer_set_t *visited;
92852 + bool is_found;
92853 + enum marked is_marked;
92854 + location_t loc;
92855 +
92856 + visited = pointer_set_create();
92857 + is_found = pre_expand(visited, arg);
92858 + pointer_set_destroy(visited);
92859 +
92860 + is_marked = mark_status(fndecl, argnum + 1);
92861 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
92862 + return true;
92863 +
92864 + if (is_found) {
92865 + loc = DECL_SOURCE_LOCATION(fndecl);
92866 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
92867 + return true;
92868 + }
92869 + return false;
92870 +}
92871 +
92872 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
92873 +{
92874 + struct pointer_set_t *visited;
92875 + tree arg, newarg;
92876 + bool match;
92877 +
92878 + match = get_function_arg(&argnum, fndecl);
92879 + if (!match)
92880 + return;
92881 + gcc_assert(gimple_call_num_args(stmt) > argnum);
92882 + arg = gimple_call_arg(stmt, argnum);
92883 + if (arg == NULL_TREE)
92884 + return;
92885 +
92886 + if (is_gimple_constant(arg))
92887 + return;
92888 +
92889 + if (search_attributes(fndecl, arg, argnum))
92890 + return;
92891 +
92892 + if (TREE_CODE(arg) != SSA_NAME)
92893 + return;
92894 +
92895 + check_arg_type(arg);
92896 +
92897 + visited = pointer_set_create();
92898 + newarg = expand(visited, arg);
92899 + pointer_set_destroy(visited);
92900 +
92901 + if (newarg == NULL_TREE)
92902 + return;
92903 +
92904 + change_function_arg(stmt, arg, argnum, newarg);
92905 +
92906 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
92907 +}
92908 +
92909 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
92910 +{
92911 + tree p = TREE_VALUE(attr);
92912 + do {
92913 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
92914 + p = TREE_CHAIN(p);
92915 + } while (p);
92916 +}
92917 +
92918 +static void handle_function_by_hash(gimple stmt, tree fndecl)
92919 +{
92920 + tree orig_fndecl;
92921 + unsigned int num;
92922 + const struct size_overflow_hash *hash;
92923 +
92924 + orig_fndecl = get_original_function_decl(fndecl);
92925 + if (C_DECL_IMPLICIT(orig_fndecl))
92926 + return;
92927 + hash = get_function_hash(orig_fndecl);
92928 + if (!hash)
92929 + return;
92930 +
92931 + for (num = 1; num <= MAX_PARAM; num++)
92932 + if (hash->param & (1U << num))
92933 + handle_function_arg(stmt, fndecl, num - 1);
92934 +}
92935 +
92936 +static void set_plf_false(void)
92937 +{
92938 + basic_block bb;
92939 +
92940 + FOR_ALL_BB(bb) {
92941 + gimple_stmt_iterator si;
92942 +
92943 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
92944 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
92945 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
92946 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
92947 + }
92948 +}
92949 +
92950 +static unsigned int handle_function(void)
92951 +{
92952 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
92953 +
92954 + set_plf_false();
92955 +
92956 + do {
92957 + gimple_stmt_iterator gsi;
92958 + next = bb->next_bb;
92959 +
92960 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92961 + tree fndecl, attr;
92962 + gimple stmt = gsi_stmt(gsi);
92963 +
92964 + if (!(is_gimple_call(stmt)))
92965 + continue;
92966 + fndecl = gimple_call_fndecl(stmt);
92967 + if (fndecl == NULL_TREE)
92968 + continue;
92969 + if (gimple_call_num_args(stmt) == 0)
92970 + continue;
92971 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
92972 + if (!attr || !TREE_VALUE(attr))
92973 + handle_function_by_hash(stmt, fndecl);
92974 + else
92975 + handle_function_by_attribute(stmt, attr, fndecl);
92976 + gsi = gsi_for_stmt(stmt);
92977 + next = gimple_bb(stmt)->next_bb;
92978 + }
92979 + bb = next;
92980 + } while (bb);
92981 + return 0;
92982 +}
92983 +
92984 +static struct gimple_opt_pass size_overflow_pass = {
92985 + .pass = {
92986 + .type = GIMPLE_PASS,
92987 + .name = "size_overflow",
92988 +#if BUILDING_GCC_VERSION >= 4008
92989 + .optinfo_flags = OPTGROUP_NONE,
92990 +#endif
92991 + .gate = NULL,
92992 + .execute = handle_function,
92993 + .sub = NULL,
92994 + .next = NULL,
92995 + .static_pass_number = 0,
92996 + .tv_id = TV_NONE,
92997 + .properties_required = PROP_cfg,
92998 + .properties_provided = 0,
92999 + .properties_destroyed = 0,
93000 + .todo_flags_start = 0,
93001 + .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
93002 + }
93003 +};
93004 +
93005 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
93006 +{
93007 + tree fntype;
93008 +
93009 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
93010 +
93011 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
93012 + fntype = build_function_type_list(void_type_node,
93013 + const_char_ptr_type_node,
93014 + unsigned_type_node,
93015 + const_char_ptr_type_node,
93016 + const_char_ptr_type_node,
93017 + NULL_TREE);
93018 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
93019 +
93020 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
93021 + TREE_PUBLIC(report_size_overflow_decl) = 1;
93022 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
93023 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
93024 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
93025 +}
93026 +
93027 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93028 +{
93029 + int i;
93030 + const char * const plugin_name = plugin_info->base_name;
93031 + const int argc = plugin_info->argc;
93032 + const struct plugin_argument * const argv = plugin_info->argv;
93033 + bool enable = true;
93034 +
93035 + struct register_pass_info size_overflow_pass_info = {
93036 + .pass = &size_overflow_pass.pass,
93037 + .reference_pass_name = "ssa",
93038 + .ref_pass_instance_number = 1,
93039 + .pos_op = PASS_POS_INSERT_AFTER
93040 + };
93041 +
93042 + if (!plugin_default_version_check(version, &gcc_version)) {
93043 + error(G_("incompatible gcc/plugin versions"));
93044 + return 1;
93045 + }
93046 +
93047 + for (i = 0; i < argc; ++i) {
93048 + if (!strcmp(argv[i].key, "no-size-overflow")) {
93049 + enable = false;
93050 + continue;
93051 + }
93052 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93053 + }
93054 +
93055 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
93056 + if (enable) {
93057 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
93058 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
93059 + }
93060 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
93061 +
93062 + return 0;
93063 +}
93064 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
93065 new file mode 100644
93066 index 0000000..ac2901e
93067 --- /dev/null
93068 +++ b/tools/gcc/stackleak_plugin.c
93069 @@ -0,0 +1,327 @@
93070 +/*
93071 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
93072 + * Licensed under the GPL v2
93073 + *
93074 + * Note: the choice of the license means that the compilation process is
93075 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
93076 + * but for the kernel it doesn't matter since it doesn't link against
93077 + * any of the gcc libraries
93078 + *
93079 + * gcc plugin to help implement various PaX features
93080 + *
93081 + * - track lowest stack pointer
93082 + *
93083 + * TODO:
93084 + * - initialize all local variables
93085 + *
93086 + * BUGS:
93087 + * - none known
93088 + */
93089 +#include "gcc-plugin.h"
93090 +#include "config.h"
93091 +#include "system.h"
93092 +#include "coretypes.h"
93093 +#include "tree.h"
93094 +#include "tree-pass.h"
93095 +#include "flags.h"
93096 +#include "intl.h"
93097 +#include "toplev.h"
93098 +#include "plugin.h"
93099 +//#include "expr.h" where are you...
93100 +#include "diagnostic.h"
93101 +#include "plugin-version.h"
93102 +#include "tm.h"
93103 +#include "function.h"
93104 +#include "basic-block.h"
93105 +#include "gimple.h"
93106 +#include "rtl.h"
93107 +#include "emit-rtl.h"
93108 +
93109 +#if BUILDING_GCC_VERSION >= 4008
93110 +#define TODO_dump_func 0
93111 +#endif
93112 +
93113 +extern void print_gimple_stmt(FILE *, gimple, int, int);
93114 +
93115 +int plugin_is_GPL_compatible;
93116 +
93117 +static int track_frame_size = -1;
93118 +static const char track_function[] = "pax_track_stack";
93119 +static const char check_function[] = "pax_check_alloca";
93120 +static bool init_locals;
93121 +
93122 +static struct plugin_info stackleak_plugin_info = {
93123 + .version = "201302112000",
93124 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
93125 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
93126 +};
93127 +
93128 +static bool gate_stackleak_track_stack(void);
93129 +static unsigned int execute_stackleak_tree_instrument(void);
93130 +static unsigned int execute_stackleak_final(void);
93131 +
93132 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
93133 + .pass = {
93134 + .type = GIMPLE_PASS,
93135 + .name = "stackleak_tree_instrument",
93136 +#if BUILDING_GCC_VERSION >= 4008
93137 + .optinfo_flags = OPTGROUP_NONE,
93138 +#endif
93139 + .gate = gate_stackleak_track_stack,
93140 + .execute = execute_stackleak_tree_instrument,
93141 + .sub = NULL,
93142 + .next = NULL,
93143 + .static_pass_number = 0,
93144 + .tv_id = TV_NONE,
93145 + .properties_required = PROP_gimple_leh | PROP_cfg,
93146 + .properties_provided = 0,
93147 + .properties_destroyed = 0,
93148 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
93149 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
93150 + }
93151 +};
93152 +
93153 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
93154 + .pass = {
93155 + .type = RTL_PASS,
93156 + .name = "stackleak_final",
93157 +#if BUILDING_GCC_VERSION >= 4008
93158 + .optinfo_flags = OPTGROUP_NONE,
93159 +#endif
93160 + .gate = gate_stackleak_track_stack,
93161 + .execute = execute_stackleak_final,
93162 + .sub = NULL,
93163 + .next = NULL,
93164 + .static_pass_number = 0,
93165 + .tv_id = TV_NONE,
93166 + .properties_required = 0,
93167 + .properties_provided = 0,
93168 + .properties_destroyed = 0,
93169 + .todo_flags_start = 0,
93170 + .todo_flags_finish = TODO_dump_func
93171 + }
93172 +};
93173 +
93174 +static bool gate_stackleak_track_stack(void)
93175 +{
93176 + return track_frame_size >= 0;
93177 +}
93178 +
93179 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
93180 +{
93181 + gimple check_alloca;
93182 + tree fntype, fndecl, alloca_size;
93183 +
93184 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
93185 + fndecl = build_fn_decl(check_function, fntype);
93186 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
93187 +
93188 + // insert call to void pax_check_alloca(unsigned long size)
93189 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
93190 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
93191 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
93192 +}
93193 +
93194 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
93195 +{
93196 + gimple track_stack;
93197 + tree fntype, fndecl;
93198 +
93199 + fntype = build_function_type_list(void_type_node, NULL_TREE);
93200 + fndecl = build_fn_decl(track_function, fntype);
93201 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
93202 +
93203 + // insert call to void pax_track_stack(void)
93204 + track_stack = gimple_build_call(fndecl, 0);
93205 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
93206 +}
93207 +
93208 +#if BUILDING_GCC_VERSION == 4005
93209 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
93210 +{
93211 + tree fndecl;
93212 +
93213 + if (!is_gimple_call(stmt))
93214 + return false;
93215 + fndecl = gimple_call_fndecl(stmt);
93216 + if (!fndecl)
93217 + return false;
93218 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
93219 + return false;
93220 +// print_node(stderr, "pax", fndecl, 4);
93221 + return DECL_FUNCTION_CODE(fndecl) == code;
93222 +}
93223 +#endif
93224 +
93225 +static bool is_alloca(gimple stmt)
93226 +{
93227 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
93228 + return true;
93229 +
93230 +#if BUILDING_GCC_VERSION >= 4007
93231 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
93232 + return true;
93233 +#endif
93234 +
93235 + return false;
93236 +}
93237 +
93238 +static unsigned int execute_stackleak_tree_instrument(void)
93239 +{
93240 + basic_block bb, entry_bb;
93241 + bool prologue_instrumented = false, is_leaf = true;
93242 +
93243 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
93244 +
93245 + // 1. loop through BBs and GIMPLE statements
93246 + FOR_EACH_BB(bb) {
93247 + gimple_stmt_iterator gsi;
93248 +
93249 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
93250 + gimple stmt;
93251 +
93252 + stmt = gsi_stmt(gsi);
93253 +
93254 + if (is_gimple_call(stmt))
93255 + is_leaf = false;
93256 +
93257 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
93258 + if (!is_alloca(stmt))
93259 + continue;
93260 +
93261 + // 2. insert stack overflow check before each __builtin_alloca call
93262 + stackleak_check_alloca(&gsi);
93263 +
93264 + // 3. insert track call after each __builtin_alloca call
93265 + stackleak_add_instrumentation(&gsi);
93266 + if (bb == entry_bb)
93267 + prologue_instrumented = true;
93268 + }
93269 + }
93270 +
93271 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
93272 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
93273 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
93274 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
93275 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
93276 + return 0;
93277 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
93278 + return 0;
93279 +
93280 + // 4. insert track call at the beginning
93281 + if (!prologue_instrumented) {
93282 + gimple_stmt_iterator gsi;
93283 +
93284 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
93285 + if (dom_info_available_p(CDI_DOMINATORS))
93286 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
93287 + gsi = gsi_start_bb(bb);
93288 + stackleak_add_instrumentation(&gsi);
93289 + }
93290 +
93291 + return 0;
93292 +}
93293 +
93294 +static unsigned int execute_stackleak_final(void)
93295 +{
93296 + rtx insn, next;
93297 +
93298 + if (cfun->calls_alloca)
93299 + return 0;
93300 +
93301 + // keep calls only if function frame is big enough
93302 + if (get_frame_size() >= track_frame_size)
93303 + return 0;
93304 +
93305 + // 1. find pax_track_stack calls
93306 + for (insn = get_insns(); insn; insn = next) {
93307 + // 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))
93308 + rtx body;
93309 +
93310 + next = NEXT_INSN(insn);
93311 + if (!CALL_P(insn))
93312 + continue;
93313 + body = PATTERN(insn);
93314 + if (GET_CODE(body) != CALL)
93315 + continue;
93316 + body = XEXP(body, 0);
93317 + if (GET_CODE(body) != MEM)
93318 + continue;
93319 + body = XEXP(body, 0);
93320 + if (GET_CODE(body) != SYMBOL_REF)
93321 + continue;
93322 + if (strcmp(XSTR(body, 0), track_function))
93323 + continue;
93324 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
93325 + // 2. delete call
93326 + delete_insn_and_edges(insn);
93327 +#if BUILDING_GCC_VERSION >= 4007
93328 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
93329 + insn = next;
93330 + next = NEXT_INSN(insn);
93331 + delete_insn_and_edges(insn);
93332 + }
93333 +#endif
93334 + }
93335 +
93336 +// print_simple_rtl(stderr, get_insns());
93337 +// print_rtl(stderr, get_insns());
93338 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
93339 +
93340 + return 0;
93341 +}
93342 +
93343 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93344 +{
93345 + const char * const plugin_name = plugin_info->base_name;
93346 + const int argc = plugin_info->argc;
93347 + const struct plugin_argument * const argv = plugin_info->argv;
93348 + int i;
93349 + struct register_pass_info stackleak_tree_instrument_pass_info = {
93350 + .pass = &stackleak_tree_instrument_pass.pass,
93351 +// .reference_pass_name = "tree_profile",
93352 + .reference_pass_name = "optimized",
93353 + .ref_pass_instance_number = 1,
93354 + .pos_op = PASS_POS_INSERT_BEFORE
93355 + };
93356 + struct register_pass_info stackleak_final_pass_info = {
93357 + .pass = &stackleak_final_rtl_opt_pass.pass,
93358 + .reference_pass_name = "final",
93359 + .ref_pass_instance_number = 1,
93360 + .pos_op = PASS_POS_INSERT_BEFORE
93361 + };
93362 +
93363 + if (!plugin_default_version_check(version, &gcc_version)) {
93364 + error(G_("incompatible gcc/plugin versions"));
93365 + return 1;
93366 + }
93367 +
93368 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
93369 +
93370 + for (i = 0; i < argc; ++i) {
93371 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
93372 + if (!argv[i].value) {
93373 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93374 + continue;
93375 + }
93376 + track_frame_size = atoi(argv[i].value);
93377 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
93378 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
93379 + continue;
93380 + }
93381 + if (!strcmp(argv[i].key, "initialize-locals")) {
93382 + if (argv[i].value) {
93383 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
93384 + continue;
93385 + }
93386 + init_locals = true;
93387 + continue;
93388 + }
93389 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93390 + }
93391 +
93392 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
93393 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
93394 +
93395 + return 0;
93396 +}
93397 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
93398 index 6789d78..4afd019e 100644
93399 --- a/tools/perf/util/include/asm/alternative-asm.h
93400 +++ b/tools/perf/util/include/asm/alternative-asm.h
93401 @@ -5,4 +5,7 @@
93402
93403 #define altinstruction_entry #
93404
93405 + .macro pax_force_retaddr rip=0, reload=0
93406 + .endm
93407 +
93408 #endif
93409 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
93410 index 1cd693a..f4a7b20 100644
93411 --- a/virt/kvm/kvm_main.c
93412 +++ b/virt/kvm/kvm_main.c
93413 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
93414
93415 static cpumask_var_t cpus_hardware_enabled;
93416 static int kvm_usage_count = 0;
93417 -static atomic_t hardware_enable_failed;
93418 +static atomic_unchecked_t hardware_enable_failed;
93419
93420 struct kmem_cache *kvm_vcpu_cache;
93421 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
93422
93423 -static __read_mostly struct preempt_ops kvm_preempt_ops;
93424 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
93425 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
93426 +static struct preempt_ops kvm_preempt_ops = {
93427 + .sched_in = kvm_sched_in,
93428 + .sched_out = kvm_sched_out,
93429 +};
93430
93431 struct dentry *kvm_debugfs_dir;
93432
93433 @@ -731,7 +736,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
93434 /* We can read the guest memory with __xxx_user() later on. */
93435 if (user_alloc &&
93436 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
93437 - !access_ok(VERIFY_WRITE,
93438 + !__access_ok(VERIFY_WRITE,
93439 (void __user *)(unsigned long)mem->userspace_addr,
93440 mem->memory_size)))
93441 goto out;
93442 @@ -1783,7 +1788,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
93443 return 0;
93444 }
93445
93446 -static struct file_operations kvm_vcpu_fops = {
93447 +static file_operations_no_const kvm_vcpu_fops __read_only = {
93448 .release = kvm_vcpu_release,
93449 .unlocked_ioctl = kvm_vcpu_ioctl,
93450 #ifdef CONFIG_COMPAT
93451 @@ -2304,7 +2309,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
93452 return 0;
93453 }
93454
93455 -static struct file_operations kvm_vm_fops = {
93456 +static file_operations_no_const kvm_vm_fops __read_only = {
93457 .release = kvm_vm_release,
93458 .unlocked_ioctl = kvm_vm_ioctl,
93459 #ifdef CONFIG_COMPAT
93460 @@ -2402,7 +2407,7 @@ out:
93461 return r;
93462 }
93463
93464 -static struct file_operations kvm_chardev_ops = {
93465 +static file_operations_no_const kvm_chardev_ops __read_only = {
93466 .unlocked_ioctl = kvm_dev_ioctl,
93467 .compat_ioctl = kvm_dev_ioctl,
93468 .llseek = noop_llseek,
93469 @@ -2428,7 +2433,7 @@ static void hardware_enable_nolock(void *junk)
93470
93471 if (r) {
93472 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
93473 - atomic_inc(&hardware_enable_failed);
93474 + atomic_inc_unchecked(&hardware_enable_failed);
93475 printk(KERN_INFO "kvm: enabling virtualization on "
93476 "CPU%d failed\n", cpu);
93477 }
93478 @@ -2482,10 +2487,10 @@ static int hardware_enable_all(void)
93479
93480 kvm_usage_count++;
93481 if (kvm_usage_count == 1) {
93482 - atomic_set(&hardware_enable_failed, 0);
93483 + atomic_set_unchecked(&hardware_enable_failed, 0);
93484 on_each_cpu(hardware_enable_nolock, NULL, 1);
93485
93486 - if (atomic_read(&hardware_enable_failed)) {
93487 + if (atomic_read_unchecked(&hardware_enable_failed)) {
93488 hardware_disable_all_nolock();
93489 r = -EBUSY;
93490 }
93491 @@ -2843,7 +2848,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
93492 kvm_arch_vcpu_put(vcpu);
93493 }
93494
93495 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93496 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93497 struct module *module)
93498 {
93499 int r;
93500 @@ -2879,7 +2884,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93501 if (!vcpu_align)
93502 vcpu_align = __alignof__(struct kvm_vcpu);
93503 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
93504 - 0, NULL);
93505 + SLAB_USERCOPY, NULL);
93506 if (!kvm_vcpu_cache) {
93507 r = -ENOMEM;
93508 goto out_free_3;
93509 @@ -2889,9 +2894,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93510 if (r)
93511 goto out_free;
93512
93513 + pax_open_kernel();
93514 kvm_chardev_ops.owner = module;
93515 kvm_vm_fops.owner = module;
93516 kvm_vcpu_fops.owner = module;
93517 + pax_close_kernel();
93518
93519 r = misc_register(&kvm_dev);
93520 if (r) {
93521 @@ -2901,9 +2908,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93522
93523 register_syscore_ops(&kvm_syscore_ops);
93524
93525 - kvm_preempt_ops.sched_in = kvm_sched_in;
93526 - kvm_preempt_ops.sched_out = kvm_sched_out;
93527 -
93528 r = kvm_init_debug();
93529 if (r) {
93530 printk(KERN_ERR "kvm: create debugfs files failed\n");